CRIS: Return something from profile write
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / cris / kernel / profile.c
blob195ec5fa0dd2a25f14d612e13f18d174756695b4
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;
16 void cris_profile_sample(struct pt_regs *regs)
18 if (!prof_running)
19 return;
21 if (user_mode(regs))
22 *(unsigned int*)sample_buffer_pos = current->pid;
23 else
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;
33 static ssize_t
34 read_cris_profile(struct file *file, char __user *buf,
35 size_t count, loff_t *ppos)
37 unsigned long p = *ppos;
38 ssize_t ret;
40 ret = simple_read_from_buffer(buf, count, ppos, sample_buffer,
41 SAMPLE_BUFFER_SIZE);
42 if (ret < 0)
43 return ret;
45 memset(sample_buffer + p, 0, ret);
47 return ret;
50 static ssize_t
51 write_cris_profile(struct file *file, const char __user *buf,
52 size_t count, loff_t *ppos)
54 sample_buffer_pos = sample_buffer;
55 memset(sample_buffer, 0, SAMPLE_BUFFER_SIZE);
56 return count < SAMPLE_BUFFER_SIZE ? count : SAMPLE_BUFFER_SIZE;
59 static const struct file_operations cris_proc_profile_operations = {
60 .read = read_cris_profile,
61 .write = write_cris_profile,
64 static int __init init_cris_profile(void)
66 struct proc_dir_entry *entry;
68 sample_buffer = kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL);
69 if (!sample_buffer) {
70 return -ENOMEM;
73 sample_buffer_pos = sample_buffer;
75 entry = proc_create("system_profile", S_IWUSR | S_IRUGO, NULL,
76 &cris_proc_profile_operations);
77 if (entry) {
78 entry->size = SAMPLE_BUFFER_SIZE;
80 prof_running = 1;
82 return 0;
84 __initcall(init_cris_profile);