debuggers.hg

view xen/common/perfc.c @ 3705:4294cfa9fad3

bitkeeper revision 1.1159.212.95 (4204aa0ee0re5Xx1zWrJ9ejxzgRs3w)

Various cleanups. Remove PDB pending simpler GDB stub and/or NetBSD debugger.
Force emacs mode to appropriate tabbing in various files.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Sat Feb 05 11:12:14 2005 +0000 (2005-02-05)
parents fd0d4d8e6193
children 88957a238191
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil -*- */
3 #include <xen/lib.h>
4 #include <xen/smp.h>
5 #include <xen/time.h>
6 #include <xen/perfc.h>
7 #include <xen/keyhandler.h>
8 #include <public/dom0_ops.h>
9 #include <asm/uaccess.h>
11 #undef PERFCOUNTER
12 #undef PERFCOUNTER_CPU
13 #undef PERFCOUNTER_ARRAY
14 #undef PERFSTATUS
15 #undef PERFSTATUS_CPU
16 #undef PERFSTATUS_ARRAY
17 #define PERFCOUNTER( var, name ) { name, TYPE_SINGLE, 0 },
18 #define PERFCOUNTER_CPU( var, name ) { name, TYPE_CPU, 0 },
19 #define PERFCOUNTER_ARRAY( var, name, size ) { name, TYPE_ARRAY, size },
20 #define PERFSTATUS( var, name ) { name, TYPE_S_SINGLE, 0 },
21 #define PERFSTATUS_CPU( var, name ) { name, TYPE_S_CPU, 0 },
22 #define PERFSTATUS_ARRAY( var, name, size ) { name, TYPE_S_ARRAY, size },
23 static struct {
24 char *name;
25 enum { TYPE_SINGLE, TYPE_CPU, TYPE_ARRAY,
26 TYPE_S_SINGLE, TYPE_S_CPU, TYPE_S_ARRAY
27 } type;
28 int nr_elements;
29 } perfc_info[] = {
30 #include <xen/perfc_defn.h>
31 };
33 #define NR_PERFCTRS (sizeof(perfc_info) / sizeof(perfc_info[0]))
35 struct perfcounter_t perfcounters;
37 void perfc_printall(unsigned char key)
38 {
39 int i, j, sum;
40 s_time_t now = NOW();
41 atomic_t *counters = (atomic_t *)&perfcounters;
43 printk("Xen performance counters SHOW (now = 0x%08X:%08X)\n",
44 (u32)(now>>32), (u32)now);
46 for ( i = 0; i < NR_PERFCTRS; i++ )
47 {
48 printk("%-32s ", perfc_info[i].name);
49 switch ( perfc_info[i].type )
50 {
51 case TYPE_SINGLE:
52 case TYPE_S_SINGLE:
53 printk("TOTAL[%10d]", atomic_read(&counters[0]));
54 counters += 1;
55 break;
56 case TYPE_CPU:
57 case TYPE_S_CPU:
58 for ( j = sum = 0; j < smp_num_cpus; j++ )
59 sum += atomic_read(&counters[j]);
60 printk("TOTAL[%10d] ", sum);
61 for ( j = 0; j < smp_num_cpus; j++ )
62 printk("CPU%02d[%10d] ", j, atomic_read(&counters[j]));
63 counters += NR_CPUS;
64 break;
65 case TYPE_ARRAY:
66 case TYPE_S_ARRAY:
67 for ( j = sum = 0; j < perfc_info[i].nr_elements; j++ )
68 sum += atomic_read(&counters[j]);
69 printk("TOTAL[%10d] ", sum);
70 for ( j = 0; j < perfc_info[i].nr_elements; j++ )
71 printk("ARR%02d[%10d] ", j, atomic_read(&counters[j]));
72 counters += j;
73 break;
74 }
75 printk("\n");
76 }
77 }
79 void perfc_reset(unsigned char key)
80 {
81 int i, j, sum;
82 s_time_t now = NOW();
83 atomic_t *counters = (atomic_t *)&perfcounters;
85 if ( key != '\0' )
86 printk("Xen performance counters RESET (now = 0x%08X:%08X)\n",
87 (u32)(now>>32), (u32)now);
89 /* leave STATUS counters alone -- don't reset */
91 for ( i = 0; i < NR_PERFCTRS; i++ )
92 {
93 switch ( perfc_info[i].type )
94 {
95 case TYPE_SINGLE:
96 atomic_set(&counters[0],0);
97 case TYPE_S_SINGLE:
98 counters += 1;
99 break;
100 case TYPE_CPU:
101 for ( j = sum = 0; j < smp_num_cpus; j++ )
102 atomic_set(&counters[j],0);
103 case TYPE_S_CPU:
104 counters += NR_CPUS;
105 break;
106 case TYPE_ARRAY:
107 for ( j = sum = 0; j < perfc_info[i].nr_elements; j++ )
108 atomic_set(&counters[j],0);
109 case TYPE_S_ARRAY:
110 counters += perfc_info[i].nr_elements;
111 break;
112 }
113 }
114 }
116 static dom0_perfc_desc_t perfc_d[NR_PERFCTRS];
117 static int perfc_init = 0;
118 static int perfc_copy_info(dom0_perfc_desc_t *desc)
119 {
120 unsigned int i, j;
121 atomic_t *counters = (atomic_t *)&perfcounters;
123 if ( desc == NULL )
124 return 0;
126 /* We only copy the name and array-size information once. */
127 if ( !perfc_init )
128 {
129 for ( i = 0; i < NR_PERFCTRS; i++ )
130 {
131 strncpy(perfc_d[i].name, perfc_info[i].name,
132 sizeof(perfc_d[i].name));
133 perfc_d[i].name[sizeof(perfc_d[i].name)-1] = '\0';
135 switch ( perfc_info[i].type )
136 {
137 case TYPE_SINGLE:
138 case TYPE_S_SINGLE:
139 perfc_d[i].nr_vals = 1;
140 break;
141 case TYPE_CPU:
142 case TYPE_S_CPU:
143 perfc_d[i].nr_vals = smp_num_cpus;
144 break;
145 case TYPE_ARRAY:
146 case TYPE_S_ARRAY:
147 perfc_d[i].nr_vals = perfc_info[i].nr_elements;
148 break;
149 }
151 if ( perfc_d[i].nr_vals > ARRAY_SIZE(perfc_d[i].vals) )
152 perfc_d[i].nr_vals = ARRAY_SIZE(perfc_d[i].vals);
153 }
155 perfc_init = 1;
156 }
158 /* We gather the counts together every time. */
159 for ( i = 0; i < NR_PERFCTRS; i++ )
160 {
161 switch ( perfc_info[i].type )
162 {
163 case TYPE_SINGLE:
164 case TYPE_S_SINGLE:
165 perfc_d[i].vals[0] = atomic_read(&counters[0]);
166 counters += 1;
167 break;
168 case TYPE_CPU:
169 case TYPE_S_CPU:
170 for ( j = 0; j < perfc_d[i].nr_vals; j++ )
171 perfc_d[i].vals[j] = atomic_read(&counters[j]);
172 counters += NR_CPUS;
173 break;
174 case TYPE_ARRAY:
175 case TYPE_S_ARRAY:
176 for ( j = 0; j < perfc_d[i].nr_vals; j++ )
177 perfc_d[i].vals[j] = atomic_read(&counters[j]);
178 counters += perfc_info[i].nr_elements;
179 break;
180 }
181 }
183 return (copy_to_user(desc, perfc_d, NR_PERFCTRS * sizeof(*desc)) ?
184 -EFAULT : 0);
185 }
187 /* Dom0 control of perf counters */
188 int perfc_control(dom0_perfccontrol_t *pc)
189 {
190 static spinlock_t lock = SPIN_LOCK_UNLOCKED;
191 u32 op = pc->op;
192 int rc;
194 pc->nr_counters = NR_PERFCTRS;
196 spin_lock(&lock);
198 switch ( op )
199 {
200 case DOM0_PERFCCONTROL_OP_RESET:
201 perfc_copy_info(pc->desc);
202 perfc_reset(0);
203 rc = 0;
204 break;
206 case DOM0_PERFCCONTROL_OP_QUERY:
207 perfc_copy_info(pc->desc);
208 rc = 0;
209 break;
211 default:
212 rc = -EINVAL;
213 break;
214 }
216 spin_unlock(&lock);
218 return rc;
219 }