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

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

httpforall now only loads file if explicit path is given.

  • 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 <fstream.hfa>
12#include <kernel.hfa>
13#include <parseargs.hfa>
14
15#include <stdlib.h>
16#include <string.h>
17
18Options options @= {
19        false, // log
20
21        { // file_cache
22                0,     // path
23                0,     // open_flags;
24                42u,   // hash_seed;
25                0,     // size;
26                false, // list;
27                false  // fixed_fds
28        },
29
30        { // socket
31                8080, // port
32                10,   // backlog
33                1024  // buflen
34        },
35
36        { // cluster
37                1,     // nprocs;
38                1,     // nworkers;
39                {},     // params;
40                false, // procstats
41                false, // viewhalts
42                0,     // instance;
43        }
44};
45
46void parse_options( int argc, char * argv[] ) {
47        bool subthrd = false;
48        bool eagrsub = false;
49        bool fixedfd = false;
50        bool sqkpoll = false;
51        bool iokpoll = false;
52        unsigned sublen = 16;
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                { 's', "submitthread",   "If set, cluster uses polling thread to submit I/O", subthrd, parse_settrue },
65                { 'e', "eagersubmit",    "If set, cluster submits I/O eagerly but still aggregates submits", eagrsub, parse_settrue},
66                { 'f', "fixed-fds",      "If set, files are open eagerly and pre-registered with the cluster", fixedfd, parse_settrue},
67                { 'k', "kpollsubmit",    "If set, cluster uses IORING_SETUP_SQPOLL, implies -f", sqkpoll, parse_settrue },
68                { 'i', "kpollcomplete",  "If set, cluster uses IORING_SETUP_IOPOLL", iokpoll, parse_settrue },
69                {'\0', "submitlength",   "Max number of submitions that can be submitted together", sublen },
70
71        };
72        int opt_cnt = sizeof(opt) / sizeof(cfa_option);
73
74        char **left;
75        parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left );
76
77        options.clopts.params.poller_submits = subthrd;
78        options.clopts.params.eager_submits  = eagrsub;
79
80        if( fixedfd ) {
81                options.file_cache.fixed_fds = true;
82        }
83
84        if( sqkpoll ) {
85                options.clopts.params.poll_submit = true;
86                options.file_cache.fixed_fds = true;
87        }
88
89        if( iokpoll ) {
90                options.clopts.params.poll_complete = true;
91                options.file_cache.open_flags |= O_DIRECT;
92        }
93
94        options.clopts.params.num_ready = sublen;
95
96        if( left[0] == 0p ) { return "."; }
97
98        const char * path = left[0];
99        left++;
100
101        if( left[0] != 0p ) {
102                serr | "Too many trailing arguments!";
103                exit(EXIT_FAILURE);
104        }
105
106        options.file_cache.path = path;
107}
Note: See TracBrowser for help on using the repository browser.