Changeset d95969a for libcfa/src/concurrency/io/setup.cfa
- Timestamp:
- Jan 25, 2021, 3:45:42 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:
- c292244
- Parents:
- b6a8b31 (diff), 7158202 (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
-
libcfa/src/concurrency/io/setup.cfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/io/setup.cfa
rb6a8b31 rd95969a 42 42 void ^?{}(io_context & this, bool cluster_context) {} 43 43 44 void register_fixed_files( io_context &, int *, unsigned ) {} 45 void register_fixed_files( cluster &, int *, unsigned ) {} 46 44 47 #else 45 48 #include <errno.h> … … 110 113 111 114 static struct { 112 pthread_t thrd; // pthread handle to io poller thread 113 void * stack; // pthread stack for io poller thread 114 int epollfd; // file descriptor to the epoll instance 115 volatile bool run; // Whether or not to continue 115 pthread_t thrd; // pthread handle to io poller thread 116 void * stack; // pthread stack for io poller thread 117 int epollfd; // file descriptor to the epoll instance 118 volatile bool run; // Whether or not to continue 119 volatile bool stopped; // Whether the poller has finished running 120 volatile uint64_t epoch; // Epoch used for memory reclamation 116 121 } iopoll; 117 122 … … 126 131 __cfadbg_print_safe(io_core, "Kernel : Starting io poller thread\n" ); 127 132 128 iopoll.run = true; 129 iopoll.stack = __create_pthread( &iopoll.thrd, iopoll_loop, 0p ); 133 iopoll.stack = __create_pthread( &iopoll.thrd, iopoll_loop, 0p ); 134 iopoll.run = true; 135 iopoll.stopped = false; 136 iopoll.epoch = 0; 130 137 } 131 138 … … 171 178 while( iopoll.run ) { 172 179 __cfadbg_print_safe(io_core, "Kernel I/O - epoll : waiting on io_uring contexts\n"); 180 181 // increment the epoch to notify any deleters we are starting a new cycle 182 __atomic_fetch_add(&iopoll.epoch, 1, __ATOMIC_SEQ_CST); 173 183 174 184 // Wait for events … … 197 207 } 198 208 } 209 210 __atomic_store_n(&iopoll.stopped, true, __ATOMIC_SEQ_CST); 199 211 200 212 __cfadbg_print_safe(io_core, "Kernel : IO poller thread stopping\n" ); … … 493 505 // I/O Context Sleep 494 506 //============================================================================================= 495 #define IOEVENTS EPOLLIN | EPOLLONESHOT496 497 507 static inline void __ioctx_epoll_ctl($io_ctx_thread & ctx, int op, const char * error) { 498 508 struct epoll_event ev; 499 ev.events = IOEVENTS;509 ev.events = EPOLLIN | EPOLLONESHOT; 500 510 ev.data.u64 = (__u64)&ctx; 501 511 int ret = epoll_ctl(iopoll.epollfd, op, ctx.ring->efd, &ev); … … 514 524 } 515 525 526 void __ioctx_unregister($io_ctx_thread & ctx) { 527 // Read the current epoch so we know when to stop 528 size_t curr = __atomic_load_n(&iopoll.epoch, __ATOMIC_SEQ_CST); 529 530 // Remove the fd from the iopoller 531 __ioctx_epoll_ctl(ctx, EPOLL_CTL_DEL, "REMOVE"); 532 533 // Notify the io poller thread of the shutdown 534 iopoll.run = false; 535 sigval val = { 1 }; 536 pthread_sigqueue( iopoll.thrd, SIGUSR1, val ); 537 538 // Make sure all this is done 539 __atomic_thread_fence(__ATOMIC_SEQ_CST); 540 541 // Wait for the next epoch 542 while(curr == iopoll.epoch && !iopoll.stopped) Pause(); 543 } 544 516 545 //============================================================================================= 517 546 // I/O Context Misc Setup … … 520 549 int ret = syscall( __NR_io_uring_register, ctx.thrd.ring->fd, IORING_REGISTER_FILES, files, count ); 521 550 if( ret < 0 ) { 522 abort( "KERNEL ERROR: IO_URING SYSCALL- (%d) %s\n", (int)errno, strerror(errno) );551 abort( "KERNEL ERROR: IO_URING REGISTER - (%d) %s\n", (int)errno, strerror(errno) ); 523 552 } 524 553
Note:
See TracChangeset
for help on using the changeset viewer.