Threads without names confuse rtps
PATCH 1/1 Threads without names confuse rtps
If a Xenomai thread is created with a NULL name parameter, this way:
// no-name.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <rtdk.h>
#include <native/task.h>
int main(void)
{
int err;
RT_TASK task;
mlockall(MCL_CURRENT|MCL_FUTURE);
rt_print_auto_init(1);
if ((err = rt_task_shadow(& task, NULL, 50, T_JOINABLE)) != 0) {
fprintf(stderr, "rt_task_shadow: %s\n", strerror(-err));
exit(EXIT_FAILURE);
}
while (1)
rt_task_sleep(1000000000);
return 0;
}Then, the rtps display is wrong, because the "name" field in /proc/acct is empty:
[Panda]# /usr/xenomai/sbin/rtps
PID TIME THREAD CMD
0 002:40:47.105,569 ROOT/0 - 0 002:41:08.762,505 ROOT/1 - 31267 000:00:00.007,737 1 0 0 40038203 0 00000000 672522999738 1901211134 27510920737 IR/proc/31267/cmdline ./no-name
[Panda]#
Here is a small patch to correct the reading of /proc/acct in case the name is missing. And now:
[Panda]# /root/rtps
PID TIME THREAD CMD
0 002:46:17.807,037 ROOT/0 - 0 002:46:39.469,616 ROOT/1 - 31267 000:00:00.011,491 ./no-name 0 000:00:28.439,650 IRQ29: [timer] -
[Panda]#
src/utils/ps/rtps.c renamed from /src/utils/ps/rtps.c +16 -5
@@ -7,12 +7,14 @@#define PROC_ACCT "/proc/xenomai/acct"#define PROC_PID "/proc/%d/cmdline" -#define ACCT_FMT "%u %d %lu %lu %lu %lx %Lu %Lu %Lu %[^\n]" -#define ACCT_NFMT 10 +#define ACCT_FMT_1 "%u %d %lu %lu %lu %lx %Lu %Lu %Lu" +#define ACCT_FMT_2 ACCT_FMT_1 " %[^\n]" +#define ACCT_NFMT_1 9 +#define ACCT_NFMT_2 10int main (int argc,char *argv[]) { -char cmdpath[sizeof (PROC_PID ) +32 ], cmdbuf[BUFSIZ ], name[64 ]; +char cmdpath[sizeof (PROC_PID ) +32 ], cmdbuf[BUFSIZ ], acctbuf[BUFSIZ ], name[64 ];unsigned long ssw, csw, pf, state, sec;unsigned long long account_period, exectime_period, exectime_total, v;
@@ -27,10 +29,19 @@printf ("%-6s %-17s %-24s %s\n\n" ,"PID" ,"TIME" ,"THREAD" ,"CMD" ); -while (fscanf (acctfp,ACCT_FMT , +while (fgets (acctbuf,sizeof (acctbuf), acctfp) !=NULL ) { +if (sscanf (acctbuf,ACCT_FMT_2 , &cpu, &pid, &ssw, &csw, &pf, &state, &account_period, &exectime_period, - &exectime_total, name) ==ACCT_NFMT ) { + &exectime_total, name) !=ACCT_NFMT_2 ) { +strcpy (name,"" ); +if (sscanf (acctbuf,ACCT_FMT_1 , + &cpu, &pid, &ssw, &csw, &pf, &state, + &account_period, &exectime_period, + &exectime_total) !=ACCT_NFMT_1 ) { +break ; + } + }snprintf (cmdpath,sizeof (cmdpath),PROC_PID , pid); cmdfp =fopen (cmdpath,"r" );
Gilles Chanteperdrix
AppliedQuoted 1 line · Christophe Blaess
If a Xenomai thread is created with a NULL name parameter, this way:
Applied, thanks.
Signature · 1 line
Gilles.