Convert to common mips3_cp0_counter clock.
Convert to timecounters. From Rivo Nurges (rix at estpak dot ee). ok soren@, tested by simon@. Note that this means we aren't using the gt clock, and maybe we should clean that up a bit.
This commit is contained in:
parent
fcdc9ed735
commit
5ebcd1bf4f
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: autoconf.c,v 1.21 2006/07/18 12:51:01 tsutsui Exp $ */
|
||||
/* $NetBSD: autoconf.c,v 1.22 2006/09/07 03:38:54 gdamore Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 Soren S. Jorvang. All rights reserved.
|
||||
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.21 2006/07/18 12:51:01 tsutsui Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.22 2006/09/07 03:38:54 gdamore Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -53,26 +53,13 @@ cpu_configure(void)
|
|||
(void)splhigh();
|
||||
|
||||
evcnt_attach_static(&hardclock_ev);
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
evcnt_attach_static(&statclock_ev);
|
||||
#endif
|
||||
icu_init();
|
||||
|
||||
if (config_rootfound("mainbus", NULL) == NULL)
|
||||
panic("no mainbus found");
|
||||
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
/*
|
||||
* Enable interrupt sources.
|
||||
* We can't enable CPU INT5 which is used by statclock(9) here
|
||||
* until cpu_initclocks(9) is called because there is no way
|
||||
* to disable it other than setting status register by spl(9).
|
||||
*/
|
||||
_spllower(MIPS_INT_MASK_5);
|
||||
#else
|
||||
/* enable all interrupts */
|
||||
_splnone();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: clock.c,v 1.14 2006/09/04 20:30:40 tsutsui Exp $ */
|
||||
/* $NetBSD: clock.c,v 1.15 2006/09/07 03:38:54 gdamore Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 Soren S. Jorvang. All rights reserved.
|
||||
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.14 2006/09/04 20:30:40 tsutsui Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.15 2006/09/07 03:38:54 gdamore Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
|
@ -41,159 +41,3 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.14 2006/09/04 20:30:40 tsutsui Exp $");
|
|||
void (*timer_start)(void *);
|
||||
long (*timer_read)(void *);
|
||||
void *timer_cookie;
|
||||
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
/*
|
||||
* Statistics clock variance, in usec. Variance must be a
|
||||
* power of two. Since this gives us an even number, not an odd number,
|
||||
* we discard one case and compensate. That is, a variance of 1024 would
|
||||
* give us offsets in [0..1023]. Instead, we take offsets in [1..1023].
|
||||
* This is symmetric about the point 512, or statvar/2, and thus averages
|
||||
* to that value (assuming uniform random numbers).
|
||||
*/
|
||||
static const uint32_t statvar = 1024;
|
||||
static uint32_t statint; /* number of clock ticks for stathz */
|
||||
static uint32_t statmin; /* minimum stat clock count in ticks */
|
||||
static uint32_t statprev;/* last value of we set statclock to */
|
||||
static u_int statcountperusec; /* number of ticks per usec at current stathz */
|
||||
#endif
|
||||
|
||||
void
|
||||
cpu_initclocks(void)
|
||||
{
|
||||
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
if (stathz == 0)
|
||||
stathz = hz;
|
||||
|
||||
if (profhz == 0)
|
||||
profhz = hz * 5;
|
||||
|
||||
setstatclockrate(stathz);
|
||||
#endif
|
||||
|
||||
/* start timer interrups for hardclock */
|
||||
if (timer_start == NULL)
|
||||
panic("cpu_initclocks(): no timer configured");
|
||||
(*timer_start)(timer_cookie);
|
||||
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
/* enable statclock intr (CPU INT5) */
|
||||
_splnone();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
setstatclockrate(int newhz)
|
||||
{
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
uint32_t countpersecond, statvarticks;
|
||||
|
||||
statprev = mips3_cp0_count_read();
|
||||
|
||||
statint = ((curcpu()->ci_cpu_freq + newhz / 2) / newhz) / 2;
|
||||
|
||||
/* Get the total ticks a second */
|
||||
countpersecond = statint * newhz;
|
||||
|
||||
/* now work out how many ticks per usec */
|
||||
statcountperusec = countpersecond / 1000000;
|
||||
|
||||
/* calculate a variance range of statvar */
|
||||
statvarticks = statcountperusec * statvar;
|
||||
|
||||
/* minimum is statint - 50% of variant */
|
||||
statmin = statint - (statvarticks / 2);
|
||||
|
||||
mips3_cp0_compare_write(statprev + statint);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
void
|
||||
statclockintr(struct clockframe *cfp)
|
||||
{
|
||||
uint32_t curcount, statnext, delta, r;
|
||||
int lost;
|
||||
|
||||
lost = 0;
|
||||
|
||||
do {
|
||||
r = (uint32_t)random() & (statvar - 1);
|
||||
} while (r == 0);
|
||||
statnext = statprev + statmin + (r * statcountperusec);
|
||||
|
||||
mips3_cp0_compare_write(statnext);
|
||||
curcount = mips3_cp0_count_read();
|
||||
delta = statnext - curcount;
|
||||
|
||||
while (__predict_false((int32_t)delta < 0)) {
|
||||
lost++;
|
||||
delta += statint;
|
||||
}
|
||||
if (__predict_false(lost > 0)) {
|
||||
statnext = curcount + delta;
|
||||
mips3_cp0_compare_write(statnext);
|
||||
for (; lost > 0; lost--)
|
||||
statclock(cfp);
|
||||
}
|
||||
statclock(cfp);
|
||||
|
||||
statprev = statnext;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
microtime(struct timeval *tvp)
|
||||
{
|
||||
int s;
|
||||
static struct timeval lasttime;
|
||||
|
||||
s = splclock();
|
||||
|
||||
*tvp = time;
|
||||
|
||||
if (timer_read)
|
||||
tvp->tv_usec += (*timer_read)(timer_cookie);
|
||||
|
||||
if (tvp->tv_usec >= 1000000) {
|
||||
tvp->tv_usec -= 1000000;
|
||||
tvp->tv_sec++;
|
||||
}
|
||||
|
||||
if (tvp->tv_sec == lasttime.tv_sec &&
|
||||
tvp->tv_usec <= lasttime.tv_usec &&
|
||||
(tvp->tv_usec = lasttime.tv_usec + 1) >= 1000000) {
|
||||
tvp->tv_sec++;
|
||||
tvp->tv_usec -= 1000000;
|
||||
}
|
||||
|
||||
lasttime = *tvp;
|
||||
splx(s);
|
||||
}
|
||||
|
||||
void
|
||||
delay(unsigned int n)
|
||||
{
|
||||
uint32_t cur, last, delta, usecs;
|
||||
|
||||
last = mips3_cp0_count_read();
|
||||
delta = usecs = 0;
|
||||
|
||||
while (n > usecs) {
|
||||
cur = mips3_cp0_count_read();
|
||||
|
||||
/* Check to see if the timer has wrapped around. */
|
||||
if (cur < last)
|
||||
delta += ((curcpu()->ci_cycles_per_hz - last) + cur);
|
||||
else
|
||||
delta += (cur - last);
|
||||
|
||||
last = cur;
|
||||
|
||||
if (delta >= curcpu()->ci_divisor_delay) {
|
||||
usecs += delta / curcpu()->ci_divisor_delay;
|
||||
delta %= curcpu()->ci_divisor_delay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: clockvar.h,v 1.4 2006/07/18 12:51:01 tsutsui Exp $ */
|
||||
/* $NetBSD: clockvar.h,v 1.5 2006/09/07 03:38:54 gdamore Exp $ */
|
||||
/*
|
||||
* Copyright (C) 2004 Izumi Tsutsui. All rights reserved.
|
||||
*
|
||||
|
@ -27,11 +27,6 @@
|
|||
|
||||
extern struct evcnt hardclock_ev;
|
||||
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
void statclockintr(struct clockframe *);
|
||||
extern struct evcnt statclock_ev;
|
||||
#endif
|
||||
|
||||
extern void (*timer_start)(void *);
|
||||
extern long (*timer_read)(void *);
|
||||
extern void *timer_cookie;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: machdep.c,v 1.71 2006/07/18 12:51:01 tsutsui Exp $ */
|
||||
/* $NetBSD: machdep.c,v 1.72 2006/09/07 03:38:54 gdamore Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Izumi Tsutsui.
|
||||
|
@ -53,7 +53,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.71 2006/07/18 12:51:01 tsutsui Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.72 2006/09/07 03:38:54 gdamore Exp $");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_kgdb.h"
|
||||
|
@ -72,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.71 2006/07/18 12:51:01 tsutsui Exp $")
|
|||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
#include <mips/mips3_clock.h>
|
||||
#include <machine/bootinfo.h>
|
||||
#include <machine/bus.h>
|
||||
#include <machine/cpu.h>
|
||||
|
@ -128,10 +129,6 @@ int cpuspeed;
|
|||
|
||||
struct evcnt hardclock_ev =
|
||||
EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "cpu", "hardclock");
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
struct evcnt statclock_ev =
|
||||
EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "cpu", "statclock");
|
||||
#endif
|
||||
|
||||
u_int cobalt_id;
|
||||
static const char * const cobalt_model[] =
|
||||
|
@ -677,15 +674,9 @@ cpu_intr(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
|
|||
uvmexp.intrs++;
|
||||
|
||||
if (ipending & MIPS_INT_MASK_5) {
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
cf.pc = pc;
|
||||
cf.sr = status;
|
||||
|
||||
statclockintr(&cf);
|
||||
statclock_ev.ev_count++;
|
||||
#else
|
||||
mips3_cp0_compare_write(0);
|
||||
#endif
|
||||
/* call the common MIPS3 clock interrupt handler */
|
||||
mips3_clockintr(status, pc);
|
||||
|
||||
cause &= ~MIPS_INT_MASK_5;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: files.cobalt,v 1.25 2006/04/15 13:33:05 tsutsui Exp $
|
||||
# $NetBSD: files.cobalt,v 1.26 2006/09/07 03:38:55 gdamore Exp $
|
||||
|
||||
maxpartitions 16
|
||||
|
||||
|
@ -9,6 +9,8 @@ include "dev/wscons/files.wscons"
|
|||
include "dev/rasops/files.rasops"
|
||||
include "dev/wsfont/files.wsfont"
|
||||
|
||||
file arch/mips/mips/mips3_clock.c
|
||||
|
||||
device mainbus {[addr = -1], [level = -1]}: pcibus
|
||||
attach mainbus at root
|
||||
file arch/cobalt/cobalt/mainbus.c mainbus
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: intr.h,v 1.22 2006/07/18 12:51:01 tsutsui Exp $ */
|
||||
/* $NetBSD: intr.h,v 1.23 2006/09/07 03:38:55 gdamore Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 Soren S. Jorvang. All rights reserved.
|
||||
|
@ -80,12 +80,7 @@ void _clrsoftintr(int);
|
|||
#define SPLBIO (SPLSOFT | MIPS_INT_MASK_4)
|
||||
#define SPLNET (SPLBIO | MIPS_INT_MASK_1 | MIPS_INT_MASK_2)
|
||||
#define SPLTTY (SPLNET | MIPS_INT_MASK_3)
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
#define SPLCLOCK (SPLTTY | MIPS_INT_MASK_0)
|
||||
#define SPLSTATCLOCK (SPLCLOCK | MIPS_INT_MASK_5)
|
||||
#else
|
||||
#define SPLCLOCK (SPLTTY | MIPS_INT_MASK_0 | MIPS_INT_MASK_5)
|
||||
#endif
|
||||
#define splbio() _splraise(SPLBIO)
|
||||
#define splnet() _splraise(SPLNET)
|
||||
#define spltty() _splraise(SPLTTY)
|
||||
|
@ -93,11 +88,7 @@ void _clrsoftintr(int);
|
|||
#define splserial() _splraise(SPLTTY)
|
||||
#define splclock() _splraise(SPLCLOCK)
|
||||
#define splvm() splclock()
|
||||
#ifdef ENABLE_INT5_STATCLOCK
|
||||
#define splstatclock() _splraise(SPLSTATCLOCK)
|
||||
#else
|
||||
#define splstatclock() splclock()
|
||||
#endif
|
||||
#define spllowersoftclock() _spllower(MIPS_SOFT_INT_MASK_0)
|
||||
|
||||
#define splsched() splhigh()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: param.h,v 1.12 2006/04/21 16:52:15 tsutsui Exp $ */
|
||||
/* $NetBSD: param.h,v 1.13 2006/09/07 03:38:55 gdamore Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -112,8 +112,8 @@
|
|||
#ifdef _KERNEL
|
||||
#ifndef _LOCORE
|
||||
|
||||
void delay(unsigned int);
|
||||
#define DELAY(n) delay(n)
|
||||
void delay(int n);
|
||||
#define DELAY delay
|
||||
|
||||
#include <machine/intr.h>
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
/* $NetBSD: types.h,v 1.6 2006/09/04 20:30:40 tsutsui Exp $ */
|
||||
/* $NetBSD: types.h,v 1.7 2006/09/07 03:38:55 gdamore Exp $ */
|
||||
|
||||
#include <mips/types.h>
|
||||
|
||||
#define __HAVE_DEVICE_REGISTER
|
||||
#define __HAVE_GENERIC_SOFT_INTERRUPTS
|
||||
#define __HAVE_GENERIC_TODR
|
||||
#define __HAVE_TIMECOUNTER
|
||||
|
|
Loading…
Reference in New Issue