Changeset 5407cdc for benchmark/io/http/http_ring.cpp
- Timestamp:
- Apr 28, 2021, 4:56:50 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8d66610
- Parents:
- feacef9 (diff), b7fd2db6 (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. - File:
-
- 1 edited
-
benchmark/io/http/http_ring.cpp (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/http_ring.cpp
rfeacef9 r5407cdc 20 20 socklen_t *addrlen; 21 21 int flags; 22 unsigned cnt; 22 23 } acpt; 23 24 … … 67 68 thread_local stats_block_t stats; 68 69 stats_block_t global_stats; 70 71 thread_local struct __attribute__((aligned(128))) { 72 size_t to_submit = 0; 73 } local; 69 74 70 75 // Get an array of current connections … … 192 197 static void submit(struct io_uring * ring, struct io_uring_sqe * sqe, connection * conn) { 193 198 (void)ring; 199 local.to_submit++; 194 200 #ifdef USE_ASYNC 195 201 io_uring_sqe_set_flags(sqe, IOSQE_ASYNC); … … 406 412 switch(state) { 407 413 case ACCEPTING: 408 connection::accept(ring, opt);414 // connection::accept(ring, opt); 409 415 newconn(ring, res); 410 416 break; … … 420 426 421 427 //========================================================= 428 extern "C" { 429 #include <sys/eventfd.h> // use for termination 430 } 431 422 432 // Main loop of the WebServer 423 433 // Effectively uses one thread_local copy of everything per kernel thread … … 427 437 struct io_uring * ring = opt.ring; 428 438 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 429 451 // Track the shutdown using a event_fd 430 452 char endfd_buf[8]; … … 433 455 // Accept our first connection 434 456 // May not take effect until io_uring_submit_and_wait 435 connection::accept(ring, opt); 457 for(unsigned i = 0; i < opt.acpt.cnt; i++) { 458 connection::accept(ring, opt); 459 } 436 460 437 461 int reset = 1; // Counter to print stats once in a while … … 441 465 while(!done) { 442 466 // Submit all the answers we have and wait for responses 443 int ret = io_uring_submit_and_wait(ring, 1); 467 int ret = io_uring_submit(ring); 468 local.to_submit = 0; 444 469 445 470 // check errors … … 452 477 sqes += ret; 453 478 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 } 454 489 455 490 struct io_uring_cqe *cqe; … … 463 498 break; 464 499 } 500 501 if(local.to_submit > 30) break; 465 502 466 503 auto req = (class connection *)cqe->user_data; … … 509 546 #include <pthread.h> // for pthreads 510 547 #include <signal.h> // for signal(SIGPIPE, SIG_IGN); 511 #include <sys/eventfd.h> // use for termination512 548 #include <sys/socket.h> // for sockets in general 513 549 #include <netinet/in.h> // for sockaddr_in, AF_INET … … 528 564 unsigned entries = 256; // number of entries per ring/kernel thread 529 565 unsigned backlog = 262144; // backlog argument to listen 566 unsigned preaccept = 1; // start by accepting X per threads 530 567 bool attach = false; // Whether or not to attach all the rings 531 568 bool sqpoll = false; // Whether or not to use SQ Polling … … 534 571 // Arguments Parsing 535 572 int c; 536 while ((c = getopt (argc, argv, "t:p:e:b: aS")) != -1) {573 while ((c = getopt (argc, argv, "t:p:e:b:c:aS")) != -1) { 537 574 switch (c) 538 575 { … … 548 585 case 'b': 549 586 backlog = atoi(optarg); 587 break; 588 case 'c': 589 preaccept = atoi(optarg); 550 590 break; 551 591 case 'a': … … 681 721 thrd_opts[i].acpt.addrlen = (socklen_t*)&addrlen; 682 722 thrd_opts[i].acpt.flags = 0; 723 thrd_opts[i].acpt.cnt = preaccept; 683 724 thrd_opts[i].endfd = efd; 684 725 thrd_opts[i].ring = &thrd_rings[i].storage;
Note:
See TracChangeset
for help on using the changeset viewer.