Changeset d60d30e for libcfa/src/concurrency
- Timestamp:
- Feb 19, 2021, 3:10:10 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 4c4d854
- Parents:
- 4f762d3
- Location:
- libcfa/src/concurrency
- Files:
-
- 3 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 ); -
libcfa/src/concurrency/stats.cfa
r4f762d3 rd60d30e 25 25 26 26 #if defined(CFA_HAVE_LINUX_IO_URING_H) 27 stats->io.submit_q.submit_avg.rdy = 0; 28 stats->io.submit_q.submit_avg.csm = 0; 29 stats->io.submit_q.submit_avg.cnt = 0; 30 stats->io.submit_q.look_avg.val = 0; 31 stats->io.submit_q.look_avg.cnt = 0; 32 stats->io.submit_q.look_avg.block = 0; 33 stats->io.submit_q.alloc_avg.val = 0; 34 stats->io.submit_q.alloc_avg.cnt = 0; 35 stats->io.submit_q.alloc_avg.block = 0; 36 stats->io.submit_q.helped = 0; 37 stats->io.submit_q.leader = 0; 38 stats->io.submit_q.busy = 0; 39 stats->io.complete_q.completed_avg.val = 0; 40 stats->io.complete_q.completed_avg.cnt = 0; 41 stats->io.complete_q.blocks = 0; 27 stats->io.alloc.fast = 0; 28 stats->io.alloc.slow = 0; 29 stats->io.alloc.fail = 0; 30 stats->io.alloc.revoke = 0; 31 stats->io.alloc.block = 0; 32 stats->io.submit.fast = 0; 33 stats->io.submit.slow = 0; 34 stats->io.flush.external = 0; 35 stats->io.calls.count = 0; 36 stats->io.calls.submitted = 0; 37 stats->io.calls.completed = 0; 38 stats->io.calls.blocks = 0; 39 stats->io.calls.errors.busy = 0; 42 40 #endif 43 41 } … … 60 58 61 59 #if defined(CFA_HAVE_LINUX_IO_URING_H) 62 __atomic_fetch_add( &cltr->io.submit_q.submit_avg.rdy , proc->io.submit_q.submit_avg.rdy , __ATOMIC_SEQ_CST ); proc->io.submit_q.submit_avg.rdy = 0; 63 __atomic_fetch_add( &cltr->io.submit_q.submit_avg.csm , proc->io.submit_q.submit_avg.csm , __ATOMIC_SEQ_CST ); proc->io.submit_q.submit_avg.csm = 0; 64 __atomic_fetch_add( &cltr->io.submit_q.submit_avg.avl , proc->io.submit_q.submit_avg.avl , __ATOMIC_SEQ_CST ); proc->io.submit_q.submit_avg.avl = 0; 65 __atomic_fetch_add( &cltr->io.submit_q.submit_avg.cnt , proc->io.submit_q.submit_avg.cnt , __ATOMIC_SEQ_CST ); proc->io.submit_q.submit_avg.cnt = 0; 66 __atomic_fetch_add( &cltr->io.submit_q.look_avg.val , proc->io.submit_q.look_avg.val , __ATOMIC_SEQ_CST ); proc->io.submit_q.look_avg.val = 0; 67 __atomic_fetch_add( &cltr->io.submit_q.look_avg.cnt , proc->io.submit_q.look_avg.cnt , __ATOMIC_SEQ_CST ); proc->io.submit_q.look_avg.cnt = 0; 68 __atomic_fetch_add( &cltr->io.submit_q.look_avg.block , proc->io.submit_q.look_avg.block , __ATOMIC_SEQ_CST ); proc->io.submit_q.look_avg.block = 0; 69 __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.val , proc->io.submit_q.alloc_avg.val , __ATOMIC_SEQ_CST ); proc->io.submit_q.alloc_avg.val = 0; 70 __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.cnt , proc->io.submit_q.alloc_avg.cnt , __ATOMIC_SEQ_CST ); proc->io.submit_q.alloc_avg.cnt = 0; 71 __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.block , proc->io.submit_q.alloc_avg.block , __ATOMIC_SEQ_CST ); proc->io.submit_q.alloc_avg.block = 0; 72 __atomic_fetch_add( &cltr->io.submit_q.helped , proc->io.submit_q.helped , __ATOMIC_SEQ_CST ); proc->io.submit_q.helped = 0; 73 __atomic_fetch_add( &cltr->io.submit_q.leader , proc->io.submit_q.leader , __ATOMIC_SEQ_CST ); proc->io.submit_q.leader = 0; 74 __atomic_fetch_add( &cltr->io.submit_q.busy , proc->io.submit_q.busy , __ATOMIC_SEQ_CST ); proc->io.submit_q.busy = 0; 75 __atomic_fetch_add( &cltr->io.complete_q.completed_avg.val, proc->io.complete_q.completed_avg.val, __ATOMIC_SEQ_CST ); proc->io.complete_q.completed_avg.val = 0; 76 __atomic_fetch_add( &cltr->io.complete_q.completed_avg.cnt, proc->io.complete_q.completed_avg.cnt, __ATOMIC_SEQ_CST ); proc->io.complete_q.completed_avg.cnt = 0; 77 __atomic_fetch_add( &cltr->io.complete_q.blocks , proc->io.complete_q.blocks , __ATOMIC_SEQ_CST ); proc->io.complete_q.blocks = 0; 60 __atomic_fetch_add( &cltr->io.alloc.fast , proc->io.alloc.fast , __ATOMIC_SEQ_CST ); proc->io.alloc.fast = 0; 61 __atomic_fetch_add( &cltr->io.alloc.slow , proc->io.alloc.slow , __ATOMIC_SEQ_CST ); proc->io.alloc.slow = 0; 62 __atomic_fetch_add( &cltr->io.alloc.fail , proc->io.alloc.fail , __ATOMIC_SEQ_CST ); proc->io.alloc.fail = 0; 63 __atomic_fetch_add( &cltr->io.alloc.revoke , proc->io.alloc.revoke , __ATOMIC_SEQ_CST ); proc->io.alloc.revoke = 0; 64 __atomic_fetch_add( &cltr->io.alloc.block , proc->io.alloc.block , __ATOMIC_SEQ_CST ); proc->io.alloc.block = 0; 65 __atomic_fetch_add( &cltr->io.submit.fast , proc->io.submit.fast , __ATOMIC_SEQ_CST ); proc->io.submit.fast = 0; 66 __atomic_fetch_add( &cltr->io.submit.slow , proc->io.submit.slow , __ATOMIC_SEQ_CST ); proc->io.submit.slow = 0; 67 __atomic_fetch_add( &cltr->io.flush.external , proc->io.flush.external , __ATOMIC_SEQ_CST ); proc->io.flush.external = 0; 68 __atomic_fetch_add( &cltr->io.calls.count , proc->io.calls.count , __ATOMIC_SEQ_CST ); proc->io.calls.count = 0; 69 __atomic_fetch_add( &cltr->io.calls.submitted , proc->io.calls.submitted , __ATOMIC_SEQ_CST ); proc->io.calls.submitted = 0; 70 __atomic_fetch_add( &cltr->io.calls.completed , proc->io.calls.completed , __ATOMIC_SEQ_CST ); proc->io.calls.completed = 0; 71 __atomic_fetch_add( &cltr->io.calls.blocks , proc->io.calls.blocks , __ATOMIC_SEQ_CST ); proc->io.calls.blocks = 0; 72 __atomic_fetch_add( &cltr->io.calls.errors.busy, proc->io.calls.errors.busy, __ATOMIC_SEQ_CST ); proc->io.calls.errors.busy = 0; 78 73 #endif 79 74 } … … 123 118 #if defined(CFA_HAVE_LINUX_IO_URING_H) 124 119 if( flags & CFA_STATS_IO ) { 125 double avgrdy = ((double)io.submit_q.submit_avg.rdy) / io.submit_q.submit_avg.cnt;126 double avg csm = ((double)io.submit_q.submit_avg.csm) / io.submit_q.submit_avg.cnt;120 uint64_t total_allocs = io.alloc.fast + io.alloc.slow; 121 double avgfasta = ((double)io.alloc.fast) / total_allocs; 127 122 128 double lavgv = 0; 129 double lavgb = 0; 130 if(io.submit_q.look_avg.cnt != 0) { 131 lavgv = ((double)io.submit_q.look_avg.val ) / io.submit_q.look_avg.cnt; 132 lavgb = ((double)io.submit_q.look_avg.block) / io.submit_q.look_avg.cnt; 133 } 123 uint64_t total_submits = io.submit.fast + io.submit.slow; 124 double avgfasts = ((double)io.submit.fast) / total_submits; 134 125 135 double aavgv = 0; 136 double aavgb = 0; 137 if(io.submit_q.alloc_avg.cnt != 0) { 138 aavgv = ((double)io.submit_q.alloc_avg.val ) / io.submit_q.alloc_avg.cnt; 139 aavgb = ((double)io.submit_q.alloc_avg.block) / io.submit_q.alloc_avg.cnt; 140 } 126 double avgsubs = ((double)io.calls.submitted) / io.calls.count; 127 double avgcomp = ((double)io.calls.completed) / io.calls.count; 141 128 142 129 __cfaabi_bits_print_safe( STDOUT_FILENO, 143 130 "----- %s \"%s\" (%p) - I/O Stats -----\n" 144 "- total submit calls: %'15" PRIu64 "\n"145 "- avg ready entries : %'18.2lf\n"146 "- avg submitted entries : %'18.2lf\n"147 "- total helped entries : %'15" PRIu64 "\n"148 "- total leader entries: %'15" PRIu64 "\n"149 "- total busy submit: %'15" PRIu64 "\n"150 "- total ready search: %'15" PRIu64 "\n"151 "- avg ready search len : %'18.2lf\n"152 "- avg ready search block : %'18.2lf\n"153 "- total alloc search: %'15" PRIu64 "\n"154 "- avg alloc search len : %'18.2lf\n"155 "- avg alloc search block : %'18.2lf\n"156 "- total wait calls : %'15" PRIu64 "\n"157 "- avg completion/wait : %'18.2lf\n"158 "- total completion blocks: %'15" PRIu64 "\n"131 "- total allocations : %'15" PRIu64 "\n" 132 "- fast allocations : %'15" PRIu64 " (%'18.2lf) \n" 133 "- fast enomem : %'15" PRIu64 "\n" 134 "- slow allocations : %'15" PRIu64 "\n" 135 "- revokes for alloc : %'15" PRIu64 "\n" 136 "- blocks for alloc : %'15" PRIu64 "\n" 137 "- total submits : %'15" PRIu64 "\n" 138 "- fast submits : %'15" PRIu64 " (%'18.2lf) \n" 139 "- slow submits : %'15" PRIu64 "\n" 140 "- flush external submits : %'15" PRIu64 "\n" 141 "- io_uring_enter calls : %'15" PRIu64 "\n" 142 "- submits : %'15" PRIu64 " (%'18.2lf) \n" 143 "- completes : %'15" PRIu64 " (%'18.2lf) \n" 144 "- blocking calls : %'15" PRIu64 "\n" 145 "- io_uring_enter EBUSYs : %'15" PRIu64 "\n" 159 146 "\n" 160 147 , type, name, id 161 , io.submit_q.submit_avg.cnt 162 , avgrdy, avgcsm 163 , io.submit_q.helped, io.submit_q.leader, io.submit_q.busy 164 , io.submit_q.look_avg.cnt 165 , lavgv, lavgb 166 , io.submit_q.alloc_avg.cnt 167 , aavgv, aavgb 168 , io.complete_q.completed_avg.cnt 169 , ((double)io.complete_q.completed_avg.val) / io.complete_q.completed_avg.cnt 170 , io.complete_q.blocks 148 , total_allocs 149 , io.alloc.fast, avgfasta 150 , io.alloc.fail 151 , io.alloc.slow 152 , io.alloc.revoke 153 , io.alloc.block 154 , total_submits 155 , io.submit.fast, avgfasts 156 , io.submit.slow 157 , io.flush.external 158 , io.calls.count 159 , io.calls.submitted, avgsubs 160 , io.calls.completed, avgcomp 161 , io.calls.blocks 162 , io.calls.errors.busy 171 163 ); 172 164 } -
libcfa/src/concurrency/stats.hfa
r4f762d3 rd60d30e 66 66 struct __attribute__((aligned(64))) __stats_io_t{ 67 67 struct { 68 volatile uint64_t fast; 69 volatile uint64_t slow; 70 volatile uint64_t fail; 71 volatile uint64_t revoke; 72 volatile uint64_t block; 73 } alloc; 74 struct { 75 volatile uint64_t fast; 76 volatile uint64_t slow; 77 } submit; 78 struct { 79 volatile uint64_t external; 80 } flush; 81 struct { 82 volatile uint64_t count; 83 volatile uint64_t submitted; 84 volatile uint64_t completed; 85 volatile uint64_t blocks; 68 86 struct { 69 volatile uint64_t rdy; 70 volatile uint64_t csm; 71 volatile uint64_t avl; 72 volatile uint64_t cnt; 73 } submit_avg; 74 struct { 75 volatile uint64_t val; 76 volatile uint64_t cnt; 77 volatile uint64_t block; 78 } look_avg; 79 struct { 80 volatile uint64_t val; 81 volatile uint64_t cnt; 82 volatile uint64_t block; 83 } alloc_avg; 84 volatile uint64_t helped; 85 volatile uint64_t leader; 86 volatile uint64_t busy; 87 } submit_q; 88 struct { 89 struct { 90 volatile uint64_t val; 91 volatile uint64_t cnt; 92 } completed_avg; 93 volatile uint64_t blocks; 94 } complete_q; 87 volatile uint64_t busy; 88 } errors; 89 } calls; 95 90 }; 96 91 #endif
Note: See TracChangeset
for help on using the changeset viewer.