Cleanup syscall code to look more like it's mips64 equivalent.
[linux-2.6/linux-mips.git] / kernel / profile.c
blob4f6d22ce33f207e561305f69d1b2d6368b46922a
1 /*
2 * linux/kernel/profile.c
3 */
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>
10 #include <linux/mm.h>
12 extern char _stext, _etext;
14 unsigned int * prof_buffer;
15 unsigned long prof_len;
16 unsigned long prof_shift;
17 int prof_on;
19 int __init profile_setup(char * str)
21 int par;
22 if (get_option(&str,&par)) {
23 prof_shift = par;
24 prof_on = 1;
25 printk(KERN_INFO "kernel profiling enabled\n");
27 return 1;
31 void __init profile_init(void)
33 unsigned int size;
35 if (!prof_on)
36 return;
38 /* only text is profiled */
39 prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
40 prof_len >>= prof_shift;
42 size = prof_len * sizeof(unsigned int) + PAGE_SIZE - 1;
43 prof_buffer = (unsigned int *) alloc_bootmem(size);
46 /* Profile event notifications */
48 #ifdef CONFIG_PROFILING
50 static DECLARE_RWSEM(profile_rwsem);
51 static struct notifier_block * exit_task_notifier;
52 static struct notifier_block * exit_mmap_notifier;
53 static struct notifier_block * exec_unmap_notifier;
55 void profile_exit_task(struct task_struct * task)
57 down_read(&profile_rwsem);
58 notifier_call_chain(&exit_task_notifier, 0, task);
59 up_read(&profile_rwsem);
62 void profile_exit_mmap(struct mm_struct * mm)
64 down_read(&profile_rwsem);
65 notifier_call_chain(&exit_mmap_notifier, 0, mm);
66 up_read(&profile_rwsem);
69 void profile_exec_unmap(struct mm_struct * mm)
71 down_read(&profile_rwsem);
72 notifier_call_chain(&exec_unmap_notifier, 0, mm);
73 up_read(&profile_rwsem);
76 int profile_event_register(enum profile_type type, struct notifier_block * n)
78 int err = -EINVAL;
80 down_write(&profile_rwsem);
82 switch (type) {
83 case EXIT_TASK:
84 err = notifier_chain_register(&exit_task_notifier, n);
85 break;
86 case EXIT_MMAP:
87 err = notifier_chain_register(&exit_mmap_notifier, n);
88 break;
89 case EXEC_UNMAP:
90 err = notifier_chain_register(&exec_unmap_notifier, n);
91 break;
94 up_write(&profile_rwsem);
96 return err;
100 int profile_event_unregister(enum profile_type type, struct notifier_block * n)
102 int err = -EINVAL;
104 down_write(&profile_rwsem);
106 switch (type) {
107 case EXIT_TASK:
108 err = notifier_chain_unregister(&exit_task_notifier, n);
109 break;
110 case EXIT_MMAP:
111 err = notifier_chain_unregister(&exit_mmap_notifier, n);
112 break;
113 case EXEC_UNMAP:
114 err = notifier_chain_unregister(&exec_unmap_notifier, n);
115 break;
118 up_write(&profile_rwsem);
119 return err;
122 static struct notifier_block * profile_listeners;
123 static rwlock_t profile_lock = RW_LOCK_UNLOCKED;
125 int register_profile_notifier(struct notifier_block * nb)
127 int err;
128 write_lock_irq(&profile_lock);
129 err = notifier_chain_register(&profile_listeners, nb);
130 write_unlock_irq(&profile_lock);
131 return err;
135 int unregister_profile_notifier(struct notifier_block * nb)
137 int err;
138 write_lock_irq(&profile_lock);
139 err = notifier_chain_unregister(&profile_listeners, nb);
140 write_unlock_irq(&profile_lock);
141 return err;
145 void profile_hook(struct pt_regs * regs)
147 read_lock(&profile_lock);
148 notifier_call_chain(&profile_listeners, 0, regs);
149 read_unlock(&profile_lock);
152 EXPORT_SYMBOL_GPL(register_profile_notifier);
153 EXPORT_SYMBOL_GPL(unregister_profile_notifier);
155 #endif /* CONFIG_PROFILING */
157 EXPORT_SYMBOL_GPL(profile_event_register);
158 EXPORT_SYMBOL_GPL(profile_event_unregister);