[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>
This commit is contained in:
Michael Brown
2017-01-25 20:59:15 +00:00
parent d37e025b81
commit 302f1eeb80
24 changed files with 369 additions and 318 deletions
+4 -4
View File
@@ -1321,7 +1321,7 @@ struct net80211_probe_ctx * net80211_probe_start ( struct net80211_device *dev,
ctx->ticks_start = currticks();
ctx->ticks_beacon = 0;
ctx->ticks_channel = currticks();
ctx->hop_time = ticks_per_sec() / ( active ? 2 : 6 );
ctx->hop_time = TICKS_PER_SEC / ( active ? 2 : 6 );
/*
* Channels on 2.4GHz overlap, and the most commonly used
@@ -1363,8 +1363,8 @@ struct net80211_probe_ctx * net80211_probe_start ( struct net80211_device *dev,
int net80211_probe_step ( struct net80211_probe_ctx *ctx )
{
struct net80211_device *dev = ctx->dev;
u32 start_timeout = NET80211_PROBE_TIMEOUT * ticks_per_sec();
u32 gather_timeout = ticks_per_sec();
u32 start_timeout = NET80211_PROBE_TIMEOUT * TICKS_PER_SEC;
u32 gather_timeout = TICKS_PER_SEC;
u32 now = currticks();
struct io_buffer *iob;
int signal;
@@ -2606,7 +2606,7 @@ static void net80211_rx_frag ( struct net80211_device *dev,
/* start a frag cache entry */
int i, newest = -1;
u32 curr_ticks = currticks(), newest_ticks = 0;
u32 timeout = ticks_per_sec() * NET80211_FRAG_TIMEOUT;
u32 timeout = TICKS_PER_SEC * NET80211_FRAG_TIMEOUT;
for ( i = 0; i < NET80211_NR_CONCURRENT_FRAGS; i++ ) {
if ( dev->frags[i].in_use == 0 )