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>
9 #define SAMPLE_BUFFER_SIZE 8192
11 static char* sample_buffer;
12 static char* sample_buffer_pos;
13 static int prof_running = 0;
16 cris_profile_sample(struct pt_regs* regs)
22 *(unsigned int*)sample_buffer_pos = current->pid;
24 *(unsigned int*)sample_buffer_pos = 0;
26 *(unsigned int*)(sample_buffer_pos + 4) = instruction_pointer(regs);
27 sample_buffer_pos += 8;
29 if (sample_buffer_pos == sample_buffer + SAMPLE_BUFFER_SIZE)
30 sample_buffer_pos = sample_buffer;
34 read_cris_profile(struct file *file, char __user *buf,
35 size_t count, loff_t *ppos)
37 unsigned long p = *ppos;
39 if (p > SAMPLE_BUFFER_SIZE)
42 if (p + count > SAMPLE_BUFFER_SIZE)
43 count = SAMPLE_BUFFER_SIZE - p;
44 if (copy_to_user(buf, sample_buffer + p,count))
47 memset(sample_buffer + p, 0, count);
54 write_cris_profile(struct file *file, const char __user *buf,
55 size_t count, loff_t *ppos)
57 sample_buffer_pos = sample_buffer;
58 memset(sample_buffer, 0, SAMPLE_BUFFER_SIZE);
61 static const struct file_operations cris_proc_profile_operations = {
62 .read = read_cris_profile,
63 .write = write_cris_profile,
67 __init init_cris_profile(void)
69 struct proc_dir_entry *entry;
71 sample_buffer = kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL);
76 sample_buffer_pos = sample_buffer;
78 entry = proc_create("system_profile", S_IWUSR | S_IRUGO, NULL,
79 &cris_proc_profile_operations);
81 entry->size = SAMPLE_BUFFER_SIZE;
88 __initcall(init_cris_profile);