oprofile: Fix crash when unloading module (hr timer mode)
[linux-2.6.git] / drivers / oprofile / timer_int.c
index dc0ae4d..878fba1 100644 (file)
@@ -21,6 +21,7 @@
 #include "oprof.h"
 
 static DEFINE_PER_CPU(struct hrtimer, oprofile_hrtimer);
+static int ctr_running;
 
 static enum hrtimer_restart oprofile_hrtimer_notify(struct hrtimer *hrtimer)
 {
@@ -33,6 +34,9 @@ static void __oprofile_hrtimer_start(void *unused)
 {
        struct hrtimer *hrtimer = &__get_cpu_var(oprofile_hrtimer);
 
+       if (!ctr_running)
+               return;
+
        hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        hrtimer->function = oprofile_hrtimer_notify;
 
@@ -42,7 +46,10 @@ static void __oprofile_hrtimer_start(void *unused)
 
 static int oprofile_hrtimer_start(void)
 {
+       get_online_cpus();
+       ctr_running = 1;
        on_each_cpu(__oprofile_hrtimer_start, NULL, 1);
+       put_online_cpus();
        return 0;
 }
 
@@ -50,6 +57,9 @@ static void __oprofile_hrtimer_stop(int cpu)
 {
        struct hrtimer *hrtimer = &per_cpu(oprofile_hrtimer, cpu);
 
+       if (!ctr_running)
+               return;
+
        hrtimer_cancel(hrtimer);
 }
 
@@ -57,8 +67,11 @@ static void oprofile_hrtimer_stop(void)
 {
        int cpu;
 
+       get_online_cpus();
        for_each_online_cpu(cpu)
                __oprofile_hrtimer_stop(cpu);
+       ctr_running = 0;
+       put_online_cpus();
 }
 
 static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
@@ -84,7 +97,7 @@ static struct notifier_block __refdata oprofile_cpu_notifier = {
        .notifier_call = oprofile_cpu_notify,
 };
 
-int __init oprofile_timer_init(struct oprofile_operations *ops)
+int oprofile_timer_init(struct oprofile_operations *ops)
 {
        int rc;
 
@@ -97,10 +110,11 @@ int __init oprofile_timer_init(struct oprofile_operations *ops)
        ops->start = oprofile_hrtimer_start;
        ops->stop = oprofile_hrtimer_stop;
        ops->cpu_type = "timer";
+       printk(KERN_INFO "oprofile: using timer interrupt.\n");
        return 0;
 }
 
-void __exit oprofile_timer_exit(void)
+void oprofile_timer_exit(void)
 {
        unregister_hotcpu_notifier(&oprofile_cpu_notifier);
 }