#include "options.hfa" #define _GNU_SOURCE #define __USE_GNU extern "C" { #include #include #include } #include #include #include Options options @= { { // experiment FileExperiment, // type }, { // file_cache 0, // open_flags; 42u, // hash_seed; 0, // size; false, // list; false // fixed_fds }, { // socket 8080, // port 10, // backlog 1024 // buflen }, { // cluster 1, // nprocs; 1, // nworkers; 0, // flags; false, // procstats false, // viewhalts 0, // instance; } }; static bool parse(const char * arg, ExprimentType & value) { if(strcmp(arg, "file") == 0) { value = FileExperiment; return true; } if(strcmp(arg, "plaintext") == 0) { value = HelloWorldExperiment; return true; } return false; } const char * parse_options( int argc, char * argv[] ) { bool subthrd = false; bool eagrsub = false; bool fixedfd = false; bool sqkpoll = false; bool iokpoll = false; unsigned sublen = 16; static cfa_option opt[] = { {'p', "port", "Port the server will listen on", options.socket.port}, {'c', "cpus", "Number of processors to use", options.clopts.nprocs}, {'T', "experiment", "Experiment type to run: file, plaintext", options.experiment.type}, {'t', "threads", "Number of worker threads to use", options.clopts.nworkers}, {'b', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog}, {'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}, {'S', "seed", "seed to use for hashing", options.file_cache.hash_seed }, {'C', "cache-size", "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size }, {'l', "list-files", "List the files in the specified path and exit", options.file_cache.list, parse_settrue }, {'s', "submitthread", "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue }, {'e', "eagersubmit", "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue}, {'f', "fixed-fds", "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue}, {'k', "kpollsubmit", "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue }, {'i', "kpollcomplete", "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue }, {'L', "submitlength", "Max number of submitions that can be submitted together", sublen }, }; int opt_cnt = sizeof(opt) / sizeof(cfa_option); char **left; parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left ); options.clopts.params.poller_submits = subthrd; options.clopts.params.eager_submits = eagrsub; if( fixedfd ) { options.file_cache.fixed_fds = true; } if( sqkpoll ) { options.clopts.params.poll_submit = true; options.file_cache.fixed_fds = true; } if( iokpoll ) { options.clopts.params.poll_complete = true; options.file_cache.open_flags |= O_DIRECT; } options.clopts.params.num_ready = sublen; if( left[0] == 0p ) { return "."; } const char * path = left[0]; left++; if( left[0] != 0p ) { abort("Too many trailing arguments!\n"); } return path; }