ia64/xen-unstable

view patches/linux-2.6.16.13/xenoprof-generic.patch @ 10570:8dc4af3f192c

[IA64] Implement and use DOM0_DOMAIN_STEUP.

DOM0_GETMEMLIST now reads ptes and use gpfn.
Domain builder reworked: calls DOMAIN_SETUP, setup start_info page.
SAL data are now in domain memory.
is_vti field added in domain.arch.
Many cleanups (indentation, static, warnings).

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Wed Jul 05 09:28:32 2006 -0600 (2006-07-05)
parents 23591d2c46aa
children a67c1bcb5522
line source
1 diff -pru ../pristine-linux-2.6.16.13/drivers/oprofile/buffer_sync.c ./drivers/oprofile/buffer_sync.c
2 --- ../pristine-linux-2.6.16.13/drivers/oprofile/buffer_sync.c 2006-05-03 05:38:44.000000000 +0800
3 +++ ./drivers/oprofile/buffer_sync.c 2006-06-27 12:14:53.000000000 +0800
4 @@ -6,6 +6,10 @@
5 *
6 * @author John Levon <levon@movementarian.org>
7 *
8 + * Modified by Aravind Menon for Xen
9 + * These modifications are:
10 + * Copyright (C) 2005 Hewlett-Packard Co.
11 + *
12 * This is the core of the buffer management. Each
13 * CPU buffer is processed and entered into the
14 * global event buffer. Such processing is necessary
15 @@ -275,15 +279,30 @@ static void add_cpu_switch(int i)
16 last_cookie = INVALID_COOKIE;
17 }
19 -static void add_kernel_ctx_switch(unsigned int in_kernel)
20 +static void add_cpu_mode_switch(unsigned int cpu_mode)
21 {
22 add_event_entry(ESCAPE_CODE);
23 - if (in_kernel)
24 - add_event_entry(KERNEL_ENTER_SWITCH_CODE);
25 - else
26 - add_event_entry(KERNEL_EXIT_SWITCH_CODE);
27 + switch (cpu_mode) {
28 + case CPU_MODE_USER:
29 + add_event_entry(USER_ENTER_SWITCH_CODE);
30 + break;
31 + case CPU_MODE_KERNEL:
32 + add_event_entry(KERNEL_ENTER_SWITCH_CODE);
33 + break;
34 + case CPU_MODE_XEN:
35 + add_event_entry(XEN_ENTER_SWITCH_CODE);
36 + break;
37 + case CPU_MODE_PASSIVE_START:
38 + add_event_entry(PASSIVE_START_CODE);
39 + break;
40 + case CPU_MODE_PASSIVE_STOP:
41 + add_event_entry(PASSIVE_STOP_CODE);
42 + break;
43 + default:
44 + break;
45 + }
46 }
47 -
48 +
49 static void
50 add_user_ctx_switch(struct task_struct const * task, unsigned long cookie)
51 {
52 @@ -348,9 +367,9 @@ static int add_us_sample(struct mm_struc
53 * for later lookup from userspace.
54 */
55 static int
56 -add_sample(struct mm_struct * mm, struct op_sample * s, int in_kernel)
57 +add_sample(struct mm_struct * mm, struct op_sample * s, int cpu_mode)
58 {
59 - if (in_kernel) {
60 + if (cpu_mode >= CPU_MODE_KERNEL) {
61 add_sample_entry(s->eip, s->event);
62 return 1;
63 } else if (mm) {
64 @@ -496,10 +515,11 @@ void sync_buffer(int cpu)
65 struct mm_struct *mm = NULL;
66 struct task_struct * new;
67 unsigned long cookie = 0;
68 - int in_kernel = 1;
69 + int cpu_mode = 1;
70 unsigned int i;
71 sync_buffer_state state = sb_buffer_start;
72 unsigned long available;
73 + int domain_switch = NO_DOMAIN_SWITCH;
75 down(&buffer_sem);
77 @@ -513,12 +533,19 @@ void sync_buffer(int cpu)
78 struct op_sample * s = &cpu_buf->buffer[cpu_buf->tail_pos];
80 if (is_code(s->eip)) {
81 - if (s->event <= CPU_IS_KERNEL) {
82 + if (s->event < CPU_TRACE_BEGIN) {
83 /* kernel/userspace switch */
84 - in_kernel = s->event;
85 + cpu_mode = s->event;
86 if (state == sb_buffer_start)
87 state = sb_sample_start;
88 - add_kernel_ctx_switch(s->event);
89 +
90 + if (s->event == CPU_MODE_PASSIVE_START)
91 + domain_switch = DOMAIN_SWITCH_START_EVENT1;
92 + else if (s->event == CPU_MODE_PASSIVE_STOP)
93 + domain_switch = DOMAIN_SWITCH_STOP_EVENT1;
94 +
95 + if (domain_switch != DOMAIN_SWITCH_START_EVENT2)
96 + add_cpu_mode_switch(s->event);
97 } else if (s->event == CPU_TRACE_BEGIN) {
98 state = sb_bt_start;
99 add_trace_begin();
100 @@ -535,11 +562,20 @@ void sync_buffer(int cpu)
101 add_user_ctx_switch(new, cookie);
102 }
103 } else {
104 - if (state >= sb_bt_start &&
105 - !add_sample(mm, s, in_kernel)) {
106 - if (state == sb_bt_start) {
107 - state = sb_bt_ignore;
108 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
109 + if (domain_switch == DOMAIN_SWITCH_START_EVENT1) {
110 + add_event_entry(s->event);
111 + domain_switch = DOMAIN_SWITCH_START_EVENT2;
112 + } else if (domain_switch == DOMAIN_SWITCH_START_EVENT1) {
113 + add_sample_entry(s->eip, s->event);
114 + } else if (domain_switch == DOMAIN_SWITCH_STOP_EVENT1) {
115 + domain_switch = NO_DOMAIN_SWITCH;
116 + } else {
117 + if (state >= sb_bt_start &&
118 + !add_sample(mm, s, cpu_mode)) {
119 + if (state == sb_bt_start) {
120 + state = sb_bt_ignore;
121 + atomic_inc(&oprofile_stats.bt_lost_no_mapping);
122 + }
123 }
124 }
125 }
126 diff -pru ../pristine-linux-2.6.16.13/drivers/oprofile/cpu_buffer.c ./drivers/oprofile/cpu_buffer.c
127 --- ../pristine-linux-2.6.16.13/drivers/oprofile/cpu_buffer.c 2006-05-03 05:38:44.000000000 +0800
128 +++ ./drivers/oprofile/cpu_buffer.c 2006-06-19 22:43:53.000000000 +0800
129 @@ -6,6 +6,10 @@
130 *
131 * @author John Levon <levon@movementarian.org>
132 *
133 + * Modified by Aravind Menon for Xen
134 + * These modifications are:
135 + * Copyright (C) 2005 Hewlett-Packard Co.
136 + *
137 * Each CPU has a local buffer that stores PC value/event
138 * pairs. We also log context switches when we notice them.
139 * Eventually each CPU's buffer is processed into the global
140 @@ -58,7 +62,7 @@ int alloc_cpu_buffers(void)
141 goto fail;
143 b->last_task = NULL;
144 - b->last_is_kernel = -1;
145 + b->last_cpu_mode = -1;
146 b->tracing = 0;
147 b->buffer_size = buffer_size;
148 b->tail_pos = 0;
149 @@ -114,7 +118,7 @@ void cpu_buffer_reset(struct oprofile_cp
150 * collected will populate the buffer with proper
151 * values to initialize the buffer
152 */
153 - cpu_buf->last_is_kernel = -1;
154 + cpu_buf->last_cpu_mode = -1;
155 cpu_buf->last_task = NULL;
156 }
158 @@ -164,13 +168,13 @@ add_code(struct oprofile_cpu_buffer * bu
159 * because of the head/tail separation of the writer and reader
160 * of the CPU buffer.
161 *
162 - * is_kernel is needed because on some architectures you cannot
163 + * cpu_mode is needed because on some architectures you cannot
164 * tell if you are in kernel or user space simply by looking at
165 - * pc. We tag this in the buffer by generating kernel enter/exit
166 - * events whenever is_kernel changes
167 + * pc. We tag this in the buffer by generating kernel/user (and xen)
168 + * enter events whenever cpu_mode changes
169 */
170 static int log_sample(struct oprofile_cpu_buffer * cpu_buf, unsigned long pc,
171 - int is_kernel, unsigned long event)
172 + int cpu_mode, unsigned long event)
173 {
174 struct task_struct * task;
176 @@ -181,16 +185,14 @@ static int log_sample(struct oprofile_cp
177 return 0;
178 }
180 - is_kernel = !!is_kernel;
181 -
182 task = current;
184 /* notice a switch from user->kernel or vice versa */
185 - if (cpu_buf->last_is_kernel != is_kernel) {
186 - cpu_buf->last_is_kernel = is_kernel;
187 - add_code(cpu_buf, is_kernel);
188 + if (cpu_buf->last_cpu_mode != cpu_mode) {
189 + cpu_buf->last_cpu_mode = cpu_mode;
190 + add_code(cpu_buf, cpu_mode);
191 }
192 -
193 +
194 /* notice a task switch */
195 if (cpu_buf->last_task != task) {
196 cpu_buf->last_task = task;
197 diff -pru ../pristine-linux-2.6.16.13/drivers/oprofile/cpu_buffer.h ./drivers/oprofile/cpu_buffer.h
198 --- ../pristine-linux-2.6.16.13/drivers/oprofile/cpu_buffer.h 2006-05-03 05:38:44.000000000 +0800
199 +++ ./drivers/oprofile/cpu_buffer.h 2006-06-27 10:38:08.000000000 +0800
200 @@ -36,7 +36,7 @@ struct oprofile_cpu_buffer {
201 volatile unsigned long tail_pos;
202 unsigned long buffer_size;
203 struct task_struct * last_task;
204 - int last_is_kernel;
205 + int last_cpu_mode;
206 int tracing;
207 struct op_sample * buffer;
208 unsigned long sample_received;
209 @@ -51,7 +51,13 @@ extern struct oprofile_cpu_buffer cpu_bu
210 void cpu_buffer_reset(struct oprofile_cpu_buffer * cpu_buf);
212 /* transient events for the CPU buffer -> event buffer */
213 -#define CPU_IS_KERNEL 1
214 -#define CPU_TRACE_BEGIN 2
215 +#define CPU_MODE_USER 0
216 +#define CPU_MODE_KERNEL 1
217 +#define CPU_MODE_XEN 2
218 +#define CPU_MODE_PASSIVE_START 3
219 +#define CPU_MODE_PASSIVE_STOP 4
220 +#define CPU_TRACE_BEGIN 5
221 +
222 +#define IGNORED_PC 0
224 #endif /* OPROFILE_CPU_BUFFER_H */
225 diff -pru ../pristine-linux-2.6.16.13/drivers/oprofile/event_buffer.h ./drivers/oprofile/event_buffer.h
226 --- ../pristine-linux-2.6.16.13/drivers/oprofile/event_buffer.h 2006-05-03 05:38:44.000000000 +0800
227 +++ ./drivers/oprofile/event_buffer.h 2006-06-19 22:43:53.000000000 +0800
228 @@ -29,11 +29,14 @@ void wake_up_buffer_waiter(void);
229 #define CPU_SWITCH_CODE 2
230 #define COOKIE_SWITCH_CODE 3
231 #define KERNEL_ENTER_SWITCH_CODE 4
232 -#define KERNEL_EXIT_SWITCH_CODE 5
233 +#define USER_ENTER_SWITCH_CODE 5
234 #define MODULE_LOADED_CODE 6
235 #define CTX_TGID_CODE 7
236 #define TRACE_BEGIN_CODE 8
237 #define TRACE_END_CODE 9
238 +#define XEN_ENTER_SWITCH_CODE 10
239 +#define PASSIVE_START_CODE 11
240 +#define PASSIVE_STOP_CODE 12
242 #define INVALID_COOKIE ~0UL
243 #define NO_COOKIE 0UL
244 diff -pru ../pristine-linux-2.6.16.13/drivers/oprofile/oprof.c ./drivers/oprofile/oprof.c
245 --- ../pristine-linux-2.6.16.13/drivers/oprofile/oprof.c 2006-05-03 05:38:44.000000000 +0800
246 +++ ./drivers/oprofile/oprof.c 2006-06-19 23:45:17.000000000 +0800
247 @@ -5,6 +5,10 @@
248 * @remark Read the file COPYING
249 *
250 * @author John Levon <levon@movementarian.org>
251 + *
252 + * Modified by Aravind Menon for Xen
253 + * These modifications are:
254 + * Copyright (C) 2005 Hewlett-Packard Co.
255 */
257 #include <linux/kernel.h>
258 @@ -19,7 +23,7 @@
259 #include "cpu_buffer.h"
260 #include "buffer_sync.h"
261 #include "oprofile_stats.h"
262 -
263 +
264 struct oprofile_operations oprofile_ops;
266 unsigned long oprofile_started;
267 @@ -33,6 +37,32 @@ static DECLARE_MUTEX(start_sem);
268 */
269 static int timer = 0;
271 +int oprofile_set_active(int active_domains[], unsigned int adomains)
272 +{
273 + int err;
274 +
275 + if (!oprofile_ops.set_active)
276 + return -EINVAL;
277 +
278 + down(&start_sem);
279 + err = oprofile_ops.set_active(active_domains, adomains);
280 + up(&start_sem);
281 + return err;
282 +}
283 +
284 +int oprofile_set_passive(int passive_domains[], unsigned int pdomains)
285 +{
286 + int err;
287 +
288 + if (!oprofile_ops.set_passive)
289 + return -EINVAL;
290 +
291 + down(&start_sem);
292 + err = oprofile_ops.set_passive(passive_domains, pdomains);
293 + up(&start_sem);
294 + return err;
295 +}
296 +
297 int oprofile_setup(void)
298 {
299 int err;
300 diff -pru ../pristine-linux-2.6.16.13/drivers/oprofile/oprof.h ./drivers/oprofile/oprof.h
301 --- ../pristine-linux-2.6.16.13/drivers/oprofile/oprof.h 2006-05-03 05:38:44.000000000 +0800
302 +++ ./drivers/oprofile/oprof.h 2006-06-19 23:42:36.000000000 +0800
303 @@ -35,5 +35,8 @@ void oprofile_create_files(struct super_
304 void oprofile_timer_init(struct oprofile_operations * ops);
306 int oprofile_set_backtrace(unsigned long depth);
307 +
308 +int oprofile_set_active(int active_domains[], unsigned int adomains);
309 +int oprofile_set_passive(int passive_domains[], unsigned int pdomains);
311 #endif /* OPROF_H */
312 diff -pru ../pristine-linux-2.6.16.13/drivers/oprofile/oprofile_files.c ./drivers/oprofile/oprofile_files.c
313 --- ../pristine-linux-2.6.16.13/drivers/oprofile/oprofile_files.c 2006-05-03 05:38:44.000000000 +0800
314 +++ ./drivers/oprofile/oprofile_files.c 2006-06-19 23:29:07.000000000 +0800
315 @@ -5,15 +5,21 @@
316 * @remark Read the file COPYING
317 *
318 * @author John Levon <levon@movementarian.org>
319 + *
320 + * Modified by Aravind Menon for Xen
321 + * These modifications are:
322 + * Copyright (C) 2005 Hewlett-Packard Co.
323 */
325 #include <linux/fs.h>
326 #include <linux/oprofile.h>
327 +#include <asm/uaccess.h>
328 +#include <linux/ctype.h>
330 #include "event_buffer.h"
331 #include "oprofile_stats.h"
332 #include "oprof.h"
333 -
334 +
335 unsigned long fs_buffer_size = 131072;
336 unsigned long fs_cpu_buffer_size = 8192;
337 unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
338 @@ -117,11 +123,202 @@ static ssize_t dump_write(struct file *
339 static struct file_operations dump_fops = {
340 .write = dump_write,
341 };
342 -
343 +
344 +#define TMPBUFSIZE 512
345 +
346 +static unsigned int adomains = 0;
347 +static int active_domains[MAX_OPROF_DOMAINS + 1];
348 +static DEFINE_MUTEX(adom_mutex);
349 +
350 +static ssize_t adomain_write(struct file * file, char const __user * buf,
351 + size_t count, loff_t * offset)
352 +{
353 + char *tmpbuf;
354 + char *startp, *endp;
355 + int i;
356 + unsigned long val;
357 + ssize_t retval = count;
358 +
359 + if (*offset)
360 + return -EINVAL;
361 + if (count > TMPBUFSIZE - 1)
362 + return -EINVAL;
363 +
364 + if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
365 + return -ENOMEM;
366 +
367 + if (copy_from_user(tmpbuf, buf, count)) {
368 + kfree(tmpbuf);
369 + return -EFAULT;
370 + }
371 + tmpbuf[count] = 0;
372 +
373 + mutex_lock(&adom_mutex);
374 +
375 + startp = tmpbuf;
376 + /* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
377 + for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
378 + val = simple_strtoul(startp, &endp, 0);
379 + if (endp == startp)
380 + break;
381 + while (ispunct(*endp) || isspace(*endp))
382 + endp++;
383 + active_domains[i] = val;
384 + if (active_domains[i] != val)
385 + /* Overflow, force error below */
386 + i = MAX_OPROF_DOMAINS + 1;
387 + startp = endp;
388 + }
389 + /* Force error on trailing junk */
390 + adomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
391 +
392 + kfree(tmpbuf);
393 +
394 + if (adomains > MAX_OPROF_DOMAINS
395 + || oprofile_set_active(active_domains, adomains)) {
396 + adomains = 0;
397 + retval = -EINVAL;
398 + }
399 +
400 + mutex_unlock(&adom_mutex);
401 + return retval;
402 +}
403 +
404 +static ssize_t adomain_read(struct file * file, char __user * buf,
405 + size_t count, loff_t * offset)
406 +{
407 + char * tmpbuf;
408 + size_t len;
409 + int i;
410 + ssize_t retval;
411 +
412 + if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
413 + return -ENOMEM;
414 +
415 + mutex_lock(&adom_mutex);
416 +
417 + len = 0;
418 + for (i = 0; i < adomains; i++)
419 + len += snprintf(tmpbuf + len,
420 + len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
421 + "%u ", active_domains[i]);
422 + WARN_ON(len > TMPBUFSIZE);
423 + if (len != 0 && len <= TMPBUFSIZE)
424 + tmpbuf[len-1] = '\n';
425 +
426 + mutex_unlock(&adom_mutex);
427 +
428 + retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
429 +
430 + kfree(tmpbuf);
431 + return retval;
432 +}
433 +
434 +
435 +static struct file_operations active_domain_ops = {
436 + .read = adomain_read,
437 + .write = adomain_write,
438 +};
439 +
440 +static unsigned int pdomains = 0;
441 +static int passive_domains[MAX_OPROF_DOMAINS];
442 +static DEFINE_MUTEX(pdom_mutex);
443 +
444 +static ssize_t pdomain_write(struct file * file, char const __user * buf,
445 + size_t count, loff_t * offset)
446 +{
447 + char *tmpbuf;
448 + char *startp, *endp;
449 + int i;
450 + unsigned long val;
451 + ssize_t retval = count;
452 +
453 + if (*offset)
454 + return -EINVAL;
455 + if (count > TMPBUFSIZE - 1)
456 + return -EINVAL;
457 +
458 + if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
459 + return -ENOMEM;
460 +
461 + if (copy_from_user(tmpbuf, buf, count)) {
462 + kfree(tmpbuf);
463 + return -EFAULT;
464 + }
465 + tmpbuf[count] = 0;
466 +
467 + mutex_lock(&pdom_mutex);
468 +
469 + startp = tmpbuf;
470 + /* Parse one more than MAX_OPROF_DOMAINS, for easy error checking */
471 + for (i = 0; i <= MAX_OPROF_DOMAINS; i++) {
472 + val = simple_strtoul(startp, &endp, 0);
473 + if (endp == startp)
474 + break;
475 + while (ispunct(*endp) || isspace(*endp))
476 + endp++;
477 + passive_domains[i] = val;
478 + if (passive_domains[i] != val)
479 + /* Overflow, force error below */
480 + i = MAX_OPROF_DOMAINS + 1;
481 + startp = endp;
482 + }
483 + /* Force error on trailing junk */
484 + pdomains = *startp ? MAX_OPROF_DOMAINS + 1 : i;
485 +
486 + kfree(tmpbuf);
487 +
488 + if (pdomains > MAX_OPROF_DOMAINS
489 + || oprofile_set_passive(passive_domains, pdomains)) {
490 + pdomains = 0;
491 + retval = -EINVAL;
492 + }
493 +
494 + mutex_unlock(&pdom_mutex);
495 + return retval;
496 +}
497 +
498 +static ssize_t pdomain_read(struct file * file, char __user * buf,
499 + size_t count, loff_t * offset)
500 +{
501 + char * tmpbuf;
502 + size_t len;
503 + int i;
504 + ssize_t retval;
505 +
506 + if (!(tmpbuf = kmalloc(TMPBUFSIZE, GFP_KERNEL)))
507 + return -ENOMEM;
508 +
509 + mutex_lock(&pdom_mutex);
510 +
511 + len = 0;
512 + for (i = 0; i < pdomains; i++)
513 + len += snprintf(tmpbuf + len,
514 + len < TMPBUFSIZE ? TMPBUFSIZE - len : 0,
515 + "%u ", passive_domains[i]);
516 + WARN_ON(len > TMPBUFSIZE);
517 + if (len != 0 && len <= TMPBUFSIZE)
518 + tmpbuf[len-1] = '\n';
519 +
520 + mutex_unlock(&pdom_mutex);
521 +
522 + retval = simple_read_from_buffer(buf, count, offset, tmpbuf, len);
523 +
524 + kfree(tmpbuf);
525 + return retval;
526 +}
527 +
528 +static struct file_operations passive_domain_ops = {
529 + .read = pdomain_read,
530 + .write = pdomain_write,
531 +};
532 +
533 void oprofile_create_files(struct super_block * sb, struct dentry * root)
534 {
535 oprofilefs_create_file(sb, root, "enable", &enable_fops);
536 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
537 + oprofilefs_create_file(sb, root, "active_domains", &active_domain_ops);
538 + oprofilefs_create_file(sb, root, "passive_domains", &passive_domain_ops);
539 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
540 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size);
541 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
542 --- ../pristine-linux-2.6.16.13/include/linux/oprofile.h 2006-05-03 05:38:44.000000000 +0800
543 +++ ./include/linux/oprofile.h 2006-06-19 23:52:00.000000000 +0800
544 @@ -16,6 +16,8 @@
545 #include <linux/types.h>
546 #include <linux/spinlock.h>
547 #include <asm/atomic.h>
548 +
549 +#include <xen/interface/xenoprof.h>
551 struct super_block;
552 struct dentry;
553 @@ -27,6 +29,11 @@ struct oprofile_operations {
554 /* create any necessary configuration files in the oprofile fs.
555 * Optional. */
556 int (*create_files)(struct super_block * sb, struct dentry * root);
557 + /* setup active domains with Xen */
558 + int (*set_active)(int *active_domains, unsigned int adomains);
559 + /* setup passive domains with Xen */
560 + int (*set_passive)(int *passive_domains, unsigned int pdomains);
561 +
562 /* Do any necessary interrupt setup. Optional. */
563 int (*setup)(void);
564 /* Do any necessary interrupt shutdown. Optional. */