public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 7/9] trace: use this_cpu_ptr per-cpu helper
@ 2012-11-09  2:21 Shan Wei
  2012-11-09 20:15 ` Christoph Lameter
  0 siblings, 1 reply; 3+ messages in thread
From: Shan Wei @ 2012-11-09  2:21 UTC (permalink / raw)
  To: rostedt, fweisbec, Kernel-Maillist, mingo, cl, Shan Wei

From: Shan Wei <davidshan@tencent.com>


Signed-off-by: Shan Wei <davidshan@tencent.com>
---
v3:
  directly return member address of per-cpu variable.
---
 kernel/trace/blktrace.c |    2 +-
 kernel/trace/trace.c    |    5 +----
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index c0bd030..71259e2 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -147,7 +147,7 @@ void __trace_note_message(struct blk_trace *bt, const char *fmt, ...)
 		return;
 
 	local_irq_save(flags);
-	buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
+	buf = this_cpu_ptr(bt->msg_data);
 	va_start(args, fmt);
 	n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
 	va_end(args);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 31e4f55..65cb003 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1495,7 +1495,6 @@ static struct trace_buffer_struct *trace_percpu_nmi_buffer;
 static char *get_trace_buf(void)
 {
 	struct trace_buffer_struct *percpu_buffer;
-	struct trace_buffer_struct *buffer;
 
 	/*
 	 * If we have allocated per cpu buffers, then we do not
@@ -1513,9 +1512,7 @@ static char *get_trace_buf(void)
 	if (!percpu_buffer)
 		return NULL;
 
-	buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
-
-	return buffer->buffer;
+	return (char *)this_cpu_ptr(&percpu_buffer->buffer);
 }
 
 static int alloc_percpu_trace_buffer(void)
-- 
1.7.1

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

* Re: [PATCH v3 7/9] trace: use this_cpu_ptr per-cpu helper
  2012-11-09  2:21 [PATCH v3 7/9] trace: use this_cpu_ptr per-cpu helper Shan Wei
@ 2012-11-09 20:15 ` Christoph Lameter
  2012-11-12  2:05   ` Shan Wei
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Lameter @ 2012-11-09 20:15 UTC (permalink / raw)
  To: Shan Wei; +Cc: rostedt, fweisbec, Kernel-Maillist, mingo

On Fri, 9 Nov 2012, Shan Wei wrote:

> -	return buffer->buffer;
> +	return (char *)this_cpu_ptr(&percpu_buffer->buffer);
>  }

Add a comment to explain the cast?


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

* Re: [PATCH v3 7/9] trace: use this_cpu_ptr per-cpu helper
  2012-11-09 20:15 ` Christoph Lameter
@ 2012-11-12  2:05   ` Shan Wei
  0 siblings, 0 replies; 3+ messages in thread
From: Shan Wei @ 2012-11-12  2:05 UTC (permalink / raw)
  To: Christoph Lameter; +Cc: rostedt, fweisbec, Kernel-Maillist, mingo

Christoph Lameter said, at 2012/11/10 4:15:
> On Fri, 9 Nov 2012, Shan Wei wrote:
> 
>> -	return buffer->buffer;
>> +	return (char *)this_cpu_ptr(&percpu_buffer->buffer);
>>  }
> 
> Add a comment to explain the cast?

typeof(&buffer) is a pointer to array of 1024 char, or char (*)[1024].
But, typeof(&buffer[0]) is a pointer to char which match the return type of get_trace_buf().
As well-known, the value of &buffer is equal to &buffer[0].
so return this_cpu_ptr(&percpu_buffer->buffer[0]) can avoid this cast. 

I will submit v4 version patch which improve it.

Thanks~

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

end of thread, other threads:[~2012-11-12  2:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-09  2:21 [PATCH v3 7/9] trace: use this_cpu_ptr per-cpu helper Shan Wei
2012-11-09 20:15 ` Christoph Lameter
2012-11-12  2:05   ` Shan Wei

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