From: Philippe Gerum <rpm@xenomai.org>
To: Konstantinos Chalas <konchalas@gmail.com>, Xenomai <xenomai@xenomai.org>
Subject: Re: [Xenomai] timer_create( ) example in Xenomai-3
Date: Wed, 9 Sep 2015 15:53:50 +0200 [thread overview]
Message-ID: <55F039EE.2010502@xenomai.org> (raw)
In-Reply-To: <55F03436.5040202@gmail.com>
On 09/09/2015 03:29 PM, Konstantinos Chalas wrote:
> For future reference, this is what a working POSIX timer in Xenomai
> looks like:
>
Good you got it working. A few additional hints:
> void* print_time (void* args)
> {
> struct timespec tp;
> char buffer [80];
> struct itimerspec new_value, old_value;
> struct sigaction action;
> struct sigevent sevent;
> sigset_t set;
> int signum = SIGALRM;
>
> sevent.sigev_notify = SIGEV_THREAD_ID;
> sevent.sigev_notify_thread_id = syscall(__NR_gettid);
> sevent.sigev_signo = signum;
>
Passing a NULL sigevent will get you the exact same behavior, i.e.:
signum=SIGALRM, SIGEV_THREAD_ID to the calling thread. With the proper
fix mentioned earlier, that is.
> sigemptyset(&set);
> sigaddset(&set, signum);
> sigprocmask(SIG_BLOCK, &set, NULL);
This masking is useless, and do not apply to Xenomai/cobalt signals but
to regular ones. Cobalt signals are synchronous only, so you won't
receive any async notification via some handler. sigwait*() is required
to pull the pending signals explicitly. You can see this as all signals
managed by Cobalt being implicitly blocked for any rt thread - of
course, this does not apply to regular Linux signals which behave as usual.
> while(1){
> /* wait for signal (1 s) */
> if (sigwait (&set, &signum) == -1)
> perror ("sigwait");
sigwait() does not return -1, but a positive error number if something
went wrong.
>
> if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1)
> perror ("clock_gettime");
>
> sprintf (buffer, "%ld s %ld ns overrun = %d\n", tp.tv_sec,
> tp.tv_nsec, timer_getoverrun (timer1));
Another way to retrieve the count of overruns for a timer without the
extra call is to invoke sigwaitinfo(&set, &siginfo), fetching that value
from siginfo.si_overrun.
--
Philippe.
prev parent reply other threads:[~2015-09-09 13:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-07 11:53 [Xenomai] timer_create( ) example in Xenomai-3 Konstantinos Chalas
2015-09-07 12:52 ` Philippe Gerum
2015-09-09 13:29 ` Konstantinos Chalas
2015-09-09 13:37 ` Gilles Chanteperdrix
2015-09-09 13:53 ` Philippe Gerum [this message]
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=55F039EE.2010502@xenomai.org \
--to=rpm@xenomai.org \
--cc=konchalas@gmail.com \
--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.