Source-Changes-HG archive

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

[src/trunk]: src/sys Track if a process has been through a round-robin cycle ...



details:   https://anonhg.NetBSD.org/src/rev/5bc10299f7a4
branches:  trunk
changeset: 484042:5bc10299f7a4
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Mar 23 20:37:58 2000 +0000

description:
Track if a process has been through a round-robin cycle without yielding
the CPU, and mark that it should yield if that happens.

Based on a discussion with Artur Grabowski.

diffstat:

 sys/kern/kern_synch.c |  69 +++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/sys/proc.h        |  14 +++++++++-
 2 files changed, 80 insertions(+), 3 deletions(-)

diffs (142 lines):

diff -r 7b802ceaa11b -r 5bc10299f7a4 sys/kern/kern_synch.c
--- a/sys/kern/kern_synch.c     Thu Mar 23 20:33:37 2000 +0000
+++ b/sys/kern/kern_synch.c     Thu Mar 23 20:37:58 2000 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: kern_synch.c,v 1.68 2000/03/23 06:30:12 thorpej Exp $  */
+/*     $NetBSD: kern_synch.c,v 1.69 2000/03/23 20:37:59 thorpej Exp $  */
 
 /*-
- * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -125,7 +125,21 @@
 roundrobin(arg)
        void *arg;
 {
+       int s;
 
+       if (curproc != NULL) {
+               s = splstatclock();
+               if (curproc->p_schedflags & PSCHED_SEENRR) {
+                       /*
+                        * The process has already been through a roundrobin
+                        * without switching and may be hogging the CPU.
+                        * Indicate that the process should yield.
+                        */
+                       curproc->p_schedflags |= PSCHED_SHOULDYIELD;
+               } else
+                       curproc->p_schedflags |= PSCHED_SEENRR;
+               splx(s);
+       }
        need_resched();
        callout_reset(&roundrobin_ch, hz / 10, roundrobin, NULL);
 }
@@ -687,6 +701,51 @@
 }
 
 /*
+ * General yield call.  Puts the current process back on its run queue and
+ * performs a voluntary context switch.
+ */
+void
+yield()
+{
+       struct proc *p = curproc;
+       int s;
+
+       p->p_priority = p->p_usrpri;
+       s = splstatclock();
+       setrunqueue(p);
+       p->p_stats->p_ru.ru_nvcsw++;
+       mi_switch();
+       splx(s);
+}
+
+/*
+ * General preemption call.  Puts the current process back on its run queue
+ * and performs an involuntary context switch.  If a process is supplied,
+ * we switch to that process.  Otherwise, we use the normal process selection
+ * criteria.
+ */
+void
+preempt(newp)
+       struct proc *newp;
+{
+       struct proc *p = curproc;
+       int s;
+
+       /*
+        * XXX Switching to a specific process is not supported yet.
+        */
+       if (newp != NULL)
+               panic("preempt: cpu_preempt not yet implemented");
+
+       p->p_priority = p->p_usrpri;
+       s = splstatclock(); 
+       setrunqueue(p);
+       p->p_stats->p_ru.ru_nivcsw++;
+       mi_switch();
+       splx(s);
+}
+
+/*
  * The machine independent parts of mi_switch().
  * Must be called at splstatclock() or higher.
  */
@@ -745,6 +804,12 @@
        }
 
        /*
+        * Process is about to yield the CPU; clear the appropriate
+        * scheduling flags.
+        */
+       p->p_schedflags &= ~PSCHED_SWITCHCLEAR;
+
+       /*
         * Pick a new current process and record its start time.
         */
        uvmexp.swtch++;
diff -r 7b802ceaa11b -r 5bc10299f7a4 sys/sys/proc.h
--- a/sys/sys/proc.h    Thu Mar 23 20:33:37 2000 +0000
+++ b/sys/sys/proc.h    Thu Mar 23 20:37:58 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proc.h,v 1.87 2000/03/23 06:31:51 thorpej Exp $        */
+/*     $NetBSD: proc.h,v 1.88 2000/03/23 20:37:58 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1986, 1989, 1991, 1993
@@ -161,6 +161,7 @@
        const char *p_wmesg;     /* Reason for sleep. */
        u_int   p_swtime;        /* Time swapped in or out. */
        u_int   p_slptime;       /* Time since last blocked. */
+       int     p_schedflags;    /* PSCHED_* flags */
 
        struct  callout p_realit_ch;    /* real time callout */
        struct  itimerval p_realtimer;  /* Alarm timer. */
@@ -248,6 +249,15 @@
 #define        P_32            0x40000 /* 32-bit process -- only used on 64-bit kernels */
 
 /*
+ * These flags are kept in p_schedflags.  p_schedflags may be modified
+ * only at splstatclock().
+ */
+#define        PSCHED_SEENRR           0x0001  /* process has been in roundrobin() */
+#define        PSCHED_SHOULDYIELD      0x0002  /* process should yield */
+
+#define        PSCHED_SWITCHCLEAR      (PSCHED_SEENRR|PSCHED_SHOULDYIELD)
+
+/*
  * Macro to compute the exit signal to be delivered.
  */
 #define        P_EXITSIG(p)    (((p)->p_flag & (P_TRACED|P_FSTRACE)) ? SIGCHLD : \
@@ -367,6 +377,8 @@
 void   fixjobc __P((struct proc *p, struct pgrp *pgrp, int entering));
 int    inferior __P((struct proc *p));
 int    leavepgrp __P((struct proc *p));
+void   yield __P((void));
+void   preempt __P((struct proc *));
 void   mi_switch __P((void));
 void   pgdelete __P((struct pgrp *pgrp));
 void   procinit __P((void));



Home | Main Index | Thread Index | Old Index