ia64/xen-unstable

view xen/include/xen/perfc.h @ 6497:a66a41032226

Some fixes to the performance counters code.
Signed-off-by: Ross McIlroy <mcilrorc@dcs.gla.ac.uk>
author kaf24@firebug.cl.cam.ac.uk
date Tue Aug 30 17:00:26 2005 +0000 (2005-08-30)
parents ddd290cc8f0d
children 1fc6473ecc01 f0dc15fd3c1b
line source
2 #ifndef __XEN_PERFC_H__
3 #define __XEN_PERFC_H__
5 #ifdef PERF_COUNTERS
7 #include <xen/lib.h>
8 #include <asm/atomic.h>
10 /*
11 * NOTE: new counters must be defined in perfc_defn.h
12 *
13 * PERFCOUNTER (counter, string) define a new performance counter
14 * PERFCOUNTER_CPU (counter, string, size) define a counter per CPU
15 * PERFCOUNTER_ARRY (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_CPU (counter, string, size) define a status var per CPU
20 * PERFSTATUS_ARRY (counter, string, size) define an array of status vars
21 *
22 * unsigned long perfc_value (counter) get value of a counter
23 * unsigned long perfc_valuec (counter) get value of a per CPU counter
24 * unsigned long perfc_valuea (counter, index) get value of an array counter
25 * unsigned long perfc_set (counter, val) set value of a counter
26 * unsigned long perfc_setc (counter, val) set value of a per CPU counter
27 * unsigned long perfc_seta (counter, index, val) set value of an array counter
28 * void perfc_incr (counter) increment a counter
29 * void perfc_incrc (counter, index) increment a per CPU counter
30 * void perfc_incra (counter, index) increment an array counter
31 * void perfc_add (counter, value) add a value to a counter
32 * void perfc_addc (counter, value) add a value to a per CPU counter
33 * void perfc_adda (counter, index, value) add a value to array counter
34 * void perfc_print (counter) print out the counter
35 */
37 #define PERFCOUNTER( var, name ) \
38 atomic_t var[1];
39 #define PERFCOUNTER_CPU( var, name ) \
40 atomic_t var[NR_CPUS];
41 #define PERFCOUNTER_ARRAY( var, name, size ) \
42 atomic_t var[size];
43 #define PERFSTATUS( var, name ) \
44 atomic_t var[1];
45 #define PERFSTATUS_CPU( var, name ) \
46 atomic_t var[NR_CPUS];
47 #define PERFSTATUS_ARRAY( var, name, size ) \
48 atomic_t var[size];
50 struct perfcounter {
51 #include <xen/perfc_defn.h>
52 };
54 extern struct perfcounter perfcounters;
56 #define perfc_value(x) atomic_read(&perfcounters.x[0])
57 #define perfc_valuec(x) atomic_read(&perfcounters.x[smp_processor_id()])
58 #define perfc_valuea(x,y) \
59 do { \
60 if ( (y) < (sizeof(perfcounters.x) / sizeof(*perfcounters.x)) ) \
61 atomic_read(&perfcounters.x[y]); \
62 } while ( 0 )
63 #define perfc_set(x,v) atomic_set(&perfcounters.x[0], v)
64 #define perfc_setc(x,v) atomic_set(&perfcounters.x[smp_processor_id()], v)
65 #define perfc_seta(x,y,v) \
66 do { \
67 if ( (y) < (sizeof(perfcounters.x) / sizeof(*perfcounters.x)) ) \
68 atomic_set(&perfcounters.x[y], v); \
69 } while ( 0 )
70 #define perfc_incr(x) atomic_inc(&perfcounters.x[0])
71 #define perfc_decr(x) atomic_dec(&perfcounters.x[0])
72 #define perfc_incrc(x) atomic_inc(&perfcounters.x[smp_processor_id()])
73 #define perfc_decrc(x) atomic_dec(&perfcounters.x[smp_processor_id()])
74 #define perfc_incra(x,y) \
75 do { \
76 if ( (y) < (sizeof(perfcounters.x) / sizeof(*perfcounters.x)) ) \
77 atomic_inc(&perfcounters.x[y]); \
78 } while ( 0 )
79 #define perfc_add(x,y) atomic_add((y), &perfcounters.x[0])
80 #define perfc_addc(x,y) atomic_add((y), &perfcounters.x[smp_processor_id()])
81 #define perfc_adda(x,y,z) \
82 do { \
83 if ( (y) < (sizeof(perfcounters.x) / sizeof(*perfcounters.x)) ) \
84 atomic_add((z), &perfcounters.x[y]); \
85 } while ( 0 )
87 /*
88 * Histogram: special treatment for 0 and 1 count. After that equally spaced
89 * with last bucket taking the rest.
90 */
91 #ifdef PERF_ARRAYS
92 #define perfc_incr_histo(_x,_v,_n) \
93 do { \
94 if ( (_v) == 0 ) \
95 perfc_incra(_x, 0); \
96 else if ( (_v) == 1 ) \
97 perfc_incra(_x, 1); \
98 else if ( (((_v)-2) / PERFC_ ## _n ## _BUCKET_SIZE) < \
99 (PERFC_MAX_ ## _n - 3) ) \
100 perfc_incra(_x, (((_v)-2) / PERFC_ ## _n ## _BUCKET_SIZE) + 2); \
101 else \
102 perfc_incra(_x, PERFC_MAX_ ## _n - 1); \
103 } while ( 0 )
104 #else
105 #define perfc_incr_histo(_x,_v,_n) ((void)0)
106 #endif
108 #else /* PERF_COUNTERS */
110 #define perfc_value(x) (0)
111 #define perfc_valuec(x) (0)
112 #define perfc_valuea(x,y) (0)
113 #define perfc_set(x,v) ((void)0)
114 #define perfc_setc(x,v) ((void)0)
115 #define perfc_seta(x,y,v) ((void)0)
116 #define perfc_incr(x) ((void)0)
117 #define perfc_decr(x) ((void)0)
118 #define perfc_incrc(x) ((void)0)
119 #define perfc_decrc(x) ((void)0)
120 #define perfc_incra(x,y) ((void)0)
121 #define perfc_decra(x,y) ((void)0)
122 #define perfc_add(x,y) ((void)0)
123 #define perfc_addc(x,y) ((void)0)
124 #define perfc_adda(x,y,z) ((void)0)
125 #define perfc_incr_histo(x,y,z) ((void)0)
127 #endif /* PERF_COUNTERS */
129 #endif /* __XEN_PERFC_H__ */