* [Xenomai-help] How to avoid a tight real time loop
@ 2010-06-15 12:30 Daniele Nicolodi
2010-06-15 12:46 ` Gilles Chanteperdrix
2010-06-15 22:11 ` Alexis Berlemont
0 siblings, 2 replies; 6+ messages in thread
From: Daniele Nicolodi @ 2010-06-15 12:30 UTC (permalink / raw)
To: xenomai
Hello. In my application I need to read data from an ADC card in blocks
of a given number of samples. For efficiency I'm using an mmapped buffer
to exchange data with the ADC driver. I'm setting up the acquisition,
and then calling a loop like this:
unsigned int required = <compute required number of bytes>;
unsigned int read = 0;
while (1) {
while (read < required) {
read = a4l_pool(...);
}
process(buffer, ...);
}
However if I run this loop in a real time thread the tight while loop is
an obvious cpu hog: the watchdog kicks in and kills the thread.
There is not an analogy API that can be used to require a certain amount
of data to the ADC driver. How can I code this loop to let other
processes to run?
Thanks. Cheers,
--
Daniele
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai-help] How to avoid a tight real time loop
2010-06-15 12:30 [Xenomai-help] How to avoid a tight real time loop Daniele Nicolodi
@ 2010-06-15 12:46 ` Gilles Chanteperdrix
2010-06-15 22:11 ` Alexis Berlemont
1 sibling, 0 replies; 6+ messages in thread
From: Gilles Chanteperdrix @ 2010-06-15 12:46 UTC (permalink / raw)
To: Daniele Nicolodi; +Cc: xenomai
Daniele Nicolodi wrote:
> Hello. In my application I need to read data from an ADC card in blocks
> of a given number of samples. For efficiency I'm using an mmapped buffer
> to exchange data with the ADC driver. I'm setting up the acquisition,
> and then calling a loop like this:
>
> unsigned int required = <compute required number of bytes>;
> unsigned int read = 0;
> while (1) {
> while (read < required) {
> read = a4l_pool(...);
> }
> process(buffer, ...);
> }
>
> However if I run this loop in a real time thread the tight while loop is
> an obvious cpu hog: the watchdog kicks in and kills the thread.
>
> There is not an analogy API that can be used to require a certain amount
> of data to the ADC driver. How can I code this loop to let other
> processes to run?
You should define a period, and how much data you want to process during
this period. Then make your task periodic, and wait for the next period
at the beginning of the loop.
>
> Thanks. Cheers,
--
Gilles.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai-help] How to avoid a tight real time loop
2010-06-15 12:30 [Xenomai-help] How to avoid a tight real time loop Daniele Nicolodi
2010-06-15 12:46 ` Gilles Chanteperdrix
@ 2010-06-15 22:11 ` Alexis Berlemont
2010-06-16 16:49 ` Daniele Nicolodi
2010-06-16 18:19 ` Gilles Chanteperdrix
1 sibling, 2 replies; 6+ messages in thread
From: Alexis Berlemont @ 2010-06-15 22:11 UTC (permalink / raw)
To: Daniele Nicolodi; +Cc: xenomai
Hi,
Daniele Nicolodi wrote:
> Hello. In my application I need to read data from an ADC card in blocks
> of a given number of samples. For efficiency I'm using an mmapped buffer
> to exchange data with the ADC driver. I'm setting up the acquisition,
> and then calling a loop like this:
>
> unsigned int required = <compute required number of bytes>;
> unsigned int read = 0;
> while (1) {
> while (read < required) {
> read = a4l_pool(...);
> }
> process(buffer, ...);
> }
>
> However if I run this loop in a real time thread the tight while loop is
> an obvious cpu hog: the watchdog kicks in and kills the thread.
>
> There is not an analogy API that can be used to require a certain amount
> of data to the ADC driver. How can I code this loop to let other
> processes to run?
As a matter of fact, there is something in the API which could have
helped you in an unmapped configuration. If you set the flag
A4L_CMD_BULK in the field "flags" of the command structure, a call to
a4l_async_read() only returns when the data size specified as argument
is available.
Unfortunately, I have not done the same thing with a4l_poll, I might
have added the requested size as an additional argument to a4l_poll.
Any idea on how to extend the API without breaking it ?
>
> Thanks. Cheers,
> --
> Daniele
>
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
--
Alexis.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai-help] How to avoid a tight real time loop
2010-06-15 22:11 ` Alexis Berlemont
@ 2010-06-16 16:49 ` Daniele Nicolodi
2010-06-16 18:19 ` Gilles Chanteperdrix
1 sibling, 0 replies; 6+ messages in thread
From: Daniele Nicolodi @ 2010-06-16 16:49 UTC (permalink / raw)
To: Alexis Berlemont; +Cc: xenomai
On 16/06/10 00:11, Alexis Berlemont wrote:
>> There is not an analogy API that can be used to require a certain amount
>> of data to the ADC driver. How can I code this loop to let other
>> processes to run?
>
> As a matter of fact, there is something in the API which could have
> helped you in an unmapped configuration. If you set the flag
> A4L_CMD_BULK in the field "flags" of the command structure, a call to
> a4l_async_read() only returns when the data size specified as argument
> is available.
Unfortunately copying memory data around would decrease too much the
performance of my data acquisition code. By the way, I think that using
the O_NONBLOCK fcntl flag on the device descriptor file descriptor would
be the best way to activate this feature.
> Unfortunately, I have not done the same thing with a4l_poll, I might
> have added the requested size as an additional argument to a4l_poll.
>
> Any idea on how to extend the API without breaking it ?
I do not see any way rather than augmenting the function signature with
an additional parameter. If you want to maintain API compatibility the
only thing to do is to add a different function.
Cheers,
--
Daniele
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai-help] How to avoid a tight real time loop
2010-06-15 22:11 ` Alexis Berlemont
2010-06-16 16:49 ` Daniele Nicolodi
@ 2010-06-16 18:19 ` Gilles Chanteperdrix
2010-06-24 22:50 ` Alexis Berlemont
1 sibling, 1 reply; 6+ messages in thread
From: Gilles Chanteperdrix @ 2010-06-16 18:19 UTC (permalink / raw)
To: Alexis Berlemont; +Cc: xenomai
Alexis Berlemont wrote:
> Hi,
>
> Daniele Nicolodi wrote:
>> Hello. In my application I need to read data from an ADC card in blocks
>> of a given number of samples. For efficiency I'm using an mmapped buffer
>> to exchange data with the ADC driver. I'm setting up the acquisition,
>> and then calling a loop like this:
>>
>> unsigned int required = <compute required number of bytes>;
>> unsigned int read = 0;
>> while (1) {
>> while (read < required) {
>> read = a4l_pool(...);
>> }
>> process(buffer, ...);
>> }
>>
>> However if I run this loop in a real time thread the tight while loop is
>> an obvious cpu hog: the watchdog kicks in and kills the thread.
>>
>> There is not an analogy API that can be used to require a certain amount
>> of data to the ADC driver. How can I code this loop to let other
>> processes to run?
>
> As a matter of fact, there is something in the API which could have
> helped you in an unmapped configuration. If you set the flag
> A4L_CMD_BULK in the field "flags" of the command structure, a call to
> a4l_async_read() only returns when the data size specified as argument
> is available.
>
> Unfortunately, I have not done the same thing with a4l_poll, I might
> have added the requested size as an additional argument to a4l_poll.
>
> Any idea on how to extend the API without breaking it ?
Maybe it would be possible to use the standard "select" call, with a
threshold configurable with an ioctl ?
--
Gilles.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai-help] How to avoid a tight real time loop
2010-06-16 18:19 ` Gilles Chanteperdrix
@ 2010-06-24 22:50 ` Alexis Berlemont
0 siblings, 0 replies; 6+ messages in thread
From: Alexis Berlemont @ 2010-06-24 22:50 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
Gilles Chanteperdrix wrote:
> Alexis Berlemont wrote:
> > Hi,
> >
> > Daniele Nicolodi wrote:
> >> Hello. In my application I need to read data from an ADC card in blocks
> >> of a given number of samples. For efficiency I'm using an mmapped buffer
> >> to exchange data with the ADC driver. I'm setting up the acquisition,
> >> and then calling a loop like this:
> >>
> >> unsigned int required = <compute required number of bytes>;
> >> unsigned int read = 0;
> >> while (1) {
> >> while (read < required) {
> >> read = a4l_pool(...);
> >> }
> >> process(buffer, ...);
> >> }
> >>
> >> However if I run this loop in a real time thread the tight while loop is
> >> an obvious cpu hog: the watchdog kicks in and kills the thread.
> >>
> >> There is not an analogy API that can be used to require a certain amount
> >> of data to the ADC driver. How can I code this loop to let other
> >> processes to run?
> >
> > As a matter of fact, there is something in the API which could have
> > helped you in an unmapped configuration. If you set the flag
> > A4L_CMD_BULK in the field "flags" of the command structure, a call to
> > a4l_async_read() only returns when the data size specified as argument
> > is available.
> >
> > Unfortunately, I have not done the same thing with a4l_poll, I might
> > have added the requested size as an additional argument to a4l_poll.
> >
> > Any idea on how to extend the API without breaking it ?
>
> Maybe it would be possible to use the standard "select" call, with a
> threshold configurable with an ioctl ?
Thanks. I added your idea in my TODO list.
>
>
> --
> Gilles.
--
Alexis.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-06-24 22:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-15 12:30 [Xenomai-help] How to avoid a tight real time loop Daniele Nicolodi
2010-06-15 12:46 ` Gilles Chanteperdrix
2010-06-15 22:11 ` Alexis Berlemont
2010-06-16 16:49 ` Daniele Nicolodi
2010-06-16 18:19 ` Gilles Chanteperdrix
2010-06-24 22:50 ` Alexis Berlemont
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.