* powerpc/xmon: Add xmon command to dump process/task similar to ps(1) @ 2015-11-23 15:01 Douglas Miller 2015-11-23 15:01 ` [PATCH] " Douglas Miller 0 siblings, 1 reply; 5+ messages in thread From: Douglas Miller @ 2015-11-23 15:01 UTC (permalink / raw) To: linuxppc-dev Add 'P' command with optional task_struct address to dump all/one task's information: task pointer, kernel stack pointer, PID, PPID, state (interpreted), CPU where (last) running, and command. Introduce XMON_PROTECT macro to standardize memory-access-fault protection (setjmp). Initially used only by the 'P' command. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] powerpc/xmon: Add xmon command to dump process/task similar to ps(1) 2015-11-23 15:01 powerpc/xmon: Add xmon command to dump process/task similar to ps(1) Douglas Miller @ 2015-11-23 15:01 ` Douglas Miller 2016-02-09 10:58 ` Michael Ellerman 2016-02-17 12:41 ` Michael Ellerman 0 siblings, 2 replies; 5+ messages in thread From: Douglas Miller @ 2015-11-23 15:01 UTC (permalink / raw) To: linuxppc-dev Add 'P' command with optional task_struct address to dump all/one task's information: task pointer, kernel stack pointer, PID, PPID, state (interpreted), CPU where (last) running, and command. Introduce XMON_PROTECT macro to standardize memory-access-fault protection (setjmp). Initially used only by the 'P' command. Signed-off-by: Douglas Miller <dougmill@linux.vnet.ibm.com> --- arch/powerpc/xmon/xmon.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index 13c6e20..8e203f0 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -149,6 +149,7 @@ static int cpu_cmd(void); static void csum(void); static void bootcmds(void); static void proccall(void); +static void proclist(void); void dump_segments(void); static void symbol_lookup(void); static void xmon_show_stack(unsigned long sp, unsigned long lr, @@ -191,6 +192,24 @@ extern void xmon_leave(void); || ('A' <= (c) && (c) <= 'Z')) #define isspace(c) (c == ' ' || c == '\t' || c == 10 || c == 13 || c == 0) +/* + * Wrap a statement (typically function call) in setjmp to + * protect it from memory access errors. msg... are printf + * fmt+args used if error is trapped. + */ +#define XMON_PROTECT(stmt, msg...) \ + if (setjmp(bus_error_jmp) != 0) { \ + catch_memory_errors = 0; \ + printf(msg); \ + } else { \ + catch_memory_errors = 1; \ + sync(); \ + stmt; \ + sync(); \ + __delay(200); \ + catch_memory_errors = 0; \ + } + static char *help_string = "\ Commands:\n\ b show breakpoints\n\ @@ -228,6 +247,7 @@ Commands:\n\ mz zero a block of memory\n\ mi show information about memory allocation\n\ p call a procedure\n\ + P list processes/tasks\n\ r print registers\n\ s single step\n" #ifdef CONFIG_SPU_BASE @@ -947,6 +967,9 @@ cmds(struct pt_regs *excp) case 'p': proccall(); break; + case 'P': + proclist(); + break; #ifdef CONFIG_PPC_STD_MMU case 'u': dump_segments(); @@ -2450,6 +2473,46 @@ memzcan(void) printf("%.8x\n", a - mskip); } +static void procshow(struct task_struct *tsk) +{ + char state; + + /* + * Cloned from kdb_task_state_char(), which is not entirely + * appropriate for calling from xmon. This could be moved + * to a common, generic, routine used by both. + */ + state = (tsk->state == 0) ? 'R' : + (tsk->state < 0) ? 'U' : + (tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' : + (tsk->state & TASK_STOPPED) ? 'T' : + (tsk->state & TASK_TRACED) ? 'C' : + (tsk->exit_state & EXIT_ZOMBIE) ? 'Z' : + (tsk->exit_state & EXIT_DEAD) ? 'E' : + (tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?'; + + printf("%p %016lx %6d %6d %c %2d %s\n", tsk, + tsk->thread.ksp, + tsk->pid, tsk->parent->pid, + state, task_thread_info(tsk)->cpu, + tsk->comm); +} + +static void proclist(void) +{ + unsigned long tskv; + struct task_struct *tsk = NULL; + + printf(" task_struct ->thread.ksp PID PPID S P CMD\n"); + if (scanhex(&tskv)) { + tsk = (struct task_struct *)tskv; + XMON_PROTECT(procshow(tsk), "*** Error dumping task %p\n", tsk); + } else { + XMON_PROTECT(for_each_process(tsk) procshow(tsk), + "*** Error dumping task %p\n", tsk); + } +} + static void proccall(void) { unsigned long args[8]; -- 1.7.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: powerpc/xmon: Add xmon command to dump process/task similar to ps(1) 2015-11-23 15:01 ` [PATCH] " Douglas Miller @ 2016-02-09 10:58 ` Michael Ellerman 2016-02-09 14:07 ` Douglas Miller 2016-02-17 12:41 ` Michael Ellerman 1 sibling, 1 reply; 5+ messages in thread From: Michael Ellerman @ 2016-02-09 10:58 UTC (permalink / raw) To: Douglas Miller, linuxppc-dev On Mon, 2015-23-11 at 15:01:15 UTC, Douglas Miller wrote: > Add 'P' command with optional task_struct address to dump all/one task's > information: task pointer, kernel stack pointer, PID, PPID, state > (interpreted), CPU where (last) running, and command. > > Introduce XMON_PROTECT macro to standardize memory-access-fault > protection (setjmp). Initially used only by the 'P' command. Hi Doug, Sorry this has taken a while, it keeps getting preempted by more important patches. I'm also not a big fan of the protect macro, it works for this case, but it's already a bit ugly calling for_each_process() inside the macro, and it would be even worse for multi line logic. I think I'd rather just open code it, and hopefully we can come up with a better solution for catching errors in the long run. I also renamed the routines to use "task", because "proc" in xmon is already used to mean "procedure", and the struct is task_struct after all. How does this look? cheers diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index 47e195d66a9a..942796fa4767 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -163,6 +163,7 @@ static int cpu_cmd(void); static void csum(void); static void bootcmds(void); static void proccall(void); +static void show_tasks(void); void dump_segments(void); static void symbol_lookup(void); static void xmon_show_stack(unsigned long sp, unsigned long lr, @@ -238,6 +239,7 @@ Commands:\n\ mz zero a block of memory\n\ mi show information about memory allocation\n\ p call a procedure\n\ + P list processes/tasks\n\ r print registers\n\ s single step\n" #ifdef CONFIG_SPU_BASE @@ -967,6 +969,9 @@ cmds(struct pt_regs *excp) case 'p': proccall(); break; + case 'P': + show_tasks(); + break; #ifdef CONFIG_PPC_STD_MMU case 'u': dump_segments(); @@ -2566,6 +2571,61 @@ memzcan(void) printf("%.8x\n", a - mskip); } +static void show_task(struct task_struct *tsk) +{ + char state; + + /* + * Cloned from kdb_task_state_char(), which is not entirely + * appropriate for calling from xmon. This could be moved + * to a common, generic, routine used by both. + */ + state = (tsk->state == 0) ? 'R' : + (tsk->state < 0) ? 'U' : + (tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' : + (tsk->state & TASK_STOPPED) ? 'T' : + (tsk->state & TASK_TRACED) ? 'C' : + (tsk->exit_state & EXIT_ZOMBIE) ? 'Z' : + (tsk->exit_state & EXIT_DEAD) ? 'E' : + (tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?'; + + printf("%p %016lx %6d %6d %c %2d %s\n", tsk, + tsk->thread.ksp, + tsk->pid, tsk->parent->pid, + state, task_thread_info(tsk)->cpu, + tsk->comm); +} + +static void show_tasks(void) +{ + unsigned long tskv; + struct task_struct *tsk = NULL; + + printf(" task_struct ->thread.ksp PID PPID S P CMD\n"); + + if (scanhex(&tskv)) + tsk = (struct task_struct *)tskv; + + if (setjmp(bus_error_jmp) != 0) { + catch_memory_errors = 0; + printf("*** Error dumping task %p\n", tsk); + return; + } + + catch_memory_errors = 1; + sync(); + + if (tsk) + show_task(tsk); + else + for_each_process(tsk) + show_task(tsk); + + sync(); + __delay(200); + catch_memory_errors = 0; +} + static void proccall(void) { unsigned long args[8]; ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: powerpc/xmon: Add xmon command to dump process/task similar to ps(1) 2016-02-09 10:58 ` Michael Ellerman @ 2016-02-09 14:07 ` Douglas Miller 0 siblings, 0 replies; 5+ messages in thread From: Douglas Miller @ 2016-02-09 14:07 UTC (permalink / raw) To: linuxppc-dev That looks fine to me. Thanks! On 02/09/2016 04:58 AM, Michael Ellerman wrote: > On Mon, 2015-23-11 at 15:01:15 UTC, Douglas Miller wrote: >> Add 'P' command with optional task_struct address to dump all/one task's >> information: task pointer, kernel stack pointer, PID, PPID, state >> (interpreted), CPU where (last) running, and command. >> >> Introduce XMON_PROTECT macro to standardize memory-access-fault >> protection (setjmp). Initially used only by the 'P' command. > Hi Doug, > > Sorry this has taken a while, it keeps getting preempted by more important > patches. > > I'm also not a big fan of the protect macro, it works for this case, but it's > already a bit ugly calling for_each_process() inside the macro, and it would be > even worse for multi line logic. > > I think I'd rather just open code it, and hopefully we can come up with a > better solution for catching errors in the long run. > > I also renamed the routines to use "task", because "proc" in xmon is already > used to mean "procedure", and the struct is task_struct after all. > > How does this look? > > cheers > > diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c > index 47e195d66a9a..942796fa4767 100644 > --- a/arch/powerpc/xmon/xmon.c > +++ b/arch/powerpc/xmon/xmon.c > @@ -163,6 +163,7 @@ static int cpu_cmd(void); > static void csum(void); > static void bootcmds(void); > static void proccall(void); > +static void show_tasks(void); > void dump_segments(void); > static void symbol_lookup(void); > static void xmon_show_stack(unsigned long sp, unsigned long lr, > @@ -238,6 +239,7 @@ Commands:\n\ > mz zero a block of memory\n\ > mi show information about memory allocation\n\ > p call a procedure\n\ > + P list processes/tasks\n\ > r print registers\n\ > s single step\n" > #ifdef CONFIG_SPU_BASE > @@ -967,6 +969,9 @@ cmds(struct pt_regs *excp) > case 'p': > proccall(); > break; > + case 'P': > + show_tasks(); > + break; > #ifdef CONFIG_PPC_STD_MMU > case 'u': > dump_segments(); > @@ -2566,6 +2571,61 @@ memzcan(void) > printf("%.8x\n", a - mskip); > } > > +static void show_task(struct task_struct *tsk) > +{ > + char state; > + > + /* > + * Cloned from kdb_task_state_char(), which is not entirely > + * appropriate for calling from xmon. This could be moved > + * to a common, generic, routine used by both. > + */ > + state = (tsk->state == 0) ? 'R' : > + (tsk->state < 0) ? 'U' : > + (tsk->state & TASK_UNINTERRUPTIBLE) ? 'D' : > + (tsk->state & TASK_STOPPED) ? 'T' : > + (tsk->state & TASK_TRACED) ? 'C' : > + (tsk->exit_state & EXIT_ZOMBIE) ? 'Z' : > + (tsk->exit_state & EXIT_DEAD) ? 'E' : > + (tsk->state & TASK_INTERRUPTIBLE) ? 'S' : '?'; > + > + printf("%p %016lx %6d %6d %c %2d %s\n", tsk, > + tsk->thread.ksp, > + tsk->pid, tsk->parent->pid, > + state, task_thread_info(tsk)->cpu, > + tsk->comm); > +} > + > +static void show_tasks(void) > +{ > + unsigned long tskv; > + struct task_struct *tsk = NULL; > + > + printf(" task_struct ->thread.ksp PID PPID S P CMD\n"); > + > + if (scanhex(&tskv)) > + tsk = (struct task_struct *)tskv; > + > + if (setjmp(bus_error_jmp) != 0) { > + catch_memory_errors = 0; > + printf("*** Error dumping task %p\n", tsk); > + return; > + } > + > + catch_memory_errors = 1; > + sync(); > + > + if (tsk) > + show_task(tsk); > + else > + for_each_process(tsk) > + show_task(tsk); > + > + sync(); > + __delay(200); > + catch_memory_errors = 0; > +} > + > static void proccall(void) > { > unsigned long args[8]; > > _______________________________________________ > Linuxppc-dev mailing list > Linuxppc-dev@lists.ozlabs.org > https://lists.ozlabs.org/listinfo/linuxppc-dev ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: powerpc/xmon: Add xmon command to dump process/task similar to ps(1) 2015-11-23 15:01 ` [PATCH] " Douglas Miller 2016-02-09 10:58 ` Michael Ellerman @ 2016-02-17 12:41 ` Michael Ellerman 1 sibling, 0 replies; 5+ messages in thread From: Michael Ellerman @ 2016-02-17 12:41 UTC (permalink / raw) To: Douglas Miller, linuxppc-dev On Mon, 2015-23-11 at 15:01:15 UTC, Douglas Miller wrote: > Add 'P' command with optional task_struct address to dump all/one task's > information: task pointer, kernel stack pointer, PID, PPID, state > (interpreted), CPU where (last) running, and command. > > Introduce XMON_PROTECT macro to standardize memory-access-fault > protection (setjmp). Initially used only by the 'P' command. > > Signed-off-by: Douglas Miller <dougmill@linux.vnet.ibm.com> Applied to powerpc next, thanks. https://git.kernel.org/powerpc/c/6dfb54049f9a99b24fe5d5cd2d cheers ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-17 12:41 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-11-23 15:01 powerpc/xmon: Add xmon command to dump process/task similar to ps(1) Douglas Miller 2015-11-23 15:01 ` [PATCH] " Douglas Miller 2016-02-09 10:58 ` Michael Ellerman 2016-02-09 14:07 ` Douglas Miller 2016-02-17 12:41 ` 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).