All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Webb <jeff.webb@domain.hid>
To: Xenomai help <xenomai@xenomai.org>
Subject: [Xenomai-help] Real-time printf in Xenomai 2.6.0
Date: Thu, 23 Feb 2012 16:02:58 -0600	[thread overview]
Message-ID: <4F46B792.8070204@domain.hid> (raw)
In-Reply-To: <4F3BDC1E.9090707@domain.hid>

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

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

[-- Attachment #2: printf_test.c --]
[-- Type: text/x-csrc, Size: 1028 bytes --]

#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;
}

  parent reply	other threads:[~2012-02-23 22:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-15 16:03 [Xenomai-help] signal handling in Xenomai 2.6.0 Jeff Webb
2012-02-15 16:23 ` Gilles Chanteperdrix
2012-02-15 17:23   ` Jeff Webb
2012-02-23 22:02   ` Jeff Webb [this message]
2012-02-23 22:26     ` [Xenomai-help] Real-time printf " Gilles Chanteperdrix
2012-02-23 23:07       ` Jeff Webb
2012-02-23 23:14         ` Gilles Chanteperdrix
2012-04-15 17:42         ` Gilles Chanteperdrix
2012-04-17 22:22           ` Jeff Webb

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=4F46B792.8070204@domain.hid \
    --to=jeff.webb@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.