[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 | |
---|
| 11 | #include <kernel.hfa> |
---|
[42f1d739] | 12 | #include <parseargs.hfa> |
---|
[2ecbd7b] | 13 | |
---|
| 14 | Options options @= { |
---|
| 15 | { // file_cache |
---|
| 16 | 0, // open_flags; |
---|
| 17 | 42u, // hash_seed; |
---|
| 18 | 0, // size; |
---|
| 19 | false, // list; |
---|
| 20 | false // fixed_fds |
---|
| 21 | }, |
---|
| 22 | |
---|
| 23 | { // socket |
---|
| 24 | 8080, // port |
---|
[03ed863] | 25 | 10, // backlog |
---|
| 26 | 1024 // buflen |
---|
[2ecbd7b] | 27 | }, |
---|
| 28 | |
---|
| 29 | { // cluster |
---|
| 30 | 1, // nprocs; |
---|
| 31 | 1, // nworkers; |
---|
| 32 | 0, // flags; |
---|
| 33 | 10, // chan_size; |
---|
| 34 | false, // procstats |
---|
| 35 | false, // viewhalts |
---|
| 36 | 0, // instance; |
---|
| 37 | } |
---|
| 38 | }; |
---|
| 39 | |
---|
| 40 | const char * parse_options( int argc, char * argv[] ) { |
---|
| 41 | bool uthrdpo = false; |
---|
| 42 | bool subthrd = false; |
---|
| 43 | bool eagrsub = false; |
---|
| 44 | bool fixedfd = false; |
---|
| 45 | bool sqkpoll = false; |
---|
| 46 | bool iokpoll = false; |
---|
| 47 | unsigned sublen = 16; |
---|
| 48 | |
---|
| 49 | static cfa_option opt[] = { |
---|
| 50 | {'p', "port", "Port the server will listen on", options.socket.port}, |
---|
| 51 | {'c', "cpus", "Number of processors to use", options.clopts.nprocs}, |
---|
| 52 | {'t', "threads", "Number of worker threads to use", options.clopts.nworkers}, |
---|
| 53 | {'b', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog}, |
---|
| 54 | {'B', "channel-size", "Maximum number of accepted connection pending", options.clopts.chan_size}, |
---|
[03ed863] | 55 | {'r', "request_len", "Maximum number of bytes in the http request, requests with more data will be answered with Http Code 414", options.socket.buflen}, |
---|
[2ecbd7b] | 56 | {'S', "seed", "seed to use for hashing", options.file_cache.hash_seed }, |
---|
| 57 | {'C', "cache-size", "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size }, |
---|
| 58 | {'l', "list-files", "List the files in the specified path and exit", options.file_cache.list, parse_settrue }, |
---|
| 59 | {'u', "userthread", "If set, cluster uses user-thread to poll I/O", uthrdpo, parse_settrue }, |
---|
| 60 | {'s', "submitthread", "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue }, |
---|
| 61 | {'e', "eagersubmit", "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue}, |
---|
| 62 | {'f', "fixed-fds", "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue}, |
---|
| 63 | {'k', "kpollsubmit", "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue }, |
---|
| 64 | {'i', "kpollcomplete", "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue }, |
---|
| 65 | {'L', "submitlength", "Max number of submitions that can be submitted together", sublen }, |
---|
| 66 | |
---|
| 67 | }; |
---|
| 68 | int opt_cnt = sizeof(opt) / sizeof(cfa_option); |
---|
| 69 | |
---|
| 70 | char **left; |
---|
| 71 | parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left ); |
---|
| 72 | |
---|
| 73 | if( uthrdpo ) { |
---|
| 74 | options.clopts.flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | if( subthrd ) { |
---|
| 78 | options.clopts.flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | if( eagrsub ) { |
---|
| 82 | options.clopts.flags |= CFA_CLUSTER_IO_EAGER_SUBMITS; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | if( fixedfd ) { |
---|
| 86 | options.file_cache.fixed_fds = true; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if( sqkpoll ) { |
---|
| 90 | options.clopts.flags |= CFA_CLUSTER_IO_KERNEL_POLL_SUBMITS; |
---|
| 91 | options.file_cache.fixed_fds = true; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | if( iokpoll ) { |
---|
| 95 | options.clopts.flags |= CFA_CLUSTER_IO_KERNEL_POLL_COMPLETES; |
---|
| 96 | options.file_cache.open_flags |= O_DIRECT; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | options.clopts.flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET); |
---|
| 100 | |
---|
| 101 | if( left[0] == 0p ) { return "."; } |
---|
| 102 | |
---|
| 103 | const char * path = left[0]; |
---|
| 104 | left++; |
---|
| 105 | |
---|
| 106 | if( left[0] != 0p ) { |
---|
| 107 | abort("Too many trailing arguments!\n"); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | return path; |
---|
| 111 | } |
---|