From: "Petr Cervenka" <grugh@centrum.cz>
To: "Gilles Chanteperdrix" <gilles.chanteperdrix@xenomai.org>
Cc: Xenomai <xenomai@xenomai.org>
Subject: Re: [Xenomai] non-blocking rt_task_suspend(NULL)
Date: Wed, 16 Apr 2014 14:22:26 +0200 [thread overview]
Message-ID: <20140416142226.659BA9DF@centrum.cz> (raw)
In-Reply-To: <534E4885.3060400@xenomai.org>
> Od: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
>
> CC: "Xenomai" <xenomai@xenomai.org>
>On 04/15/2014 02:42 PM, Petr Cervenka wrote:
>> Hello I have a problem with the rt_task_suspend(NULL) call. I'm using
>> it for synchronization of two (producer / consumer like) tasks. 1)
>> When the consumer task has no work to do, it stops itself by calling
>> of the rt_task_suspend(NULL). 2) When the producer creates new work
>> for consumer, it wakes it up by calling of
>> rt_task_resume(&consumerTask). The problem is, that consumer seldom
>> switches to a state, that it sleeps by rt_task_suspend no more. And
>> the task then takes all the CPU time. The return code is 0. But I
>> already have seen couple of -4 (-EINTR) values in the past also.
>> Consumer task status was 00300380 before and 00300184 (if there is
>> small safety sleep present). I can use for example RT_EVENT variable
>> instead, but I'm curious if you by chance don't know, what is
>> happening? Xenomai 2.6.3, Linux 3.5.7
>
>Could you post the example of code you are using to get this issue?
>
It's and application with many threads, mutexes and others. It's also special measuring HW dependent. I can post here some simplified example. But I don't think it would be possible to reproduce the same behavior easily. It happens in my configuration only probably once per day and very unpredictably.
But I have more details. I replaced rt_task_suspend / rt_task_resume by rt_event_wait / rt_event_signal. It failed similar way, but this time the result of wait was -4 (-EINTR). And (after several millions of invocations) it recovered itself.
// consumer task -----------------------------------------------------------------------------
void CAsyncReaderWriter::taskCycle() {
unsigned long eventMask;
while (!terminated) {
// wait for new data !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//int res = rt_task_suspend(NULL);
int res = rt_event_wait(&event, EVENT_READ | EVENT_WRITE | EVENT_END, &eventMask, EV_ANY, TM_INFINITE);
if (res < 0) {
LOG_PRINT("wait result: %d (%s)\n", res, strerror(-res));
}
rt_event_clear(&event, EVENT_READ | EVENT_WRITE | EVENT_END, NULL);
// synchronized data processing with checking of the "terminated" flag
rt_mutex_acquire(&mutex, TM_INFINITE);
while (!terminated && !dataQueue.empty()) {
TDataElement *dataElement = dataQueue.pop_front();
rt_mutex_release(&mutex);
// slow work including hard disk usage
...
rt_mutex_acquire(&mutex, TM_INFINITE);
// return free data element
freeData.push_back(dataElement);
}
rt_mutex_release(&mutex);
// safety sleep added after some freezes caused by 100% CPU load
rt_task_sleep(rt_timer_ns2ticks(100000));
}
}
// called from producer -------------------------------------------------------------------------
void CAsyncReaderWriter::write(const TParams ¶ms) {
TDataElement *dataElement = NULL;
// get free element
rt_mutex_acquire(&mutex, TM_INFINITE);
if (freeData.empty()) {
rt_mutex_release(&mutex);
throw std::runtime_error(ERRORMSG("no free data elements"));
}
dataElement = freeData.back();
freeData.pop_back();
rt_mutex_release(&mutex);
// copy params
dataElement->params = params;
// add to circle buffer
rt_mutex_acquire(&mutex, TM_INFINITE);
if (dataQueue.full()) {
freeData.push_back(dataElement);
rt_mutex_release(&mutex);
throw std::runtime_error(ERRORMSG("data queue is full"));
}
dataQueue.push_back(dataElement);
rt_mutex_release(&mutex);
// wake-up task !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//rt_task_resume(&task);
rt_event_signal(&event, EVENT_WRITE);
}
next prev parent reply other threads:[~2014-04-16 12:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-15 12:42 [Xenomai] non-blocking rt_task_suspend(NULL) Petr Cervenka
2014-04-16 9:08 ` Gilles Chanteperdrix
2014-04-16 12:22 ` Petr Cervenka [this message]
2014-04-16 12:26 ` Gilles Chanteperdrix
-- strict thread matches above, loose matches on Subject: below --
2014-04-16 14:20 Petr Cervenka
2014-04-16 14:28 ` Gilles Chanteperdrix
2014-04-16 16:02 Petr Cervenka
2014-04-16 16:17 ` Gilles Chanteperdrix
2014-04-18 8:51 ` Petr Cervenka
2014-04-22 17:20 ` Gilles Chanteperdrix
2014-04-24 15:06 ` Petr Cervenka
2014-04-24 17:53 ` Gilles Chanteperdrix
2014-04-25 8:38 ` Petr Cervenka
2014-05-02 12:13 Petr Cervenka
2014-05-02 12:30 ` Gilles Chanteperdrix
2014-05-02 13:16 ` Philippe Gerum
2014-05-06 8:17 ` Petr Cervenka
2014-05-06 8:39 ` Philippe Gerum
2014-05-06 8:56 ` Philippe Gerum
2014-05-06 9:29 ` Petr Cervenka
2014-05-06 12:57 ` Philippe Gerum
2014-05-07 13:13 ` Petr Cervenka
2014-05-08 15:53 ` Philippe Gerum
2014-05-12 12:37 ` Petr Cervenka
2014-05-12 13:09 ` Philippe Gerum
2014-05-20 12:27 ` Petr Cervenka
2014-05-20 12:54 ` Philippe Gerum
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=20140416142226.659BA9DF@centrum.cz \
--to=grugh@centrum.cz \
--cc=gilles.chanteperdrix@xenomai.org \
--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.