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