From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Stephen Bryant <sbxenomai@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Unexpected preemption of highest priority thread
Date: Wed, 21 Jul 2010 13:06:07 +0200 [thread overview]
Message-ID: <4C46D49F.6030102@domain.hid> (raw)
In-Reply-To: <AANLkTilWSsSuCKRxQg0NIkeeR28eqpdJfaVm_CiemnqF@mail.gmail.com>
Stephen Bryant wrote:
> Hi,
>
> I have some code (simplified example below) which uses
> 'pthread_wait_np(&Overrun)' within a while loop, using a period of
> 1,000,000ns (1ms) which has been set using 'pthread_make_periodic_np()'.
> This wakes the thread up less than 2,000ns late in general, sometimes
> 20,000ns late, and at most less than 45,000ns late.
Since you do not tell us, I guess you are running on x86. Depending on
the x86 you are running, 45 us may be high.
To ensure that I perform
> the tasks within the thread from a consistent 'millisecond tick' I set an
> expected time value 45,000ns later than the earliest wake time each period,
> and then use a busy loop until the current time equals this expected time.
> This busy loop takes < 600ns per cycle, and so the latency from my expected
> time should be a maximum of 600ns.
This reasoning is flawed: you may be preempted by interrupts any time.
Including just about at the time where you were going to exit the busy
loop. Unless you spin irqs off, and only reenable irqs when the job the
thread is supposed to be doing is done. And if you have an SMI issue,
even turning off the interrupts will not help.
The latencies I am actually seeing are as
> high as 13,000ns, and these occur during this busy loop (I have timed it),
> implying that this loop is being preempted.
>
> while(1)
> {
> pthread_wait_np(&Overrun);
>
> WakeTime = GetTime();
> while(WakeTime < ExpectedTime)
> { WakeTime = GetTime(); } // Preempted here
>
> DoWork();
>
> ExpectedTime += Period;
> }
>
> This is a Xenomai POSIX thread with a priority of 99, and is the only thread
> within my program with a priority of 99 or higher. There are no context
> switches occuring within this thread (confirmed using pthread_set_mode_np(0,
> PTHREAD_WARNSW)).
>
> I have had a brief experimentation with kernel settings, for example
> applying the SMI workaround, but this produces no difference to the
> preemption that I measure.
The question is: is the SMI workaround working for your chipset? If that
is the case, you should get messages in the kernel logs.
--
Gilles.
next prev parent reply other threads:[~2010-07-21 11:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-21 10:54 [Xenomai-help] Unexpected preemption of highest priority thread Stephen Bryant
2010-07-21 11:06 ` Gilles Chanteperdrix [this message]
2010-07-21 12:05 ` Stephen Bryant
2010-07-21 13:04 ` Stephen Bryant
2010-07-21 13:06 ` Gilles Chanteperdrix
2010-07-22 7:49 ` Stephen Bryant
2010-07-22 7:54 ` Gilles Chanteperdrix
2010-07-22 9:09 ` Stephen Bryant
2010-07-22 10:56 ` Gilles Chanteperdrix
2010-07-26 10:27 ` Stephen Bryant
2010-07-26 12:11 ` Gilles Chanteperdrix
2010-07-26 12:31 ` Stephen Bryant
2010-07-26 13:45 ` Gilles Chanteperdrix
2010-07-27 13:20 ` Stephen Bryant
2010-07-27 13:30 ` 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=4C46D49F.6030102@domain.hid \
--to=gilles.chanteperdrix@xenomai.org \
--cc=sbxenomai@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.