diff options
author | Michael Brown | 2008-03-10 14:02:53 +0100 |
---|---|---|
committer | Michael Brown | 2008-03-10 14:02:53 +0100 |
commit | 3e781eb87f7b5bfa638f94234bb5e9d64508b0a4 (patch) | |
tree | 5884ac0438320638c846166856a4b54b3564bd23 /src/core | |
parent | [PXE] Work around a buffer-size bug in WinPE (diff) | |
parent | Use plain C in timer_rdtsc for division instead of inline asssembly. (diff) | |
download | ipxe-3e781eb87f7b5bfa638f94234bb5e9d64508b0a4.tar.gz ipxe-3e781eb87f7b5bfa638f94234bb5e9d64508b0a4.tar.xz ipxe-3e781eb87f7b5bfa638f94234bb5e9d64508b0a4.zip |
Merge branch 'xl0-timer'
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/config.c | 11 | ||||
-rw-r--r-- | src/core/getkey.c | 2 | ||||
-rw-r--r-- | src/core/misc.c | 14 | ||||
-rw-r--r-- | src/core/random.c | 2 | ||||
-rw-r--r-- | src/core/serial.c | 2 | ||||
-rw-r--r-- | src/core/timer.c | 103 |
6 files changed, 103 insertions, 31 deletions
diff --git a/src/core/config.c b/src/core/config.c index e7db221a..24db3557 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -75,6 +75,17 @@ REQUIRE_OBJECT ( syslog ); #endif /* + * Timers + */ + +#ifdef TIMER_BIOS +REQUIRE_OBJECT ( timer_bios ); +#endif + +#ifdef TIMER_RDTSC +REQUIRE_OBJECT ( timer_rdtsc ); +#endif +/* * Drag in all requested protocols * */ diff --git a/src/core/getkey.c b/src/core/getkey.c index 71ec6cc1..1551cf37 100644 --- a/src/core/getkey.c +++ b/src/core/getkey.c @@ -17,9 +17,9 @@ */ #include <console.h> -#include <latch.h> #include <gpxe/process.h> #include <gpxe/keys.h> +#include <gpxe/timer.h> /** @file * diff --git a/src/core/misc.c b/src/core/misc.c index 4219a36c..a54f5a10 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -4,20 +4,8 @@ MISC Support Routines #include <stdlib.h> #include <byteswap.h> -#include <latch.h> #include <gpxe/in.h> - -/************************************************************************** -SLEEP -**************************************************************************/ -unsigned int sleep(unsigned int secs) -{ - unsigned long tmo; - - for (tmo = currticks()+secs*TICKS_PER_SEC; currticks() < tmo; ) { - } - return 0; -} +#include <gpxe/timer.h> /************************************************************************** INET_ATON - Convert an ascii x.x.x.x to binary form diff --git a/src/core/random.c b/src/core/random.c index e4a70d43..d34e763a 100644 --- a/src/core/random.c +++ b/src/core/random.c @@ -5,7 +5,7 @@ */ #include <stdlib.h> -#include <latch.h> +#include <gpxe/timer.h> static int32_t rnd_seed = 0; diff --git a/src/core/serial.c b/src/core/serial.c index f325bc45..f6d0ecbb 100644 --- a/src/core/serial.c +++ b/src/core/serial.c @@ -15,7 +15,7 @@ #include "console.h" #include <gpxe/init.h> #include "io.h" -#include "timer.h" +#include <unistd.h> #include "config/serial.h" /* Set default values if none specified */ diff --git a/src/core/timer.c b/src/core/timer.c index c56e5310..e736f528 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -1,27 +1,100 @@ -/* A couple of routines to implement a low-overhead timer for drivers */ - - /* +/* + * core/timer.c + * + * Copyright (C) 2007 Alexey Zaytsev <alexey.zaytsev@gmail.com> + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2, or (at - * your option) any later version. + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "timer.h" +#include <stddef.h> +#include <assert.h> +#include <gpxe/init.h> +#include <gpxe/timer.h> +#include <stdio.h> -/* Machine Independant timer helper functions */ +static struct timer ts_table[0] + __table_start ( struct timer, timers ); +static struct timer ts_table_end[0] + __table_end ( struct timer, timers ); -void mdelay(unsigned int msecs) + +static struct timer *used_ts = NULL; + +/* + * This function may be used in custom timer driver. + * + * This udelay implementation works well if you've got a + * fast currticks(). + */ +void generic_currticks_udelay(unsigned int usecs) { - unsigned int i; - for(i = 0; i < msecs; i++) { - udelay(1000); - } + tick_t t; + + t = currticks(); + while (t + usecs > currticks()) + ; /* xxx: Relax the cpu some way. */ } -void waiton_timer2(unsigned int ticks) + +static void timer_init(void) { - load_timer2(ticks); - while(timer2_running()) { + struct timer *ts; + + for (ts = ts_table; ts < ts_table_end; ts++) { + if (ts->init && ts->init() >= 0) { + used_ts = ts; + break; + } } + + assert(used_ts); } + +struct init_fn ts_init_fn __init_fn ( INIT_NORMAL ) = { + .initialise = timer_init, +}; + +/* Functions for public use. */ + +tick_t currticks(void) +{ + tick_t ct; + assert(used_ts); + + ct = used_ts->currticks(); + DBG("currticks: %ld seconds and %06ld microseconds\n", ct/USECS_IN_SEC, ct%USECS_IN_SEC); + + return ct; +} + +void udelay(unsigned int usecs) +{ + used_ts->udelay(usecs); +} + +void mdelay(unsigned int msecs) +{ + while(msecs--) + used_ts->udelay(USECS_IN_MSEC); +} + +unsigned int sleep(unsigned int secs) +{ + while (secs--) + mdelay(MSECS_IN_SEC); + + return 0; +} + |