Changeset d60d30e for libcfa/src/concurrency/io.cfa
- Timestamp:
- Feb 19, 2021, 3:10:10 PM (2 years ago)
- Branches:
- arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 4c4d854
- Parents:
- 4f762d3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/io.cfa
r4f762d3 rd60d30e 17 17 18 18 #if defined(__CFA_DEBUG__) 19 #define __CFA_DEBUG_PRINT_IO__20 #define __CFA_DEBUG_PRINT_IO_CORE__19 // #define __CFA_DEBUG_PRINT_IO__ 20 // #define __CFA_DEBUG_PRINT_IO_CORE__ 21 21 #endif 22 22 … … 83 83 //============================================================================================= 84 84 static int __io_uring_enter( struct $io_context & ctx, unsigned to_submit, bool get ) { 85 __STATS__( false, io.calls.count++; ) 85 86 bool need_sys_to_submit = false; 86 87 bool need_sys_to_complete = false; … … 109 110 if( need_sys_to_submit || need_sys_to_complete ) { 110 111 __cfadbg_print_safe(io_core, "Kernel I/O : IO_URING enter %d %u %u\n", ctx.fd, to_submit, flags); 112 __STATS__( false, io.calls.blocks++; ) 111 113 ret = syscall( __NR_io_uring_enter, ctx.fd, to_submit, 0, flags, (sigset_t *)0p, _NSIG / 8); 112 114 __cfadbg_print_safe(io_core, "Kernel I/O : IO_URING %d returned %d\n", ctx.fd, ret); … … 124 126 static inline __u32 __release_sqes( struct $io_context & ); 125 127 126 static [int, bool] __drain_io( & struct $io_contextctx ) {128 static bool __drain_io( struct $io_context & ctx ) { 127 129 unsigned to_submit = __flush( ctx ); 128 130 int ret = __io_uring_enter( ctx, to_submit, true ); … … 132 134 case EINTR: 133 135 case EBUSY: 134 return [0, true]; 136 // Update statistics 137 __STATS__( false, io.calls.errors.busy ++; ) 138 return true; 135 139 break; 136 140 default: … … 141 145 // update statistics 142 146 if (to_submit > 0) { 143 __STATS__( false, 144 if( to_submit > 0 ) { 145 io.submit_q.submit_avg.rdy += to_submit; 146 io.submit_q.submit_avg.csm += ret; 147 io.submit_q.submit_avg.cnt += 1; 148 } 149 ) 147 __STATS__( false, io.calls.submitted += ret; ) 150 148 /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num ); 151 149 … … 170 168 // Nothing was new return 0 171 169 if (head == tail) { 172 return [0, to_submit > 0];170 return ctx.sq.to_submit > 0; 173 171 } 174 172 175 173 __u32 count = tail - head; 176 174 /* paranoid */ verify( count != 0 ); 175 __STATS__( false, io.calls.submitted += count; ) 176 177 177 for(i; count) { 178 178 unsigned idx = (head + i) & mask; … … 195 195 __atomic_store_n( ctx.cq.head, head + count, __ATOMIC_SEQ_CST ); 196 196 197 return [count, count > 0 || to_submit > 0];197 return count > 0 || to_submit > 0; 198 198 } 199 199 … … 212 212 213 213 // Drain the io 214 int count; 215 bool again; 216 [count, again] = __drain_io( this ); 214 bool again = __drain_io( this ); 217 215 218 216 if(!again) reset--; 219 220 // Update statistics221 __STATS__( false,222 io.complete_q.completed_avg.val += count;223 io.complete_q.completed_avg.cnt += 1;224 )225 217 226 218 // If we got something, just yield and check again … … 241 233 242 234 __STATS__( false, 243 io.c omplete_q.blocks += 1;235 io.calls.blocks += 1; 244 236 ) 245 237 __cfadbg_print_safe(io_core, "Kernel I/O : Parking io poller %d (%p)\n", this.fd, &this); … … 342 334 // Mark the instance as no longer in-use and re-enable interrupts 343 335 __atomic_store_n( &proc->io.lock, false, __ATOMIC_RELEASE ); 336 __STATS__( true, io.alloc.fast += 1; ) 344 337 enable_interrupts( __cfaabi_dbg_ctx ); 345 338 … … 350 343 } 351 344 // The fast path failed, fallback 345 __STATS__( true, io.alloc.fail += 1; ) 352 346 } 353 347 354 348 // Fast path failed, fallback on arbitration 355 349 __atomic_store_n( &proc->io.lock, false, __ATOMIC_RELEASE ); 350 __STATS__( true, io.alloc.slow += 1; ) 356 351 enable_interrupts( __cfaabi_dbg_ctx ); 357 352 … … 409 404 // Mark the instance as no longer in-use, re-enable interrupts and return 410 405 __atomic_store_n( &proc->io.lock, false, __ATOMIC_RELEASE ); 406 __STATS__( true, io.submit.fast += 1; ) 411 407 enable_interrupts( __cfaabi_dbg_ctx ); 412 408 … … 417 413 // Fast path failed, fallback on arbitration 418 414 __atomic_store_n( &proc->io.lock, false, __ATOMIC_RELEASE ); 415 __STATS__( true, io.submit.slow += 1; ) 419 416 enable_interrupts( __cfaabi_dbg_ctx ); 420 417 … … 556 553 __revoke( this, c ); 557 554 555 __STATS__( false, io.alloc.revoke += 1; ) 556 558 557 if(__alloc(c, idxs, want)) { 559 558 __assign( this, c, proc); … … 564 563 __cfadbg_print_safe(io, "Kernel I/O : waiting for available resources\n"); 565 564 565 __STATS__( false, io.alloc.block += 1; ) 566 566 567 // No one has any resources left, wait for something to finish 567 568 // Mark as pending … … 626 627 static void __ioarbiter_flush( $io_arbiter & mutex this, $io_context * ctx ) { 627 628 /* paranoid */ verify( &this == ctx->arbiter ); 629 630 __STATS__( false, io.flush.external += 1; ) 628 631 629 632 __revoke( this, ctx );
Note: See TracChangeset
for help on using the changeset viewer.