[timer] Formalise the timer API

We now have two implementations for the timer API: one using the
time-of-day counter at 40:70 and one using RDTSC.  Both make use of
timer2_udelay().
This commit is contained in:
Michael Brown
2008-10-12 19:56:52 +01:00
parent e6f276ece3
commit 16f1e35775
22 changed files with 386 additions and 284 deletions

View File

@@ -1,41 +1,73 @@
#ifndef GPXE_TIMER_H
#define GPXE_TIMER_H
#ifndef _GPXE_TIMER_H
#define _GPXE_TIMER_H
#include <stddef.h>
#include <gpxe/tables.h>
/** @file
*
* gPXE timer API
*
* The timer API provides udelay() for fixed delays, and currticks()
* for a monotonically increasing tick counter.
*/
typedef unsigned long tick_t;
#include <gpxe/api.h>
#include <config/timer.h>
#define MSECS_IN_SEC (1000)
#define USECS_IN_SEC (1000*1000)
#define USECS_IN_MSEC (1000)
/**
* Calculate static inline timer API function name
*
* @v _prefix Subsystem prefix
* @v _api_func API function
* @ret _subsys_func Subsystem API function
*/
#define TIMER_INLINE( _subsys, _api_func ) \
SINGLE_API_INLINE ( TIMER_PREFIX_ ## _subsys, _api_func )
#define TICKS_PER_SEC USECS_IN_SEC
/**
* Provide a timer API implementation
*
* @v _prefix Subsystem prefix
* @v _api_func API function
* @v _func Implementing function
*/
#define PROVIDE_TIMER( _subsys, _api_func, _func ) \
PROVIDE_SINGLE_API ( TIMER_PREFIX_ ## _subsys, _api_func, _func )
extern tick_t currticks ( void );
/**
* Provide a static inline timer API implementation
*
* @v _prefix Subsystem prefix
* @v _api_func API function
*/
#define PROVIDE_TIMER_INLINE( _subsys, _api_func ) \
PROVIDE_SINGLE_API_INLINE ( TIMER_PREFIX_ ## _subsys, _api_func )
extern void generic_currticks_udelay ( unsigned int usecs );
/* Include all architecture-independent I/O API headers */
/** A timer */
struct timer {
/** Initialise timer
*
* @ret rc Return status code
*/
int ( * init ) ( void );
/** Read current time
*
* @ret ticks Current time, in ticks
*/
tick_t ( * currticks ) ( void );
/** Delay
*
* @v usecs Time to delay, in microseconds
*/
void ( * udelay ) ( unsigned int usecs );
};
/* Include all architecture-dependent I/O API headers */
#include <bits/timer.h>
#define __timer( order ) __table ( struct timer, timers, order )
/**
* Delay for a fixed number of microseconds
*
* @v usecs Number of microseconds for which to delay
*/
void udelay ( unsigned long usecs );
#endif /* GPXE_TIMER_H */
/**
* Get current system time in ticks
*
* @ret ticks Current time, in ticks
*/
unsigned long currticks ( void );
/**
* Get number of ticks per second
*
* @ret ticks_per_sec Number of ticks per second
*/
unsigned long ticks_per_sec ( void );
/** Number of ticks per second */
#define TICKS_PER_SEC ( ticks_per_sec() )
#endif /* _GPXE_TIMER_H */

View File

@@ -4,7 +4,6 @@
#include <stddef.h>
#include <stdarg.h>
unsigned int sleep ( unsigned int seconds );
extern int execv ( const char *command, char * const argv[] );
/**
@@ -22,10 +21,21 @@ extern int execv ( const char *command, char * const argv[] );
rc; \
} )
void udelay(unsigned int usecs);
void mdelay(unsigned int msecs);
/* Pick up udelay() */
#include <gpxe/timer.h>
#define usleep(x) udelay(x)
/*
* sleep() prototype is defined by POSIX.1. usleep() prototype is
* defined by 4.3BSD. udelay() and mdelay() prototypes are chosen to
* be reasonably sensible.
*
*/
extern unsigned int sleep ( unsigned int seconds );
extern void mdelay ( unsigned long msecs );
static inline __always_inline void usleep ( unsigned long usecs ) {
udelay ( usecs );
}
#endif /* _UNISTD_H */