| 1 | #pragma once | 
|---|
| 2 |  | 
|---|
| 3 | // #define CFA_STATS_ARRAY 10000 | 
|---|
| 4 | // #define __CFA_NO_STATISTICS__ | 
|---|
| 5 |  | 
|---|
| 6 | #include <stdint.h> | 
|---|
| 7 |  | 
|---|
| 8 | enum { | 
|---|
| 9 | CFA_STATS_READY_Q  = 0x01, | 
|---|
| 10 | CFA_STATS_IO = 0x02, | 
|---|
| 11 | }; | 
|---|
| 12 |  | 
|---|
| 13 | #if defined(__CFA_NO_STATISTICS__) | 
|---|
| 14 | struct __stats_t; | 
|---|
| 15 | static inline void __init_stats( struct __stats_t * ) {} | 
|---|
| 16 | static inline void __tally_stats( struct __stats_t *, struct __stats_t * ) {} | 
|---|
| 17 | static inline void __print_stats( struct __stats_t *, int, const char *, const char *, void * ) {} | 
|---|
| 18 | #else | 
|---|
| 19 | struct __stats_readyQ_pop_t { | 
|---|
| 20 | // number of attemps at poping something | 
|---|
| 21 | volatile uint64_t attempt; | 
|---|
| 22 |  | 
|---|
| 23 | // number of successes at poping | 
|---|
| 24 | volatile uint64_t success; | 
|---|
| 25 | }; | 
|---|
| 26 |  | 
|---|
| 27 | struct __attribute__((aligned(64))) __stats_readyQ_t { | 
|---|
| 28 | // Push statistic | 
|---|
| 29 | struct { | 
|---|
| 30 | struct { | 
|---|
| 31 | // number of attemps at pushing something to preferred queues | 
|---|
| 32 | volatile uint64_t attempt; | 
|---|
| 33 |  | 
|---|
| 34 | // number of successes at pushing to preferred queues | 
|---|
| 35 | volatile uint64_t success; | 
|---|
| 36 | } | 
|---|
| 37 | // Stats for local queue within cluster | 
|---|
| 38 | local, | 
|---|
| 39 |  | 
|---|
| 40 | // Stats for non-local queues within cluster | 
|---|
| 41 | share, | 
|---|
| 42 |  | 
|---|
| 43 | // Stats from outside cluster | 
|---|
| 44 | extrn; | 
|---|
| 45 | } push; | 
|---|
| 46 |  | 
|---|
| 47 | // Pop statistic | 
|---|
| 48 | struct { | 
|---|
| 49 | // pop from local queue | 
|---|
| 50 | __stats_readyQ_pop_t local; | 
|---|
| 51 |  | 
|---|
| 52 | // pop before looking at local queue | 
|---|
| 53 | __stats_readyQ_pop_t help; | 
|---|
| 54 |  | 
|---|
| 55 | // pop from some other queue | 
|---|
| 56 | __stats_readyQ_pop_t steal; | 
|---|
| 57 |  | 
|---|
| 58 | // pop when searching queues sequentially | 
|---|
| 59 | __stats_readyQ_pop_t search; | 
|---|
| 60 | } pop; | 
|---|
| 61 |  | 
|---|
| 62 | struct { | 
|---|
| 63 | volatile uint64_t migration; | 
|---|
| 64 | volatile uint64_t extunpark; | 
|---|
| 65 | volatile  int64_t threads;  // number of threads in the system, includes only local change | 
|---|
| 66 | volatile  int64_t cthreads; // number of threads in the system, includes only local change | 
|---|
| 67 | } threads; | 
|---|
| 68 | struct { | 
|---|
| 69 | volatile uint64_t halts; | 
|---|
| 70 | volatile uint64_t cancels; | 
|---|
| 71 | volatile uint64_t wakes; | 
|---|
| 72 | volatile uint64_t exits; | 
|---|
| 73 | } sleep; | 
|---|
| 74 | }; | 
|---|
| 75 |  | 
|---|
| 76 | #if defined(CFA_HAVE_LINUX_IO_URING_H) | 
|---|
| 77 | struct __attribute__((aligned(64))) __stats_io_t{ | 
|---|
| 78 | struct { | 
|---|
| 79 | volatile uint64_t fast; | 
|---|
| 80 | volatile uint64_t slow; | 
|---|
| 81 | volatile uint64_t fail; | 
|---|
| 82 | volatile uint64_t revoke; | 
|---|
| 83 | volatile uint64_t block; | 
|---|
| 84 | } alloc; | 
|---|
| 85 | struct { | 
|---|
| 86 | volatile uint64_t fast; | 
|---|
| 87 | volatile uint64_t slow; | 
|---|
| 88 | } submit; | 
|---|
| 89 | struct { | 
|---|
| 90 | volatile uint64_t external; | 
|---|
| 91 | } flush; | 
|---|
| 92 | struct { | 
|---|
| 93 | volatile uint64_t drain; | 
|---|
| 94 | volatile uint64_t completed; | 
|---|
| 95 | volatile uint64_t flush; | 
|---|
| 96 | volatile uint64_t submitted; | 
|---|
| 97 | struct { | 
|---|
| 98 | volatile uint64_t busy; | 
|---|
| 99 | } errors; | 
|---|
| 100 | } calls; | 
|---|
| 101 | struct { | 
|---|
| 102 | volatile uint64_t sleeps; | 
|---|
| 103 | } poller; | 
|---|
| 104 | }; | 
|---|
| 105 | #endif | 
|---|
| 106 |  | 
|---|
| 107 | #if defined(CFA_STATS_ARRAY) | 
|---|
| 108 | struct __stats_elem_t { | 
|---|
| 109 | long long int ts; | 
|---|
| 110 | int64_t value; | 
|---|
| 111 | }; | 
|---|
| 112 | #endif | 
|---|
| 113 |  | 
|---|
| 114 | struct __attribute__((aligned(128))) __stats_t { | 
|---|
| 115 | __stats_readyQ_t ready; | 
|---|
| 116 | #if defined(CFA_HAVE_LINUX_IO_URING_H) | 
|---|
| 117 | __stats_io_t    io; | 
|---|
| 118 | #endif | 
|---|
| 119 |  | 
|---|
| 120 | #if defined(CFA_STATS_ARRAY) | 
|---|
| 121 | struct { | 
|---|
| 122 | __stats_elem_t * values; | 
|---|
| 123 | volatile size_t cnt; | 
|---|
| 124 | } array; | 
|---|
| 125 | #endif | 
|---|
| 126 |  | 
|---|
| 127 | }; | 
|---|
| 128 |  | 
|---|
| 129 | void __init_stats ( struct __stats_t * ); | 
|---|
| 130 | void __tally_stats( struct __stats_t *, struct __stats_t * ); | 
|---|
| 131 | void __print_stats( struct __stats_t *, int, const char *, const char *, void * ); | 
|---|
| 132 | #if defined(CFA_STATS_ARRAY) | 
|---|
| 133 | void __push_stat ( struct __stats_t *, int64_t value, bool external, const char * name, void * handle); | 
|---|
| 134 | void __flush_stat( struct __stats_t *, const char *, void * ); | 
|---|
| 135 | #else | 
|---|
| 136 | static inline void __push_stat ( struct __stats_t *, int64_t, bool, const char *, void * ) {} | 
|---|
| 137 | static inline void __flush_stat( struct __stats_t *, const char *, void * ) {} | 
|---|
| 138 | #endif | 
|---|
| 139 | #endif | 
|---|
| 140 |  | 
|---|