Deleted Added
full compact
kern_synch.c (31333) kern_synch.c (31352)
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95
39 * $Id: kern_synch.c,v 1.39 1997/09/21 22:00:14 gibbs Exp $
39 * $Id: kern_synch.c,v 1.40 1997/11/21 11:36:56 bde Exp $
40 */
41
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/proc.h>
47#include <sys/kernel.h>

--- 11 unchanged lines hidden (view full) ---

59#include <machine/limits.h> /* for UCHAR_MAX = typeof(p_priority)_MAX */
60
61static void rqinit __P((void *));
62SYSINIT(runqueue, SI_SUB_RUN_QUEUE, SI_ORDER_FIRST, rqinit, NULL)
63
64u_char curpriority; /* usrpri of curproc */
65int lbolt; /* once a second sleep address */
66
40 */
41
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/proc.h>
47#include <sys/kernel.h>

--- 11 unchanged lines hidden (view full) ---

59#include <machine/limits.h> /* for UCHAR_MAX = typeof(p_priority)_MAX */
60
61static void rqinit __P((void *));
62SYSINIT(runqueue, SI_SUB_RUN_QUEUE, SI_ORDER_FIRST, rqinit, NULL)
63
64u_char curpriority; /* usrpri of curproc */
65int lbolt; /* once a second sleep address */
66
67extern void endtsleep __P((void *));
68extern void updatepri __P((struct proc *p));
67static void endtsleep __P((void *));
68static void updatepri __P((struct proc *p));
69
70#define MAXIMUM_SCHEDULE_QUANTUM (1000000) /* arbitrary limit */
71#ifndef DEFAULT_SCHEDULE_QUANTUM
72#define DEFAULT_SCHEDULE_QUANTUM 10
73#endif
74static int quantum = DEFAULT_SCHEDULE_QUANTUM; /* default value */
75
76static int

--- 94 unchanged lines hidden (view full) ---

171 * power: 5.68 10.32 14.94 19.55
172 */
173
174/* calculations for digital decay to forget 90% of usage in 5*loadav sec */
175#define loadfactor(loadav) (2 * (loadav))
176#define decay_cpu(loadfac, cpu) (((loadfac) * (cpu)) / ((loadfac) + FSCALE))
177
178/* decay 95% of `p_pctcpu' in 60 seconds; see CCPU_SHIFT before changing */
69
70#define MAXIMUM_SCHEDULE_QUANTUM (1000000) /* arbitrary limit */
71#ifndef DEFAULT_SCHEDULE_QUANTUM
72#define DEFAULT_SCHEDULE_QUANTUM 10
73#endif
74static int quantum = DEFAULT_SCHEDULE_QUANTUM; /* default value */
75
76static int

--- 94 unchanged lines hidden (view full) ---

171 * power: 5.68 10.32 14.94 19.55
172 */
173
174/* calculations for digital decay to forget 90% of usage in 5*loadav sec */
175#define loadfactor(loadav) (2 * (loadav))
176#define decay_cpu(loadfac, cpu) (((loadfac) * (cpu)) / ((loadfac) + FSCALE))
177
178/* decay 95% of `p_pctcpu' in 60 seconds; see CCPU_SHIFT before changing */
179fixpt_t ccpu = 0.95122942450071400909 * FSCALE; /* exp(-1/20) */
179static fixpt_t ccpu = 0.95122942450071400909 * FSCALE; /* exp(-1/20) */
180
181/*
182 * If `ccpu' is not equal to `exp(-1/20)' and you still want to use the
183 * faster/more-accurate formula, you'll have to estimate CCPU_SHIFT below
184 * and possibly adjust FSHIFT in "param.h" so that (FSHIFT >= CCPU_SHIFT).
185 *
186 * To estimate CCPU_SHIFT for exp(-1/20), the following formula was used:
187 * 1 - exp(-1/20) ~= 0.0487 ~= 0.0488 == 1 (fixed pt, *11* bits).

--- 72 unchanged lines hidden (view full) ---

260 timeout(schedcpu, (void *)0, hz);
261}
262
263/*
264 * Recalculate the priority of a process after it has slept for a while.
265 * For all load averages >= 1 and max p_estcpu of 255, sleeping for at
266 * least six times the loadfactor will decay p_estcpu to zero.
267 */
180
181/*
182 * If `ccpu' is not equal to `exp(-1/20)' and you still want to use the
183 * faster/more-accurate formula, you'll have to estimate CCPU_SHIFT below
184 * and possibly adjust FSHIFT in "param.h" so that (FSHIFT >= CCPU_SHIFT).
185 *
186 * To estimate CCPU_SHIFT for exp(-1/20), the following formula was used:
187 * 1 - exp(-1/20) ~= 0.0487 ~= 0.0488 == 1 (fixed pt, *11* bits).

--- 72 unchanged lines hidden (view full) ---

260 timeout(schedcpu, (void *)0, hz);
261}
262
263/*
264 * Recalculate the priority of a process after it has slept for a while.
265 * For all load averages >= 1 and max p_estcpu of 255, sleeping for at
266 * least six times the loadfactor will decay p_estcpu to zero.
267 */
268void
268static void
269updatepri(p)
270 register struct proc *p;
271{
272 register unsigned int newcpu = p->p_estcpu;
273 register fixpt_t loadfac = loadfactor(averunnable.ldavg[0]);
274
275 if (p->p_slptime > 5 * loadfac)
276 p->p_estcpu = 0;

--- 7 unchanged lines hidden (view full) ---

284}
285
286/*
287 * We're only looking at 7 bits of the address; everything is
288 * aligned to 4, lots of things are aligned to greater powers
289 * of 2. Shift right by 8, i.e. drop the bottom 256 worth.
290 */
291#define TABLESIZE 128
269updatepri(p)
270 register struct proc *p;
271{
272 register unsigned int newcpu = p->p_estcpu;
273 register fixpt_t loadfac = loadfactor(averunnable.ldavg[0]);
274
275 if (p->p_slptime > 5 * loadfac)
276 p->p_estcpu = 0;

--- 7 unchanged lines hidden (view full) ---

284}
285
286/*
287 * We're only looking at 7 bits of the address; everything is
288 * aligned to 4, lots of things are aligned to greater powers
289 * of 2. Shift right by 8, i.e. drop the bottom 256 worth.
290 */
291#define TABLESIZE 128
292TAILQ_HEAD(slpquehead, proc) slpque[TABLESIZE];
292static TAILQ_HEAD(slpquehead, proc) slpque[TABLESIZE];
293#define LOOKUP(x) (((long)(x) >> 8) & (TABLESIZE - 1))
294
295/*
296 * During autoconfiguration or after a panic, a sleep will simply
297 * lower the priority briefly to allow interrupts, then return.
298 * The priority to be used (safepri) is machine-dependent, thus this
299 * value is initialized and maintained in the machine-dependent layers.
300 * This priority will typically be 0, or the lowest priority

--- 122 unchanged lines hidden (view full) ---

423}
424
425/*
426 * Implement timeout for tsleep.
427 * If process hasn't been awakened (wchan non-zero),
428 * set timeout flag and undo the sleep. If proc
429 * is stopped, just unsleep so it will remain stopped.
430 */
293#define LOOKUP(x) (((long)(x) >> 8) & (TABLESIZE - 1))
294
295/*
296 * During autoconfiguration or after a panic, a sleep will simply
297 * lower the priority briefly to allow interrupts, then return.
298 * The priority to be used (safepri) is machine-dependent, thus this
299 * value is initialized and maintained in the machine-dependent layers.
300 * This priority will typically be 0, or the lowest priority

--- 122 unchanged lines hidden (view full) ---

423}
424
425/*
426 * Implement timeout for tsleep.
427 * If process hasn't been awakened (wchan non-zero),
428 * set timeout flag and undo the sleep. If proc
429 * is stopped, just unsleep so it will remain stopped.
430 */
431void
431static void
432endtsleep(arg)
433 void *arg;
434{
435 register struct proc *p;
436 int s;
437
438 p = (struct proc *)arg;
439 s = splhigh();

--- 278 unchanged lines hidden ---
432endtsleep(arg)
433 void *arg;
434{
435 register struct proc *p;
436 int s;
437
438 p = (struct proc *)arg;
439 s = splhigh();

--- 278 unchanged lines hidden ---