* unreliable time function inside IRQ?
@ 2014-03-25 21:56 Ge Gao
2014-03-29 11:05 ` Jonathan Cameron
0 siblings, 1 reply; 5+ messages in thread
From: Ge Gao @ 2014-03-25 21:56 UTC (permalink / raw)
To: Lars-Peter Clausen, Jonathan Cameron; +Cc: linux-iio@vger.kernel.org
Dear all,
Had to bring this question again to see whether anyone see the same problem. IIO fetches the timestamp inside IRQ using iio_get_time_ns(), which in turn call ktime_get_real_ts(&ts). However, I notice that the clock taken during interrupt is not always reliable. Sometimes the clock does not update. It is updated after one or more interrupts. It is very easy to reproduce. First find a hardware generating fixed interval of interrupts and using IIO driver to run it. Print out the timestamp. You could find that the timestamp distance is not always correct. For example, if you run a 5 Hz interrupt, most of time you will interrupt timestamp interval is around 200ms. However, sometimes, you could see interval sequence like ...200, 192, 208, 200, 200, 182, 218, 200.......
I searched online and only found one result, which is exactly the same as I observed. Below is the link:
http://stackoverflow.com/questions/17080516/unable-unreliable-to-use-clock-gettime-in-hard-irq-context
But no one answer the question.
Is there anyone see the same problem? Thanks.
Best Regards,
Ge GAO
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: unreliable time function inside IRQ?
2014-03-25 21:56 unreliable time function inside IRQ? Ge Gao
@ 2014-03-29 11:05 ` Jonathan Cameron
2014-03-31 17:44 ` Ge Gao
0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2014-03-29 11:05 UTC (permalink / raw)
To: Ge Gao, Lars-Peter Clausen; +Cc: linux-iio@vger.kernel.org
On 25/03/14 21:56, Ge Gao wrote:
> Dear all, Had to bring this question again to see whether anyone see
> the same problem. IIO fetches the timestamp inside IRQ using
> iio_get_time_ns(), which in turn call ktime_get_real_ts(&ts).
> However, I notice that the clock taken during interrupt is not always
> reliable. Sometimes the clock does not update. It is updated after
> one or more interrupts. It is very easy to reproduce. First find a
> hardware generating fixed interval of interrupts and using IIO driver
> to run it. Print out the timestamp. You could find that the timestamp
> distance is not always correct. For example, if you run a 5 Hz
> interrupt, most of time you will interrupt timestamp interval is
> around 200ms. However, sometimes, you could see interval sequence
> like ...200, 192, 208, 200, 200, 182, 218, 200....... I searched
> online and only found one result, which is exactly the same as I
> observed. Below is the link:
> http://stackoverflow.com/questions/17080516/unable-unreliable-to-use-clock-gettime-in-hard-irq-context
>
>
But no one answer the question.
> Is there anyone see the same problem? Thanks.
Hi Ge,
I'm afraid I don't know the cause of this.
It's also entirely possible that other interrupts are occurring that
are delaying the processing of some of your interrupts.
The slightly interesting bit is that you seem to be getting interrupts
apparently early sometimes. I would have expected a longer delay then
a shorter one if it was something else interfering.
It might be related to the implementation of the high resolution
timers on your platform. Perhaps they are being updated by a high
precision, low frequency source. Mind you, in that case I think
you'd expect to see only one value being out rather than the single
early value you appear to be seeing here. For some reason it seems
that occasionally you are handling interrupts earlier than the
majority of the time... Odd!
What is the platform you are seeing this on?
Jonathan
>
> Best Regards,
>
> Ge GAO
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: unreliable time function inside IRQ?
2014-03-29 11:05 ` Jonathan Cameron
@ 2014-03-31 17:44 ` Ge Gao
2014-03-31 19:07 ` Lars-Peter Clausen
0 siblings, 1 reply; 5+ messages in thread
From: Ge Gao @ 2014-03-31 17:44 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen; +Cc: linux-iio@vger.kernel.org
Dear Jonathan,
Thanks for answering my question. I am using Panda board(OMAP4430). It is =
using a 32K counter clock as the high resolution clock(arch/arm/plat-omap/c=
outer_32k.c). But I also observe the same thing in Nexus 7 first generation=
(announced in 2012), which uses Nvidia Tegra 3 platform. I suspect the data=
that represents the time is cached, or it is using some older value in the=
interrupt case.
It could be the Linux's time function problem. Is that possible? I actually=
tried using Jiffy, which is the built-in software clock. The time between =
each interrupt also varies big. My HZ setting is 1000. I also tried a later=
version of Linux, which is 3.7 or later. The result is the same.
The implementation of the time function is very simple. Below is the funct=
ion from 32K clock counter. It is reading the hardware clock, compute the d=
ifference between a static variable and update the time. For a different cl=
ock, only the "clocksource_32k.mult", "clocksource_32k.shift", would be dif=
ferent.
Thanks.
Best Regards,
Ge GAO
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
static struct timespec persistent_ts;
static cycles_t cycles, last_cycles;
void read_persistent_clock(struct timespec *ts)
{
unsigned long long nsecs;
cycles_t delta;
struct timespec *tsp =3D &persistent_ts;
last_cycles =3D cycles;
cycles =3D clocksource_32k.read(&clocksource_32k);
delta =3D cycles - last_cycles;
nsecs =3D clocksource_cyc2ns(delta,
clocksource_32k.mult, clocksource_32k.shift);
timespec_add_ns(tsp, nsecs);
*ts =3D *tsp;
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
-----Original Message-----
From: Jonathan Cameron [mailto:jic23@kernel.org]=20
Sent: Saturday, March 29, 2014 4:06 AM
To: Ge Gao; Lars-Peter Clausen
Cc: linux-iio@vger.kernel.org
Subject: Re: unreliable time function inside IRQ?
On 25/03/14 21:56, Ge Gao wrote:
> Dear all, Had to bring this question again to see whether anyone see=20
> the same problem. IIO fetches the timestamp inside IRQ using=20
> iio_get_time_ns(), which in turn call ktime_get_real_ts(&ts).
> However, I notice that the clock taken during interrupt is not always=20
> reliable. Sometimes the clock does not update. It is updated after one=20
> or more interrupts. It is very easy to reproduce. First find a=20
> hardware generating fixed interval of interrupts and using IIO driver=20
> to run it. Print out the timestamp. You could find that the timestamp=20
> distance is not always correct. For example, if you run a 5 Hz=20
> interrupt, most of time you will interrupt timestamp interval is=20
> around 200ms. However, sometimes, you could see interval sequence like=20
> ...200, 192, 208, 200, 200, 182, 218, 200....... I searched online and=20
> only found one result, which is exactly the same as I observed. Below=20
> is the link:
> http://stackoverflow.com/questions/17080516/unable-unreliable-to-use-c
> lock-gettime-in-hard-irq-context
>
>
But no one answer the question.
> Is there anyone see the same problem? Thanks.
Hi Ge,
I'm afraid I don't know the cause of this.
It's also entirely possible that other interrupts are occurring that are de=
laying the processing of some of your interrupts.
The slightly interesting bit is that you seem to be getting interrupts appa=
rently early sometimes. I would have expected a longer delay then a shorte=
r one if it was something else interfering.
It might be related to the implementation of the high resolution timers on =
your platform. Perhaps they are being updated by a high precision, low fre=
quency source. Mind you, in that case I think you'd expect to see only one=
value being out rather than the single early value you appear to be seeing=
here. For some reason it seems that occasionally you are handling interru=
pts earlier than the majority of the time... Odd!
What is the platform you are seeing this on?
Jonathan
>
> Best Regards,
>
> Ge GAO
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio"=20
> in the body of a message to majordomo@vger.kernel.org More majordomo=20
> info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: unreliable time function inside IRQ?
2014-03-31 17:44 ` Ge Gao
@ 2014-03-31 19:07 ` Lars-Peter Clausen
2014-03-31 21:25 ` Ge Gao
0 siblings, 1 reply; 5+ messages in thread
From: Lars-Peter Clausen @ 2014-03-31 19:07 UTC (permalink / raw)
To: Ge Gao; +Cc: Jonathan Cameron, linux-iio@vger.kernel.org
On 03/31/2014 07:44 PM, Ge Gao wrote:
> Dear Jonathan,
> Thanks for answering my question. I am using Panda board(OMAP4430). It is using a 32K counter clock as the high resolution clock(arch/arm/plat-omap/couter_32k.c). But I also observe the same thing in Nexus 7 first generation(announced in 2012), which uses Nvidia Tegra 3 platform. I suspect the data that represents the time is cached, or it is using some older value in the interrupt case.
> It could be the Linux's time function problem. Is that possible? I actually tried using Jiffy, which is the built-in software clock. The time between each interrupt also varies big. My HZ setting is 1000. I also tried a later version of Linux, which is 3.7 or later. The result is the same.
> The implementation of the time function is very simple. Below is the function from 32K clock counter. It is reading the hardware clock, compute the difference between a static variable and update the time. For a different clock, only the "clocksource_32k.mult", "clocksource_32k.shift", would be different.
> Thanks.
You have to consider that there will be other things running with IRQs off,
which will cause some jitter for your IRQ handler. This is nothing IIO specific.
- Lars
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: unreliable time function inside IRQ?
2014-03-31 19:07 ` Lars-Peter Clausen
@ 2014-03-31 21:25 ` Ge Gao
0 siblings, 0 replies; 5+ messages in thread
From: Ge Gao @ 2014-03-31 21:25 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio@vger.kernel.org
If there is other IRQ running causing this, the IRQ time would be late. How=
ever, this is not the case. I can see the time stamp value is smaller than =
it should be, while I observe from scope that IRQ comes in at a steady rate=
.
Thanks.
Ge
-----Original Message-----
From: Lars-Peter Clausen [mailto:lars@metafoo.de]=20
Sent: Monday, March 31, 2014 12:07 PM
To: Ge Gao
Cc: Jonathan Cameron; linux-iio@vger.kernel.org
Subject: Re: unreliable time function inside IRQ?
On 03/31/2014 07:44 PM, Ge Gao wrote:
> Dear Jonathan,
> Thanks for answering my question. I am using Panda board(OMAP4430). It i=
s using a 32K counter clock as the high resolution clock(arch/arm/plat-omap=
/couter_32k.c). But I also observe the same thing in Nexus 7 first generati=
on(announced in 2012), which uses Nvidia Tegra 3 platform. I suspect the da=
ta that represents the time is cached, or it is using some older value in t=
he interrupt case.
> It could be the Linux's time function problem. Is that possible? I actual=
ly tried using Jiffy, which is the built-in software clock. The time betwee=
n each interrupt also varies big. My HZ setting is 1000. I also tried a lat=
er version of Linux, which is 3.7 or later. The result is the same.
> The implementation of the time function is very simple. Below is the fun=
ction from 32K clock counter. It is reading the hardware clock, compute the=
difference between a static variable and update the time. For a different =
clock, only the "clocksource_32k.mult", "clocksource_32k.shift", would be d=
ifferent.
> Thanks.
You have to consider that there will be other things running with IRQs off,=
=20
which will cause some jitter for your IRQ handler. This is nothing IIO spec=
ific.
- Lars
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-03-31 21:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-25 21:56 unreliable time function inside IRQ? Ge Gao
2014-03-29 11:05 ` Jonathan Cameron
2014-03-31 17:44 ` Ge Gao
2014-03-31 19:07 ` Lars-Peter Clausen
2014-03-31 21:25 ` Ge Gao
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.