2012-10-31 11:23:21

by Shan Wei

[permalink] [raw]
Subject: [PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

From: Shan Wei <[email protected]>


Signed-off-by: Shan Wei <[email protected]>
---
kernel/trace/blktrace.c | 2 +-
kernel/trace/trace.c | 2 +-
2 files changed, 2 insertions(+), 2 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..81ae35b 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1513,7 +1513,7 @@ static char *get_trace_buf(void)
if (!percpu_buffer)
return NULL;

- buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
+ buffer = this_cpu_ptr(percpu_buffer);

return buffer->buffer;
}
--
1.7.1


Subject: Re: [PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

On Wed, 31 Oct 2012, Shan Wei wrote:

> From: Shan Wei <[email protected]>
>
>
> Signed-off-by: Shan Wei <[email protected]>
> ---
> kernel/trace/blktrace.c | 2 +-
> kernel/trace/trace.c | 2 +-
> 2 files changed, 2 insertions(+), 2 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);

Ok

> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 31e4f55..81ae35b 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -1513,7 +1513,7 @@ static char *get_trace_buf(void)
> if (!percpu_buffer)
> return NULL;
>
> - buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
> + buffer = this_cpu_ptr(percpu_buffer);
>
> return buffer->buffer;


Just do a

return this_cpu_read(percpu_buffer->buffer);

and get rid of the this_cpu_ptr op

2012-11-02 15:26:13

by Shan Wei

[permalink] [raw]
Subject: Re: [PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

Christoph Lameter said, at 2012/11/1 1:50:
>>
>> - buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
>> + buffer = this_cpu_ptr(percpu_buffer);
>>
>> return buffer->buffer;
>
>
> Just do a
>
> return this_cpu_read(percpu_buffer->buffer);
>
> and get rid of the this_cpu_ptr op

can not do that.
kernel/trace/trace.c:1515: error: incompatible types when assigning to type 'char[1024]' from type 'char *'


Subject: Re: [PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

On Fri, 2 Nov 2012, Shan Wei wrote:

> Christoph Lameter said, at 2012/11/1 1:50:
> >>
> >> - buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
> >> + buffer = this_cpu_ptr(percpu_buffer);
> >>
> >> return buffer->buffer;
> >
> >
> > Just do a
> >
> > return this_cpu_read(percpu_buffer->buffer);
> >
> > and get rid of the this_cpu_ptr op
>
> can not do that.
> kernel/trace/trace.c:1515: error: incompatible types when assigning to type 'char[1024]' from type 'char *'

hmm.... what is actually returned is a pointer to char right? And buffer
is char[1024] so I guess then you need to pass a pointer to char to
this_cpu_read.

return this_cpu_read(&(percpu_buffer->buffer))

2012-11-03 04:51:30

by Shan Wei

[permalink] [raw]
Subject: Re: [PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

Christoph Lameter said, at 2012/11/3 1:53:
>
> hmm.... what is actually returned is a pointer to char right? And buffer
> is char[1024] so I guess then you need to pass a pointer to char to
> this_cpu_read.
>
> return this_cpu_read(&(percpu_buffer->buffer))

still error....

kernel/trace/trace.c: In function 'get_trace_buf':
kernel/trace/trace.c:1517: error: lvalue required as unary '&' operand
kernel/trace/trace.c:1517: warning: type defaults to 'int' in declaration of 'type name'
kernel/trace/trace.c:1517: warning: cast from pointer to integer of different size
kernel/trace/trace.c:1517: warning: return from incompatible pointer type
kernel/trace/trace.c:1498: warning: unused variable 'buffer'
kernel/trace/trace.c:1517: error: memory input 1 is not directly addressable
kernel/trace/trace.c:1517: error: memory input 1 is not directly addressable

this_cpu_read just read the actual value which a pointer point to.
some case, we just need the pointer.
It's better to use this_cpu_ptr.
return (char *)this_cpu_ptr(&percpu_buffer->buffer);

Subject: Re: [PATCH 8/9] trace: use this_cpu_ptr per-cpu helper

On Sat, 3 Nov 2012, Shan Wei wrote:

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

Makes sense since buffer is the actual start of the bytes and not a
pointer to a buffer like what I thought.