linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [RFC] powerpc: xmon: Add address lookup for percpu symbols
@ 2016-11-17  9:40 Boqun Feng
  2016-11-22  9:20 ` [RFC v2] " Boqun Feng
  0 siblings, 1 reply; 3+ messages in thread
From: Boqun Feng @ 2016-11-17  9:40 UTC (permalink / raw)
  To: linux-kernel, linuxppc-dev
  Cc: Boqun Feng, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, Andrew Donnellan, Christophe Leroy,
	Aneesh Kumar K.V, Rashmica Gupta, Douglas Miller

Currently, in xmon, there is no obvious way to get an address for a
percpu symbol for a particular cpu. Having such an ability would be good
for debugging the system when percpu variables got involved.

Therefore, this patch introduces a new xmon command "lp" to lookup the
address for percpu symbols. Usage of "lp" is similar to "ls", except
that we could add a cpu number to choose the variable of which cpu we
want to lookup. If no cpu number is given, lookup for current cpu.

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
---
 arch/powerpc/xmon/xmon.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 760545519a0b..3556966a29a5 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -229,6 +229,7 @@ Commands:\n\
   f	flush cache\n\
   la	lookup symbol+offset of specified address\n\
   ls	lookup address of specified symbol\n\
+  lp s [#]	lookup address of percpu symbol s for current cpu, or cpu #\n\
   m	examine/change memory\n\
   mm	move a block of memory\n\
   ms	set a block of memory\n\
@@ -2943,7 +2944,7 @@ static void
 symbol_lookup(void)
 {
 	int type = inchar();
-	unsigned long addr;
+	unsigned long addr, cpu, offset;
 	static char tmp[64];
 
 	switch (type) {
@@ -2967,6 +2968,31 @@ symbol_lookup(void)
 		catch_memory_errors = 0;
 		termch = 0;
 		break;
+	case 'p':
+		getstring(tmp, 64);
+		if (setjmp(bus_error_jmp) == 0) {
+			catch_memory_errors = 1;
+			sync();
+			addr = kallsyms_lookup_name(tmp);
+			sync();
+		}
+
+		if (scanhex(&cpu) && cpu < num_possible_cpus())
+			offset = per_cpu_offset(cpu);
+		else {
+			offset = my_cpu_offset;
+			cpu = raw_smp_processor_id();
+		}
+
+		if (addr)
+			printf("%s for cpu 0x%lx: %lx\n", tmp, cpu,
+							  addr + offset);
+		else
+			printf("Percpu symbol '%s' not found.\n", tmp);
+
+		catch_memory_errors = 0;
+		termch = 0;
+		break;
 	}
 }
 
-- 
2.10.1

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

* [RFC v2] powerpc: xmon: Add address lookup for percpu symbols
  2016-11-17  9:40 [RFC] powerpc: xmon: Add address lookup for percpu symbols Boqun Feng
@ 2016-11-22  9:20 ` Boqun Feng
  2018-08-13 11:22   ` [RFC,v2] " Michael Ellerman
  0 siblings, 1 reply; 3+ messages in thread
From: Boqun Feng @ 2016-11-22  9:20 UTC (permalink / raw)
  To: linux-kernel, linuxppc-dev
  Cc: Boqun Feng, Benjamin Herrenschmidt, Paul Mackerras,
	Michael Ellerman, Andrew Donnellan, Christophe Leroy,
	Aneesh Kumar K.V, Rashmica Gupta, Douglas Miller

Currently, in xmon, there is no obvious way to get an address for a
percpu symbol for a particular cpu. Having such an ability would be good
for debugging the system when percpu variables got involved.

Therefore, this patch introduces a new xmon command "lp" to lookup the
address for percpu symbols. Usage of "lp" is similar to "ls", except
that we could add a cpu number to choose the variable of which cpu we
want to lookup. If no cpu number is given, lookup for current cpu.

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
---
v1 --> v2:

o	Using per_cpu_ptr() and this_cpu_ptr() instead of
	per_cpu_offset() and my_cpu_offset, because the latter
	are undefined on !SMP kernel.

o	Only print the address of percpu symbols, i.e. symbols
	in [__per_cpu_start, __per_cpu_end)

 arch/powerpc/xmon/xmon.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 760545519a0b..2747c94400a2 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -49,6 +49,7 @@
 
 #include <asm/opal.h>
 #include <asm/firmware.h>
+#include <asm/sections.h>
 
 #ifdef CONFIG_PPC64
 #include <asm/hvcall.h>
@@ -229,6 +230,7 @@ Commands:\n\
   f	flush cache\n\
   la	lookup symbol+offset of specified address\n\
   ls	lookup address of specified symbol\n\
+  lp s [#]	lookup address of percpu symbol s for current cpu, or cpu #\n\
   m	examine/change memory\n\
   mm	move a block of memory\n\
   ms	set a block of memory\n\
@@ -2943,7 +2945,8 @@ static void
 symbol_lookup(void)
 {
 	int type = inchar();
-	unsigned long addr;
+	unsigned long addr, cpu;
+	void __percpu *ptr = NULL;
 	static char tmp[64];
 
 	switch (type) {
@@ -2967,6 +2970,36 @@ symbol_lookup(void)
 		catch_memory_errors = 0;
 		termch = 0;
 		break;
+	case 'p':
+		getstring(tmp, 64);
+		if (setjmp(bus_error_jmp) == 0) {
+			catch_memory_errors = 1;
+			sync();
+			ptr = (void __percpu *)kallsyms_lookup_name(tmp);
+			sync();
+		}
+
+		if (ptr && ptr >= (void __percpu *)__per_cpu_start
+			&& ptr < (void __percpu *)__per_cpu_end) {
+
+			if (scanhex(&cpu) && cpu < num_possible_cpus())
+				addr = (unsigned long)per_cpu_ptr(ptr, cpu);
+			else {
+				cpu = raw_smp_processor_id();
+				addr = (unsigned long)this_cpu_ptr(ptr);
+			}
+
+			printf("%s for cpu 0x%lx: %lx\n", tmp, cpu, addr);
+
+		} else {
+			printf("Percpu symbol '%s' not found.\n", tmp);
+		}
+
+
+
+		catch_memory_errors = 0;
+		termch = 0;
+		break;
 	}
 }
 
-- 
2.10.1

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

* Re: [RFC,v2] powerpc: xmon: Add address lookup for percpu symbols
  2016-11-22  9:20 ` [RFC v2] " Boqun Feng
@ 2018-08-13 11:22   ` Michael Ellerman
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2018-08-13 11:22 UTC (permalink / raw)
  To: Boqun Feng, linux-kernel, linuxppc-dev
  Cc: Douglas Miller, Boqun Feng, Rashmica Gupta, Paul Mackerras,
	Aneesh Kumar K.V, Andrew Donnellan

On Tue, 2016-11-22 at 09:20:09 UTC, Boqun Feng wrote:
> Currently, in xmon, there is no obvious way to get an address for a
> percpu symbol for a particular cpu. Having such an ability would be good
> for debugging the system when percpu variables got involved.
> 
> Therefore, this patch introduces a new xmon command "lp" to lookup the
> address for percpu symbols. Usage of "lp" is similar to "ls", except
> that we could add a cpu number to choose the variable of which cpu we
> want to lookup. If no cpu number is given, lookup for current cpu.
> 
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/302c7b0c4ff5aed585419603f835de

cheers

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

end of thread, other threads:[~2018-08-13 11:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-17  9:40 [RFC] powerpc: xmon: Add address lookup for percpu symbols Boqun Feng
2016-11-22  9:20 ` [RFC v2] " Boqun Feng
2018-08-13 11:22   ` [RFC,v2] " Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).