Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - QNX timer query: (5 Items)
   
QNX timer query  
Hello,

I want to use QNX timer to get clock resolution in terms of millisecond.  I am successful in getting resolution in terms
 of integer values such as 32ms, 16ms, and even 1ms.

But when I set the timer interval to 5.3ms, the timer times out in non-uniform intervals (5ms, 5ms, 6ms, 5ms....).  What
 might be the cause for this behavior?
 
I set the timer parameters as shown below:

struct itimerspec       itime;
struct _pulse   		pl;
int                     rcvid;
float                 ms_interval = 5.3;

itime.it_value.tv_sec = 0;
itime.it_value.tv_nsec = ms_interval * 1000000;
itime.it_interval.tv_sec = 0;
itime.it_interval.tv_nsec = ms_interval * 1000000;
timer_settime(timer_id, 0, &itime, NULL);

while(1)
{
	rcvid = MsgReceive(chid, &pl, sizeof(pl), NULL);
	if (rcvid == 0)
	{ /* we got a pulse */
		if (pl.code == TIMER_START_PULSE)
		{
			printf("we got a pulse from our timer\n");
		}
	}
}

I measure the timer interval uses kernel traces captured using tracelogger.

Thank you in advance.

Best Regards,
Divya
Re: QNX timer query  
Hello,

You'll find the detailed answer and discussion you are looking for in the documentation article
"Tick, Tock: Understanding the Microkernel's Concept of Time" here:
http://www.qnx.com/developers/docs/am11/topic/com.qnx.doc.neutrino.prog/topic/timing.html

Specifically look at the sub-section "Oversleeping: errors in delays".

Regards,

Eric
Re: QNX timer query  
With a resolution of 1 ms, 5 ms is too short for a 5.3 ms timer. I thought a timer set to 5.3 ms would always time out 
at 6 ms, because POSIX does not allow to wake it up before the set value? 
Re: QNX timer query  
Hi,

there is normally no problem to set the system resolution to 0.1 ms.
You can  Use ClockPeriod(), to change this.

The default of 1 ms was a good system default 20 years ago.

-Michael


Am 26.05.2015 um 06:39 schrieb Divya Bettampady:
> Hello,
>
> I want to use QNX timer to get clock resolution in terms of millisecond.  I am successful in getting resolution in 
terms of integer values such as 32ms, 16ms, and even 1ms.
>
> But when I set the timer interval to 5.3ms, the timer times out in non-uniform intervals (5ms, 5ms, 6ms, 5ms....).  
What might be the cause for this behavior?
>
> I set the timer parameters as shown below:
>
> struct itimerspec       itime;
> struct _pulse   		pl;
> int                     rcvid;
> float                 ms_interval = 5.3;
>
> itime.it_value.tv_sec = 0;
> itime.it_value.tv_nsec = ms_interval * 1000000;
> itime.it_interval.tv_sec = 0;
> itime.it_interval.tv_nsec = ms_interval * 1000000;
> timer_settime(timer_id, 0, &itime, NULL);
>
> while(1)
> {
> 	rcvid = MsgReceive(chid, &pl, sizeof(pl), NULL);
> 	if (rcvid == 0)
> 	{ /* we got a pulse */
> 		if (pl.code == TIMER_START_PULSE)
> 		{
> 			printf("we got a pulse from our timer\n");
> 		}
> 	}
> }
>
> I measure the timer interval uses kernel traces captured using tracelogger.
>
> Thank you in advance.
>
> Best Regards,
> Divya
>
>
>
> _______________________________________________
>
> General
> http://community.qnx.com/sf/go/post113861
> To cancel your subscription to this discussion, please e-mail general-community-unsubscribe@community.qnx.com
>
>

Re: QNX timer query  
Note that this has a few side effects to consider when changing the system tick size as suggested above:
1) increased system overhead of going into the kernel's timer handler more often
2) changes the round-robin scheduling time slice to 4 times whatever the new tick size is set to
3) changes the timer resolution (which was the desired effect in the previous reply)