[2ecbd7b] | 1 | #include "options.hfa"
|
---|
| 2 |
|
---|
| 3 | #define _GNU_SOURCE
|
---|
| 4 | #define __USE_GNU
|
---|
| 5 | extern "C" {
|
---|
| 6 | #include <sys/types.h>
|
---|
| 7 | #include <sys/stat.h>
|
---|
| 8 | #include <fcntl.h>
|
---|
| 9 | }
|
---|
| 10 |
|
---|
[a6b587f] | 11 | #include <bitmanip.hfa>
|
---|
[b57db73] | 12 | #include <fstream.hfa>
|
---|
[2ecbd7b] | 13 | #include <kernel.hfa>
|
---|
[42f1d739] | 14 | #include <parseargs.hfa>
|
---|
[2ecbd7b] | 15 |
|
---|
[b57db73] | 16 | #include <stdlib.h>
|
---|
[5ad381b] | 17 | #include <string.h>
|
---|
| 18 |
|
---|
[2ecbd7b] | 19 | Options options @= {
|
---|
[481ee28] | 20 | false, // log
|
---|
[5ad381b] | 21 |
|
---|
[2ecbd7b] | 22 | { // file_cache
|
---|
[b57db73] | 23 | 0, // path
|
---|
[2ecbd7b] | 24 | 0, // open_flags;
|
---|
| 25 | 42u, // hash_seed;
|
---|
| 26 | 0, // size;
|
---|
| 27 | false, // list;
|
---|
| 28 | false // fixed_fds
|
---|
| 29 | },
|
---|
| 30 |
|
---|
| 31 | { // socket
|
---|
| 32 | 8080, // port
|
---|
[03ed863] | 33 | 10, // backlog
|
---|
| 34 | 1024 // buflen
|
---|
[2ecbd7b] | 35 | },
|
---|
| 36 |
|
---|
| 37 | { // cluster
|
---|
| 38 | 1, // nprocs;
|
---|
| 39 | 1, // nworkers;
|
---|
[b57db73] | 40 | {}, // params;
|
---|
[2ecbd7b] | 41 | false, // procstats
|
---|
| 42 | false, // viewhalts
|
---|
| 43 | 0, // instance;
|
---|
| 44 | }
|
---|
| 45 | };
|
---|
| 46 |
|
---|
[b57db73] | 47 | void parse_options( int argc, char * argv[] ) {
|
---|
[2ecbd7b] | 48 | bool subthrd = false;
|
---|
| 49 | bool eagrsub = false;
|
---|
| 50 | bool fixedfd = false;
|
---|
| 51 | bool sqkpoll = false;
|
---|
| 52 | bool iokpoll = false;
|
---|
| 53 | unsigned sublen = 16;
|
---|
[a6b587f] | 54 | unsigned nentries = 16;
|
---|
| 55 |
|
---|
[2ecbd7b] | 56 |
|
---|
| 57 | static cfa_option opt[] = {
|
---|
[bdbc24d] | 58 | { 'p', "port", "Port the server will listen on", options.socket.port},
|
---|
| 59 | { 'c', "cpus", "Number of processors to use", options.clopts.nprocs},
|
---|
| 60 | { 't', "threads", "Number of worker threads to use", options.clopts.nworkers},
|
---|
| 61 | {'\0', "log", "Enable logs", options.log, parse_settrue},
|
---|
| 62 | {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
|
---|
| 63 | {'\0', "request_len", "Maximum number of bytes in the http request, requests with more data will be answered with Http Code 414", options.socket.buflen},
|
---|
| 64 | {'\0', "seed", "seed to use for hashing", options.file_cache.hash_seed },
|
---|
| 65 | {'\0', "cache-size", "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size },
|
---|
| 66 | {'\0', "list-files", "List the files in the specified path and exit", options.file_cache.list, parse_settrue },
|
---|
| 67 | { 's', "submitthread", "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue },
|
---|
| 68 | { 'e', "eagersubmit", "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue},
|
---|
| 69 | { 'f', "fixed-fds", "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue},
|
---|
| 70 | { 'k', "kpollsubmit", "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue },
|
---|
| 71 | { 'i', "kpollcomplete", "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue },
|
---|
| 72 | {'\0', "submitlength", "Max number of submitions that can be submitted together", sublen },
|
---|
[a6b587f] | 73 | {'\0', "numentries", "Number of I/O entries", nentries },
|
---|
[2ecbd7b] | 74 |
|
---|
| 75 | };
|
---|
| 76 | int opt_cnt = sizeof(opt) / sizeof(cfa_option);
|
---|
| 77 |
|
---|
| 78 | char **left;
|
---|
| 79 | parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left );
|
---|
| 80 |
|
---|
[a6b587f] | 81 | if( !is_pow2(nentries) ) {
|
---|
| 82 | unsigned v = nentries;
|
---|
| 83 | v--;
|
---|
| 84 | v |= v >> 1;
|
---|
| 85 | v |= v >> 2;
|
---|
| 86 | v |= v >> 4;
|
---|
| 87 | v |= v >> 8;
|
---|
| 88 | v |= v >> 16;
|
---|
| 89 | v++;
|
---|
| 90 | serr | "Warning: num_entries not a power of 2" | '(' | nentries | ')' | "raising to " | v;
|
---|
| 91 | nentries = v;
|
---|
| 92 | }
|
---|
| 93 | options.clopts.params.num_entries = nentries;
|
---|
| 94 |
|
---|
[d11d6eb] | 95 | options.clopts.params.poller_submits = subthrd;
|
---|
| 96 | options.clopts.params.eager_submits = eagrsub;
|
---|
[2ecbd7b] | 97 |
|
---|
| 98 | if( fixedfd ) {
|
---|
| 99 | options.file_cache.fixed_fds = true;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | if( sqkpoll ) {
|
---|
[d11d6eb] | 103 | options.clopts.params.poll_submit = true;
|
---|
[2ecbd7b] | 104 | options.file_cache.fixed_fds = true;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | if( iokpoll ) {
|
---|
[d11d6eb] | 108 | options.clopts.params.poll_complete = true;
|
---|
[2ecbd7b] | 109 | options.file_cache.open_flags |= O_DIRECT;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[d11d6eb] | 112 | options.clopts.params.num_ready = sublen;
|
---|
[2ecbd7b] | 113 |
|
---|
[a6b587f] | 114 | if( left[0] == 0p ) { return; }
|
---|
[2ecbd7b] | 115 |
|
---|
| 116 | const char * path = left[0];
|
---|
| 117 | left++;
|
---|
| 118 |
|
---|
| 119 | if( left[0] != 0p ) {
|
---|
[a6b587f] | 120 | serr | "Too many trailing arguments!" | '\'' | path | '\'';
|
---|
| 121 | while(left[0] != 0p) {
|
---|
| 122 | serr | " - " | left[0];
|
---|
| 123 | left++;
|
---|
| 124 | }
|
---|
[b57db73] | 125 | exit(EXIT_FAILURE);
|
---|
[2ecbd7b] | 126 | }
|
---|
| 127 |
|
---|
[b57db73] | 128 | options.file_cache.path = path;
|
---|
[2ecbd7b] | 129 | }
|
---|