public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Question on HPET timer reading from device driver?
@ 2010-07-13  9:45 Samuel Xu
  2010-07-13 11:49 ` Clemens Ladisch
  0 siblings, 1 reply; 3+ messages in thread
From: Samuel Xu @ 2010-07-13  9:45 UTC (permalink / raw)
  To: linux-kernel

HI:
I am a freshman for HPET timer. Previously, I use TSC counter, to use
rdtsc to get the time stamp. elapsed cycle can be counter from 2 time
stamps.
As a advanced replacement of TSC, I suppose HPET timer can be
conveniently to read time stamp from both kernel mode user  and user
mode apps.
While I failed to find a way to get time stamp value of HPET in Linux
kenerl (I am doing a driver and want to know elapsed cycle from driver
code).

I tried hpet_readl() from my driver code, while hit compiling error.
Is it a correct API for kernel driver to invoke?
I also read the Linux Documentation of HPET, which contain a user mode
demo app to generate a periodic timer via HPET, while missing the time
stamp reading.

Any hint?

Thanks!

Samuel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question on HPET timer reading from device driver?
  2010-07-13  9:45 Question on HPET timer reading from device driver? Samuel Xu
@ 2010-07-13 11:49 ` Clemens Ladisch
  2010-07-13 13:45   ` Samuel Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Clemens Ladisch @ 2010-07-13 11:49 UTC (permalink / raw)
  To: Samuel Xu; +Cc: linux-kernel

Samuel Xu wrote:
> While I failed to find a way to get time stamp value of HPET in Linux
> kenerl (I am doing a driver and want to know elapsed cycle from driver
> code).

The HPET is x86-specific any might not be available on every machine.

> I tried hpet_readl() from my driver code, while hit compiling error.

This function is intended for internal use by the kernel and not for
drivers, so it is not exported for modules.

You can hack your own accessor function by calling ioremap() on the HPET
address (0xfed00000 or 0xfefff000 or whatever) and reading from that
memory.

A more portable way to get a time stamp is getrawmonotonic().

> I also read the Linux Documentation of HPET, which contain a user mode
> demo app to generate a periodic timer via HPET, while missing the time
> stamp reading.

There is no ioctl for this; call mmap() on /dev/hpet and then read the
main counter value from offset 0xf0 of that memory.

A more portable way to get a time stamp is to use clock_gettime() with
CLOCK_MONOTONIC_RAW.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question on HPET timer reading from device driver?
  2010-07-13 11:49 ` Clemens Ladisch
@ 2010-07-13 13:45   ` Samuel Xu
  0 siblings, 0 replies; 3+ messages in thread
From: Samuel Xu @ 2010-07-13 13:45 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: linux-kernel

Thanks Clemens!
Besides calling ioremap() on specific HPET address, is there more
elegant interface, "offically" for kernel mode driver accessing HPET?


2010/7/13 Clemens Ladisch <clemens@ladisch.de>:
> Samuel Xu wrote:
>> While I failed to find a way to get time stamp value of HPET in Linux
>> kenerl (I am doing a driver and want to know elapsed cycle from driver
>> code).
>
> The HPET is x86-specific any might not be available on every machine.
>
>> I tried hpet_readl() from my driver code, while hit compiling error.
>
> This function is intended for internal use by the kernel and not for
> drivers, so it is not exported for modules.
>
> You can hack your own accessor function by calling ioremap() on the HPET
> address (0xfed00000 or 0xfefff000 or whatever) and reading from that
> memory.
>
> A more portable way to get a time stamp is getrawmonotonic().
>
>> I also read the Linux Documentation of HPET, which contain a user mode
>> demo app to generate a periodic timer via HPET, while missing the time
>> stamp reading.
>
> There is no ioctl for this; call mmap() on /dev/hpet and then read the
> main counter value from offset 0xf0 of that memory.
>
> A more portable way to get a time stamp is to use clock_gettime() with
> CLOCK_MONOTONIC_RAW.
>
>
> Regards,
> Clemens
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-13 13:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-13  9:45 Question on HPET timer reading from device driver? Samuel Xu
2010-07-13 11:49 ` Clemens Ladisch
2010-07-13 13:45   ` Samuel Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox