Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to avoid busy wait when polling for completion status?: (3 Items)
   
How to avoid busy wait when polling for completion status?  
Hi,

I am trying to optimize a piece of code that checks for completion of an operation by polling the status regiser (of an 
HW accelerator) in a loop. The operation takes about  400us and I would like to yield the CPU to other threads for this 
duration of time so that the CPU is utilized efficiently. I tried inserting "usleep(400)" before checking the status 
register. However, I noticed that the minimum time the thread sleeps is more than 1000us (on iMX53 Sabre board running 
QNX) even if I try usleeep(1). For the current application sleeping for more than 1000us after initiating the operation 
results in misssing other deadlines. So I have a couple of questions.

1. Is usleep(n) not working for small n a known feature/bug in QNX. I am new to QNX. Is there anything special one needs
 to do for usleep(n) for small n to work?

2. Is there another way to relinquish control for say between 300 and 500 us so that the CPU utilization is better and 
the deadline is not missed. This efficiency is important because this operation happens about 6 times  evey 10ms.

Thanks,
Venkat
Re: How to avoid busy wait when polling for completion status?  
Config a free HW timer to 400us and InterruptWait .
Sent from BlackBerry

----- Original Message -----
From: Venkat Natarajan [mailto:community-noreply@qnx.com]
Sent: Wednesday, December 21, 2011 09:21 PM
To: ostech-core_os <post90732@community.qnx.com>
Subject: How to avoid busy wait when polling for completion status?

Hi,

I am trying to optimize a piece of code that checks for completion of an operation by polling the status regiser (of an 
HW accelerator) in a loop. The operation takes about  400us and I would like to yield the CPU to other threads for this 
duration of time so that the CPU is utilized efficiently. I tried inserting "usleep(400)" before checking the status 
register. However, I noticed that the minimum time the thread sleeps is more than 1000us (on iMX53 Sabre board running 
QNX) even if I try usleeep(1). For the current application sleeping for more than 1000us after initiating the operation 
results in misssing other deadlines. So I have a couple of questions.

1. Is usleep(n) not working for small n a known feature/bug in QNX. I am new to QNX. Is there anything special one needs
 to do for usleep(n) for small n to work?

2. Is there another way to relinquish control for say between 300 and 500 us so that the CPU utilization is better and 
the deadline is not missed. This efficiency is important because this operation happens about 6 times  evey 10ms.

Thanks,
Venkat



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post90732
Re: How to avoid busy wait when polling for completion status?  
Hi,

do you have a x86 CPU ?  if yes, you could reconfigure for a short time 
frame the real-time clock (IRQ8) for a clock cycle of 128us.
This allows you to read the status register every 128us in the ISR of 
the IRQ8  ... and the ISR could trigger a suspended interrupt thread 
(InterruptWait) if the status register shows the expected value.

If you are on an ARM CPU,  try to use one of the HW timers of the ARM 
based SoC.

The minimum time resolution of the timer services of QNX6 is 1ms ... 
QNX6 doesn't support concepts like high resolution timers of LINUX.

Best Regards

Armin Steinhoff

http://www.steinhoff-automation.com





Venkat Natarajan wrote:
> Hi,
>
> I am trying to optimize a piece of code that checks for completion of an operation by polling the status regiser (of 
an HW accelerator) in a loop. The operation takes about  400us and I would like to yield the CPU to other threads for 
this duration of time so that the CPU is utilized efficiently. I tried inserting "usleep(400)" before checking the 
status register. However, I noticed that the minimum time the thread sleeps is more than 1000us (on iMX53 Sabre board 
running QNX) even if I try usleeep(1). For the current application sleeping for more than 1000us after initiating the 
operation results in misssing other deadlines. So I have a couple of questions.
>
> 1. Is usleep(n) not working for small n a known feature/bug in QNX. I am new to QNX. Is there anything special one 
needs to do for usleep(n) for small n to work?
>
> 2. Is there another way to relinquish control for say between 300 and 500 us so that the CPU utilization is better and
 the deadline is not missed. This efficiency is important because this operation happens about 6 times  evey 10ms.
>
> Thanks,
> Venkat
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post90732
>
>