Commit 6c6c2796 authored by Pekka Paalanen's avatar Pekka Paalanen Committed by Thomas Gleixner

ftrace: add readpos to struct trace_seq; add trace_seq_to_user()

Refactor code from tracing_read_pipe() and create trace_seq_to_user().
Moved trace_seq_reset() call before iter->trace->read() call so that
when all leftover data is returned, trace_seq is reset automatically.
Signed-off-by: default avatarPekka Paalanen <pq@iki.fi>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 2bb6f8d6
...@@ -400,6 +400,26 @@ static void ...@@ -400,6 +400,26 @@ static void
trace_seq_reset(struct trace_seq *s) trace_seq_reset(struct trace_seq *s)
{ {
s->len = 0; s->len = 0;
s->readpos = 0;
}
ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
{
int len;
int ret;
if (s->len <= s->readpos)
return -EBUSY;
len = s->len - s->readpos;
if (cnt > len)
cnt = len;
ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
if (ret)
return -EFAULT;
s->readpos += len;
return cnt;
} }
static void static void
...@@ -2361,46 +2381,32 @@ tracing_read_pipe(struct file *filp, char __user *ubuf, ...@@ -2361,46 +2381,32 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
struct trace_iterator *iter = filp->private_data; struct trace_iterator *iter = filp->private_data;
struct trace_array_cpu *data; struct trace_array_cpu *data;
static cpumask_t mask; static cpumask_t mask;
static int start;
unsigned long flags; unsigned long flags;
#ifdef CONFIG_FTRACE #ifdef CONFIG_FTRACE
int ftrace_save; int ftrace_save;
#endif #endif
int read = 0;
int cpu; int cpu;
int len; ssize_t sret;
int ret;
/* return any leftover data */ /* return any leftover data */
if (iter->seq.len > start) { sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
len = iter->seq.len - start; if (sret != -EBUSY)
if (cnt > len) return sret;
cnt = len; sret = 0;
ret = copy_to_user(ubuf, iter->seq.buffer + start, cnt);
if (ret)
cnt = -EFAULT;
start += len;
return cnt; trace_seq_reset(&iter->seq);
}
mutex_lock(&trace_types_lock); mutex_lock(&trace_types_lock);
if (iter->trace->read) { if (iter->trace->read) {
ret = iter->trace->read(iter, filp, ubuf, cnt, ppos); sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
if (ret) { if (sret)
read = ret;
goto out; goto out;
}
} }
trace_seq_reset(&iter->seq);
start = 0;
while (trace_empty(iter)) { while (trace_empty(iter)) {
if ((filp->f_flags & O_NONBLOCK)) { if ((filp->f_flags & O_NONBLOCK)) {
read = -EAGAIN; sret = -EAGAIN;
goto out; goto out;
} }
...@@ -2426,7 +2432,7 @@ tracing_read_pipe(struct file *filp, char __user *ubuf, ...@@ -2426,7 +2432,7 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
iter->tr->waiter = NULL; iter->tr->waiter = NULL;
if (signal_pending(current)) { if (signal_pending(current)) {
read = -EINTR; sret = -EINTR;
goto out; goto out;
} }
...@@ -2496,6 +2502,7 @@ tracing_read_pipe(struct file *filp, char __user *ubuf, ...@@ -2496,6 +2502,7 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
} }
while (find_next_entry_inc(iter) != NULL) { while (find_next_entry_inc(iter) != NULL) {
int ret;
int len = iter->seq.len; int len = iter->seq.len;
ret = print_trace_line(iter); ret = print_trace_line(iter);
...@@ -2526,24 +2533,16 @@ tracing_read_pipe(struct file *filp, char __user *ubuf, ...@@ -2526,24 +2533,16 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
local_irq_restore(flags); local_irq_restore(flags);
/* Now copy what we have to the user */ /* Now copy what we have to the user */
read = iter->seq.len; sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
if (read > cnt) if (iter->seq.readpos >= iter->seq.len)
read = cnt;
ret = copy_to_user(ubuf, iter->seq.buffer, read);
if (read < iter->seq.len)
start = read;
else
trace_seq_reset(&iter->seq); trace_seq_reset(&iter->seq);
if (sret == -EBUSY)
if (ret) sret = 0;
read = -EFAULT;
out: out:
mutex_unlock(&trace_types_lock); mutex_unlock(&trace_types_lock);
return read; return sret;
} }
static ssize_t static ssize_t
......
...@@ -155,6 +155,7 @@ struct tracer { ...@@ -155,6 +155,7 @@ struct tracer {
struct trace_seq { struct trace_seq {
unsigned char buffer[PAGE_SIZE]; unsigned char buffer[PAGE_SIZE];
unsigned int len; unsigned int len;
unsigned int readpos;
}; };
/* /*
...@@ -301,6 +302,8 @@ extern int trace_selftest_startup_sched_switch(struct tracer *trace, ...@@ -301,6 +302,8 @@ extern int trace_selftest_startup_sched_switch(struct tracer *trace,
extern void *head_page(struct trace_array_cpu *data); extern void *head_page(struct trace_array_cpu *data);
extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...); extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
size_t cnt);
extern long ns2usecs(cycle_t nsec); extern long ns2usecs(cycle_t nsec);
extern unsigned long trace_flags; extern unsigned long trace_flags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment