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(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.avl = 0; |
---|
30 | stats->io.submit_q.submit_avg.cnt = 0; |
---|
31 | stats->io.submit_q.look_avg.val = 0; |
---|
32 | stats->io.submit_q.look_avg.cnt = 0; |
---|
33 | stats->io.submit_q.look_avg.block = 0; |
---|
34 | stats->io.submit_q.alloc_avg.val = 0; |
---|
35 | stats->io.submit_q.alloc_avg.cnt = 0; |
---|
36 | stats->io.submit_q.alloc_avg.block = 0; |
---|
37 | stats->io.complete_q.completed_avg.val = 0; |
---|
38 | stats->io.complete_q.completed_avg.slow_cnt = 0; |
---|
39 | stats->io.complete_q.completed_avg.fast_cnt = 0; |
---|
40 | #endif |
---|
41 | } |
---|
42 | |
---|
43 | void __tally_stats( struct __stats_t * cltr, struct __stats_t * proc ) { |
---|
44 | __atomic_fetch_add( &cltr->ready.pick.push.attempt , proc->ready.pick.push.attempt , __ATOMIC_SEQ_CST ); |
---|
45 | __atomic_fetch_add( &cltr->ready.pick.push.success , proc->ready.pick.push.success , __ATOMIC_SEQ_CST ); |
---|
46 | __atomic_fetch_add( &cltr->ready.pick.push.local , proc->ready.pick.push.local , __ATOMIC_SEQ_CST ); |
---|
47 | __atomic_fetch_add( &cltr->ready.pick.push.lsuccess, proc->ready.pick.push.lsuccess, __ATOMIC_SEQ_CST ); |
---|
48 | __atomic_fetch_add( &cltr->ready.pick.pop .probe , proc->ready.pick.pop .probe , __ATOMIC_SEQ_CST ); |
---|
49 | __atomic_fetch_add( &cltr->ready.pick.pop .attempt , proc->ready.pick.pop .attempt , __ATOMIC_SEQ_CST ); |
---|
50 | __atomic_fetch_add( &cltr->ready.pick.pop .success , proc->ready.pick.pop .success , __ATOMIC_SEQ_CST ); |
---|
51 | __atomic_fetch_add( &cltr->ready.pick.pop .local , proc->ready.pick.pop .local , __ATOMIC_SEQ_CST ); |
---|
52 | __atomic_fetch_add( &cltr->ready.pick.pop .lsuccess, proc->ready.pick.pop .lsuccess, __ATOMIC_SEQ_CST ); |
---|
53 | __atomic_fetch_add( &cltr->ready.threads.migration, proc->ready.threads.migration, __ATOMIC_SEQ_CST ); |
---|
54 | __atomic_fetch_add( &cltr->ready.sleep.halts , proc->ready.sleep.halts , __ATOMIC_SEQ_CST ); |
---|
55 | __atomic_fetch_add( &cltr->ready.sleep.cancels, proc->ready.sleep.cancels, __ATOMIC_SEQ_CST ); |
---|
56 | __atomic_fetch_add( &cltr->ready.sleep.wakes , proc->ready.sleep.wakes , __ATOMIC_SEQ_CST ); |
---|
57 | __atomic_fetch_add( &cltr->ready.sleep.exits , proc->ready.sleep.exits , __ATOMIC_SEQ_CST ); |
---|
58 | |
---|
59 | #if defined(HAVE_LINUX_IO_URING_H) |
---|
60 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.rdy , proc->io.submit_q.submit_avg.rdy , __ATOMIC_SEQ_CST ); |
---|
61 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.csm , proc->io.submit_q.submit_avg.csm , __ATOMIC_SEQ_CST ); |
---|
62 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.avl , proc->io.submit_q.submit_avg.avl , __ATOMIC_SEQ_CST ); |
---|
63 | __atomic_fetch_add( &cltr->io.submit_q.submit_avg.cnt , proc->io.submit_q.submit_avg.cnt , __ATOMIC_SEQ_CST ); |
---|
64 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.val , proc->io.submit_q.look_avg.val , __ATOMIC_SEQ_CST ); |
---|
65 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.cnt , proc->io.submit_q.look_avg.cnt , __ATOMIC_SEQ_CST ); |
---|
66 | __atomic_fetch_add( &cltr->io.submit_q.look_avg.block , proc->io.submit_q.look_avg.block , __ATOMIC_SEQ_CST ); |
---|
67 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.val , proc->io.submit_q.alloc_avg.val , __ATOMIC_SEQ_CST ); |
---|
68 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.cnt , proc->io.submit_q.alloc_avg.cnt , __ATOMIC_SEQ_CST ); |
---|
69 | __atomic_fetch_add( &cltr->io.submit_q.alloc_avg.block , proc->io.submit_q.alloc_avg.block , __ATOMIC_SEQ_CST ); |
---|
70 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.val , proc->io.complete_q.completed_avg.val , __ATOMIC_SEQ_CST ); |
---|
71 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.slow_cnt, proc->io.complete_q.completed_avg.slow_cnt, __ATOMIC_SEQ_CST ); |
---|
72 | __atomic_fetch_add( &cltr->io.complete_q.completed_avg.fast_cnt, proc->io.complete_q.completed_avg.fast_cnt, __ATOMIC_SEQ_CST ); |
---|
73 | #endif |
---|
74 | } |
---|
75 | |
---|
76 | void __print_stats( struct __stats_t * stats, int flags, bool cluster, const char * name, void * id ) with( *stats ) { |
---|
77 | |
---|
78 | if( flags & CFA_STATS_READY_Q ) { |
---|
79 | double push_sur = (100.0 * ((double)ready.pick.push.success) / ready.pick.push.attempt); |
---|
80 | double pop_sur = (100.0 * ((double)ready.pick.pop .success) / ready.pick.pop .attempt); |
---|
81 | |
---|
82 | double push_len = ((double)ready.pick.push.attempt) / ready.pick.push.success; |
---|
83 | double pop_len = ((double)ready.pick.pop .attempt) / ready.pick.pop .success; |
---|
84 | |
---|
85 | double lpush_sur = (100.0 * ((double)ready.pick.push.lsuccess) / ready.pick.push.local); |
---|
86 | double lpop_sur = (100.0 * ((double)ready.pick.pop .lsuccess) / ready.pick.pop .local); |
---|
87 | |
---|
88 | double lpush_len = ((double)ready.pick.push.local) / ready.pick.push.lsuccess; |
---|
89 | double lpop_len = ((double)ready.pick.pop .local) / ready.pick.pop .lsuccess; |
---|
90 | |
---|
91 | __cfaabi_bits_print_safe( STDOUT_FILENO, |
---|
92 | "----- %s \"%s\" (%p) - Ready Q Stats -----\n" |
---|
93 | "- total threads run : %'15" PRIu64 "\n" |
---|
94 | "- total threads scheduled: %'15" PRIu64 "\n" |
---|
95 | "- push average probe len : %'18.2lf, %'18.2lf%% (%'15" PRIu64 " attempts)\n" |
---|
96 | "- pop average probe len : %'18.2lf, %'18.2lf%% (%'15" PRIu64 " attempts)\n" |
---|
97 | "- local push avg prb len : %'18.2lf, %'18.2lf%% (%'15" PRIu64 " attempts)\n" |
---|
98 | "- local pop avg prb len : %'18.2lf, %'18.2lf%% (%'15" PRIu64 " attempts)\n" |
---|
99 | "- thread migrations : %'15" PRIu64 "\n" |
---|
100 | "- Idle Sleep -\n" |
---|
101 | "-- halts : %'15" PRIu64 "\n" |
---|
102 | "-- cancelled halts : %'15" PRIu64 "\n" |
---|
103 | "-- schedule wake : %'15" PRIu64 "\n" |
---|
104 | "-- wake on exit : %'15" PRIu64 "\n" |
---|
105 | "\n" |
---|
106 | , cluster ? "Cluster" : "Processor", name, id |
---|
107 | , ready.pick.pop.success |
---|
108 | , ready.pick.push.success |
---|
109 | , push_len, push_sur, ready.pick.push.attempt |
---|
110 | , pop_len , pop_sur , ready.pick.pop .attempt |
---|
111 | , lpush_len, lpush_sur, ready.pick.push.local |
---|
112 | , lpop_len , lpop_sur , ready.pick.pop .local |
---|
113 | , ready.threads.migration |
---|
114 | , ready.sleep.halts, ready.sleep.cancels, ready.sleep.wakes, ready.sleep.exits |
---|
115 | ); |
---|
116 | } |
---|
117 | |
---|
118 | #if defined(HAVE_LINUX_IO_URING_H) |
---|
119 | if( flags & CFA_STATS_IO ) { |
---|
120 | double avgrdy = ((double)io.submit_q.submit_avg.rdy) / io.submit_q.submit_avg.cnt; |
---|
121 | double avgcsm = ((double)io.submit_q.submit_avg.csm) / io.submit_q.submit_avg.cnt; |
---|
122 | double avgavl = ((double)io.submit_q.submit_avg.avl) / io.submit_q.submit_avg.cnt; |
---|
123 | |
---|
124 | double lavgv = 0; |
---|
125 | double lavgb = 0; |
---|
126 | if(io.submit_q.look_avg.cnt != 0) { |
---|
127 | lavgv = ((double)io.submit_q.look_avg.val ) / io.submit_q.look_avg.cnt; |
---|
128 | lavgb = ((double)io.submit_q.look_avg.block) / io.submit_q.look_avg.cnt; |
---|
129 | } |
---|
130 | |
---|
131 | double aavgv = 0; |
---|
132 | double aavgb = 0; |
---|
133 | if(io.submit_q.alloc_avg.cnt != 0) { |
---|
134 | aavgv = ((double)io.submit_q.alloc_avg.val ) / io.submit_q.alloc_avg.cnt; |
---|
135 | aavgb = ((double)io.submit_q.alloc_avg.block) / io.submit_q.alloc_avg.cnt; |
---|
136 | } |
---|
137 | |
---|
138 | __cfaabi_bits_print_safe( STDOUT_FILENO, |
---|
139 | "----- %s \"%s\" (%p) - I/O Stats -----\n" |
---|
140 | "- total submit calls : %'15" PRIu64 "\n" |
---|
141 | "- avg ready entries : %'18.2lf\n" |
---|
142 | "- avg submitted entries : %'18.2lf\n" |
---|
143 | "- avg available entries : %'18.2lf\n" |
---|
144 | "- total ready search : %'15" PRIu64 "\n" |
---|
145 | "- avg ready search len : %'18.2lf\n" |
---|
146 | "- avg ready search block : %'18.2lf\n" |
---|
147 | "- total alloc search : %'15" PRIu64 "\n" |
---|
148 | "- avg alloc search len : %'18.2lf\n" |
---|
149 | "- avg alloc search block : %'18.2lf\n" |
---|
150 | "- total wait calls : %'15" PRIu64 " (%'" PRIu64 " slow, %'" PRIu64 " fast)\n" |
---|
151 | "- avg completion/wait : %'18.2lf\n" |
---|
152 | "\n" |
---|
153 | , cluster ? "Cluster" : "Processor", name, id |
---|
154 | , io.submit_q.submit_avg.cnt |
---|
155 | , avgrdy, avgcsm, avgavl |
---|
156 | , io.submit_q.look_avg.cnt |
---|
157 | , lavgv, lavgb |
---|
158 | , io.submit_q.alloc_avg.cnt |
---|
159 | , aavgv, aavgb |
---|
160 | , io.complete_q.completed_avg.slow_cnt + io.complete_q.completed_avg.fast_cnt |
---|
161 | , io.complete_q.completed_avg.slow_cnt, io.complete_q.completed_avg.fast_cnt |
---|
162 | , ((double)io.complete_q.completed_avg.val) / (io.complete_q.completed_avg.slow_cnt + io.complete_q.completed_avg.fast_cnt) |
---|
163 | ); |
---|
164 | } |
---|
165 | #endif |
---|
166 | } |
---|
167 | #endif |
---|