2 * linux/kernel/profile.c
5 #include <linux/config.h>
6 #include <linux/module.h>
7 #include <linux/profile.h>
8 #include <linux/bootmem.h>
9 #include <linux/notifier.h>
11 #include <asm/sections.h>
13 unsigned int * prof_buffer;
14 unsigned long prof_len;
15 unsigned long prof_shift;
18 int __init profile_setup(char * str)
21 if (get_option(&str,&par)) {
24 printk(KERN_INFO "kernel profiling enabled\n");
30 void __init profile_init(void)
37 /* only text is profiled */
38 prof_len = _etext - _stext;
39 prof_len >>= prof_shift;
41 size = prof_len * sizeof(unsigned int) + PAGE_SIZE - 1;
42 prof_buffer = (unsigned int *) alloc_bootmem(size);
45 /* Profile event notifications */
47 #ifdef CONFIG_PROFILING
49 static DECLARE_RWSEM(profile_rwsem);
50 static struct notifier_block * exit_task_notifier;
51 static struct notifier_block * exit_mmap_notifier;
52 static struct notifier_block * exec_unmap_notifier;
54 void profile_exit_task(struct task_struct * task)
56 down_read(&profile_rwsem);
57 notifier_call_chain(&exit_task_notifier, 0, task);
58 up_read(&profile_rwsem);
61 void profile_exit_mmap(struct mm_struct * mm)
63 down_read(&profile_rwsem);
64 notifier_call_chain(&exit_mmap_notifier, 0, mm);
65 up_read(&profile_rwsem);
68 void profile_exec_unmap(struct mm_struct * mm)
70 down_read(&profile_rwsem);
71 notifier_call_chain(&exec_unmap_notifier, 0, mm);
72 up_read(&profile_rwsem);
75 int profile_event_register(enum profile_type type, struct notifier_block * n)
79 down_write(&profile_rwsem);
83 err = notifier_chain_register(&exit_task_notifier, n);
86 err = notifier_chain_register(&exit_mmap_notifier, n);
89 err = notifier_chain_register(&exec_unmap_notifier, n);
93 up_write(&profile_rwsem);
99 int profile_event_unregister(enum profile_type type, struct notifier_block * n)
103 down_write(&profile_rwsem);
107 err = notifier_chain_unregister(&exit_task_notifier, n);
110 err = notifier_chain_unregister(&exit_mmap_notifier, n);
113 err = notifier_chain_unregister(&exec_unmap_notifier, n);
117 up_write(&profile_rwsem);
121 static struct notifier_block * profile_listeners;
122 static rwlock_t profile_lock = RW_LOCK_UNLOCKED;
124 int register_profile_notifier(struct notifier_block * nb)
127 write_lock_irq(&profile_lock);
128 err = notifier_chain_register(&profile_listeners, nb);
129 write_unlock_irq(&profile_lock);
134 int unregister_profile_notifier(struct notifier_block * nb)
137 write_lock_irq(&profile_lock);
138 err = notifier_chain_unregister(&profile_listeners, nb);
139 write_unlock_irq(&profile_lock);
144 void profile_hook(struct pt_regs * regs)
146 read_lock(&profile_lock);
147 notifier_call_chain(&profile_listeners, 0, regs);
148 read_unlock(&profile_lock);
151 EXPORT_SYMBOL_GPL(register_profile_notifier);
152 EXPORT_SYMBOL_GPL(unregister_profile_notifier);
154 #endif /* CONFIG_PROFILING */
156 EXPORT_SYMBOL_GPL(profile_event_register);
157 EXPORT_SYMBOL_GPL(profile_event_unregister);