From c6ac4d2581148e58ebe25494dfb76f81ab35c93b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 19 Feb 2016 15:33:32 -0600 Subject: [PATCH] NSH: ps command will show CPU if SMP is enabled --- ChangeLog.txt | 2 ++ nshlib/nsh_proccmds.c | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index b4eec3b68..2019f99bc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1550,4 +1550,6 @@ table (2016-02-08). * apps/nshlib: Add an 'arp' command that will support access to the OS ARP table (2016-02-08). + * apps/nshlib: 'ps' command will show CPU if SMP is enabled + (2016-02-19). diff --git a/nshlib/nsh_proccmds.c b/nshlib/nsh_proccmds.c index 5d49d62f0..7a1122a83 100644 --- a/nshlib/nsh_proccmds.c +++ b/nshlib/nsh_proccmds.c @@ -90,8 +90,11 @@ struct nsh_taskstatus_s #ifdef HAVE_GROUPID FAR const char *td_groupid; /* Group ID */ #else - FAR const char *td_ppid; /* Parent thread ID */ + FAR const char *td_ppid; /* Parent thread ID */ #endif +#endif +#ifdef CONFIG_SMP + FAR const char *td_cpu; /* CPU */ #endif FAR const char *td_state; /* Thread state */ FAR const char *td_event; /* Thread wait event */ @@ -116,6 +119,9 @@ static const char g_groupid[] = "Group:"; static const char g_ppid[] = "PPID:"; #endif #endif +#ifdef CONFIG_SMP +static const char g_cpu[] = "CPU:"; +#endif static const char g_state[] = "State:"; static const char g_flags[] = "Flags:"; static const char g_priority[] = "Priority:"; @@ -190,6 +196,15 @@ static void nsh_parse_statusline(FAR char *line, #endif #endif +#ifdef CONFIG_SMP + else if (strncmp(line, g_cpu, strlen(g_cpu)) == 0) + { + /* Save the current CPU */ + + status->td_cpu = nsh_trimspaces(&line[12]); + } +#endif + else if (strncmp(line, g_state, strlen(g_state)) == 0) { FAR char *ptr; @@ -279,6 +294,9 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath, #else status.td_ppid = ""; #endif +#endif +#ifdef CONFIG_SMP + status.td_cpu = ""; #endif status.td_state = ""; status.td_event = ""; @@ -347,6 +365,10 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath, #endif #endif +#ifdef CONFIG_SMP + nsh_output(vtbl, "%3s ", status.td_cpu); +#endif + nsh_output(vtbl, "%3s %-8s %-7s %3s %-8s %-9s ", status.td_priority, status.td_policy, status.td_type, status.td_flags, status.td_state, status.td_event); @@ -446,6 +468,10 @@ int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif #endif +#ifdef CONFIG_SMP + nsh_output(vtbl, "%3s ", "CPU"); +#endif + nsh_output(vtbl, "%3s %-8s %-7s %3s %-8s %-9s ", "PRI", "POLICY", "TYPE", "NPX", "STATE", "EVENT");