mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-04-11 16:55:20 +00:00
tracing: Have saved_cmdlines use the seq_read infrastructure
Current tracing_saved_cmdlines_read() implementation is naive; It allocates a large buffer, constructs output data to that buffer for each read operation, and then copies a portion of the buffer to the user space buffer. This has several issues such as slow memory allocation, high CPU usage, and even corruption of the output data. The seq_read infrastructure is made to handle this type of work. By converting it to use seq_read() the code becomes smaller, simplified, as well as correct. Link: http://lkml.kernel.org/p/20140220084431.3839.51793.stgit@yunodevel Signed-off-by: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: linux-kernel@vger.kernel.org Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
This commit is contained in:
parent
81dc9f0ef2
commit
42584c81c5
1 changed files with 55 additions and 36 deletions
|
@ -3699,55 +3699,74 @@ static const struct file_operations tracing_readme_fops = {
|
||||||
.llseek = generic_file_llseek,
|
.llseek = generic_file_llseek,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssize_t
|
static void *saved_cmdlines_next(struct seq_file *m, void *v, loff_t *pos)
|
||||||
tracing_saved_cmdlines_read(struct file *file, char __user *ubuf,
|
|
||||||
size_t cnt, loff_t *ppos)
|
|
||||||
{
|
{
|
||||||
char *buf_comm;
|
unsigned int *ptr = v;
|
||||||
char *file_buf;
|
|
||||||
char *buf;
|
|
||||||
int len = 0;
|
|
||||||
int pid;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL);
|
if (*pos || m->count)
|
||||||
if (!file_buf)
|
ptr++;
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL);
|
(*pos)++;
|
||||||
if (!buf_comm) {
|
|
||||||
kfree(file_buf);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = file_buf;
|
for (; ptr < &map_cmdline_to_pid[SAVED_CMDLINES]; ptr++) {
|
||||||
|
if (*ptr == -1 || *ptr == NO_CMDLINE_MAP)
|
||||||
for (i = 0; i < SAVED_CMDLINES; i++) {
|
|
||||||
int r;
|
|
||||||
|
|
||||||
pid = map_cmdline_to_pid[i];
|
|
||||||
if (pid == -1 || pid == NO_CMDLINE_MAP)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
trace_find_cmdline(pid, buf_comm);
|
return ptr;
|
||||||
r = sprintf(buf, "%d %s\n", pid, buf_comm);
|
|
||||||
buf += r;
|
|
||||||
len += r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
len = simple_read_from_buffer(ubuf, cnt, ppos,
|
return NULL;
|
||||||
file_buf, len);
|
}
|
||||||
|
|
||||||
kfree(file_buf);
|
static void *saved_cmdlines_start(struct seq_file *m, loff_t *pos)
|
||||||
kfree(buf_comm);
|
{
|
||||||
|
void *v;
|
||||||
|
loff_t l = 0;
|
||||||
|
|
||||||
return len;
|
v = &map_cmdline_to_pid[0];
|
||||||
|
while (l <= *pos) {
|
||||||
|
v = saved_cmdlines_next(m, v, &l);
|
||||||
|
if (!v)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void saved_cmdlines_stop(struct seq_file *m, void *v)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static int saved_cmdlines_show(struct seq_file *m, void *v)
|
||||||
|
{
|
||||||
|
char buf[TASK_COMM_LEN];
|
||||||
|
unsigned int *pid = v;
|
||||||
|
|
||||||
|
trace_find_cmdline(*pid, buf);
|
||||||
|
seq_printf(m, "%d %s\n", *pid, buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct seq_operations tracing_saved_cmdlines_seq_ops = {
|
||||||
|
.start = saved_cmdlines_start,
|
||||||
|
.next = saved_cmdlines_next,
|
||||||
|
.stop = saved_cmdlines_stop,
|
||||||
|
.show = saved_cmdlines_show,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int tracing_saved_cmdlines_open(struct inode *inode, struct file *filp)
|
||||||
|
{
|
||||||
|
if (tracing_disabled)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
return seq_open(filp, &tracing_saved_cmdlines_seq_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations tracing_saved_cmdlines_fops = {
|
static const struct file_operations tracing_saved_cmdlines_fops = {
|
||||||
.open = tracing_open_generic,
|
.open = tracing_saved_cmdlines_open,
|
||||||
.read = tracing_saved_cmdlines_read,
|
.read = seq_read,
|
||||||
.llseek = generic_file_llseek,
|
.llseek = seq_lseek,
|
||||||
|
.release = seq_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
|
|
Loading…
Add table
Reference in a new issue