Skip to contentSkip to conversation

signal handling in Xenomai 2.6.0

Xenomai-help Jeff Webb 2 participants 9 messages Feb 15, 2012 – Apr 17, 2012

lore
Share & tools
lore

Jeff Webb

author
#0 lore raw

I am not able to block signals using pthread_sigmask or sigprocmask on my Xenomai 2.6.0 system. If I compile my test program without Xenomai, it works as I intended and blocks the requested signals. If I compile it for Xenomai, the requested signals are not blocked. After scratching my head for some time, I tried running the program on an older machine running Xenomai 2.5.5.2, and it worked as I intended and blocked the requested signals. I have not tried upgrading the Xenomai 2.5.5.2 machine to 2.6.0 to see if the problem is somehow related to the hardware on the newer machine. I haven't noticed any other problems with Xenomai 2.6.0 on the newer machine; the latency and performance appear to be what I would expect.

My test program is attached. I printed the current thread in the signal handler, and thought that the output might be of interest. This is output from the program running under Xenomai 2.6.0:

  $ ./sigtest
  main thread: 7f6ff32c8700
  mlockall returned 0
  sigaction returned 0
  pthread_sigmask returned 0
  ^Csignal handled in: 7f6ff32f2700
  end of main
  $

If I comment out the call topthread_sigmask, I get this output:

  $ ./sigtest
  main thread: 7f446ba09700
  mlockall returned 0
  sigaction returned 0
  pthread_sigmask returned 0
  ^Csignal handled in: 7f446ba09700
  end of main
  $

It appears to me that in the first case, the signal is being blocked in the main thread, but is being handled in another (shadow?) thread.

Can someone confirm that this code works on Xenomai 2.6.0?

Thanks,

Jeff Webb

#include <stdio.h>
#include <pthread.h>
#include <signal.h>
#include <sys/mman.h>

sig_atomic_t abort_program = 0;

void signal_handler(int sig)
{
abort_program = 1;
printf("signal handled in: %lx\n", pthread_self());
}

int main(void)

{
    int err;
    struct sigaction action;
    sigset_t mask;

    printf("main thread: %lx\n", pthread_self());

    err = mlockall(MCL_CURRENT | MCL_FUTURE);
    printf("mlockall returned %d\n", err);

    action.sa_handler = signal_handler;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    err = sigaction(SIGINT, &action, NULL);
    printf("sigaction returned %d\n", err);
    
    sigemptyset(&mask);
    sigaddset(&mask, SIGINT);
    err = pthread_sigmask(SIG_BLOCK, &mask, NULL);
    printf("pthread_sigmask returned %d\n", err);    

    while(!abort_program)
    {}

    printf("end of main\n");
  
    return 0;
}
#1 lore raw
Quoted 26 lines · Jeff Webb

I am not able to block signals using pthread_sigmask or sigprocmask on my Xenomai 2.6.0 system. If I compile my test program without Xenomai, it works as I intended and blocks the requested signals. If I compile it for Xenomai, the requested signals are not blocked. After scratching my head for some time, I tried running the program on an older machine running Xenomai 2.5.5.2, and it worked as I intended and blocked the requested signals. I have not tried upgrading the Xenomai 2.5.5.2 machine to 2.6.0 to see if the problem is somehow related to the hardware on the newer machine. I haven't noticed any other problems with Xenomai 2.6.0 on the newer machine; the latency and performance appear to be what I would expect.

My test program is attached. I printed the current thread in the signal handler, and thought that the output might be of interest. This is output from the program running under Xenomai 2.6.0:

$ ./sigtest main thread: 7f6ff32c8700 mlockall returned 0 sigaction
returned 0 pthread_sigmask returned 0 ^Csignal handled in:
7f6ff32f2700 end of main $

If I comment out the call topthread_sigmask, I get this output:

$ ./sigtest main thread: 7f446ba09700 mlockall returned 0 sigaction
returned 0 pthread_sigmask returned 0 ^Csignal handled in:
7f446ba09700 end of main $
Quoted 5 lines

It appears to me that in the first case, the signal is being blocked in the main thread, but is being handled in another (shadow?) thread.

Can someone confirm that this code works on Xenomai 2.6.0?

Please try the following patch:

src/skins/common/rt_print.c +5 -0
index 5533e29..78dcda8 100644
@@ -612,6 +612,11 @@ static void unlock(void *cookie)
 
 static void *printer_loop(void *arg)
 {
+	sigset_t mask;
+
+	sigfillset(&mask);
+	pthread_sigmask(SIG_BLOCK, &mask, NULL);
+
 	while (1) {
 		pthread_cleanup_push(unlock, &buffer_lock);
 		pthread_mutex_lock(&buffer_lock);
Signature · 1 line
					    Gilles.
author
#2 lore raw
Quoted 10 lines · Gilles Chanteperdrix
Quoted 6 lines · Jeff Webb

I am not able to block signals using pthread_sigmask or sigprocmask on my Xenomai 2.6.0 system. If I compile my test program without Xenomai, it works as I intended and blocks the requested signals. If I compile it for Xenomai, the requested signals are not blocked.
...
Can someone confirm that this code works on Xenomai 2.6.0?

Please try the following patch:
...

Thanks, Gilles. That seems to have fixed the problem. I had to add "#include <signal.h>" at the top of rt_print.c to get your patched version to compile. I just rebuilt my userspace packages, not the kernel.

Thanks again for the quick response.

-Jeff

author
#3 lore raw

[Xenomai-help] Real-time printf in Xenomai 2.6.0

In reply to Gilles Chanteperdrix

I was happy to see that printf now works from real-time POSIX threads in Xenomai 2.6.0. Unfortunately, I'm seeing some strange behavior that surfaces when I try to print the string "\n" by itself. When I run the attached example program, I get:

  $ ./printf_test
  start
  CPU time limit exceeded
  $

IfI replace the two printf calls with rt_printf calls and #include <rtdk.h>,I get the expected result:

  $ ./rt_printf_test
  start
  1
  2
  3
  4
  ^C
  $

The original example also works if these two lines:

        printf("%d", count);
        printf("\n");

are replaced with:

        printf("%d\n", count);

Can someone confirm if this a bug in Xenomai 2.6.0, something specific to my HW/SW installation, or some mistake in my test program?

Thanks,

Jeff

#include <stdio.h>
#include <pthread.h>
#include <sys/mman.h>
#include <malloc.h>

int count = 0;

void * rt_loop(void * arg)

{
    struct timespec dt_ts;
    dt_ts.tv_sec  = 1;
    dt_ts.tv_nsec = 0;    

    pthread_set_mode_np(0, PTHREAD_WARNSW);

    printf("start\n");

    while (1)
    {
        count++;
        clock_nanosleep(CLOCK_REALTIME, 0, &dt_ts, NULL);
        printf("%d", count);
        printf("\n");
    }
    
    return NULL;
}

int main(void)

{
    pthread_attr_t attr;
    pthread_t rt_thread;
    struct sched_param sparam;
  
    mlockall(MCL_CURRENT | MCL_FUTURE);

    sparam.sched_priority = 16;

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
    pthread_attr_setschedparam(&attr, &sparam);
    pthread_create(&rt_thread, &attr, &rt_loop, NULL);
    pthread_attr_destroy(&attr);

    pthread_join(rt_thread, NULL);

    return 0;
}
#4 lore raw

Re: [Xenomai-help] Real-time printf in Xenomai 2.6.0

Quoted 20 lines · Jeff Webb

I was happy to see that printf now works from real-time POSIX threads in Xenomai 2.6.0. Unfortunately, I'm seeing some strange behavior that surfaces when I try to print the string "\n" by itself. When I run the attached example program, I get:

   $ ./printf_test
   start
   CPU time limit exceeded
   $

IfI replace the two printf calls with rt_printf calls and #include <rtdk.h>,I get the expected result:

   $ ./rt_printf_test
   start
   1
   2
   3
   4
   ^C
   $

The original example also works if these two lines:

Quoted 8 lines
         printf("%d", count);
         printf("\n");

are replaced with:

         printf("%d\n", count);

Can someone confirm if this a bug in Xenomai 2.6.0, something specific to my HW/SW installation, or some mistake in my test program?

I would bet the call to printf is replaced with something else (such as putchar). Could you disassemble the test to check this?

Note that I have fixed similar issues in xenomai-2.6 current repository, so you could give it a try.

Signature · 1 line
                                                                Gilles.
author
#5 lore raw

Re: [Xenomai-help] Real-time printf in Xenomai 2.6.0

Quoted 24 lines · Gilles Chanteperdrix
Quoted 23 lines · Jeff Webb

I was happy to see that printf now works from real-time POSIX threads in Xenomai 2.6.0. Unfortunately, I'm seeing some strange behavior that surfaces when I try to print the string "\n" by itself. When I run the attached example program, I get:

    $ ./printf_test
    start
    CPU time limit exceeded
    $

IfI replace the two printf calls with rt_printf calls and #include<rtdk.h>,I get the expected result:

    $ ./rt_printf_test
    start
    1
    2
    3
    4
    ^C
    $

The original example also works if these two lines:

          printf("%d", count);
          printf("\n");
Quoted 8 lines
Quoted 5 lines

are replaced with:

          printf("%d\n", count);

Can someone confirm if this a bug in Xenomai 2.6.0, something specific to my HW/SW installation, or some mistake in my test program?

I would bet the call to printf is replaced with something else (such as putchar). Could you disassemble the test to check this?

Yes, it appears that putchar is called indeed.

Quoted 2 lines

Note that I have fixed similar issues in xenomai-2.6 current repository, so you could give it a try.

I may give that a try. Now that I have confirmed that putchar is the issue, do you think xenomai-2.6 current will fix the problem? Is putchar now wrapped as well? I noticed that puts appears to be wrapped from the disassembly output.

Thanks again for all the help,

Jeff

#6 lore raw

Re: [Xenomai-help] Real-time printf in Xenomai 2.6.0

Quoted 31 lines · Jeff Webb
Quoted 19 lines · Gilles Chanteperdrix
Quoted 18 lines · Jeff Webb

I was happy to see that printf now works from real-time POSIX threads in Xenomai 2.6.0. Unfortunately, I'm seeing some strange behavior that surfaces when I try to print the string "\n" by itself. When I run the attached example program, I get:

$ ./printf_test start CPU time limit exceeded $

IfI replace the two printf calls with rt_printf calls and #include<rtdk.h>,I get the expected result:

$ ./rt_printf_test start 1 2 3 4 ^C $

The original example also works if these two lines:

printf("%d", count); printf("\n");

are replaced with:

Quoted 8 lines
Quoted 5 lines

printf("%d\n", count);

Can someone confirm if this a bug in Xenomai 2.6.0, something specific to my HW/SW installation, or some mistake in my test program?

I would bet the call to printf is replaced with something else (such as putchar). Could you disassemble the test to check this?

Yes, it appears that putchar is called indeed.

Quoted 7 lines
Quoted 2 lines

Note that I have fixed similar issues in xenomai-2.6 current repository, so you could give it a try.

I may give that a try. Now that I have confirmed that putchar is the issue, do you think xenomai-2.6 current will fix the problem? Is putchar now wrapped as well? I noticed that puts appears to be wrapped from the disassembly output.

No, it is not yet wrapped.

Signature · 1 line
                                                                Gilles.
#7 lore raw

Re: [Xenomai-help] Real-time printf in Xenomai 2.6.0

In reply to Jeff Webb
Quoted 31 lines · Jeff Webb
Quoted 19 lines · Gilles Chanteperdrix
Quoted 18 lines · Jeff Webb

I was happy to see that printf now works from real-time POSIX threads in Xenomai 2.6.0. Unfortunately, I'm seeing some strange behavior that surfaces when I try to print the string "\n" by itself. When I run the attached example program, I get:

$ ./printf_test start CPU time limit exceeded $

IfI replace the two printf calls with rt_printf calls and #include<rtdk.h>,I get the expected result:

$ ./rt_printf_test start 1 2 3 4 ^C $

The original example also works if these two lines:

printf("%d", count); printf("\n");

are replaced with:

Quoted 8 lines
Quoted 5 lines

printf("%d\n", count);

Can someone confirm if this a bug in Xenomai 2.6.0, something specific to my HW/SW installation, or some mistake in my test program?

I would bet the call to printf is replaced with something else (such as putchar). Could you disassemble the test to check this?

Yes, it appears that putchar is called indeed.

Quoted 7 lines
Quoted 2 lines

Note that I have fixed similar issues in xenomai-2.6 current repository, so you could give it a try.

I may give that a try. Now that I have confirmed that putchar is the issue, do you think xenomai-2.6 current will fix the problem? Is putchar now wrapped as well? I noticed that puts appears to be wrapped from the disassembly output.

It should now be fixed in xenomai-2.6 repository.

Signature · 1 line
                                                                Gilles.
author
#8 lore raw

Re: [Xenomai-help] Real-time printf in Xenomai 2.6.0

Quoted 35 lines · Gilles Chanteperdrix
Quoted 34 lines · Jeff Webb
Quoted 19 lines · Gilles Chanteperdrix
Quoted 18 lines · Jeff Webb

I was happy to see that printf now works from real-time POSIX threads in Xenomai 2.6.0. Unfortunately, I'm seeing some strange behavior that surfaces when I try to print the string "\n" by itself. When I run the attached example program, I get:

$ ./printf_test start CPU time limit exceeded $

IfI replace the two printf calls with rt_printf calls and #include<rtdk.h>,I get the expected result:

$ ./rt_printf_test start 1 2 3 4 ^C $

The original example also works if these two lines:

printf("%d", count); printf("\n");

are replaced with:

Quoted 8 lines
Quoted 5 lines

printf("%d\n", count);

Can someone confirm if this a bug in Xenomai 2.6.0, something specific to my HW/SW installation, or some mistake in my test program?

I would bet the call to printf is replaced with something else (such as putchar). Could you disassemble the test to check this?

Yes, it appears that putchar is called indeed.

Quoted 2 lines

Note that I have fixed similar issues in xenomai-2.6 current repository, so you could give it a try.

Quoted 7 lines
Quoted 4 lines

I may give that a try. Now that I have confirmed that putchar is the issue, do you think xenomai-2.6 current will fix the problem? Is putchar now wrapped as well? I noticed that puts appears to be wrapped from the disassembly output.

It should now be fixed in xenomai-2.6 repository.

Thanks for following up, Gilles.

-Jeff