Move schedticks and cp_time into schedstate_percpu. Also, allow

non-primary CPUs to call hardclock(), but make them bail about
before updating global timekeeping state (that's the job of the
primary CPU).
This commit is contained in:
thorpej 2000-06-03 20:42:42 +00:00
parent 19e7dc6fee
commit 5b281c5932
4 changed files with 42 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_clock.c,v 1.59 2000/06/02 15:53:04 simonb Exp $ */
/* $NetBSD: kern_clock.c,v 1.60 2000/06/03 20:42:42 thorpej Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -506,6 +506,15 @@ hardclock(frame)
if (stathz == 0)
statclock(frame);
#if defined(MULTIPROCESSOR)
/*
* If we are not the primary CPU, we're not allowed to do
* any more work.
*/
if (CPU_IS_PRIMARY(curcpu()) == 0)
return;
#endif
/*
* Increment the time-of-day. The increment is normally just
* ``tick''. If the machine is one which has a clock frequency
@ -1186,7 +1195,8 @@ statclock(frame)
struct gmonparam *g;
int i;
#endif
static int schedclk;
struct cpu_info *ci = curcpu();
struct schedstate_percpu *spc = &ci->ci_schedstate;
struct proc *p;
if (CLKF_USERMODE(frame)) {
@ -1201,9 +1211,9 @@ statclock(frame)
*/
p->p_uticks++;
if (p->p_nice > NZERO)
cp_time[CP_NICE]++;
spc->spc_cp_time[CP_NICE]++;
else
cp_time[CP_USER]++;
spc->spc_cp_time[CP_USER]++;
} else {
#ifdef GPROF
/*
@ -1236,23 +1246,23 @@ statclock(frame)
if (CLKF_INTR(frame)) {
if (p != NULL)
p->p_iticks++;
cp_time[CP_INTR]++;
spc->spc_cp_time[CP_INTR]++;
} else if (p != NULL) {
p->p_sticks++;
cp_time[CP_SYS]++;
spc->spc_cp_time[CP_SYS]++;
} else
cp_time[CP_IDLE]++;
spc->spc_cp_time[CP_IDLE]++;
}
pscnt = psdiv;
if (p != NULL) {
++p->p_cpticks;
/*
* If no schedclock is provided, call it here at ~~12-25 Hz,
* ~~16 Hz is best
* If no separate schedclock is provided, call it here
* at ~~12-25 Hz, ~~16 Hz is best
*/
if(schedhz == 0)
if ((++schedclk & 3) == 0)
if (schedhz == 0)
if ((++ci->ci_schedstate.spc_schedticks & 3) == 0)
schedclock(p);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_sysctl.c,v 1.69 2000/06/02 15:53:05 simonb Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.70 2000/06/03 20:42:42 thorpej Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@ -458,8 +458,10 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
case KERN_CCPU:
return (sysctl_rdint(oldp, oldlenp, newp, ccpu));
case KERN_CP_TIME:
return (sysctl_rdstruct(oldp, oldlenp, newp, cp_time,
sizeof(cp_time)));
/* XXXSMP: WRONG! */
return (sysctl_rdstruct(oldp, oldlenp, newp,
curcpu()->ci_schedstate.spc_cp_time,
sizeof(curcpu()->ci_schedstate.spc_cp_time)));
#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
case KERN_SYSVIPC_INFO:
return (sysctl_sysvipc(name + 1, namelen - 1, oldp, oldlenp));

View File

@ -1,4 +1,4 @@
/* $NetBSD: dkstat.h,v 1.11 2000/05/29 11:35:19 simonb Exp $ */
/* $NetBSD: dkstat.h,v 1.12 2000/06/03 20:42:44 thorpej Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -43,16 +43,8 @@
#ifndef _SYS_DKSTAT_H_
#define _SYS_DKSTAT_H_
#define CP_USER 0
#define CP_NICE 1
#define CP_SYS 2
#define CP_INTR 3
#define CP_IDLE 4
#define CPUSTATES 5
#define DK_NDRIVE 8
#ifdef _KERNEL
u_int64_t cp_time[CPUSTATES];
u_int64_t tk_cancc;
u_int64_t tk_nin;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sched.h,v 1.4 2000/05/27 13:51:38 sommerfeld Exp $ */
/* $NetBSD: sched.h,v 1.5 2000/06/03 20:42:44 thorpej Exp $ */
/*-
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@ -117,12 +117,26 @@ struct prochd {
struct proc *ph_rlink;
};
/*
* CPU states.
* XXX Not really scheduler state, but no other good place to put
* it right now, and it really is per-CPU.
*/
#define CP_USER 0
#define CP_NICE 1
#define CP_SYS 2
#define CP_INTR 3
#define CP_IDLE 4
#define CPUSTATES 5
/*
* Per-CPU scheduler state.
*/
struct schedstate_percpu {
struct timeval spc_runtime; /* time curproc started running */
__volatile int spc_flags; /* flags; see below */
u_int spc_schedticks; /* ticks for schedclock() */
u_int64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */
u_char spc_curpriority; /* usrpri of curproc */
};