source: benchmark/io/http/options.cfa @ d1eb9c0

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since d1eb9c0 was a6b587f, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Fix bugs and added nentries command line option.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1#include "options.hfa"
2
3#define _GNU_SOURCE
4#define __USE_GNU
5extern "C" {
6        #include <sys/types.h>
7        #include <sys/stat.h>
8        #include <fcntl.h>
9}
10
11#include <bitmanip.hfa>
12#include <fstream.hfa>
13#include <kernel.hfa>
14#include <parseargs.hfa>
15
16#include <stdlib.h>
17#include <string.h>
18
19Options options @= {
20        false, // log
21
22        { // file_cache
23                0,     // path
24                0,     // open_flags;
25                42u,   // hash_seed;
26                0,     // size;
27                false, // list;
28                false  // fixed_fds
29        },
30
31        { // socket
32                8080, // port
33                10,   // backlog
34                1024  // buflen
35        },
36
37        { // cluster
38                1,     // nprocs;
39                1,     // nworkers;
40                {},     // params;
41                false, // procstats
42                false, // viewhalts
43                0,     // instance;
44        }
45};
46
47void parse_options( int argc, char * argv[] ) {
48        bool subthrd = false;
49        bool eagrsub = false;
50        bool fixedfd = false;
51        bool sqkpoll = false;
52        bool iokpoll = false;
53        unsigned sublen = 16;
54        unsigned nentries = 16;
55
56
57        static cfa_option opt[] = {
58                { 'p', "port",           "Port the server will listen on", options.socket.port},
59                { 'c', "cpus",           "Number of processors to use", options.clopts.nprocs},
60                { 't', "threads",        "Number of worker threads to use", options.clopts.nworkers},
61                {'\0', "log",            "Enable logs", options.log, parse_settrue},
62                {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
63                {'\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},
64                {'\0', "seed",           "seed to use for hashing", options.file_cache.hash_seed },
65                {'\0', "cache-size",     "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size },
66                {'\0', "list-files",     "List the files in the specified path and exit", options.file_cache.list, parse_settrue },
67                { 's', "submitthread",   "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue },
68                { 'e', "eagersubmit",    "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue},
69                { 'f', "fixed-fds",      "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue},
70                { 'k', "kpollsubmit",    "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue },
71                { 'i', "kpollcomplete",  "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue },
72                {'\0', "submitlength",   "Max number of submitions that can be submitted together", sublen },
73                {'\0', "numentries",     "Number of I/O entries", nentries },
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
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        }
93        options.clopts.params.num_entries = nentries;
94
95        options.clopts.params.poller_submits = subthrd;
96        options.clopts.params.eager_submits  = eagrsub;
97
98        if( fixedfd ) {
99                options.file_cache.fixed_fds = true;
100        }
101
102        if( sqkpoll ) {
103                options.clopts.params.poll_submit = true;
104                options.file_cache.fixed_fds = true;
105        }
106
107        if( iokpoll ) {
108                options.clopts.params.poll_complete = true;
109                options.file_cache.open_flags |= O_DIRECT;
110        }
111
112        options.clopts.params.num_ready = sublen;
113
114        if( left[0] == 0p ) { return; }
115
116        const char * path = left[0];
117        left++;
118
119        if( left[0] != 0p ) {
120                serr | "Too many trailing arguments!" | '\'' | path | '\'';
121                while(left[0] != 0p) {
122                        serr | " - " | left[0];
123                        left++;
124                }
125                exit(EXIT_FAILURE);
126        }
127
128        options.file_cache.path = path;
129}
Note: See TracBrowser for help on using the repository browser.