Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Move schedticks and cp_time into schedstate_percpu. Als...



details:   https://anonhg.NetBSD.org/src/rev/206b948f2367
branches:  trunk
changeset: 487163:206b948f2367
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Jun 03 20:42:42 2000 +0000

description:
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).

diffstat:

 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(-)

diffs (161 lines):

diff -r 5f6bcab58329 -r 206b948f2367 sys/kern/kern_clock.c
--- a/sys/kern/kern_clock.c     Sat Jun 03 20:37:37 2000 +0000
+++ b/sys/kern/kern_clock.c     Sat Jun 03 20:42:42 2000 +0000
@@ -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 @@
        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 @@
        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 @@
                 */
                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 @@
                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 -r 5f6bcab58329 -r 206b948f2367 sys/kern/kern_sysctl.c
--- a/sys/kern/kern_sysctl.c    Sat Jun 03 20:37:37 2000 +0000
+++ b/sys/kern/kern_sysctl.c    Sat Jun 03 20:42:42 2000 +0000
@@ -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 @@
        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 -r 5f6bcab58329 -r 206b948f2367 sys/sys/dkstat.h
--- a/sys/sys/dkstat.h  Sat Jun 03 20:37:37 2000 +0000
+++ b/sys/sys/dkstat.h  Sat Jun 03 20:42:42 2000 +0000
@@ -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 -r 5f6bcab58329 -r 206b948f2367 sys/sys/sched.h
--- a/sys/sys/sched.h   Sat Jun 03 20:37:37 2000 +0000
+++ b/sys/sys/sched.h   Sat Jun 03 20:42:42 2000 +0000
@@ -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.
@@ -118,11 +118,25 @@
 };
 
 /*
+ * 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 */
 };
 



Home | Main Index | Thread Index | Old Index