| 1 | #include <stdint.h>
 | 
|---|
| 2 | #include <stdlib.hfa>
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include <unistd.h>                                                             // STDERR_FILENO
 | 
|---|
| 5 | #include <inttypes.h>
 | 
|---|
| 6 | #include "bits/debug.hfa"
 | 
|---|
| 7 | #include "stats.hfa"
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #if !defined(__CFA_NO_STATISTICS__)
 | 
|---|
| 10 |         void __init_stats( struct __stats_t * stats ) {
 | 
|---|
| 11 |                 stats->ready.pick.push.attempt  = 0;
 | 
|---|
| 12 |                 stats->ready.pick.push.success  = 0;
 | 
|---|
| 13 |                 stats->ready.pick.push.local    = 0;
 | 
|---|
| 14 |                 stats->ready.pick.push.lsuccess = 0;
 | 
|---|
| 15 |                 stats->ready.pick.pop .probe    = 0;
 | 
|---|
| 16 |                 stats->ready.pick.pop .attempt  = 0;
 | 
|---|
| 17 |                 stats->ready.pick.pop .success  = 0;
 | 
|---|
| 18 |                 stats->ready.pick.pop .local    = 0;
 | 
|---|
| 19 |                 stats->ready.pick.pop .lsuccess = 0;
 | 
|---|
| 20 |                 stats->ready.threads.migration = 0;
 | 
|---|
| 21 |                 stats->ready.sleep.halts   = 0;
 | 
|---|
| 22 |                 stats->ready.sleep.cancels = 0;
 | 
|---|
| 23 |                 stats->ready.sleep.wakes   = 0;
 | 
|---|
| 24 |                 stats->ready.sleep.exits   = 0;
 | 
|---|
| 25 | 
 | 
|---|
| 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;
 | 
|---|
| 42 |                 #endif
 | 
|---|
| 43 |         }
 | 
|---|
| 44 | 
 | 
|---|
| 45 |         void __tally_stats( struct __stats_t * cltr, struct __stats_t * proc ) {
 | 
|---|
| 46 |                 __atomic_fetch_add( &cltr->ready.pick.push.attempt , proc->ready.pick.push.attempt , __ATOMIC_SEQ_CST );
 | 
|---|
| 47 |                 __atomic_fetch_add( &cltr->ready.pick.push.success , proc->ready.pick.push.success , __ATOMIC_SEQ_CST );
 | 
|---|
| 48 |                 __atomic_fetch_add( &cltr->ready.pick.push.local   , proc->ready.pick.push.local   , __ATOMIC_SEQ_CST );
 | 
|---|
| 49 |                 __atomic_fetch_add( &cltr->ready.pick.push.lsuccess, proc->ready.pick.push.lsuccess, __ATOMIC_SEQ_CST );
 | 
|---|
| 50 |                 __atomic_fetch_add( &cltr->ready.pick.pop .probe   , proc->ready.pick.pop .probe   , __ATOMIC_SEQ_CST );
 | 
|---|
| 51 |                 __atomic_fetch_add( &cltr->ready.pick.pop .attempt , proc->ready.pick.pop .attempt , __ATOMIC_SEQ_CST );
 | 
|---|
| 52 |                 __atomic_fetch_add( &cltr->ready.pick.pop .success , proc->ready.pick.pop .success , __ATOMIC_SEQ_CST );
 | 
|---|
| 53 |                 __atomic_fetch_add( &cltr->ready.pick.pop .local   , proc->ready.pick.pop .local   , __ATOMIC_SEQ_CST );
 | 
|---|
| 54 |                 __atomic_fetch_add( &cltr->ready.pick.pop .lsuccess, proc->ready.pick.pop .lsuccess, __ATOMIC_SEQ_CST );
 | 
|---|
| 55 |                 __atomic_fetch_add( &cltr->ready.threads.migration, proc->ready.threads.migration, __ATOMIC_SEQ_CST );
 | 
|---|
| 56 |                 __atomic_fetch_add( &cltr->ready.sleep.halts  , proc->ready.sleep.halts  , __ATOMIC_SEQ_CST );
 | 
|---|
| 57 |                 __atomic_fetch_add( &cltr->ready.sleep.cancels, proc->ready.sleep.cancels, __ATOMIC_SEQ_CST );
 | 
|---|
| 58 |                 __atomic_fetch_add( &cltr->ready.sleep.wakes  , proc->ready.sleep.wakes  , __ATOMIC_SEQ_CST );
 | 
|---|
| 59 |                 __atomic_fetch_add( &cltr->ready.sleep.exits  , proc->ready.sleep.exits  , __ATOMIC_SEQ_CST );
 | 
|---|
| 60 | 
 | 
|---|
| 61 |                 #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 );
 | 
|---|
| 63 |                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.csm     , proc->io.submit_q.submit_avg.csm     , __ATOMIC_SEQ_CST );
 | 
|---|
| 64 |                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.avl     , proc->io.submit_q.submit_avg.avl     , __ATOMIC_SEQ_CST );
 | 
|---|
| 65 |                         __atomic_fetch_add( &cltr->io.submit_q.submit_avg.cnt     , proc->io.submit_q.submit_avg.cnt     , __ATOMIC_SEQ_CST );
 | 
|---|
| 66 |                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.val       , proc->io.submit_q.look_avg.val       , __ATOMIC_SEQ_CST );
 | 
|---|
| 67 |                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.cnt       , proc->io.submit_q.look_avg.cnt       , __ATOMIC_SEQ_CST );
 | 
|---|
| 68 |                         __atomic_fetch_add( &cltr->io.submit_q.look_avg.block     , proc->io.submit_q.look_avg.block     , __ATOMIC_SEQ_CST );
 | 
|---|
| 69 |                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.val      , proc->io.submit_q.alloc_avg.val      , __ATOMIC_SEQ_CST );
 | 
|---|
| 70 |                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.cnt      , proc->io.submit_q.alloc_avg.cnt      , __ATOMIC_SEQ_CST );
 | 
|---|
| 71 |                         __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.block    , proc->io.submit_q.alloc_avg.block    , __ATOMIC_SEQ_CST );
 | 
|---|
| 72 |                         __atomic_fetch_add( &cltr->io.submit_q.helped             , proc->io.submit_q.helped             , __ATOMIC_SEQ_CST );
 | 
|---|
| 73 |                         __atomic_fetch_add( &cltr->io.submit_q.leader             , proc->io.submit_q.leader             , __ATOMIC_SEQ_CST );
 | 
|---|
| 74 |                         __atomic_fetch_add( &cltr->io.submit_q.busy               , proc->io.submit_q.busy               , __ATOMIC_SEQ_CST );
 | 
|---|
| 75 |                         __atomic_fetch_add( &cltr->io.complete_q.completed_avg.val, proc->io.complete_q.completed_avg.val, __ATOMIC_SEQ_CST );
 | 
|---|
| 76 |                         __atomic_fetch_add( &cltr->io.complete_q.completed_avg.cnt, proc->io.complete_q.completed_avg.cnt, __ATOMIC_SEQ_CST );
 | 
|---|
| 77 |                         __atomic_fetch_add( &cltr->io.complete_q.blocks           , proc->io.complete_q.blocks           , __ATOMIC_SEQ_CST );
 | 
|---|
| 78 |                 #endif
 | 
|---|
| 79 |         }
 | 
|---|
| 80 | 
 | 
|---|
| 81 |         void __print_stats( struct __stats_t * stats, int flags, bool cluster, const char * name, void * id ) with( *stats ) {
 | 
|---|
| 82 | 
 | 
|---|
| 83 |                 if( flags & CFA_STATS_READY_Q ) {
 | 
|---|
| 84 |                         double push_sur = (100.0 * ((double)ready.pick.push.success) / ready.pick.push.attempt);
 | 
|---|
| 85 |                         double pop_sur  = (100.0 * ((double)ready.pick.pop .success) / ready.pick.pop .attempt);
 | 
|---|
| 86 | 
 | 
|---|
| 87 |                         double push_len = ((double)ready.pick.push.attempt) / ready.pick.push.success;
 | 
|---|
| 88 |                         double pop_len  = ((double)ready.pick.pop .attempt) / ready.pick.pop .success;
 | 
|---|
| 89 | 
 | 
|---|
| 90 |                         double lpush_sur = (100.0 * ((double)ready.pick.push.lsuccess) / ready.pick.push.local);
 | 
|---|
| 91 |                         double lpop_sur  = (100.0 * ((double)ready.pick.pop .lsuccess) / ready.pick.pop .local);
 | 
|---|
| 92 | 
 | 
|---|
| 93 |                         double lpush_len = ((double)ready.pick.push.local) / ready.pick.push.lsuccess;
 | 
|---|
| 94 |                         double lpop_len  = ((double)ready.pick.pop .local) / ready.pick.pop .lsuccess;
 | 
|---|
| 95 | 
 | 
|---|
| 96 |                         __cfaabi_bits_print_safe( STDOUT_FILENO,
 | 
|---|
| 97 |                                 "----- %s \"%s\" (%p) - Ready Q Stats -----\n"
 | 
|---|
| 98 |                                 "- total threads run      : %'15" PRIu64 "\n"
 | 
|---|
| 99 |                                 "- total threads scheduled: %'15" PRIu64 "\n"
 | 
|---|
| 100 |                                 "- push average probe len : %'18.2lf, %'18.2lf%% (%'15" PRIu64 " attempts)\n"
 | 
|---|
| 101 |                                 "- pop  average probe len : %'18.2lf, %'18.2lf%% (%'15" PRIu64 " attempts)\n"
 | 
|---|
| 102 |                                 "- local push avg prb len : %'18.2lf, %'18.2lf%% (%'15" PRIu64 " attempts)\n"
 | 
|---|
| 103 |                                 "- local pop  avg prb len : %'18.2lf, %'18.2lf%% (%'15" PRIu64 " attempts)\n"
 | 
|---|
| 104 |                                 "- thread migrations      : %'15" PRIu64 "\n"
 | 
|---|
| 105 |                                 "- Idle Sleep -\n"
 | 
|---|
| 106 |                                 "-- halts                 : %'15" PRIu64 "\n"
 | 
|---|
| 107 |                                 "-- cancelled halts       : %'15" PRIu64 "\n"
 | 
|---|
| 108 |                                 "-- schedule wake         : %'15" PRIu64 "\n"
 | 
|---|
| 109 |                                 "-- wake on exit          : %'15" PRIu64 "\n"
 | 
|---|
| 110 |                                 "\n"
 | 
|---|
| 111 |                                 , cluster ? "Cluster" : "Processor",  name, id
 | 
|---|
| 112 |                                 , ready.pick.pop.success
 | 
|---|
| 113 |                                 , ready.pick.push.success
 | 
|---|
| 114 |                                 , push_len, push_sur, ready.pick.push.attempt
 | 
|---|
| 115 |                                 , pop_len , pop_sur , ready.pick.pop .attempt
 | 
|---|
| 116 |                                 , lpush_len, lpush_sur, ready.pick.push.local
 | 
|---|
| 117 |                                 , lpop_len , lpop_sur , ready.pick.pop .local
 | 
|---|
| 118 |                                 , ready.threads.migration
 | 
|---|
| 119 |                                 , ready.sleep.halts, ready.sleep.cancels, ready.sleep.wakes, ready.sleep.exits
 | 
|---|
| 120 |                         );
 | 
|---|
| 121 |                 }
 | 
|---|
| 122 | 
 | 
|---|
| 123 |                 #if defined(CFA_HAVE_LINUX_IO_URING_H)
 | 
|---|
| 124 |                         if( flags & CFA_STATS_IO ) {
 | 
|---|
| 125 |                                 double avgrdy = ((double)io.submit_q.submit_avg.rdy) / io.submit_q.submit_avg.cnt;
 | 
|---|
| 126 |                                 double avgcsm = ((double)io.submit_q.submit_avg.csm) / io.submit_q.submit_avg.cnt;
 | 
|---|
| 127 | 
 | 
|---|
| 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 |                                 }
 | 
|---|
| 134 | 
 | 
|---|
| 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 |                                 }
 | 
|---|
| 141 | 
 | 
|---|
| 142 |                                 __cfaabi_bits_print_safe( STDOUT_FILENO,
 | 
|---|
| 143 |                                         "----- %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"
 | 
|---|
| 159 |                                         "\n"
 | 
|---|
| 160 |                                         , cluster ? "Cluster" : "Processor",  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
 | 
|---|
| 171 |                                 );
 | 
|---|
| 172 |                         }
 | 
|---|
| 173 |                 #endif
 | 
|---|
| 174 |         }
 | 
|---|
| 175 | #endif
 | 
|---|