First kick at cleaning up the RF_ETIMER code. New timer handling code

provided by Peter Galbavy via OpenBSD.
This commit is contained in:
oster 1999-08-13 03:26:55 +00:00
parent eca431e87c
commit 02acd1910a
3 changed files with 40 additions and 47 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rf_etimer.h,v 1.3 1999/02/05 00:06:11 oster Exp $ */
/* $NetBSD: rf_etimer.h,v 1.4 1999/08/13 03:26:55 oster Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
@ -26,57 +26,48 @@
* rights to redistribute these changes.
*/
/* rf_etimer.h -- header file for code related to accurate timing
* This code currently assumes that the elapsed time between START_TIMER
* and START_TIMER is less than the period of the cycle counter. This
* means the events you want to time must be less than:
* clock speed max time
* ---------- --------
* 175 MHz 24 sec
* 150 MHz 28 sec
* 125 MHz 34 sec
*
*
*/
#ifndef _RF__RF_TIMER_H_
#define _RF__RF_TIMER_H_
#include "rf_options.h"
#include "rf_utils.h"
extern unsigned int rpcc(void);
#define rf_read_cycle_counter rpcc
#define RF_DEF_TIMER_MAX_VAL 0xFFFFFFFF
typedef struct RF_EtimerVal_s {
unsigned ccnt; /* cycle count */
} RF_EtimerVal_t;
#include <sys/time.h>
struct RF_Etimer_s {
RF_EtimerVal_t st;
RF_EtimerVal_t et;
unsigned long ticks; /* elapsed time in ticks */
struct timeval st;
struct timeval et;
struct timeval diff;
};
extern long rf_timer_max_val;
extern long rf_timer_ticks_per_second;
extern unsigned long rf_timer_ticks_per_usec;
#if defined(_KERNEL)
#include <sys/kernel.h>
#define RF_ETIMER_TICKS2US(_tcks_) ( (_tcks_) / rf_timer_ticks_per_usec )
#define RF_ETIMER_START(_t_) { (_t_).st.ccnt = rf_read_cycle_counter(); }
#define RF_ETIMER_STOP(_t_) { (_t_).et.ccnt = rf_read_cycle_counter(); }
#define RF_ETIMER_EVAL(_t_) { \
if ((_t_).st.ccnt < (_t_).et.ccnt) \
(_t_).ticks = (_t_).et.ccnt - (_t_).st.ccnt; \
else \
(_t_).ticks = rf_timer_max_val - ((_t_).st.ccnt - (_t_).et.ccnt); \
}
#define RF_ETIMER_START(_t_) \
{ \
int s; \
bzero(&(_t_), sizeof (_t_)); \
s = splclock(); \
(_t_).st = mono_time; \
splx(s); \
}
#define RF_ETIMER_VAL_TICKS(_t_) ((_t_).ticks)
#define RF_ETIMER_VAL_US(_t_) (RF_ETIMER_TICKS2US((_t_).ticks))
#define RF_ETIMER_VAL_MS(_t_) (RF_ETIMER_TICKS2US((_t_).ticks)/1000)
#define RF_ETIMER_STOP(_t_) \
{ \
int s; \
s = splclock(); \
(_t_).et = mono_time; \
splx(s); \
}
#define RF_ETIMER_EVAL(_t_) \
{ \
RF_TIMEVAL_DIFF(&(_t_).st, &(_t_).et, &(_t_).diff) \
}
#define RF_ETIMER_VAL_US(_t_) (RF_TIMEVAL_TO_US((_t_).diff))
#define RF_ETIMER_VAL_MS(_t_) (RF_TIMEVAL_TO_US((_t_).diff)/1000)
#endif /* _KERNEL */
#endif /* !_RF__RF_TIMER_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: rf_revent.c,v 1.4 1999/03/14 21:53:31 oster Exp $ */
/* $NetBSD: rf_revent.c,v 1.5 1999/08/13 03:26:55 oster Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
@ -121,8 +121,7 @@ rf_GetNextReconEvent(reconDesc, row, continueFunc, continueArg)
/* mpsleep timeout value: secs = timo_val/hz. 'ticks' here is defined as cycle-counter ticks, not softclock ticks */
#define MAX_RECON_EXEC_TICKS 15000000 /* 150 Mhz => this many ticks in 100
* ms */
#define MAX_RECON_EXEC_USECS (100 * 1000) /* 100 ms */
#define RECON_DELAY_MS 25
#define RECON_TIMO ((RECON_DELAY_MS * hz) / 1000)
@ -136,10 +135,10 @@ rf_GetNextReconEvent(reconDesc, row, continueFunc, continueArg)
RF_ETIMER_STOP(reconDesc->recon_exec_timer);
RF_ETIMER_EVAL(reconDesc->recon_exec_timer);
reconDesc->reconExecTicks += RF_ETIMER_VAL_TICKS(reconDesc->recon_exec_timer);
reconDesc->reconExecTicks += RF_ETIMER_VAL_US(reconDesc->recon_exec_timer);
if (reconDesc->reconExecTicks > reconDesc->maxReconExecTicks)
reconDesc->maxReconExecTicks = reconDesc->reconExecTicks;
if (reconDesc->reconExecTicks >= MAX_RECON_EXEC_TICKS) {
if (reconDesc->reconExecTicks >= MAX_RECON_EXEC_USECS) {
/* we've been running too long. delay for
* RECON_DELAY_MS */
#if RF_RECON_STATS > 0

View File

@ -1,4 +1,4 @@
/* $NetBSD: rf_utils.h,v 1.3 1999/02/05 00:06:18 oster Exp $ */
/* $NetBSD: rf_utils.h,v 1.4 1999/08/13 03:26:55 oster Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
@ -51,6 +51,9 @@ int rf_atoi(char *p);
int rf_htoi(char *p);
#define RF_USEC_PER_SEC 1000000
#define RF_TIMEVAL_TO_US(_t_) (((_t_).tv_sec) \
* RF_USEC_PER_SEC + (_t_).tv_usec)
#define RF_TIMEVAL_DIFF(_start_,_end_,_diff_) { \
if ((_end_)->tv_usec < (_start_)->tv_usec) { \
(_diff_)->tv_usec = ((_end_)->tv_usec + RF_USEC_PER_SEC) \