[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>
|
---|
[348f81d5] | 15 | #include <stdlib.hfa>
|
---|
[2ecbd7b] | 16 |
|
---|
[b57db73] | 17 | #include <stdlib.h>
|
---|
[5ad381b] | 18 | #include <string.h>
|
---|
| 19 |
|
---|
[2ecbd7b] | 20 | Options options @= {
|
---|
[481ee28] | 21 | false, // log
|
---|
[2cd784a] | 22 | false, // stats
|
---|
[5ad381b] | 23 |
|
---|
[2ecbd7b] | 24 | { // file_cache
|
---|
[b57db73] | 25 | 0, // path
|
---|
[2ecbd7b] | 26 | 0, // open_flags;
|
---|
| 27 | 42u, // hash_seed;
|
---|
| 28 | 0, // size;
|
---|
| 29 | false, // list;
|
---|
| 30 | false // fixed_fds
|
---|
| 31 | },
|
---|
| 32 |
|
---|
| 33 | { // socket
|
---|
| 34 | 8080, // port
|
---|
[03ed863] | 35 | 10, // backlog
|
---|
| 36 | 1024 // buflen
|
---|
[2ecbd7b] | 37 | },
|
---|
| 38 |
|
---|
| 39 | { // cluster
|
---|
[348f81d5] | 40 | 1, // nclusters;
|
---|
[2ecbd7b] | 41 | 1, // nprocs;
|
---|
| 42 | 1, // nworkers;
|
---|
[b57db73] | 43 | {}, // params;
|
---|
[2ecbd7b] | 44 | false, // procstats
|
---|
| 45 | false, // viewhalts
|
---|
| 46 | 0, // instance;
|
---|
| 47 | }
|
---|
| 48 | };
|
---|
| 49 |
|
---|
[b57db73] | 50 | void parse_options( int argc, char * argv[] ) {
|
---|
[4f762d3] | 51 | // bool fixedfd = false;
|
---|
| 52 | // bool sqkpoll = false;
|
---|
| 53 | // bool iokpoll = false;
|
---|
[a6b587f] | 54 | unsigned nentries = 16;
|
---|
[348f81d5] | 55 | bool isolate = false;
|
---|
[a6b587f] | 56 |
|
---|
[2ecbd7b] | 57 |
|
---|
| 58 | static cfa_option opt[] = {
|
---|
[bdbc24d] | 59 | { 'p', "port", "Port the server will listen on", options.socket.port},
|
---|
| 60 | { 'c', "cpus", "Number of processors to use", options.clopts.nprocs},
|
---|
| 61 | { 't', "threads", "Number of worker threads to use", options.clopts.nworkers},
|
---|
[348f81d5] | 62 | {'\0', "isolate", "Create one cluster per processor", isolate, parse_settrue},
|
---|
[bdbc24d] | 63 | {'\0', "log", "Enable logs", options.log, parse_settrue},
|
---|
[2cd784a] | 64 | {'\0', "stats", "Enable statistics", options.stats, parse_settrue},
|
---|
[bdbc24d] | 65 | {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
|
---|
| 66 | {'\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},
|
---|
| 67 | {'\0', "seed", "seed to use for hashing", options.file_cache.hash_seed },
|
---|
| 68 | {'\0', "cache-size", "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size },
|
---|
| 69 | {'\0', "list-files", "List the files in the specified path and exit", options.file_cache.list, parse_settrue },
|
---|
[4f762d3] | 70 | // { 'f', "fixed-fds", "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue},
|
---|
| 71 | // { 'k', "kpollsubmit", "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue },
|
---|
| 72 | // { 'i', "kpollcomplete", "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue },
|
---|
[18a75945] | 73 | {'e', "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 | }
|
---|
[348f81d5] | 93 | if(isolate) {
|
---|
| 94 | options.clopts.nclusters = options.clopts.nprocs;
|
---|
| 95 | options.clopts.nprocs = 1;
|
---|
| 96 | }
|
---|
[a6b587f] | 97 | options.clopts.params.num_entries = nentries;
|
---|
[348f81d5] | 98 | options.clopts.instance = alloc(options.clopts.nclusters);
|
---|
| 99 | options.clopts.thrd_cnt = alloc(options.clopts.nclusters);
|
---|
| 100 | options.clopts.cltr_cnt = 0;
|
---|
| 101 | for(i; options.clopts.nclusters) {
|
---|
| 102 | options.clopts.thrd_cnt[i] = 0;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[a6b587f] | 105 |
|
---|
[4f762d3] | 106 | // if( fixedfd ) {
|
---|
| 107 | // options.file_cache.fixed_fds = true;
|
---|
| 108 | // }
|
---|
[2ecbd7b] | 109 |
|
---|
[4f762d3] | 110 | // if( sqkpoll ) {
|
---|
| 111 | // options.file_cache.fixed_fds = true;
|
---|
| 112 | // }
|
---|
[2ecbd7b] | 113 |
|
---|
[4f762d3] | 114 | // if( iokpoll ) {
|
---|
| 115 | // options.file_cache.open_flags |= O_DIRECT;
|
---|
| 116 | // }
|
---|
[2ecbd7b] | 117 |
|
---|
[a6b587f] | 118 | if( left[0] == 0p ) { return; }
|
---|
[2ecbd7b] | 119 |
|
---|
| 120 | const char * path = left[0];
|
---|
| 121 | left++;
|
---|
| 122 |
|
---|
| 123 | if( left[0] != 0p ) {
|
---|
[a6b587f] | 124 | serr | "Too many trailing arguments!" | '\'' | path | '\'';
|
---|
| 125 | while(left[0] != 0p) {
|
---|
| 126 | serr | " - " | left[0];
|
---|
| 127 | left++;
|
---|
| 128 | }
|
---|
[b57db73] | 129 | exit(EXIT_FAILURE);
|
---|
[2ecbd7b] | 130 | }
|
---|
| 131 |
|
---|
[b57db73] | 132 | options.file_cache.path = path;
|
---|
[2ecbd7b] | 133 | }
|
---|