source: benchmark/io/http/options.cfa @ 0d070ca

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

Fixed http server after merge of parseargs into libcfa

  • Property mode set to 100644
File size: 3.4 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 <kernel.hfa>
12#include <parseargs.hfa>
13
14Options options @= {
15        { // file_cache
16                0,     // open_flags;
17                42u,   // hash_seed;
18                0,     // size;
19                false, // list;
20                false  // fixed_fds
21        },
22
23        { // socket
24                8080, // port
25                10,   // backlog
26                1024  // buflen
27        },
28
29        { // cluster
30                1,     // nprocs;
31                1,     // nworkers;
32                0,     // flags;
33                10,    // chan_size;
34                false, // procstats
35                false, // viewhalts
36                0,     // instance;
37        }
38};
39
40const char * parse_options( int argc, char * argv[] ) {
41        bool uthrdpo = false;
42        bool subthrd = false;
43        bool eagrsub = false;
44        bool fixedfd = false;
45        bool sqkpoll = false;
46        bool iokpoll = false;
47        unsigned sublen = 16;
48
49        static cfa_option opt[] = {
50                {'p', "port",           "Port the server will listen on", options.socket.port},
51                {'c', "cpus",           "Number of processors to use", options.clopts.nprocs},
52                {'t', "threads",        "Number of worker threads to use", options.clopts.nworkers},
53                {'b', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
54                {'B', "channel-size",   "Maximum number of accepted connection pending", options.clopts.chan_size},
55                {'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},
56                {'S', "seed",           "seed to use for hashing", options.file_cache.hash_seed },
57                {'C', "cache-size",     "Size of the cache to use, if set to small, will uses closes power of 2", options.file_cache.size },
58                {'l', "list-files",     "List the files in the specified path and exit", options.file_cache.list, parse_settrue },
59                {'u', "userthread",     "If set, cluster uses user-thread to poll I/O", uthrdpo, parse_settrue },
60                {'s', "submitthread",   "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue },
61                {'e', "eagersubmit",    "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue},
62                {'f', "fixed-fds",      "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue},
63                {'k', "kpollsubmit",    "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue },
64                {'i', "kpollcomplete",  "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue },
65                {'L', "submitlength",   "Max number of submitions that can be submitted together", sublen },
66
67        };
68        int opt_cnt = sizeof(opt) / sizeof(cfa_option);
69
70        char **left;
71        parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left );
72
73        if( uthrdpo ) {
74                options.clopts.flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
75        }
76
77        if( subthrd ) {
78                options.clopts.flags |= CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS;
79        }
80
81        if( eagrsub ) {
82                options.clopts.flags |= CFA_CLUSTER_IO_EAGER_SUBMITS;
83        }
84
85        if( fixedfd ) {
86                options.file_cache.fixed_fds = true;
87        }
88
89        if( sqkpoll ) {
90                options.clopts.flags |= CFA_CLUSTER_IO_KERNEL_POLL_SUBMITS;
91                options.file_cache.fixed_fds = true;
92        }
93
94        if( iokpoll ) {
95                options.clopts.flags |= CFA_CLUSTER_IO_KERNEL_POLL_COMPLETES;
96                options.file_cache.open_flags |= O_DIRECT;
97        }
98
99        options.clopts.flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
100
101        if( left[0] == 0p ) { return "."; }
102
103        const char * path = left[0];
104        left++;
105
106        if( left[0] != 0p ) {
107                abort("Too many trailing arguments!\n");
108        }
109
110        return path;
111}
Note: See TracBrowser for help on using the repository browser.