Re: Drift when measuring time using add_timer

From: Yong Zhang
Date: Wed Dec 29 2010 - 03:45:32 EST


On Tue, Dec 28, 2010 at 8:05 PM, Mohan V <mohanvforum@xxxxxxxxx> wrote:
> Hello All,
>
> I am testing the timers on a OMAP4 based board. I am seeing a drift or
> the time difference between the timer value and when the function callback
> happens. This drift is around 1000ms or 1s for a expiry value of >=5mins.
> Is the time drift expected? Is this way of measuring right or is there
> any other way?
>
> OMAP4 as you may know is a multi-core processor and CONFIG_SMP is enabled
> along with the following:
> CONFIG_NO_HZ, CONFIG_HIGH_RES_TIMERS
>
> My kernel configurations:
> kernel: 2.6.37-rc7 (commit id: ffc96d)
> config: omap2plus_defconfig
>
> My driver does the following:
>
> struct timeval tv;
> test_timer_proc_write()
> {
> Â Â Â Â Â del_timer_sync(&my_timer);
> Â Â Â Â Â period = 300000; /* 5min */
> Â Â Â Â Â my_timer.expires = jiffies + msecs_to_jiffies(period);
> Â Â Â Â Â my_timer.function = func_timeout; /* Call back function*/

what's the slack of your timer?
And what about setting my_timer.slack = 0; ?

Thanks,
Yong

> Â Â Â Â Â /* Save the current time in global variable */
> Â Â Â Â Â do_gettimeofday(&timeval);
> Â Â Â Â Â /* add timer with an expiry value of 5mins*/
> Â Â Â Â Â add_timer(&my_timer);
> }
>
> /* Get the current time and print the difference between the two values */
> func_timeout()
> {
> Â Â Â Â Â struct timeval tv1;
> Â Â Â Â Â do_gettimeofday(&tv);
> Â Â Â Â Â /* take the difference between current time and saved time */
> Â Â Â Â Â ms = (tv.tv_sec - tv1.tv_sec) * 1000 + \
> Â Â Â Â Â Â Â Â Â (tv.tv_usec - tv1.tv_usec) / 1000;
> Â Â Â Â Â printk("Interval = %d\n", ms);
> }
>
> Thanks for your time.
>
> Regards,
> Mohan
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>



--
Only stand for myself.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/