]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/cris/kernel/profile.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[mirror_ubuntu-artful-kernel.git] / arch / cris / kernel / profile.c
CommitLineData
21783c97
MS
1#include <linux/init.h>
2#include <linux/errno.h>
3#include <linux/kernel.h>
4#include <linux/proc_fs.h>
5a0e3ad6 5#include <linux/slab.h>
21783c97
MS
6#include <linux/types.h>
7#include <asm/ptrace.h>
7c0f6ba6 8#include <linux/uaccess.h>
21783c97
MS
9
10#define SAMPLE_BUFFER_SIZE 8192
11
c1c8f558
JN
12static char *sample_buffer;
13static char *sample_buffer_pos;
21783c97
MS
14static int prof_running = 0;
15
c1c8f558 16void cris_profile_sample(struct pt_regs *regs)
21783c97 17{
542401d9
CG
18 if (!prof_running)
19 return;
20
21 if (user_mode(regs))
22 *(unsigned int*)sample_buffer_pos = current->pid;
23 else
24 *(unsigned int*)sample_buffer_pos = 0;
25
c1c8f558 26 *(unsigned int *)(sample_buffer_pos + 4) = instruction_pointer(regs);
542401d9
CG
27 sample_buffer_pos += 8;
28
29 if (sample_buffer_pos == sample_buffer + SAMPLE_BUFFER_SIZE)
30 sample_buffer_pos = sample_buffer;
21783c97
MS
31}
32
33static ssize_t
542401d9
CG
34read_cris_profile(struct file *file, char __user *buf,
35 size_t count, loff_t *ppos)
21783c97 36{
542401d9 37 unsigned long p = *ppos;
ed62f77b 38 ssize_t ret;
542401d9 39
ed62f77b
AM
40 ret = simple_read_from_buffer(buf, count, ppos, sample_buffer,
41 SAMPLE_BUFFER_SIZE);
42 if (ret < 0)
43 return ret;
542401d9 44
ed62f77b 45 memset(sample_buffer + p, 0, ret);
542401d9 46
ed62f77b 47 return ret;
21783c97
MS
48}
49
50static ssize_t
51write_cris_profile(struct file *file, const char __user *buf,
542401d9 52 size_t count, loff_t *ppos)
21783c97 53{
542401d9
CG
54 sample_buffer_pos = sample_buffer;
55 memset(sample_buffer, 0, SAMPLE_BUFFER_SIZE);
c1c8f558 56 return count < SAMPLE_BUFFER_SIZE ? count : SAMPLE_BUFFER_SIZE;
21783c97
MS
57}
58
5dfe4c96 59static const struct file_operations cris_proc_profile_operations = {
21783c97
MS
60 .read = read_cris_profile,
61 .write = write_cris_profile,
6038f373 62 .llseek = default_llseek,
21783c97
MS
63};
64
c1c8f558 65static int __init init_cris_profile(void)
21783c97 66{
542401d9
CG
67 struct proc_dir_entry *entry;
68
69 sample_buffer = kmalloc(SAMPLE_BUFFER_SIZE, GFP_KERNEL);
70 if (!sample_buffer) {
71 return -ENOMEM;
72 }
73
74 sample_buffer_pos = sample_buffer;
75
c293819a
DL
76 entry = proc_create("system_profile", S_IWUSR | S_IRUGO, NULL,
77 &cris_proc_profile_operations);
542401d9 78 if (entry) {
254844d3 79 proc_set_size(entry, SAMPLE_BUFFER_SIZE);
542401d9
CG
80 }
81 prof_running = 1;
82
83 return 0;
21783c97 84}
21783c97 85__initcall(init_cris_profile);
c1c8f558 86