| 1 | #include <stdint.h> | 
|---|
| 2 | #include <stdlib.hfa> | 
|---|
| 3 |  | 
|---|
| 4 | #include <unistd.h>                                                             // STDERR_FILENO | 
|---|
| 5 | #include "bits/debug.hfa" | 
|---|
| 6 | #include "stats.hfa" | 
|---|
| 7 |  | 
|---|
| 8 | #if !defined(__CFA_NO_STATISTICS__) | 
|---|
| 9 | void __init_stats( struct __stats_t * stats ) { | 
|---|
| 10 | stats->ready.pick.push.attempt  = 0; | 
|---|
| 11 | stats->ready.pick.push.success  = 0; | 
|---|
| 12 | stats->ready.pick.push.local    = 0; | 
|---|
| 13 | stats->ready.pick.push.lsuccess = 0; | 
|---|
| 14 | stats->ready.pick.pop .probe    = 0; | 
|---|
| 15 | stats->ready.pick.pop .attempt  = 0; | 
|---|
| 16 | stats->ready.pick.pop .success  = 0; | 
|---|
| 17 | stats->ready.pick.pop .local    = 0; | 
|---|
| 18 | stats->ready.pick.pop .lsuccess = 0; | 
|---|
| 19 | stats->ready.sleep.halts   = 0; | 
|---|
| 20 | stats->ready.sleep.cancels = 0; | 
|---|
| 21 | stats->ready.sleep.wakes   = 0; | 
|---|
| 22 | stats->ready.sleep.exits   = 0; | 
|---|
| 23 |  | 
|---|
| 24 | #if defined(HAVE_LINUX_IO_URING_H) | 
|---|
| 25 | stats->io.submit_q.submit_avg.rdy = 0; | 
|---|
| 26 | stats->io.submit_q.submit_avg.csm = 0; | 
|---|
| 27 | stats->io.submit_q.submit_avg.avl = 0; | 
|---|
| 28 | stats->io.submit_q.submit_avg.cnt = 0; | 
|---|
| 29 | stats->io.submit_q.look_avg.val   = 0; | 
|---|
| 30 | stats->io.submit_q.look_avg.cnt   = 0; | 
|---|
| 31 | stats->io.submit_q.look_avg.block = 0; | 
|---|
| 32 | stats->io.submit_q.alloc_avg.val   = 0; | 
|---|
| 33 | stats->io.submit_q.alloc_avg.cnt   = 0; | 
|---|
| 34 | stats->io.submit_q.alloc_avg.block = 0; | 
|---|
| 35 | stats->io.complete_q.completed_avg.val = 0; | 
|---|
| 36 | stats->io.complete_q.completed_avg.slow_cnt = 0; | 
|---|
| 37 | stats->io.complete_q.completed_avg.fast_cnt = 0; | 
|---|
| 38 | #endif | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | void __tally_stats( struct __stats_t * cltr, struct __stats_t * proc ) { | 
|---|
| 42 | __atomic_fetch_add( &cltr->ready.pick.push.attempt , proc->ready.pick.push.attempt , __ATOMIC_SEQ_CST ); | 
|---|
| 43 | __atomic_fetch_add( &cltr->ready.pick.push.success , proc->ready.pick.push.success , __ATOMIC_SEQ_CST ); | 
|---|
| 44 | __atomic_fetch_add( &cltr->ready.pick.push.local   , proc->ready.pick.push.local   , __ATOMIC_SEQ_CST ); | 
|---|
| 45 | __atomic_fetch_add( &cltr->ready.pick.push.lsuccess, proc->ready.pick.push.lsuccess, __ATOMIC_SEQ_CST ); | 
|---|
| 46 | __atomic_fetch_add( &cltr->ready.pick.pop .probe   , proc->ready.pick.pop .probe   , __ATOMIC_SEQ_CST ); | 
|---|
| 47 | __atomic_fetch_add( &cltr->ready.pick.pop .attempt , proc->ready.pick.pop .attempt , __ATOMIC_SEQ_CST ); | 
|---|
| 48 | __atomic_fetch_add( &cltr->ready.pick.pop .success , proc->ready.pick.pop .success , __ATOMIC_SEQ_CST ); | 
|---|
| 49 | __atomic_fetch_add( &cltr->ready.pick.pop .local   , proc->ready.pick.pop .local   , __ATOMIC_SEQ_CST ); | 
|---|
| 50 | __atomic_fetch_add( &cltr->ready.pick.pop .lsuccess, proc->ready.pick.pop .lsuccess, __ATOMIC_SEQ_CST ); | 
|---|
| 51 | __atomic_fetch_add( &cltr->ready.sleep.halts  , proc->ready.sleep.halts  , __ATOMIC_SEQ_CST ); | 
|---|
| 52 | __atomic_fetch_add( &cltr->ready.sleep.cancels, proc->ready.sleep.cancels, __ATOMIC_SEQ_CST ); | 
|---|
| 53 | __atomic_fetch_add( &cltr->ready.sleep.wakes  , proc->ready.sleep.wakes  , __ATOMIC_SEQ_CST ); | 
|---|
| 54 | __atomic_fetch_add( &cltr->ready.sleep.exits  , proc->ready.sleep.exits  , __ATOMIC_SEQ_CST ); | 
|---|
| 55 |  | 
|---|
| 56 | #if defined(HAVE_LINUX_IO_URING_H) | 
|---|
| 57 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.rdy          , proc->io.submit_q.submit_avg.rdy          , __ATOMIC_SEQ_CST ); | 
|---|
| 58 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.csm          , proc->io.submit_q.submit_avg.csm          , __ATOMIC_SEQ_CST ); | 
|---|
| 59 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.avl          , proc->io.submit_q.submit_avg.avl          , __ATOMIC_SEQ_CST ); | 
|---|
| 60 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.cnt          , proc->io.submit_q.submit_avg.cnt          , __ATOMIC_SEQ_CST ); | 
|---|
| 61 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.val            , proc->io.submit_q.look_avg.val            , __ATOMIC_SEQ_CST ); | 
|---|
| 62 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.cnt            , proc->io.submit_q.look_avg.cnt            , __ATOMIC_SEQ_CST ); | 
|---|
| 63 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.block          , proc->io.submit_q.look_avg.block          , __ATOMIC_SEQ_CST ); | 
|---|
| 64 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.val           , proc->io.submit_q.alloc_avg.val           , __ATOMIC_SEQ_CST ); | 
|---|
| 65 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.cnt           , proc->io.submit_q.alloc_avg.cnt           , __ATOMIC_SEQ_CST ); | 
|---|
| 66 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.block         , proc->io.submit_q.alloc_avg.block         , __ATOMIC_SEQ_CST ); | 
|---|
| 67 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.val     , proc->io.complete_q.completed_avg.val     , __ATOMIC_SEQ_CST ); | 
|---|
| 68 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.slow_cnt, proc->io.complete_q.completed_avg.slow_cnt, __ATOMIC_SEQ_CST ); | 
|---|
| 69 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.fast_cnt, proc->io.complete_q.completed_avg.fast_cnt, __ATOMIC_SEQ_CST ); | 
|---|
| 70 | #endif | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | void __print_stats( struct __stats_t * stats ) with( *stats ) { | 
|---|
| 74 |  | 
|---|
| 75 | double push_sur = (100.0 * ((double)ready.pick.push.success) / ready.pick.push.attempt); | 
|---|
| 76 | double pop_sur  = (100.0 * ((double)ready.pick.pop .success) / ready.pick.pop .attempt); | 
|---|
| 77 |  | 
|---|
| 78 | double push_len = ((double)ready.pick.push.attempt) / ready.pick.push.success; | 
|---|
| 79 | double pop_len  = ((double)ready.pick.pop .attempt) / ready.pick.pop .success; | 
|---|
| 80 |  | 
|---|
| 81 | double lpush_sur = (100.0 * ((double)ready.pick.push.lsuccess) / ready.pick.push.local); | 
|---|
| 82 | double lpop_sur  = (100.0 * ((double)ready.pick.pop .lsuccess) / ready.pick.pop .local); | 
|---|
| 83 |  | 
|---|
| 84 | double lpush_len = ((double)ready.pick.push.local) / ready.pick.push.lsuccess; | 
|---|
| 85 | double lpop_len  = ((double)ready.pick.pop .local) / ready.pick.pop .lsuccess; | 
|---|
| 86 |  | 
|---|
| 87 | #if defined(HAVE_LINUX_IO_URING_H) | 
|---|
| 88 | double avgrdy = ((double)io.submit_q.submit_avg.rdy) / io.submit_q.submit_avg.cnt; | 
|---|
| 89 | double avgcsm = ((double)io.submit_q.submit_avg.csm) / io.submit_q.submit_avg.cnt; | 
|---|
| 90 | double avgavl = ((double)io.submit_q.submit_avg.avl) / io.submit_q.submit_avg.cnt; | 
|---|
| 91 |  | 
|---|
| 92 | double lavgv = 0; | 
|---|
| 93 | double lavgb = 0; | 
|---|
| 94 | if(io.submit_q.look_avg.cnt != 0) { | 
|---|
| 95 | lavgv = ((double)io.submit_q.look_avg.val  ) / io.submit_q.look_avg.cnt; | 
|---|
| 96 | lavgb = ((double)io.submit_q.look_avg.block) / io.submit_q.look_avg.cnt; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | double aavgv = 0; | 
|---|
| 100 | double aavgb = 0; | 
|---|
| 101 | if(io.submit_q.alloc_avg.cnt != 0) { | 
|---|
| 102 | aavgv = ((double)io.submit_q.alloc_avg.val  ) / io.submit_q.alloc_avg.cnt; | 
|---|
| 103 | aavgb = ((double)io.submit_q.alloc_avg.block) / io.submit_q.alloc_avg.cnt; | 
|---|
| 104 | } | 
|---|
| 105 | #endif | 
|---|
| 106 |  | 
|---|
| 107 | __cfaabi_bits_print_safe( STDOUT_FILENO, | 
|---|
| 108 | "----- Ready Q Stats -----\n" | 
|---|
| 109 | "- total threads run      : %'15lu\n" | 
|---|
| 110 | "- total threads scheduled: %'15lu\n" | 
|---|
| 111 | "- push average probe len : %'18.2lf, %'18.2lf%% (%'15lu attempts)\n" | 
|---|
| 112 | "- pop  average probe len : %'18.2lf, %'18.2lf%% (%'15lu attempts)\n" | 
|---|
| 113 | "- local push avg prb len : %'18.2lf, %'18.2lf%% (%'15lu attempts)\n" | 
|---|
| 114 | "- local pop  avg prb len : %'18.2lf, %'18.2lf%% (%'15lu attempts)\n" | 
|---|
| 115 | "- Idle Sleep -\n" | 
|---|
| 116 | "-- halts                 : %'15lu\n" | 
|---|
| 117 | "-- cancelled halts       : %'15lu\n" | 
|---|
| 118 | "-- schedule wake         : %'15lu\n" | 
|---|
| 119 | "-- wake on exit          : %'15lu\n" | 
|---|
| 120 | #if defined(HAVE_LINUX_IO_URING_H) | 
|---|
| 121 | "\n" | 
|---|
| 122 | "----- I/O Stats -----\n" | 
|---|
| 123 | "- total submit calls     : %'15lu\n" | 
|---|
| 124 | "- avg ready entries      : %'18.2lf\n" | 
|---|
| 125 | "- avg submitted entries  : %'18.2lf\n" | 
|---|
| 126 | "- avg available entries  : %'18.2lf\n" | 
|---|
| 127 | "- total ready search     : %'15lu\n" | 
|---|
| 128 | "- avg ready search len   : %'18.2lf\n" | 
|---|
| 129 | "- avg ready search block : %'18.2lf\n" | 
|---|
| 130 | "- total alloc search     : %'15lu\n" | 
|---|
| 131 | "- avg alloc search len   : %'18.2lf\n" | 
|---|
| 132 | "- avg alloc search block : %'18.2lf\n" | 
|---|
| 133 | "- total wait calls       : %'15lu   (%'lu slow, %'lu fast)\n" | 
|---|
| 134 | "- avg completion/wait    : %'18.2lf\n" | 
|---|
| 135 | #endif | 
|---|
| 136 | , ready.pick.pop.success | 
|---|
| 137 | , ready.pick.push.success | 
|---|
| 138 | , push_len, push_sur, ready.pick.push.attempt | 
|---|
| 139 | , pop_len , pop_sur , ready.pick.pop .attempt | 
|---|
| 140 | , lpush_len, lpush_sur, ready.pick.push.local | 
|---|
| 141 | , lpop_len , lpop_sur , ready.pick.pop .local | 
|---|
| 142 | , ready.sleep.halts, ready.sleep.cancels, ready.sleep.wakes, ready.sleep.exits | 
|---|
| 143 | #if defined(HAVE_LINUX_IO_URING_H) | 
|---|
| 144 | , io.submit_q.submit_avg.cnt | 
|---|
| 145 | , avgrdy | 
|---|
| 146 | , avgcsm | 
|---|
| 147 | , avgavl | 
|---|
| 148 | , io.submit_q.look_avg.cnt | 
|---|
| 149 | , lavgv | 
|---|
| 150 | , lavgb | 
|---|
| 151 | , io.submit_q.alloc_avg.cnt | 
|---|
| 152 | , aavgv | 
|---|
| 153 | , aavgb | 
|---|
| 154 | , io.complete_q.completed_avg.slow_cnt + io.complete_q.completed_avg.fast_cnt | 
|---|
| 155 | , io.complete_q.completed_avg.slow_cnt,  io.complete_q.completed_avg.fast_cnt | 
|---|
| 156 | , ((double)io.complete_q.completed_avg.val) / (io.complete_q.completed_avg.slow_cnt + io.complete_q.completed_avg.fast_cnt) | 
|---|
| 157 | #endif | 
|---|
| 158 | ); | 
|---|
| 159 | } | 
|---|
| 160 | #endif | 
|---|