4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
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 <linux/cpu.h>
17 #include <linux/hrtimer.h>
18 #include <asm/irq_regs.h>
19 #include <asm/ptrace.h>
23 static DEFINE_PER_CPU(struct hrtimer
, oprofile_hrtimer
);
24 static int ctr_running
;
26 static enum hrtimer_restart
oprofile_hrtimer_notify(struct hrtimer
*hrtimer
)
28 oprofile_add_sample(get_irq_regs(), 0);
29 hrtimer_forward_now(hrtimer
, ns_to_ktime(TICK_NSEC
));
30 return HRTIMER_RESTART
;
33 static void __oprofile_hrtimer_start(void *unused
)
35 struct hrtimer
*hrtimer
= &__get_cpu_var(oprofile_hrtimer
);
40 hrtimer_init(hrtimer
, CLOCK_MONOTONIC
, HRTIMER_MODE_REL
);
41 hrtimer
->function
= oprofile_hrtimer_notify
;
43 hrtimer_start(hrtimer
, ns_to_ktime(TICK_NSEC
),
44 HRTIMER_MODE_REL_PINNED
);
47 static int oprofile_hrtimer_start(void)
51 on_each_cpu(__oprofile_hrtimer_start
, NULL
, 1);
56 static void __oprofile_hrtimer_stop(int cpu
)
58 struct hrtimer
*hrtimer
= &per_cpu(oprofile_hrtimer
, cpu
);
63 hrtimer_cancel(hrtimer
);
66 static void oprofile_hrtimer_stop(void)
71 for_each_online_cpu(cpu
)
72 __oprofile_hrtimer_stop(cpu
);
77 static int __cpuinit
oprofile_cpu_notify(struct notifier_block
*self
,
78 unsigned long action
, void *hcpu
)
80 long cpu
= (long) hcpu
;
84 case CPU_ONLINE_FROZEN
:
85 smp_call_function_single(cpu
, __oprofile_hrtimer_start
,
90 __oprofile_hrtimer_stop(cpu
);
96 static struct notifier_block __refdata oprofile_cpu_notifier
= {
97 .notifier_call
= oprofile_cpu_notify
,
100 int oprofile_timer_init(struct oprofile_operations
*ops
)
104 rc
= register_hotcpu_notifier(&oprofile_cpu_notifier
);
107 ops
->create_files
= NULL
;
109 ops
->shutdown
= NULL
;
110 ops
->start
= oprofile_hrtimer_start
;
111 ops
->stop
= oprofile_hrtimer_stop
;
112 ops
->cpu_type
= "timer";
116 void oprofile_timer_exit(void)
118 unregister_hotcpu_notifier(&oprofile_cpu_notifier
);