Skip to contentSkip to conversation

trace: use this_cpu_ptr per-cpu helper

PATCH In review Shan Wei 2 participants 6 messages Oct 31, 2012 – Nov 5, 2012

Subsystems (2)
lore
Share & tools
lore

Shan Wei

author
#0 lore raw

PATCH 8/9 trace: use this_cpu_ptr per-cpu helper

From: Shan Wei <[email protected]>

---
 kernel/trace/blktrace.c |    2 +-
 kernel/trace/trace.c    |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/blktrace.c +1 -1
index c0bd030..71259e2 100644
@@ -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);
kernel/trace/trace.c +1 -1
index 31e4f55..81ae35b 100644
@@ -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;
 }
Signature · 1 line
1.7.1
#1 lore raw
Quoted 14 lines · Shan Wei

From: Shan Wei <[email protected]>

---
 kernel/trace/blktrace.c |    2 +-
 kernel/trace/trace.c    |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/blktrace.c +0 -0
index c0bd030..71259e2 100644

kernel/trace/blktrace.c void __trace_note_message(struct blk_trace *bt, const char *fmt, ...) · line 153

Quoted 8 lines
kernel/trace/blktrace.c +1 -1
@@ -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

kernel/trace/trace.c static char *get_trace_buf(void) · line 1518

Quoted 12 lines
kernel/trace/trace.c +1 -1
index 31e4f55..81ae35b 100644
@@ -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

author
#2 lore raw

Christoph Lameter said, at 2012/11/1 1:50:

Quoted 4 lines
Quoted 4 lines
kernel/trace/trace.c +1 -1
-	buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
+	buffer = this_cpu_ptr(percpu_buffer);
Quoted 8 lines
Quoted 1 line

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 *'

#3 lore raw
Quoted 10 lines · Shan Wei

Christoph Lameter said, at 2012/11/1 1:50:

Quoted 9 lines

kernel/trace/trace.c static char *get_trace_buf(void) · line 1518

Quoted 5 lines
kernel/trace/trace.c +1 -1
-	buffer = per_cpu_ptr(percpu_buffer, smp_processor_id());
+	buffer = this_cpu_ptr(percpu_buffer);
 
 	return buffer->buffer;

Just do a

Quoted 6 lines
Quoted 3 lines
	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))

author
#4 lore raw

Christoph Lameter said, at 2012/11/3 1:53:

Quoted 6 lines

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);

#5 lore raw
Quoted 1 line · Shan Wei

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.