Changeset f3e87af for benchmark/io


Ignore:
Timestamp:
Jan 19, 2021, 3:32:14 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2fab24e3
Parents:
3acbf89
Message:

httpc now supports attach feature.

File:
1 edited

Legend:

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

    r3acbf89 rf3e87af  
    4545
    4646        int endfd;
    47         unsigned entries;
     47        struct io_uring * ring;
    4848
    4949        struct {
     
    297297        struct options_t & opt = *(struct options_t *)arg;
    298298
    299         struct io_uring ring_storage;
    300         struct io_uring * ring = &ring_storage;
    301         io_uring_queue_init(opt.entries, ring, 0);
     299        struct io_uring * ring = opt.ring;
    302300
    303301        char endfd_buf[8];
     
    348346        }
    349347
    350         io_uring_queue_exit(ring);
    351 
    352348        return (void*)count;
    353349}
    354350
    355351//=========================================================
     352struct __attribute__((aligned(128))) aligned_ring {
     353        struct io_uring storage;
     354};
     355
    356356#include <bit>
    357357
     
    371371        unsigned entries = 256;
    372372        unsigned backlog = 10;
     373        bool attach = false;
    373374
    374375        //===================
    375376        // Arguments
    376377        int c;
    377         while ((c = getopt (argc, argv, "t:p:e:b:")) != -1) {
     378        while ((c = getopt (argc, argv, "t:p:e:b:a")) != -1) {
    378379                switch (c)
    379380                {
     
    390391                        backlog = atoi(optarg);
    391392                        break;
     393                case 'a':
     394                        attach = true;
     395                        break;
    392396                case '?':
    393397                default:
    394                         std::cerr << "Usage: -t <threads> -p <port> -e <entries> -b <backlog>" << std::endl;
     398                        std::cerr << "Usage: -t <threads> -p <port> -e <entries> -b <backlog> -a" << std::endl;
    395399                        return EXIT_FAILURE;
    396400                }
     
    464468        //===================
    465469        // Run Server Threads
    466         std::cout << "Starting " << nthreads << " Threads" << std::endl;
    467         pthread_t thrd_hdls[nthreads];
    468         options_t thrd_opts[nthreads];
     470        std::cout << "Starting " << nthreads << " Threads";
     471        if(attach) {
     472                std::cout << " with attached Rings";
     473        }
     474        std::cout << std::endl;
     475
     476        aligned_ring thrd_rings[nthreads];
     477        pthread_t    thrd_hdls[nthreads];
     478        options_t    thrd_opts[nthreads];
    469479        for(unsigned i = 0; i < nthreads; i++) {
     480                if(!attach || i == 0) {
     481                        io_uring_queue_init(entries, &thrd_rings[i].storage, 0);
     482                }
     483                else {
     484                        struct io_uring_params p;
     485                        memset(&p, 0, sizeof(p));
     486                        p.flags = IORING_SETUP_ATTACH_WQ;
     487                        p.wq_fd = thrd_rings[0].storage.ring_fd;
     488                        io_uring_queue_init_params(entries, &thrd_rings[i].storage, &p);
     489                }
     490
    470491                thrd_opts[i].acpt.sockfd  = server_fd;
    471492                thrd_opts[i].acpt.addr    = (struct sockaddr *)&address;
    472493                thrd_opts[i].acpt.addrlen = (socklen_t*)&addrlen;
    473494                thrd_opts[i].acpt.flags   = 0;
    474                 thrd_opts[i].endfd   = efd;
    475                 thrd_opts[i].entries = entries;
     495                thrd_opts[i].endfd        = efd;
     496                thrd_opts[i].ring         = &thrd_rings[i].storage;
    476497
    477498                int ret = pthread_create(&thrd_hdls[i], nullptr, proc_loop, &thrd_opts[i]);
     
    527548                total += thrd_opts[i].result.subs;
    528549                count += thrd_opts[i].result.cnts;
     550
     551                io_uring_queue_exit(thrd_opts[i].ring);
    529552        }
    530553        std::cout << "done" << std::endl;
Note: See TracChangeset for help on using the changeset viewer.