source: benchmark/io/http/options.cfa @ 4f762d3

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

Fix httpforall after changes to I/O

  • Property mode set to 100644
File size: 3.1 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 fixedfd = false;
49        // bool sqkpoll = false;
50        // bool iokpoll = false;
51        unsigned nentries = 16;
52
53
54        static cfa_option opt[] = {
55                { 'p', "port",           "Port the server will listen on", options.socket.port},
56                { 'c', "cpus",           "Number of processors to use", options.clopts.nprocs},
57                { 't', "threads",        "Number of worker threads to use", options.clopts.nworkers},
58                {'\0', "log",            "Enable logs", options.log, parse_settrue},
59                {'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
60                {'\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},
61                {'\0', "seed",           "seed to use for hashing", options.file_cache.hash_seed },
62                {'\0', "cache-size",     "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size },
63                {'\0', "list-files",     "List the files in the specified path and exit", options.file_cache.list, 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                {'\0', "numentries",     "Number of I/O entries", nentries },
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( !is_pow2(nentries) ) {
76                unsigned v = nentries;
77                v--;
78                v |= v >> 1;
79                v |= v >> 2;
80                v |= v >> 4;
81                v |= v >> 8;
82                v |= v >> 16;
83                v++;
84                serr | "Warning: num_entries not a power of 2" | '(' | nentries | ')' | "raising to " | v;
85                nentries = v;
86        }
87        options.clopts.params.num_entries = nentries;
88
89        // if( fixedfd ) {
90        //      options.file_cache.fixed_fds = true;
91        // }
92
93        // if( sqkpoll ) {
94        //      options.file_cache.fixed_fds = true;
95        // }
96
97        // if( iokpoll ) {
98        //      options.file_cache.open_flags |= O_DIRECT;
99        // }
100
101        if( left[0] == 0p ) { return; }
102
103        const char * path = left[0];
104        left++;
105
106        if( left[0] != 0p ) {
107                serr | "Too many trailing arguments!" | '\'' | path | '\'';
108                while(left[0] != 0p) {
109                        serr | " - " | left[0];
110                        left++;
111                }
112                exit(EXIT_FAILURE);
113        }
114
115        options.file_cache.path = path;
116}
Note: See TracBrowser for help on using the repository browser.