diff options
| author | Michael Brown | 2017-01-25 21:59:15 +0100 |
|---|---|---|
| committer | Michael Brown | 2017-01-26 09:17:37 +0100 |
| commit | 302f1eeb80706fb10067efedb1279fa3f85ddda2 (patch) | |
| tree | 90e58309094b20a26cedc8244fabf72d96fe6135 /src/interface/linux | |
| parent | [cpuid] Provide cpuid_supported() to test for supported functions (diff) | |
| download | ipxe-302f1eeb80706fb10067efedb1279fa3f85ddda2.tar.gz ipxe-302f1eeb80706fb10067efedb1279fa3f85ddda2.tar.xz ipxe-302f1eeb80706fb10067efedb1279fa3f85ddda2.zip | |
[time] Allow timer to be selected at runtime
Allow the active timer (providing udelay() and currticks()) to be
selected at runtime based on probing during the INIT_EARLY stage of
initialisation.
TICKS_PER_SEC is now a fixed compile-time constant for all builds, and
is independent of the underlying clock tick rate. We choose the value
1024 to allow multiplications and divisions on seconds to be converted
to bit shifts.
TICKS_PER_MS is defined as 1, allowing multiplications and divisions
on milliseconds to be omitted entirely. The 2% inaccuracy in this
definition is negligible when using the standard BIOS timer (running
at around 18.2Hz).
TIMER_RDTSC now checks for a constant TSC before claiming to be a
usable timer. (This timer can be tested in KVM via the command-line
option "-cpu host,+invtsc".)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface/linux')
| -rw-r--r-- | src/interface/linux/linux_timer.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/interface/linux/linux_timer.c b/src/interface/linux/linux_timer.c index 7a994517b..9c5e96f2b 100644 --- a/src/interface/linux/linux_timer.c +++ b/src/interface/linux/linux_timer.c @@ -40,16 +40,6 @@ static void linux_udelay(unsigned long usecs) } /** - * Get number of ticks per second - * - * @ret ticks_per_sec Number of ticks per second - */ -static unsigned long linux_ticks_per_sec(void) -{ - return 1000; -} - -/** * Get current system time in ticks * * linux doesn't provide an easy access to jiffies so implement it by measuring @@ -67,21 +57,25 @@ static unsigned long linux_currticks(void) { static struct timeval start; static int initialized = 0; + struct timeval now; + unsigned long ticks; if (! initialized) { linux_gettimeofday(&start, NULL); initialized = 1; } - struct timeval now; linux_gettimeofday(&now, NULL); - unsigned long ticks = (now.tv_sec - start.tv_sec) * linux_ticks_per_sec(); - ticks += now.tv_usec / (long)(1000000 / linux_ticks_per_sec()); + ticks = ( ( now.tv_sec - start.tv_sec ) * TICKS_PER_SEC ); + ticks += ( now.tv_usec / ( 1000000 / TICKS_PER_SEC ) ); return ticks; } -PROVIDE_TIMER(linux, udelay, linux_udelay); -PROVIDE_TIMER(linux, currticks, linux_currticks); -PROVIDE_TIMER(linux, ticks_per_sec, linux_ticks_per_sec); +/** Linux timer */ +struct timer linux_timer __timer ( TIMER_NORMAL ) = { + .name = "linux", + .currticks = linux_currticks, + .udelay = linux_udelay, +}; |
