public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/6] tracing: tracing_stats_read() uses simple buffer instead of trace_seq
@ 2010-01-19  7:34 Lai Jiangshan
  2010-01-20 18:00 ` Frederic Weisbecker
  0 siblings, 1 reply; 2+ messages in thread
From: Lai Jiangshan @ 2010-01-19  7:34 UTC (permalink / raw)
  To: Steven Rostedt, linux-kernel, Ingo Molnar, Andrew Morton,
	Frederic Weisbecker


It seems that struct trace_seq is too heavy for tracing_stats_read().
we use simple buffer instead of struct trace_seq.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 27fecf8..aa1cd92 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3807,27 +3807,22 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
 {
 	unsigned long cpu = (unsigned long)filp->private_data;
 	struct trace_array *tr = &global_trace;
-	struct trace_seq *s;
 	unsigned long cnt;
 
-	s = kmalloc(sizeof(*s), GFP_KERNEL);
-	if (!s)
-		return -ENOMEM;
-
-	trace_seq_init(s);
+	unsigned char buf[128];
+	int len = 0;
 
 	cnt = ring_buffer_entries_cpu(tr->buffer, cpu);
-	trace_seq_printf(s, "entries: %ld\n", cnt);
+	len += sprintf(buf + len, "entries: %ld\n", cnt);
 
 	cnt = ring_buffer_overrun_cpu(tr->buffer, cpu);
-	trace_seq_printf(s, "overrun: %ld\n", cnt);
+	len += sprintf(buf + len, "overrun: %ld\n", cnt);
 
 	cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu);
-	trace_seq_printf(s, "commit overrun: %ld\n", cnt);
-
-	count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
+	len += sprintf(buf + len, "commit overrun: %ld\n", cnt);
 
-	kfree(s);
+	BUG_ON(len >= sizeof(buf)); /* should not happen, 128 is enough. */
+	count = simple_read_from_buffer(ubuf, count, ppos, buf, len);
 
 	return count;
 }


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 3/6] tracing: tracing_stats_read() uses simple buffer instead of trace_seq
  2010-01-19  7:34 [PATCH 3/6] tracing: tracing_stats_read() uses simple buffer instead of trace_seq Lai Jiangshan
@ 2010-01-20 18:00 ` Frederic Weisbecker
  0 siblings, 0 replies; 2+ messages in thread
From: Frederic Weisbecker @ 2010-01-20 18:00 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: Steven Rostedt, linux-kernel, Ingo Molnar, Andrew Morton

On Tue, Jan 19, 2010 at 03:34:08PM +0800, Lai Jiangshan wrote:
> 
> It seems that struct trace_seq is too heavy for tracing_stats_read().
> we use simple buffer instead of struct trace_seq.
> 
> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 27fecf8..aa1cd92 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3807,27 +3807,22 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
>  {
>  	unsigned long cpu = (unsigned long)filp->private_data;
>  	struct trace_array *tr = &global_trace;
> -	struct trace_seq *s;
>  	unsigned long cnt;
>  
> -	s = kmalloc(sizeof(*s), GFP_KERNEL);
> -	if (!s)
> -		return -ENOMEM;
> -
> -	trace_seq_init(s);
> +	unsigned char buf[128];



No problem with the conversion. But perhaps keep using a dynamic
buffer as 128 is a bit big for a kernel stack.


> +	int len = 0;
>  
>  	cnt = ring_buffer_entries_cpu(tr->buffer, cpu);
> -	trace_seq_printf(s, "entries: %ld\n", cnt);
> +	len += sprintf(buf + len, "entries: %ld\n", cnt);
>  
>  	cnt = ring_buffer_overrun_cpu(tr->buffer, cpu);
> -	trace_seq_printf(s, "overrun: %ld\n", cnt);
> +	len += sprintf(buf + len, "overrun: %ld\n", cnt);
>  
>  	cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu);
> -	trace_seq_printf(s, "commit overrun: %ld\n", cnt);
> -
> -	count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
> +	len += sprintf(buf + len, "commit overrun: %ld\n", cnt);
>  
> -	kfree(s);
> +	BUG_ON(len >= sizeof(buf)); /* should not happen, 128 is enough. */
> +	count = simple_read_from_buffer(ubuf, count, ppos, buf, len);
>  
>  	return count;
>  }
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-01-20 18:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-19  7:34 [PATCH 3/6] tracing: tracing_stats_read() uses simple buffer instead of trace_seq Lai Jiangshan
2010-01-20 18:00 ` Frederic Weisbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox