Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/http_ring.cpp

    ra80db97 reeb4866  
    2020                socklen_t *addrlen;
    2121                int flags;
    22                 unsigned cnt;
    2322        } acpt;
    2423
     
    6867thread_local stats_block_t stats;
    6968stats_block_t global_stats;
    70 
    71 thread_local struct __attribute__((aligned(128))) {
    72         size_t to_submit = 0;
    73 } local;
    7469
    7570// Get an array of current connections
     
    197192        static void submit(struct io_uring * ring, struct io_uring_sqe * sqe, connection * conn) {
    198193                (void)ring;
    199                 local.to_submit++;
    200194                #ifdef USE_ASYNC
    201195                        io_uring_sqe_set_flags(sqe, IOSQE_ASYNC);
     
    412406                switch(state) {
    413407                case ACCEPTING:
    414                         // connection::accept(ring, opt);
     408                        connection::accept(ring, opt);
    415409                        newconn(ring, res);
    416410                        break;
     
    426420
    427421//=========================================================
    428 extern "C" {
    429         #include <sys/eventfd.h>  // use for termination
    430 }
    431 
    432422// Main loop of the WebServer
    433423// Effectively uses one thread_local copy of everything per kernel thread
     
    437427        struct io_uring * ring = opt.ring;
    438428
    439         int blockfd = eventfd(0, 0);
    440         if (blockfd < 0) {
    441                 fprintf( stderr, "eventfd create error: (%d) %s\n", (int)errno, strerror(errno) );
    442                 exit(EXIT_FAILURE);
    443         }
    444 
    445         int ret = io_uring_register_eventfd(ring, blockfd);
    446         if (ret < 0) {
    447                 fprintf( stderr, "io_uring S&W error: (%d) %s\n", (int)-ret, strerror(-ret) );
    448                 exit(EXIT_FAILURE);
    449         }
    450 
    451429        // Track the shutdown using a event_fd
    452430        char endfd_buf[8];
     
    455433        // Accept our first connection
    456434        // May not take effect until io_uring_submit_and_wait
    457         for(unsigned i = 0; i < opt.acpt.cnt; i++) {
    458                 connection::accept(ring, opt);
    459         }
     435        connection::accept(ring, opt);
    460436
    461437        int reset = 1;       // Counter to print stats once in a while
     
    465441        while(!done) {
    466442                // Submit all the answers we have and wait for responses
    467                 int ret = io_uring_submit(ring);
    468                 local.to_submit = 0;
     443                int ret = io_uring_submit_and_wait(ring, 1);
    469444
    470445                // check errors
     
    477452                sqes += ret;
    478453                call++;
    479 
    480 
    481                 eventfd_t val;
    482                 ret = eventfd_read(blockfd, &val);
    483 
    484                 // check errors
    485                 if (ret < 0) {
    486                         fprintf( stderr, "eventfd read error: (%d) %s\n", (int)errno, strerror(errno) );
    487                         exit(EXIT_FAILURE);
    488                 }
    489454
    490455                struct io_uring_cqe *cqe;
     
    498463                                break;
    499464                        }
    500 
    501                         if(local.to_submit > 30) break;
    502465
    503466                        auto req = (class connection *)cqe->user_data;
     
    546509        #include <pthread.h>      // for pthreads
    547510        #include <signal.h>       // for signal(SIGPIPE, SIG_IGN);
     511        #include <sys/eventfd.h>  // use for termination
    548512        #include <sys/socket.h>   // for sockets in general
    549513        #include <netinet/in.h>   // for sockaddr_in, AF_INET
     
    564528        unsigned entries = 256;     // number of entries per ring/kernel thread
    565529        unsigned backlog = 262144;  // backlog argument to listen
    566         unsigned preaccept = 1;     // start by accepting X per threads
    567530        bool attach = false;        // Whether or not to attach all the rings
    568531        bool sqpoll = false;        // Whether or not to use SQ Polling
     
    571534        // Arguments Parsing
    572535        int c;
    573         while ((c = getopt (argc, argv, "t:p:e:b:c:aS")) != -1) {
     536        while ((c = getopt (argc, argv, "t:p:e:b:aS")) != -1) {
    574537                switch (c)
    575538                {
     
    585548                case 'b':
    586549                        backlog = atoi(optarg);
    587                         break;
    588                 case 'c':
    589                         preaccept = atoi(optarg);
    590550                        break;
    591551                case 'a':
     
    721681                thrd_opts[i].acpt.addrlen = (socklen_t*)&addrlen;
    722682                thrd_opts[i].acpt.flags   = 0;
    723                 thrd_opts[i].acpt.cnt     = preaccept;
    724683                thrd_opts[i].endfd        = efd;
    725684                thrd_opts[i].ring         = &thrd_rings[i].storage;
Note: See TracChangeset for help on using the changeset viewer.