FreeBSD/Linux Kernel Cross Reference
sys/kern/sched.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993-1987 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: sched.c,v $
29 * Revision 2.2 93/11/17 17:20:51 dbg
30 * machparam.h -> machspl.h
31 * [93/05/21 dbg]
32 *
33 * Created file to hold routines for periodic scheduling
34 * calculations.
35 * [93/05/11 dbg]
36 *
37 */
38
39 #include <kern/clock.h>
40 #include <kern/mach_timer.h>
41 #include <kern/sched.h>
42
43 #include <machine/machspl.h>
44
45 /*
46 * sched_tick increments once a second. Used to age priorities.
47 */
48 unsigned int sched_tick = 0;
49
50 #if SIMPLE_CLOCK
51 /*
52 * sched_usec is an exponential average of number of microseconds
53 * in a second for clock drift compensation.
54 */
55
56 int sched_usec = 0;
57 #endif /* SIMPLE_CLOCK */
58
59 extern void compute_mach_factor(void);
60 extern void ts_thread_scan(void);
61
62 /*
63 * sched_calculations:
64 *
65 * Perform various periodic scheduling and statistics
66 * functions. Runs off a periodic timer, at one-second
67 * intervals.
68 */
69 void sched_calculations(void)
70 {
71 /*
72 * Age usage one more second
73 */
74 sched_tick++;
75
76 #if SIMPLE_CLOCK
77 /*
78 * Compensate for clock drift. sched_usec is an
79 * exponential average of the number of microseconds in
80 * a second. It decays in the same fashion as cpu_usage.
81 */
82 {
83 int new_usec;
84
85 new_usec = sched_usec_elapsed();
86 sched_usec = (5*sched_usec + 3*new_usec)/8;
87 }
88 #endif /* SIMPLE_CLOCK */
89
90 /*
91 * Compute the load factors
92 */
93 compute_mach_factor();
94
95 /*
96 * Raise the priorities of low-priority timesharing threads,
97 * every other second.
98 */
99 if (sched_tick & 1)
100 ts_thread_scan();
101 }
102
103 /*
104 * Periodic timer for sched_calculations.
105 */
106 struct timer_elt sched_timer;
107
108 /*
109 * Initialize the timer.
110 */
111 void init_sched_calculations(void)
112 {
113 /*
114 * Recalculate priorities once per second
115 */
116 sched_timer.te_fcn = (void (*)(void *))sched_calculations;
117 sched_timer.te_param = 0;
118 sched_timer.te_flags = TELT_PERIODIC;
119 sched_timer.te_period.seconds = 1;
120 sched_timer.te_period.nanoseconds = 0;
121 sched_timer.te_clock = sys_clock;
122
123 timer_elt_enqueue(&sched_timer, sched_timer.te_period, FALSE);
124 }
125
Cache object: 693816f911810a09dfb8d2d6e142bf3c
|