Ignore:
Timestamp:
Aug 11, 2020, 4:40:15 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0d070ca
Parents:
07d867b (diff), 129674b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into new-ast

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/readv.cfa

    r07d867b r22f94a4  
     1#define _GNU_SOURCE
     2
    13#include <stdlib.h>
    24#include <stdio.h>
     
    1012}
    1113
     14#include <errno.h>
    1215#include <unistd.h>
    1316
    1417#include <clock.hfa>
     18#include <iofwd.hfa>
    1519#include <kernel.hfa>
    1620#include <thread.hfa>
    1721#include <time.hfa>
     22#include <stats.hfa>
     23
     24#include "../benchcltr.hfa"
    1825
    1926extern bool traceHeapOn();
    20 extern ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
    2127
    2228int fd;
     
    2430volatile size_t count = 0;
    2531
    26 unsigned long int buflen = 50;
     32unsigned long int buflen = 512;
     33bool fixed_file = false;
    2734
    28 cluster * the_cluster;
    29 
    30 thread Reader {};
     35thread __attribute__((aligned(128))) Reader {};
    3136void ?{}( Reader & this ) {
    32         ((thread&)this){ "Reader Thread", *the_cluster };
     37        ((thread&)this){ "Reader Thread", *the_benchmark_cluster };
    3338}
    3439
    35 struct my_processor {
    36         processor p;
    37 };
    38 
    39 void ?{}( my_processor & this ) {
    40         (this.p){ "I/O Processor", *the_cluster };
     40int do_read(int fd, struct iovec * iov) {
     41        // extern ssize_t cfa_preadv2(int, const struct iovec *, int, off_t, int, int = 0, Duration = -1`s, io_cancellation * = 0p, io_context * = 0p);
     42        int sflags = 0;
     43        if(fixed_file) {
     44                sflags |= CFA_IO_FIXED_FD1;
     45        }
     46        return cfa_preadv2(fd, iov, 1, 0, 0, sflags, -1`s, 0p, 0p);
    4147}
    4248
    4349void main( Reader & ) {
    44         while(!__atomic_load_n(&run, __ATOMIC_RELAXED)) yield();
     50        park( __cfaabi_dbg_ctx );
     51        /* paranoid */ assert( true == __atomic_load_n(&run, __ATOMIC_RELAXED) );
    4552
    46         char data[buflen];
     53        __attribute__((aligned(512)))  char data[buflen];
    4754        struct iovec iov = { data, buflen };
    4855
    4956        while(__atomic_load_n(&run, __ATOMIC_RELAXED)) {
    50                 int r = cfa_preadv2(fd, &iov, 1, 0, 0);
    51                 if(r < 0) abort("%s\n", strerror(-r));
     57                int r = do_read(fd, &iov);
     58                if(r < 0) abort("%s\n", strerror(errno));
    5259
    5360                __atomic_fetch_add( &count, 1, __ATOMIC_SEQ_CST );
     
    5663
    5764int main(int argc, char * argv[]) {
    58         double duration   = 5.0;
    59         unsigned long int nthreads = 2;
    60         unsigned long int nprocs   = 1;
    61         int flags = 0;
     65        BENCH_DECL
     66        unsigned num_io = 1;
     67        io_context_params params;
     68        int file_flags = 0;
     69        unsigned sublen = 16;
    6270
    6371        arg_loop:
    6472        for(;;) {
    6573                static struct option options[] = {
    66                         {"duration",   required_argument, 0, 'd'},
    67                         {"nthreads",   required_argument, 0, 't'},
    68                         {"nprocs",     required_argument, 0, 'p'},
    69                         {"bufsize",    required_argument, 0, 'b'},
    70                         {"userthread", no_argument      , 0, 'u'},
     74                        BENCH_OPT_LONG
     75                        {"bufsize",       required_argument, 0, 'b'},
     76                        {"submitthread",  no_argument      , 0, 's'},
     77                        {"eagersubmit",   no_argument      , 0, 'e'},
     78                        {"kpollsubmit",   no_argument      , 0, 'k'},
     79                        {"kpollcomplete", no_argument      , 0, 'i'},
     80                        {"fixed-files",   no_argument      , 0, 'f'},
     81                        {"open-direct",   no_argument      , 0, 'o'},
     82                        {"submitlength",  required_argument, 0, 'l'},
    7183                        {0, 0, 0, 0}
    7284                };
    7385
    7486                int idx = 0;
    75                 int opt = getopt_long(argc, argv, "d:t:p:b:u", options, &idx);
     87                int opt = getopt_long(argc, argv, BENCH_OPT_SHORT "b:sekil:", options, &idx);
    7688
    7789                const char * arg = optarg ? optarg : "";
     
    8193                        case -1:
    8294                                break arg_loop;
    83                         // Numeric Arguments
    84                         case 'd':
    85                                 duration = strtod(arg, &end);
    86                                 if(*end != '\0') {
    87                                         fprintf(stderr, "Duration must be a valid double, was %s\n", arg);
    88                                         goto usage;
    89                                 }
    90                                 break;
    91                         case 't':
    92                                 nthreads = strtoul(arg, &end, 10);
    93                                 if(*end != '\0' || nthreads < 1) {
    94                                         fprintf(stderr, "Number of threads must be a positive integer, was %s\n", arg);
    95                                         goto usage;
    96                                 }
    97                                 break;
    98                         case 'p':
    99                                 nprocs = strtoul(arg, &end, 10);
    100                                 if(*end != '\0' || nprocs < 1) {
    101                                         fprintf(stderr, "Number of processors must be a positive integer, was %s\n", arg);
    102                                         goto usage;
    103                                 }
    104                                 break;
     95                        BENCH_OPT_CASE
    10596                        case 'b':
    10697                                buflen = strtoul(arg, &end, 10);
     
    110101                                }
    111102                                break;
    112                         case 'u':
    113                                 flags |= CFA_CLUSTER_IO_POLLER_USER_THREAD;
     103                        case 's':
     104                                params.poller_submits = true;
    114105                                break;
    115                         // Other cases
     106                        case 'e':
     107                                params.eager_submits = true;
     108                                break;
     109                        case 'k':
     110                                params.poll_submit = true;
     111                        case 'f':
     112                                fixed_file = true;
     113                                break;
     114                        case 'i':
     115                                params.poll_complete = true;
     116                        case 'o':
     117                                file_flags |= O_DIRECT;
     118                                break;
     119                        case 'l':
     120                                sublen = strtoul(arg, &end, 10);
     121                                if(*end != '\0' && sublen < 16) {
     122                                        fprintf(stderr, "Submit length must be at least 16, was %s\n", arg);
     123                                        goto usage;
     124                                }
     125                                // flags |= (sublen << CFA_CLUSTER_IO_BUFFLEN_OFFSET);
     126                                break;
    116127                        default: /* ? */
    117128                                fprintf(stderr, "%d\n", opt);
    118129                        usage:
    119                                 fprintf(stderr, "Usage: %s : [options]\n", argv[0]);
    120                                 fprintf(stderr, "\n");
    121                                 fprintf(stderr, "  -d, --duration=DURATION  Duration of the experiment, in seconds\n");
    122                                 fprintf(stderr, "  -t, --nthreads=NTHREADS  Number of user threads\n");
    123                                 fprintf(stderr, "  -p, --nprocs=NPROCS      Number of kernel threads\n");
    124                                 fprintf(stderr, "  -b, --buflen=SIZE        Number of bytes to read per request\n");
     130                                bench_usage( argv );
     131                                fprintf( stderr, "  -b, --buflen=SIZE        Number of bytes to read per request\n" );
     132                                fprintf( stderr, "  -u, --userthread         If set, cluster uses user-thread to poll I/O\n" );
     133                                fprintf( stderr, "  -s, --submitthread       If set, cluster uses polling thread to submit I/O\n" );
     134                                fprintf( stderr, "  -e, --eagersubmit        If set, cluster submits I/O eagerly but still aggregates submits\n" );
     135                                fprintf( stderr, "  -k, --kpollsubmit        If set, cluster uses IORING_SETUP_SQPOLL\n" );
     136                                fprintf( stderr, "  -i, --kpollcomplete      If set, cluster uses IORING_SETUP_IOPOLL\n" );
     137                                fprintf( stderr, "  -l, --submitlength=LEN   Max number of submitions that can be submitted together\n" );
    125138                                exit(EXIT_FAILURE);
    126139                }
    127140        }
    128141
    129         fd = open(__FILE__, 0);
    130         if(fd < 0) {
     142        int lfd = open(__FILE__, file_flags);
     143        if(lfd < 0) {
    131144                fprintf(stderr, "Could not open source file\n");
    132145                exit(EXIT_FAILURE);
    133146        }
    134147
    135         printf("Running %lu threads, reading %lu bytes each, over %lu processors for %lf seconds\n", nthreads, buflen, nprocs, duration);
     148        printf("Running %d threads, reading %lu bytes each, over %d processors for %f seconds\n", nthreads, buflen, nprocs, duration);
    136149
    137150        {
    138151                Time start, end;
    139                 cluster cl = { "IO Cluster", flags };
    140                 the_cluster = &cl;
    141                 #if !defined(__CFA_NO_STATISTICS__)
    142                         print_stats_at_exit( cl );
    143                 #endif
     152                BenchCluster cl = { num_io, params, CFA_STATS_READY_Q | CFA_STATS_IO };
     153
     154                if(fixed_file) {
     155                        fd = 0;
     156                        register_fixed_files( cl.self, &lfd, 1 );
     157                }
     158                else {
     159                        fd = lfd;
     160                }
     161
    144162                {
    145                         my_processor procs[nprocs];
     163                        BenchProc procs[nprocs];
    146164                        {
    147165                                Reader threads[nthreads];
    148166
    149167                                printf("Starting\n");
    150                                 start = getTime();
     168                                bool is_tty = isatty(STDOUT_FILENO);
     169                                start = getTimeNsec();
    151170                                run = true;
    152                                 do {
    153                                         sleep(500`ms);
    154                                         end = getTime();
    155                                 } while( (end - start) < duration`s );
     171
     172                                for(i; nthreads) {
     173                                        unpark( threads[i] __cfaabi_dbg_ctx2 );
     174                                }
     175                                wait(duration, start, end, is_tty);
     176
    156177                                run = false;
    157                                 end = getTime();
    158                                 printf("Done\n");
     178                                end = getTimeNsec();
     179                                printf("\nDone\n");
    159180                        }
     181                        printf("Readers closed\n");
    160182                }
    161183                printf("Took %'ld ms\n", (end - start)`ms);
     
    166188        }
    167189
    168         close(fd);
     190        close(lfd);
    169191}
Note: See TracChangeset for help on using the changeset viewer.