Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / kernel / profile.c
index a38fa70..68afe12 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/cpu.h>
 #include <linux/profile.h>
 #include <linux/highmem.h>
+#include <linux/mutex.h>
 #include <asm/sections.h>
 #include <asm/semaphore.h>
 
@@ -35,29 +36,33 @@ struct profile_hit {
 #define NR_PROFILE_GRP         (NR_PROFILE_HIT/PROFILE_GRPSZ)
 
 /* Oprofile timer tick hook */
-int (*timer_hook)(struct pt_regs *);
+int (*timer_hook)(struct pt_regs *) __read_mostly;
 
 static atomic_t *prof_buffer;
 static unsigned long prof_len, prof_shift;
-static int prof_on;
+static int prof_on __read_mostly;
 static cpumask_t prof_cpu_mask = CPU_MASK_ALL;
 #ifdef CONFIG_SMP
 static DEFINE_PER_CPU(struct profile_hit *[2], cpu_profile_hits);
 static DEFINE_PER_CPU(int, cpu_profile_flip);
-static DECLARE_MUTEX(profile_flip_mutex);
+static DEFINE_MUTEX(profile_flip_mutex);
 #endif /* CONFIG_SMP */
 
 static int __init profile_setup(char * str)
 {
+       static char __initdata schedstr[] = "schedule";
        int par;
 
-       if (!strncmp(str, "schedule", 8)) {
+       if (!strncmp(str, schedstr, strlen(schedstr))) {
                prof_on = SCHED_PROFILING;
-               printk(KERN_INFO "kernel schedule profiling enabled\n");
-               if (str[7] == ',')
-                       str += 8;
-       }
-       if (get_option(&str,&par)) {
+               if (str[strlen(schedstr)] == ',')
+                       str += strlen(schedstr) + 1;
+               if (get_option(&str, &par))
+                       prof_shift = par;
+               printk(KERN_INFO
+                       "kernel schedule profiling enabled (shift: %ld)\n",
+                       prof_shift);
+       } else if (get_option(&str, &par)) {
                prof_shift = par;
                prof_on = CPU_PROFILING;
                printk(KERN_INFO "kernel profiling enabled (shift: %ld)\n",
@@ -82,72 +87,52 @@ void __init profile_init(void)
  
 #ifdef CONFIG_PROFILING
  
-static DECLARE_RWSEM(profile_rwsem);
-static DEFINE_RWLOCK(handoff_lock);
-static struct notifier_block * task_exit_notifier;
-static struct notifier_block * task_free_notifier;
-static struct notifier_block * munmap_notifier;
+static BLOCKING_NOTIFIER_HEAD(task_exit_notifier);
+static ATOMIC_NOTIFIER_HEAD(task_free_notifier);
+static BLOCKING_NOTIFIER_HEAD(munmap_notifier);
  
 void profile_task_exit(struct task_struct * task)
 {
-       down_read(&profile_rwsem);
-       notifier_call_chain(&task_exit_notifier, 0, task);
-       up_read(&profile_rwsem);
+       blocking_notifier_call_chain(&task_exit_notifier, 0, task);
 }
  
 int profile_handoff_task(struct task_struct * task)
 {
        int ret;
-       read_lock(&handoff_lock);
-       ret = notifier_call_chain(&task_free_notifier, 0, task);
-       read_unlock(&handoff_lock);
+       ret = atomic_notifier_call_chain(&task_free_notifier, 0, task);
        return (ret == NOTIFY_OK) ? 1 : 0;
 }
 
 void profile_munmap(unsigned long addr)
 {
-       down_read(&profile_rwsem);
-       notifier_call_chain(&munmap_notifier, 0, (void *)addr);
-       up_read(&profile_rwsem);
+       blocking_notifier_call_chain(&munmap_notifier, 0, (void *)addr);
 }
 
 int task_handoff_register(struct notifier_block * n)
 {
-       int err = -EINVAL;
-
-       write_lock(&handoff_lock);
-       err = notifier_chain_register(&task_free_notifier, n);
-       write_unlock(&handoff_lock);
-       return err;
+       return atomic_notifier_chain_register(&task_free_notifier, n);
 }
 
 int task_handoff_unregister(struct notifier_block * n)
 {
-       int err = -EINVAL;
-
-       write_lock(&handoff_lock);
-       err = notifier_chain_unregister(&task_free_notifier, n);
-       write_unlock(&handoff_lock);
-       return err;
+       return atomic_notifier_chain_unregister(&task_free_notifier, n);
 }
 
 int profile_event_register(enum profile_type type, struct notifier_block * n)
 {
        int err = -EINVAL;
  
-       down_write(&profile_rwsem);
        switch (type) {
                case PROFILE_TASK_EXIT:
-                       err = notifier_chain_register(&task_exit_notifier, n);
+                       err = blocking_notifier_chain_register(
+                                       &task_exit_notifier, n);
                        break;
                case PROFILE_MUNMAP:
-                       err = notifier_chain_register(&munmap_notifier, n);
+                       err = blocking_notifier_chain_register(
+                                       &munmap_notifier, n);
                        break;
        }
  
-       up_write(&profile_rwsem);
        return err;
 }
 
@@ -156,18 +141,17 @@ int profile_event_unregister(enum profile_type type, struct notifier_block * n)
 {
        int err = -EINVAL;
  
-       down_write(&profile_rwsem);
        switch (type) {
                case PROFILE_TASK_EXIT:
-                       err = notifier_chain_unregister(&task_exit_notifier, n);
+                       err = blocking_notifier_chain_unregister(
+                                       &task_exit_notifier, n);
                        break;
                case PROFILE_MUNMAP:
-                       err = notifier_chain_unregister(&munmap_notifier, n);
+                       err = blocking_notifier_chain_unregister(
+                                       &munmap_notifier, n);
                        break;
        }
 
-       up_write(&profile_rwsem);
        return err;
 }
 
@@ -184,7 +168,7 @@ void unregister_timer_hook(int (*hook)(struct pt_regs *))
        WARN_ON(hook != timer_hook);
        timer_hook = NULL;
        /* make sure all CPUs see the NULL hook */
-       synchronize_kernel();
+       synchronize_sched();  /* Allow ongoing interrupts to complete. */
 }
 
 EXPORT_SYMBOL_GPL(register_timer_hook);
@@ -239,7 +223,7 @@ static void profile_flip_buffers(void)
 {
        int i, j, cpu;
 
-       down(&profile_flip_mutex);
+       mutex_lock(&profile_flip_mutex);
        j = per_cpu(cpu_profile_flip, get_cpu());
        put_cpu();
        on_each_cpu(__profile_flip_buffers, NULL, 0, 1);
@@ -255,14 +239,14 @@ static void profile_flip_buffers(void)
                        hits[i].hits = hits[i].pc = 0;
                }
        }
-       up(&profile_flip_mutex);
+       mutex_unlock(&profile_flip_mutex);
 }
 
 static void profile_discard_flip_buffers(void)
 {
        int i, cpu;
 
-       down(&profile_flip_mutex);
+       mutex_lock(&profile_flip_mutex);
        i = per_cpu(cpu_profile_flip, get_cpu());
        put_cpu();
        on_each_cpu(__profile_flip_buffers, NULL, 0, 1);
@@ -270,7 +254,7 @@ static void profile_discard_flip_buffers(void)
                struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[i];
                memset(hits, 0, NR_PROFILE_HIT*sizeof(struct profile_hit));
        }
-       up(&profile_flip_mutex);
+       mutex_unlock(&profile_flip_mutex);
 }
 
 void profile_hit(int type, void *__pc)
@@ -315,7 +299,7 @@ out:
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
-static int __devinit profile_cpu_callback(struct notifier_block *info,
+static int profile_cpu_callback(struct notifier_block *info,
                                        unsigned long action, void *__cpu)
 {
        int node, cpu = (unsigned long)__cpu;
@@ -522,7 +506,7 @@ static int __init create_hash_tables(void)
        return 0;
 out_cleanup:
        prof_on = 0;
-       mb();
+       smp_mb();
        on_each_cpu(profile_nop, NULL, 0, 1);
        for_each_online_cpu(cpu) {
                struct page *page;