Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - ClockCycles() use in interrupt handlers: Page 1 of 2 (11 Items)
   
ClockCycles() use in interrupt handlers  
ClockCycles() is listed in docs as "unsafe" to call from an interrupt handler.  However, for interrupt latency tests, 
there seems to be no "safe" call for a precise timestamp.

Also release notes for 6.2.1B list "Execution of ClockCycles() inside an interrupt causes kernel crash (Ref# 14369)" as 
having been fixed, i.e. it must have been a valid use case.

Why is it listed as unsafe?  Does it re-enable interrupts on exit?

Thanks.

Re: ClockCycles() use in interrupt handlers  
I've been using ClockCycles() from the context of the clock interrupt
handler since 2004.

Dennis Kellly wrote:
> ClockCycles() is listed in docs as "unsafe" to call from an interrupt 
> handler.  However, for interrupt latency tests, there seems to be no 
> "safe" call for a precise timestamp.
> 
> Also release notes for 6.2.1B list "Execution of ClockCycles() inside an 
> interrupt causes kernel crash (Ref# 14369)" as having been fixed, i.e. 
> it must have been a valid use case.
> 
> Why is it listed as unsafe?  Does it re-enable interrupts on exit?
> 
> Thanks.
> 
> 
> 
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post5816
> 
Re: ClockCycles() use in interrupt handlers  
> ClockCycles() is listed in docs as "unsafe" to call from an interrupt handler.
>   However, for interrupt latency tests, there seems to be no "safe" call for a
>  precise timestamp.
> 
> Also release notes for 6.2.1B list "Execution of ClockCycles() inside an 
> interrupt causes kernel crash (Ref# 14369)" as having been fixed, i.e. it must
>  have been a valid use case.
> 
> Why is it listed as unsafe?  Does it re-enable interrupts on exit?
> 
> Thanks.
> 


It's safe on x86 as for the other platform I don't know
Re: ClockCycles() use in interrupt handlers  
It's probably safe only on HW which has rdtsc opcode.
When this opcode is missing, it crashes the kernel.

PKY
AW: ClockCycles() use in interrupt handlers  
Looking at the implementations in
  /usr/include/<platform>/neutrino.h
it looks like there are interrupt-safe implementations of ClockCycles()
for all platforms except for the ARM (i.e., mips, ppc, sh, and x86).

I guess a function is listed as "unsafe" as long as we cannot guarantee 
that the implementation will be [interrupt]-safe on /all/ platforms...

Oh, and the bit about re-enabling interrupts would only be true for 
kernel calls -- and those exactly you must avoid by all means in an 
interrupt handler (the handler was itself invoked by the kernel; doing
a kernel-call would introduce a reentrancy we cannot handle at that 
point). The inline-assembly-implementations of ClockCycles on non-arm-
platforms all just read some special CPU registers and maybe do a tiny 
bit of calculation; so there's no need to call kernel there.

Hope this helps,
- Thomas

> -----Ursprüngliche Nachricht-----
> Von: Dennis Kelly 
> Gesendet: 14 March 2008 16:44
> An: ostech-core_os
> Betreff: ClockCycles() use in interrupt handlers
> 
> 
> ClockCycles() is listed in docs as "unsafe" to call from an 
> interrupt handler.  However, for interrupt latency tests, 
> there seems to be no "safe" call for a precise timestamp.
> 
> Also release notes for 6.2.1B list "Execution of 
> ClockCycles() inside an interrupt causes kernel crash (Ref# 
> 14369)" as having been fixed, i.e. it must have been a valid use case.
> 
> Why is it listed as unsafe?  Does it re-enable interrupts on exit?
> 
> Thanks.
> 
> 
> 
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post5816
> 
Re: ClockCycles() use in interrupt handlers  
The documentation is wrong. ClockCyles() is safe to use in all environments
on all architectures. The kernel instrumentation wouldn't work if that
wasn't true.

On Mon, Mar 17, 2008 at 05:43:34AM -0400, Thomas Haupt wrote:
> Looking at the implementations in
>   /usr/include/<platform>/neutrino.h
> it looks like there are interrupt-safe implementations of ClockCycles()
> for all platforms except for the ARM (i.e., mips, ppc, sh, and x86).
> 
> I guess a function is listed as "unsafe" as long as we cannot guarantee 
> that the implementation will be [interrupt]-safe on /all/ platforms...
> 
> Oh, and the bit about re-enabling interrupts would only be true for 
> kernel calls -- and those exactly you must avoid by all means in an 
> interrupt handler (the handler was itself invoked by the kernel; doing
> a kernel-call would introduce a reentrancy we cannot handle at that 
> point). The inline-assembly-implementations of ClockCycles on non-arm-
> platforms all just read some special CPU registers and maybe do a tiny 
> bit of calculation; so there's no need to call kernel there.
> 
> Hope this helps,
> - Thomas
> 
> > -----Ursprüngliche Nachricht-----
> > Von: Dennis Kelly 
> > Gesendet: 14 March 2008 16:44
> > An: ostech-core_os
> > Betreff: ClockCycles() use in interrupt handlers
> > 
> > 
> > ClockCycles() is listed in docs as "unsafe" to call from an 
> > interrupt handler.  However, for interrupt latency tests, 
> > there seems to be no "safe" call for a precise timestamp.
> > 
> > Also release notes for 6.2.1B list "Execution of 
> > ClockCycles() inside an interrupt causes kernel crash (Ref# 
> > 14369)" as having been fixed, i.e. it must have been a valid use case.
> > 
> > Why is it listed as unsafe?  Does it re-enable interrupts on exit?
> > 
> > Thanks.
> > 
> > 
> > 
> > _______________________________________________
> > OSTech
> > http://community.qnx.com/sf/go/post5816
> > 
> 
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post5850

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: ClockCycles() use in interrupt handlers  
>>>The documentation is wrong.
Thanks.  It would be good if we get the docs fixed for 6.4.
RE: ClockCycles() use in interrupt handlers  
Dennis,

Can you please file a PR then? That's the best way to ensure it gets fixed.

Cheers,
-Brian 

> -----Original Message-----
> From: Dennis Kellly [mailto:dkelly@qnx.com] 
> Sent: Monday, March 17, 2008 08 53
> To: ostech-core_os
> Subject: Re: ClockCycles() use in interrupt handlers
> 
> >>>The documentation is wrong.
> Thanks.  It would be good if we get the docs fixed for 6.4.
> 
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post5854
> 
Re: RE: ClockCycles() use in interrupt handlers  
I've corrected the docs.
Re: ClockCycles() use in interrupt handlers  
Hi,

> The documentation is wrong. ClockCyles() is safe to use in all environments

since when?
I remember, that "rdtsc" instructions were emulated on 386/486 cpu's by "wrong opcode exceptions" using the PIT. This 
did "not" work in ISR's.

If this has been changed, can someone tell me the 1st QNX Version, which can use ClockCycles in ISR's on 386/486?

-Michael


> on all architectures. The kernel instrumentation wouldn't work if that
> wasn't true.
> 
> On Mon, Mar 17, 2008 at 05:43:34AM -0400, Thomas Haupt wrote:
> > Looking at the implementations in
> >   /usr/include/<platform>/neutrino.h
> > it looks like there are interrupt-safe implementations of ClockCycles()
> > for all platforms except for the ARM (i.e., mips, ppc, sh, and x86).
> > 
> > I guess a function is listed as "unsafe" as long as we cannot guarantee 
> > that the implementation will be [interrupt]-safe on /all/ platforms...
> > 
> > Oh, and the bit about re-enabling interrupts would only be true for 
> > kernel calls -- and those exactly you must avoid by all means in an 
> > interrupt handler (the handler was itself invoked by the kernel; doing
> > a kernel-call would introduce a reentrancy we cannot handle at that 
> > point). The inline-assembly-implementations of ClockCycles on non-arm-
> > platforms all just read some special CPU registers and maybe do a tiny 
> > bit of calculation; so there's no need to call kernel there.
> > 
> > Hope this helps,
> > - Thomas
> > 
> > > -----Ursprüngliche Nachricht-----
> > > Von: Dennis Kelly 
> > > Gesendet: 14 March 2008 16:44
> > > An: ostech-core_os
> > > Betreff: ClockCycles() use in interrupt handlers
> > > 
> > > 
> > > ClockCycles() is listed in docs as "unsafe" to call from an 
> > > interrupt handler.  However, for interrupt latency tests, 
> > > there seems to be no "safe" call for a precise timestamp.
> > > 
> > > Also release notes for 6.2.1B list "Execution of 
> > > ClockCycles() inside an interrupt causes kernel crash (Ref# 
> > > 14369)" as having been fixed, i.e. it must have been a valid use case.
> > > 
> > > Why is it listed as unsafe?  Does it re-enable interrupts on exit?
> > > 
> > > Thanks.
> > > 
> > > 
> > > 
> > > _______________________________________________
> > > OSTech
> > > http://community.qnx.com/sf/go/post5816
> > > 
> > 
> > _______________________________________________
> > OSTech
> > http://community.qnx.com/sf/go/post5850
> 
> -- 
> Brian Stecher (bstecher@qnx.com)        QNX Software Systems
> phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
>        +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8