1 #include <linux/init.h>
2 #include <linux/errno.h>
3 #include <linux/kernel.h>
4 #include <linux/proc_fs.h>
5 #include <linux/slab.h>
6 #include <linux/types.h>
7 #include <asm/ptrace.h>
8 #include <asm/uaccess.h>
10 #define SAMPLE_BUFFER_SIZE 8192
12 static char* sample_buffer
;
13 static char* sample_buffer_pos
;
14 static int prof_running
= 0;
17 cris_profile_sample(struct pt_regs
* regs
)
23 *(unsigned int*)sample_buffer_pos
= current
->pid
;
25 *(unsigned int*)sample_buffer_pos
= 0;
27 *(unsigned int*)(sample_buffer_pos
+ 4) = instruction_pointer(regs
);
28 sample_buffer_pos
+= 8;
30 if (sample_buffer_pos
== sample_buffer
+ SAMPLE_BUFFER_SIZE
)
31 sample_buffer_pos
= sample_buffer
;
35 read_cris_profile(struct file
*file
, char __user
*buf
,
36 size_t count
, loff_t
*ppos
)
38 unsigned long p
= *ppos
;
41 ret
= simple_read_from_buffer(buf
, count
, ppos
, sample_buffer
,
46 memset(sample_buffer
+ p
, 0, ret
);
52 write_cris_profile(struct file
*file
, const char __user
*buf
,
53 size_t count
, loff_t
*ppos
)
55 sample_buffer_pos
= sample_buffer
;
56 memset(sample_buffer
, 0, SAMPLE_BUFFER_SIZE
);
59 static const struct file_operations cris_proc_profile_operations
= {
60 .read
= read_cris_profile
,
61 .write
= write_cris_profile
,
65 __init
init_cris_profile(void)
67 struct proc_dir_entry
*entry
;
69 sample_buffer
= kmalloc(SAMPLE_BUFFER_SIZE
, GFP_KERNEL
);
74 sample_buffer_pos
= sample_buffer
;
76 entry
= proc_create("system_profile", S_IWUSR
| S_IRUGO
, NULL
,
77 &cris_proc_profile_operations
);
79 entry
->size
= SAMPLE_BUFFER_SIZE
;
86 __initcall(init_cris_profile
);