ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / oprofile / timer_int.c
1 /**
2  * @file timer_int.c
3  *
4  * @remark Copyright 2002 OProfile authors
5  * @remark Read the file COPYING
6  *
7  * @author John Levon <levon@movementarian.org>
8  */
9
10 #include <linux/kernel.h>
11 #include <linux/notifier.h>
12 #include <linux/smp.h>
13 #include <linux/oprofile.h>
14 #include <linux/profile.h>
15 #include <linux/init.h>
16 #include <asm/ptrace.h>
17  
18 static int timer_notify(struct notifier_block * self, unsigned long val, void * data)
19 {
20         struct pt_regs * regs = (struct pt_regs *)data;
21         int cpu = smp_processor_id();
22         unsigned long eip = instruction_pointer(regs);
23  
24         oprofile_add_sample(eip, !user_mode(regs), 0, cpu);
25         return 0;
26 }
27  
28  
29 static struct notifier_block timer_notifier = {
30         .notifier_call  = timer_notify,
31 };
32  
33
34 static int timer_start(void)
35 {
36         return register_profile_notifier(&timer_notifier);
37 }
38
39
40 static void timer_stop(void)
41 {
42         unregister_profile_notifier(&timer_notifier);
43 }
44
45
46 static struct oprofile_operations timer_ops = {
47         .start  = timer_start,
48         .stop   = timer_stop,
49         .cpu_type = "timer"
50 };
51
52  
53 void __init timer_init(struct oprofile_operations ** ops)
54 {
55         *ops = &timer_ops;
56         printk(KERN_INFO "oprofile: using timer interrupt.\n");
57 }