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