Changeset 8ee163e2


Ignore:
Timestamp:
Feb 17, 2022, 12:57:12 PM (2 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
f0567a8
Parents:
5614a191 (diff), 3a40df6 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/sendfile/producer.c

    r5614a191 r8ee163e2  
    4747int pipefd[2];
    4848struct io_uring ring;
     49
     50char * buf;
    4951
    5052struct stats {
     
    6264static void my_iouring (int out, int in, size_t size, struct stats *);
    6365static void my_ringlink(int out, int in, size_t size, struct stats *);
     66static void my_readwrit(int out, int in, size_t size, struct stats *);
    6467typedef void (*sender_t)(int out, int in, size_t size, struct stats *);
    6568
     
    7174        struct addrinfo * addr;
    7275        int file_fd;
     76        int ret;
    7377        switch(argc) {
    7478        case 3:
     
    7680                        // Open the file
    7781                        const char * const path = argv[2];
    78                         int ret = open(path, 0, O_RDONLY);
     82                        ret = open(path, 0, O_RDONLY);
    7983                        if(ret < 0) {
    8084                                fprintf( stderr, "cannot open file '%s': %s\n\n", path, strerror(errno) );
     
    176180        io_uring_queue_init(16, &ring, 0);
    177181
    178         {
    179                 char addr_str[INET_ADDRSTRLEN];
    180                 struct sockaddr_in * address = (struct sockaddr_in *) addr->ai_addr;
    181                 inet_ntop( AF_INET, &address->sin_addr, addr_str, INET_ADDRSTRLEN );
    182                 printf("sending '%s' to '%s:%i'\n", file_path, addr_str, ntohs(address->sin_port));
    183         }
    184 
    185         int ret = pipe(pipefd);
    186         if( ret < 0 ) {
    187                 fprintf( stderr, "pipe error: (%d) %s\n\n", (int)errno, strerror(errno) );
    188                 exit( PIPE_ERROR );
    189         }
    190 
    191         {
    192                 ret = fcntl(pipefd[0], F_GETPIPE_SZ);
    193                 if( ret < 0 ) {
    194                         fprintf( stderr, "pipe fcntl error: (%d) %s\n\n", (int)errno, strerror(errno) );
    195                         exit( PIPE_ERROR );
    196                 }
    197                 printf("%d\n", ret);
    198 
    199                 ret = fcntl(pipefd[1], F_GETPIPE_SZ);
    200                 if( ret < 0 ) {
    201                         fprintf( stderr, "pipe fcntl 2 error: (%d) %s\n\n", (int)errno, strerror(errno) );
    202                         exit( PIPE_ERROR );
    203                 }
    204                 printf("%d\n", ret);
    205         }
    206 
    207182        size_t file_size = 0;
    208183        {
     
    216191        }
    217192
     193        {
     194                char addr_str[INET_ADDRSTRLEN];
     195                struct sockaddr_in * address = (struct sockaddr_in *) addr->ai_addr;
     196                inet_ntop( AF_INET, &address->sin_addr, addr_str, INET_ADDRSTRLEN );
     197                printf("sending '%s' (%zu bytes) to '%s:%i'\n", file_path, file_size, addr_str, ntohs(address->sin_port));
     198        }
     199
     200        ret = pipe(pipefd);
     201        if( ret < 0 ) {
     202                fprintf( stderr, "pipe error: (%d) %s\n\n", (int)errno, strerror(errno) );
     203                exit( PIPE_ERROR );
     204        }
     205
     206        buf = malloc(file_size);
     207
     208        printf("--- read + write ---\n");
     209        run(my_readwrit, addr, file_fd, file_size);
    218210        printf("--- splice ---\n");
    219211        run(my_splice  , addr, file_fd, file_size);
     
    414406                        io_uring_prep_splice(sqe, in, offset, pipefd[1], -1, size, 0);
    415407                        sqe->user_data = SPLICE_IN;
     408                        sqe->flags = IOSQE_IO_LINK;
    416409                        has_in = true;
    417410                }
     
    420413                        io_uring_prep_splice(sqe, pipefd[0], -1, out, -1, in_pipe, 0);
    421414                        sqe->user_data = SPLICE_OUT;
    422                         if(has_in) sqe->flags = IOSQE_IO_LINK;
    423415                        has_out = true;
    424416                }
     
    481473        st->calls++;
    482474}
     475
     476static void my_readwrit(int out, int in, size_t size, struct stats * st) {
     477        off_t offset = 0;
     478        size_t writes = 0;
     479        for(;;) {
     480                ssize_t reti = pread(in, buf, size, offset);
     481                if( reti < 0 ) {
     482                        printf("Read in Error : (%d) %s\n\n", (int)errno, strerror(errno) );
     483                        exit( 1 );
     484                }
     485
     486                offset += reti;
     487                size -= reti;
     488
     489                size_t in_buf = reti;
     490                for(;;) {
     491                        ssize_t reto = write(out, buf, in_buf);
     492                        if( reto < 0 ) {
     493                                        printf("Write out Error : (%d) %s\n\n", (int)errno, strerror(errno) );
     494                                        exit( 1 );
     495                                }
     496
     497                        in_buf -= reto;
     498                        writes += reto;
     499                        if(0 == in_buf) break;
     500                        st->shorts.w.cnt++;
     501                        st->shorts.w.bytes += reto;
     502                }
     503                if(0 == size) break;
     504                st->shorts.r.cnt++;
     505                st->shorts.r.bytes += reti;
     506        }
     507        st->calls++;
     508        st->bytes += writes;
     509}
Note: See TracChangeset for help on using the changeset viewer.