From 5b281c593215cef736cfd6e009d50d31a35df711 Mon Sep 17 00:00:00 2001 From: thorpej Date: Sat, 3 Jun 2000 20:42:42 +0000 Subject: [PATCH] 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). --- sys/kern/kern_clock.c | 32 +++++++++++++++++++++----------- sys/kern/kern_sysctl.c | 8 +++++--- sys/sys/dkstat.h | 10 +--------- sys/sys/sched.h | 16 +++++++++++++++- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 5de59b2cc6f9..5633e5a5412c 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -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); } } diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index c36c382896cd..5ba7ed25f49d 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -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)); diff --git a/sys/sys/dkstat.h b/sys/sys/dkstat.h index d9d375021d7a..43a0a68dadcd 100644 --- a/sys/sys/dkstat.h +++ b/sys/sys/dkstat.h @@ -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; diff --git a/sys/sys/sched.h b/sys/sys/sched.h index 8d3ac5fb9aad..794b73f058cf 100644 --- a/sys/sys/sched.h +++ b/sys/sys/sched.h @@ -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 */ };