All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Blaess <mailist@domain.hid>
To: xenomai@xenomai.org
Subject: [Xenomai-core] [PATCH] Threads without names confuse rtps
Date: Sat, 31 Dec 2011 09:01:31 +0100	[thread overview]
Message-ID: <4EFEC15B.4040807@domain.hid> (raw)

[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]

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]#






[-- Attachment #2: rtps-no-name.patch --]
[-- Type: text/x-patch, Size: 1598 bytes --]

diff -Nru xenomai-2.6.0-orig//src/utils/ps/rtps.c xenomai-2.6.0/src/utils/ps/rtps.c
--- xenomai-2.6.0-orig//src/utils/ps/rtps.c	2011-10-18 20:17:18.000000000 +0200
+++ xenomai-2.6.0/src/utils/ps/rtps.c	2011-12-31 08:23:17.435303214 +0100
@@ -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 10
 
 int 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");



             reply	other threads:[~2011-12-31  8:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-31  8:01 Christophe Blaess [this message]
2012-01-01 20:33 ` [Xenomai-core] [PATCH] Threads without names confuse rtps Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EFEC15B.4040807@domain.hid \
    --to=mailist@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.