source: benchmark/io/http/options.cfa @ 289a21c

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

Implemented more options and moved them to their own file

  • Property mode set to 100644
File size: 3.2 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
13#include "parseargs.hfa"
14
15
16Options options @= {
17        { // file_cache
18                0,     // open_flags;
19                42u,   // hash_seed;
20                0,     // size;
21                false, // list;
22                false  // fixed_fds
23        },
24
25        { // socket
26                8080, // port
27                10    // backlog
28        },
29
30        { // cluster
31                1,     // nprocs;
32                1,     // nworkers;
33                0,     // flags;
34                10,    // chan_size;
35                false, // procstats
36                false, // viewhalts
37                0,     // instance;
38        }
39};
40
41const char * parse_options( int argc, char * argv[] ) {
42        bool uthrdpo = false;
43        bool subthrd = false;
44        bool eagrsub = false;
45        bool fixedfd = false;
46        bool sqkpoll = false;
47        bool iokpoll = false;
48        unsigned sublen = 16;
49
50        static cfa_option opt[] = {
51                {'p', "port",           "Port the server will listen on", options.socket.port},
52                {'c', "cpus",           "Number of processors to use", options.clopts.nprocs},
53                {'t', "threads",        "Number of worker threads to use", options.clopts.nworkers},
54                {'b', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
55                {'B', "channel-size",   "Maximum number of accepted connection pending", options.clopts.chan_size},
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.