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.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.flush = 0; |
---|
36 | stats->io.calls.submitted = 0; |
---|
37 | stats->io.calls.drain = 0; |
---|
38 | stats->io.calls.completed = 0; |
---|
39 | stats->io.calls.errors.busy = 0; |
---|
40 | stats->io.poller.sleeps = 0; |
---|
41 | #endif |
---|
42 | } |
---|
43 | |
---|
44 | void __tally_stats( struct __stats_t * cltr, struct __stats_t * proc ) { |
---|
45 | __atomic_fetch_add( &cltr->ready.pick.push.attempt , proc->ready.pick.push.attempt , __ATOMIC_SEQ_CST ); proc->ready.pick.push.attempt = 0; |
---|
46 | __atomic_fetch_add( &cltr->ready.pick.push.success , proc->ready.pick.push.success , __ATOMIC_SEQ_CST ); proc->ready.pick.push.success = 0; |
---|
47 | __atomic_fetch_add( &cltr->ready.pick.push.local , proc->ready.pick.push.local , __ATOMIC_SEQ_CST ); proc->ready.pick.push.local = 0; |
---|
48 | __atomic_fetch_add( &cltr->ready.pick.push.lsuccess, proc->ready.pick.push.lsuccess, __ATOMIC_SEQ_CST ); proc->ready.pick.push.lsuccess = 0; |
---|
49 | __atomic_fetch_add( &cltr->ready.pick.pop .probe , proc->ready.pick.pop .probe , __ATOMIC_SEQ_CST ); proc->ready.pick.pop .probe = 0; |
---|
50 | __atomic_fetch_add( &cltr->ready.pick.pop .attempt , proc->ready.pick.pop .attempt , __ATOMIC_SEQ_CST ); proc->ready.pick.pop .attempt = 0; |
---|
51 | __atomic_fetch_add( &cltr->ready.pick.pop .success , proc->ready.pick.pop .success , __ATOMIC_SEQ_CST ); proc->ready.pick.pop .success = 0; |
---|
52 | __atomic_fetch_add( &cltr->ready.pick.pop .local , proc->ready.pick.pop .local , __ATOMIC_SEQ_CST ); proc->ready.pick.pop .local = 0; |
---|
53 | __atomic_fetch_add( &cltr->ready.pick.pop .lsuccess, proc->ready.pick.pop .lsuccess, __ATOMIC_SEQ_CST ); proc->ready.pick.pop .lsuccess = 0; |
---|
54 | __atomic_fetch_add( &cltr->ready.threads.migration , proc->ready.threads.migration , __ATOMIC_SEQ_CST ); proc->ready.threads.migration = 0; |
---|
55 | __atomic_fetch_add( &cltr->ready.sleep.halts , proc->ready.sleep.halts , __ATOMIC_SEQ_CST ); proc->ready.sleep.halts = 0; |
---|
56 | __atomic_fetch_add( &cltr->ready.sleep.cancels , proc->ready.sleep.cancels , __ATOMIC_SEQ_CST ); proc->ready.sleep.cancels = 0; |
---|
57 | __atomic_fetch_add( &cltr->ready.sleep.wakes , proc->ready.sleep.wakes , __ATOMIC_SEQ_CST ); proc->ready.sleep.wakes = 0; |
---|
58 | __atomic_fetch_add( &cltr->ready.sleep.exits , proc->ready.sleep.exits , __ATOMIC_SEQ_CST ); proc->ready.sleep.exits = 0; |
---|
59 | |
---|
60 | #if defined(CFA_HAVE_LINUX_IO_URING_H) |
---|
61 | __atomic_fetch_add( &cltr->io.alloc.fast , proc->io.alloc.fast , __ATOMIC_SEQ_CST ); proc->io.alloc.fast = 0; |
---|
62 | __atomic_fetch_add( &cltr->io.alloc.slow , proc->io.alloc.slow , __ATOMIC_SEQ_CST ); proc->io.alloc.slow = 0; |
---|
63 | __atomic_fetch_add( &cltr->io.alloc.fail , proc->io.alloc.fail , __ATOMIC_SEQ_CST ); proc->io.alloc.fail = 0; |
---|
64 | __atomic_fetch_add( &cltr->io.alloc.revoke , proc->io.alloc.revoke , __ATOMIC_SEQ_CST ); proc->io.alloc.revoke = 0; |
---|
65 | __atomic_fetch_add( &cltr->io.alloc.block , proc->io.alloc.block , __ATOMIC_SEQ_CST ); proc->io.alloc.block = 0; |
---|
66 | __atomic_fetch_add( &cltr->io.submit.fast , proc->io.submit.fast , __ATOMIC_SEQ_CST ); proc->io.submit.fast = 0; |
---|
67 | __atomic_fetch_add( &cltr->io.submit.slow , proc->io.submit.slow , __ATOMIC_SEQ_CST ); proc->io.submit.slow = 0; |
---|
68 | __atomic_fetch_add( &cltr->io.flush.external , proc->io.flush.external , __ATOMIC_SEQ_CST ); proc->io.flush.external = 0; |
---|
69 | __atomic_fetch_add( &cltr->io.calls.flush , proc->io.calls.flush , __ATOMIC_SEQ_CST ); proc->io.calls.flush = 0; |
---|
70 | __atomic_fetch_add( &cltr->io.calls.submitted , proc->io.calls.submitted , __ATOMIC_SEQ_CST ); proc->io.calls.submitted = 0; |
---|
71 | __atomic_fetch_add( &cltr->io.calls.drain , proc->io.calls.drain , __ATOMIC_SEQ_CST ); proc->io.calls.drain = 0; |
---|
72 | __atomic_fetch_add( &cltr->io.calls.completed , proc->io.calls.completed , __ATOMIC_SEQ_CST ); proc->io.calls.completed = 0; |
---|
73 | __atomic_fetch_add( &cltr->io.calls.errors.busy, proc->io.calls.errors.busy, __ATOMIC_SEQ_CST ); proc->io.calls.errors.busy = 0; |
---|
74 | __atomic_fetch_add( &cltr->io.poller.sleeps , proc->io.poller.sleeps , __ATOMIC_SEQ_CST ); proc->io.poller.sleeps = 0; |
---|
75 | #endif |
---|
76 | } |
---|
77 | |
---|
78 | void __print_stats( struct __stats_t * stats, int flags, const char * type, const char * name, void * id ) with( *stats ) { |
---|
79 | |
---|
80 | if( flags & CFA_STATS_READY_Q ) { |
---|
81 | double push_len = ((double)ready.pick.push.attempt) / ready.pick.push.success; |
---|
82 | double pop_len = ((double)ready.pick.pop .attempt) / ready.pick.pop .success; |
---|
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 | __cfaabi_bits_print_safe( STDOUT_FILENO, |
---|
88 | "----- %s \"%s\" (%p) - Ready Q Stats -----\n" |
---|
89 | "- total threads : %'15" PRIu64 "run, %'15" PRIu64 "schd (%'" PRIu64 "mig )\n" |
---|
90 | "- push avg probe : %'3.2lf, %'3.2lfl (%'15" PRIu64 " attempts, %'15" PRIu64 " locals)\n" |
---|
91 | "- pop avg probe : %'3.2lf, %'3.2lfl (%'15" PRIu64 " attempts, %'15" PRIu64 " locals)\n" |
---|
92 | "- Idle Sleep : %'15" PRIu64 "h, %'15" PRIu64 "c, %'15" PRIu64 "w, %'15" PRIu64 "e\n" |
---|
93 | "\n" |
---|
94 | , type, name, id |
---|
95 | , ready.pick.pop.success |
---|
96 | , ready.pick.push.success |
---|
97 | , ready.threads.migration |
---|
98 | , push_len, lpush_len, ready.pick.push.attempt, ready.pick.push.local |
---|
99 | , pop_len , lpop_len , ready.pick.pop .attempt, ready.pick.pop .local |
---|
100 | , ready.sleep.halts, ready.sleep.cancels, ready.sleep.wakes, ready.sleep.exits |
---|
101 | ); |
---|
102 | } |
---|
103 | |
---|
104 | #if defined(CFA_HAVE_LINUX_IO_URING_H) |
---|
105 | if( flags & CFA_STATS_IO ) { |
---|
106 | uint64_t total_allocs = io.alloc.fast + io.alloc.slow; |
---|
107 | double avgfasta = ((double)io.alloc.fast) / total_allocs; |
---|
108 | |
---|
109 | uint64_t total_submits = io.submit.fast + io.submit.slow; |
---|
110 | double avgfasts = ((double)io.submit.fast) / total_submits; |
---|
111 | |
---|
112 | double avgsubs = ((double)io.calls.submitted) / io.calls.flush; |
---|
113 | double avgcomp = ((double)io.calls.completed) / io.calls.drain; |
---|
114 | |
---|
115 | __cfaabi_bits_print_safe( STDOUT_FILENO, |
---|
116 | "----- %s \"%s\" (%p) - I/O Stats -----\n" |
---|
117 | "- total allocations : %'" PRIu64 "f, %'" PRIu64 "s (%'2.2lff) \n" |
---|
118 | "- failures : %'" PRIu64 "oom, %'" PRIu64 "rvk, %'" PRIu64 "blk\n" |
---|
119 | "- total submits : %'" PRIu64 "f, %'" PRIu64 "s (%'2.2lf) \n" |
---|
120 | "- flush external : %'" PRIu64 "\n" |
---|
121 | "- io_uring_enter : %'" PRIu64 " (%'" PRIu64 ", %'" PRIu64 " EBUSY)\n" |
---|
122 | "- submits : %'" PRIu64 " (%'.2lf) \n" |
---|
123 | "- completes : %'" PRIu64 " (%'.2lf) \n" |
---|
124 | "- poller sleeping : %'" PRIu64 "\n" |
---|
125 | "\n" |
---|
126 | , type, name, id |
---|
127 | , io.alloc.fast, io.alloc.slow, avgfasta |
---|
128 | , io.alloc.fail, io.alloc.revoke, io.alloc.block |
---|
129 | , io.submit.fast, io.submit.slow, avgfasts |
---|
130 | , io.flush.external |
---|
131 | , io.calls.flush, io.calls.drain, io.calls.errors.busy |
---|
132 | , io.calls.submitted, avgsubs |
---|
133 | , io.calls.completed, avgcomp |
---|
134 | , io.poller.sleeps |
---|
135 | ); |
---|
136 | } |
---|
137 | #endif |
---|
138 | } |
---|
139 | #endif |
---|