From 8e4bff4cab0ddac6060645b0715210484d02ff40 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Wed, 30 Aug 2017 08:25:59 +0000 Subject: Initial file dump from open source release --- arch/cris/kernel/profile.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 arch/cris/kernel/profile.c (limited to 'arch/cris/kernel/profile.c') diff --git a/arch/cris/kernel/profile.c b/arch/cris/kernel/profile.c new file mode 100644 index 00000000..cd9f15b9 --- /dev/null +++ b/arch/cris/kernel/profile.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define SAMPLE_BUFFER_SIZE 8192 + +static char *sample_buffer; +static char *sample_buffer_pos; +static int prof_running = 0; + +void cris_profile_sample(struct pt_regs *regs) +{ + if (!prof_running) + return; + + if (user_mode(regs)) + *(unsigned int*)sample_buffer_pos = current->pid; + else + *(unsigned int*)sample_buffer_pos = 0; + + *(unsigned int *)(sample_buffer_pos + 4) = instruction_pointer(regs); + sample_buffer_pos += 8; + + if (sample_buffer_pos == sample_buffer + SAMPLE_BUFFER_SIZE) + sample_buffer_pos = sample_buffer; +} + +static ssize_t +read_cris_profile(struct file *file, char __user *buf, + size_t count, loff_t *ppos) +{ + unsigned long p = *ppos; + ssize_t ret; + + ret = simple_read_from_buffer(buf, count, ppos, sample_buffer, + SAMPLE_BUFFER_SIZE); + if (ret < 0) + return ret; + + memset(sample_buffer + p, 0, ret); + + return ret; +} + +static ssize_t +write_cris_profile(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) +{ + sample_buffer_pos = sample_buffer; + memset(sample_buffer, 0, SAMPLE_BUFFER_SIZE); + return count < SAMPLE_BUFFER_SIZE ? count : SAMPLE_BUFFER_SIZE; +} + +static const struct file_operations cris_proc_profile_operations = { + .read = read_cris_profile, + .write = write_cris_profile, + .llseek = default_llseek, +}; + +static int __init init_cris_profile(void) +{ + struct proc_dir_entry *entry; + + sample_buffer = kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL); + if (!sample_buffer) { + return -ENOMEM; + } + + sample_buffer_pos = sample_buffer; + + entry = proc_create("system_profile", S_IWUSR | S_IRUGO, NULL, + &cris_proc_profile_operations); + if (entry) { + proc_set_size(entry, SAMPLE_BUFFER_SIZE); + } + prof_running = 1; + + return 0; +} +__initcall(init_cris_profile); + -- cgit v1.3.1