ARM: sched_clock: provide common infrastructure for sched_clock()
authorRussell King <rmk+kernel@arm.linux.org.uk>
Wed, 15 Dec 2010 19:23:07 +0000 (19:23 +0000)
committer黄涛 <huangtao@rock-chips.com>
Fri, 11 Mar 2011 03:34:57 +0000 (11:34 +0800)
commit78a8e9426d1ffaa19c29e92a8c4a726d2364c10e
treec3dbe9b674afa157deda07df7ab7f5c045ad7fa5
parent7fe63eebbee4404585c616ec4d1b1e996c2ef3ad
ARM: sched_clock: provide common infrastructure for sched_clock()

Provide common sched_clock() infrastructure for platforms to use to
create a 64-bit ns based sched_clock() implementation from a counter
running at a non-variable clock rate.

This implementation is based upon maintaining an epoch for the counter
and an epoch for the nanosecond time.  When we desire a sched_clock()
time, we calculate the number of counter ticks since the last epoch
update, convert this to nanoseconds and add to the epoch nanoseconds.

We regularly refresh these epochs within the counter wrap interval.
We perform a similar calculation as above, and store the new epochs.

We read and write the epochs in such a way that sched_clock() can easily
(and locklessly) detect when an update is in progress, and repeat the
loading of these constants when they're known not to be stable.  The
one caveat is that sched_clock() is not called in the middle of an
update.  We achieve that by disabling IRQs.

Finally, if the clock rate is known at compile time, the counter to ns
conversion factors can be specified, allowing sched_clock() to be tightly
optimized.  We ensure that these factors are correct by providing an
initialization function which performs a run-time check.

Acked-by: Peter Zijlstra <peterz@infradead.org>
Tested-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Tested-by: Will Deacon <will.deacon@arm.com>
Tested-by: Mikael Pettersson <mikpe@it.uu.se>
Tested-by: Eric Miao <eric.y.miao@gmail.com>
Tested-by: Olof Johansson <olof@lixom.net>
Tested-by: Jamie Iles <jamie@jamieiles.com>
Reviewed-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/Kconfig
arch/arm/include/asm/sched_clock.h [new file with mode: 0644]
arch/arm/kernel/Makefile
arch/arm/kernel/sched_clock.c [new file with mode: 0644]