diff options
author | Mikael Starvik <mikael.starvik@axis.com> | 2005-07-27 14:44:40 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-07-27 19:26:00 -0400 |
commit | 21783c9746619a782c21be606f6498bbd4d4615e (patch) | |
tree | e02f3e7b583576d850b3aac2fdcf38172ee565eb | |
parent | 59c61138a556cf89692e0d5bd2c9de5df54b824f (diff) |
[PATCH] CRIS update: profiler
System-level profiler.
Signed-off-by: Mikael Starvik <starvik@axis.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | arch/cris/kernel/profile.c | 73 | ||||
-rw-r--r-- | arch/cris/kernel/time.c | 18 | ||||
-rw-r--r-- | include/asm-cris/ptrace.h | 2 |
3 files changed, 92 insertions, 1 deletions
diff --git a/arch/cris/kernel/profile.c b/arch/cris/kernel/profile.c new file mode 100644 index 000000000000..69c52189f044 --- /dev/null +++ b/arch/cris/kernel/profile.c | |||
@@ -0,0 +1,73 @@ | |||
1 | #include <linux/init.h> | ||
2 | #include <linux/errno.h> | ||
3 | #include <linux/kernel.h> | ||
4 | #include <linux/proc_fs.h> | ||
5 | #include <linux/types.h> | ||
6 | #include <asm/ptrace.h> | ||
7 | #include <asm/uaccess.h> | ||
8 | |||
9 | #define SAMPLE_BUFFER_SIZE 8192 | ||
10 | |||
11 | static char* sample_buffer; | ||
12 | static char* sample_buffer_pos; | ||
13 | static int prof_running = 0; | ||
14 | |||
15 | void | ||
16 | cris_profile_sample(struct pt_regs* regs) | ||
17 | { | ||
18 | if (!prof_running) | ||
19 | return; | ||
20 | if (user_mode(regs)) | ||
21 | *(unsigned int*)sample_buffer_pos = current->pid; | ||
22 | else | ||
23 | *(unsigned int*)sample_buffer_pos = 0; | ||
24 | *(unsigned int*)(sample_buffer_pos + 4) = instruction_pointer(regs); | ||
25 | sample_buffer_pos += 8; | ||
26 | if (sample_buffer_pos == sample_buffer + SAMPLE_BUFFER_SIZE) | ||
27 | sample_buffer_pos = sample_buffer; | ||
28 | } | ||
29 | |||
30 | static ssize_t | ||
31 | read_cris_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos) | ||
32 | { | ||
33 | unsigned long p = *ppos; | ||
34 | if (p > SAMPLE_BUFFER_SIZE) | ||
35 | return 0; | ||
36 | if (p + count > SAMPLE_BUFFER_SIZE) | ||
37 | count = SAMPLE_BUFFER_SIZE - p; | ||
38 | if (copy_to_user(buf, sample_buffer + p,count)) | ||
39 | return -EFAULT; | ||
40 | memset(sample_buffer + p, 0, count); | ||
41 | *ppos += count; | ||
42 | return count; | ||
43 | } | ||
44 | |||
45 | static ssize_t | ||
46 | write_cris_profile(struct file *file, const char __user *buf, | ||
47 | size_t count, loff_t *ppos) | ||
48 | { | ||
49 | sample_buffer_pos = sample_buffer; | ||
50 | memset(sample_buffer, 0, SAMPLE_BUFFER_SIZE); | ||
51 | } | ||
52 | |||
53 | static struct file_operations cris_proc_profile_operations = { | ||
54 | .read = read_cris_profile, | ||
55 | .write = write_cris_profile, | ||
56 | }; | ||
57 | |||
58 | static int | ||
59 | __init init_cris_profile(void) | ||
60 | { | ||
61 | struct proc_dir_entry *entry; | ||
62 | sample_buffer = (char*)kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL); | ||
63 | sample_buffer_pos = sample_buffer; | ||
64 | entry = create_proc_entry("system_profile", S_IWUSR | S_IRUGO, NULL); | ||
65 | if (entry) { | ||
66 | entry->proc_fops = &cris_proc_profile_operations; | ||
67 | entry->size = SAMPLE_BUFFER_SIZE; | ||
68 | } | ||
69 | prof_running = 1; | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | __initcall(init_cris_profile); | ||
diff --git a/arch/cris/kernel/time.c b/arch/cris/kernel/time.c index 6c28b0e7f7b4..fa2d4323da25 100644 --- a/arch/cris/kernel/time.c +++ b/arch/cris/kernel/time.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: time.c,v 1.14 2004/06/01 05:38:11 starvik Exp $ | 1 | /* $Id: time.c,v 1.18 2005/03/04 08:16:17 starvik Exp $ |
2 | * | 2 | * |
3 | * linux/arch/cris/kernel/time.c | 3 | * linux/arch/cris/kernel/time.c |
4 | * | 4 | * |
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/bcd.h> | 30 | #include <linux/bcd.h> |
31 | #include <linux/timex.h> | 31 | #include <linux/timex.h> |
32 | #include <linux/init.h> | 32 | #include <linux/init.h> |
33 | #include <linux/profile.h> | ||
33 | 34 | ||
34 | u64 jiffies_64 = INITIAL_JIFFIES; | 35 | u64 jiffies_64 = INITIAL_JIFFIES; |
35 | 36 | ||
@@ -214,6 +215,21 @@ update_xtime_from_cmos(void) | |||
214 | } | 215 | } |
215 | } | 216 | } |
216 | 217 | ||
218 | extern void cris_profile_sample(struct pt_regs* regs); | ||
219 | |||
220 | void | ||
221 | cris_do_profile(struct pt_regs* regs) | ||
222 | { | ||
223 | |||
224 | #if CONFIG_SYSTEM_PROFILER | ||
225 | cris_profile_sample(regs); | ||
226 | #endif | ||
227 | |||
228 | #if CONFIG_PROFILING | ||
229 | profile_tick(CPU_PROFILING, regs); | ||
230 | #endif | ||
231 | } | ||
232 | |||
217 | /* | 233 | /* |
218 | * Scheduler clock - returns current time in nanosec units. | 234 | * Scheduler clock - returns current time in nanosec units. |
219 | */ | 235 | */ |
diff --git a/include/asm-cris/ptrace.h b/include/asm-cris/ptrace.h index 7a8c2880e487..1ec69a7ea836 100644 --- a/include/asm-cris/ptrace.h +++ b/include/asm-cris/ptrace.h | |||
@@ -9,4 +9,6 @@ | |||
9 | #define PTRACE_SETREGS 13 | 9 | #define PTRACE_SETREGS 13 |
10 | #endif | 10 | #endif |
11 | 11 | ||
12 | #define profile_pc(regs) instruction_pointer(regs) | ||
13 | |||
12 | #endif /* _CRIS_PTRACE_H */ | 14 | #endif /* _CRIS_PTRACE_H */ |