1 #ifndef __XEN_PERFC_H__ 2 #define __XEN_PERFC_H__ 3 4 #ifdef CONFIG_PERF_COUNTERS 5 6 #include <xen/lib.h> 7 #include <xen/smp.h> 8 #include <xen/percpu.h> 9 10 /* 11 * NOTE: new counters must be defined in perfc_defn.h 12 * 13 * Counter declarations: 14 * PERFCOUNTER (counter, string) define a new performance counter 15 * PERFCOUNTER_ARRAY (counter, string, size) define an array of counters 16 * 17 * Unlike counters, status variables do not reset: 18 * PERFSTATUS (counter, string) define a new performance stauts 19 * PERFSTATUS_ARRAY (counter, string, size) define an array of status vars 20 * 21 * unsigned long perfc_value (counter) get value of a counter 22 * unsigned long perfc_valuea (counter, index) get value of an array counter 23 * unsigned long perfc_set (counter, val) set value of a counter 24 * unsigned long perfc_seta (counter, index, val) set value of an array counter 25 * void perfc_incr (counter) increment a counter 26 * void perfc_decr (counter) decrement a status 27 * void perfc_incra (counter, index) increment an array counter 28 * void perfc_add (counter, value) add a value to a counter 29 * void perfc_adda (counter, index, value) add a value to array counter 30 * void perfc_print (counter) print out the counter 31 */ 32 33 #define PERFCOUNTER( name, descr ) \ 34 PERFC_##name, 35 #define PERFCOUNTER_ARRAY( name, descr, size ) \ 36 PERFC_##name, \ 37 PERFC_LAST_##name = PERFC_ ## name + (size) - sizeof(char[2 * !!(size) - 1]), 38 39 #define PERFSTATUS PERFCOUNTER 40 #define PERFSTATUS_ARRAY PERFCOUNTER_ARRAY 41 42 enum perfcounter { 43 #include <xen/perfc_defn.h> 44 NUM_PERFCOUNTERS 45 }; 46 47 #undef PERFCOUNTER 48 #undef PERFCOUNTER_ARRAY 49 #undef PERFSTATUS 50 #undef PERFSTATUS_ARRAY 51 52 typedef unsigned perfc_t; 53 #define PRIperfc "" 54 55 DECLARE_PER_CPU(perfc_t[NUM_PERFCOUNTERS], perfcounters); 56 57 #define perfc_value(x) this_cpu(perfcounters)[PERFC_ ## x] 58 #define perfc_valuea(x,y) \ 59 ( (y) <= PERFC_LAST_ ## x - PERFC_ ## x ? \ 60 this_cpu(perfcounters)[PERFC_ ## x + (y)] : 0 ) 61 #define perfc_set(x,v) (this_cpu(perfcounters)[PERFC_ ## x] = (v)) 62 #define perfc_seta(x,y,v) \ 63 ( (y) <= PERFC_LAST_ ## x - PERFC_ ## x ? \ 64 this_cpu(perfcounters)[PERFC_ ## x + (y)] = (v) : (v) ) 65 #define perfc_incr(x) (++this_cpu(perfcounters)[PERFC_ ## x]) 66 #define perfc_decr(x) (--this_cpu(perfcounters)[PERFC_ ## x]) 67 #define perfc_incra(x,y) \ 68 ( (y) <= PERFC_LAST_ ## x - PERFC_ ## x ? \ 69 ++this_cpu(perfcounters)[PERFC_ ## x + (y)] : 0 ) 70 #define perfc_add(x,v) (this_cpu(perfcounters)[PERFC_ ## x] += (v)) 71 #define perfc_adda(x,y,v) \ 72 ( (y) <= PERFC_LAST_ ## x - PERFC_ ## x ? \ 73 this_cpu(perfcounters)[PERFC_ ## x + (y)] = (v) : (v) ) 74 75 /* 76 * Histogram: special treatment for 0 and 1 count. After that equally spaced 77 * with last bucket taking the rest. 78 */ 79 #ifdef CONFIG_PERF_ARRAYS 80 #define perfc_incr_histo(x,v) \ 81 do { \ 82 if ( (v) == 0 ) \ 83 perfc_incra(x, 0); \ 84 else if ( (v) == 1 ) \ 85 perfc_incra(x, 1); \ 86 else if ( (((v) - 2) / PERFC_ ## x ## _BUCKET_SIZE) < \ 87 (PERFC_LAST_ ## x - PERFC_ ## x - 2) ) \ 88 perfc_incra(x, (((v) - 2) / PERFC_ ## x ## _BUCKET_SIZE) + 2); \ 89 else \ 90 perfc_incra(x, PERFC_LAST_ ## x - PERFC_ ## x); \ 91 } while ( 0 ) 92 #else 93 #define perfc_incr_histo(x,v) ((void)0) 94 #endif 95 96 struct xen_sysctl_perfc_op; 97 int perfc_control(struct xen_sysctl_perfc_op *); 98 99 extern void perfc_printall(unsigned char key); 100 extern void perfc_reset(unsigned char key); 101 102 103 #else /* CONFIG_PERF_COUNTERS */ 104 105 #define perfc_value(x) (0) 106 #define perfc_valuea(x,y) (0) 107 #define perfc_set(x,v) ((void)0) 108 #define perfc_seta(x,y,v) ((void)0) 109 #define perfc_incr(x) ((void)0) 110 #define perfc_decr(x) ((void)0) 111 #define perfc_incra(x,y) ((void)0) 112 #define perfc_decra(x,y) ((void)0) 113 #define perfc_add(x,y) ((void)0) 114 #define perfc_adda(x,y,z) ((void)0) 115 #define perfc_incr_histo(x,y,z) ((void)0) 116 117 #endif /* CONFIG_PERF_COUNTERS */ 118 119 #endif /* __XEN_PERFC_H__ */ 120