2 * (c) Copyright 1990-1996 OPEN SOFTWARE FOUNDATION, INC.
3 * (c) Copyright 1990-1996 HEWLETT-PACKARD COMPANY
4 * (c) Copyright 1990-1996 DIGITAL EQUIPMENT CORPORATION
5 * (c) Copyright 1991, 1992 Siemens-Nixdorf Information Systems
6 * To anyone who acknowledges that this file is provided "AS IS" without
7 * any express or implied warranty: permission to use, copy, modify, and
8 * distribute this file for any purpose is hereby granted without fee,
9 * provided that the above copyright notices and this notice appears in
10 * all source code copies, and that none of the names listed above be used
11 * in advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. None of these organizations
13 * makes any representations about the suitability of this software for
17 * Header file for priority scheduling
29 * CONSTANTS AND MACROS
33 * Scaling factor for integer priority calculations
35 #define cma__c_prio_scale 8
37 #if _CMA_VENDOR_ == _CMA__APOLLO
39 * FIX-ME: Apollo cc 6.8 blows contant folded "<<" and ">>"
41 # define cma__scale_up(exp) ((exp) * 256)
42 # define cma__scale_dn(exp) ((exp) / 256)
44 # define cma__scale_up(exp) ((exp) << cma__c_prio_scale)
45 # define cma__scale_dn(exp) ((exp) >> cma__c_prio_scale)
50 * Min. num. of ticks between self-adjustments for priority adjusting policies.
52 #define cma__c_prio_interval 10
56 * Number of queues in each class of queues
58 #define cma__c_prio_n_id 1 /* Very-low-priority class threads */
59 #define cma__c_prio_n_bg 8 /* Background class threads */
60 #define cma__c_prio_n_0 1 /* Very low priority throughput quartile */
61 #define cma__c_prio_n_1 2 /* Low priority throughput quartile */
62 #define cma__c_prio_n_2 3 /* Medium priority throughput quartile */
63 #define cma__c_prio_n_3 4 /* High priority throughput quartile */
64 #define cma__c_prio_n_rt 1 /* Real Time priority queues */
67 * Number of queues to skip (offset) to get to the queues in this section of LA
69 #define cma__c_prio_o_id 0
70 #define cma__c_prio_o_bg cma__c_prio_o_id + cma__c_prio_n_id
71 #define cma__c_prio_o_0 cma__c_prio_o_bg + cma__c_prio_n_bg
72 #define cma__c_prio_o_1 cma__c_prio_o_0 + cma__c_prio_n_0
73 #define cma__c_prio_o_2 cma__c_prio_o_1 + cma__c_prio_n_1
74 #define cma__c_prio_o_3 cma__c_prio_o_2 + cma__c_prio_n_2
75 #define cma__c_prio_o_rt cma__c_prio_o_3 + cma__c_prio_n_3
78 * Ada_low: These threads are queued in the background queues, thus there
79 * must be enough queues to allow one queue for each Ada priority below the
82 #define cma__c_prio_o_al cma__c_prio_o_bg
85 * Total number of ready queues, for declaration purposes
87 #define cma__c_prio_n_tot \
88 cma__c_prio_n_id + cma__c_prio_n_bg + cma__c_prio_n_rt \
89 + cma__c_prio_n_0 + cma__c_prio_n_1 + cma__c_prio_n_2 + cma__c_prio_n_3
92 * Formulae for determining a thread's priority. Variable priorities (such
93 * as foreground and background) are scaled values.
95 #define cma__sched_priority(tcb) \
96 ((tcb)->sched.class == cma__c_class_fore ? cma__sched_prio_fore (tcb) \
97 :((tcb)->sched.class == cma__c_class_back ? cma__sched_prio_back (tcb) \
98 :((tcb)->sched.class == cma__c_class_rt ? cma__sched_prio_rt (tcb) \
99 :((tcb)->sched.class == cma__c_class_idle ? cma__sched_prio_idle (tcb) \
100 :(cma__bugcheck ("cma__sched_priority: unrecognized class"), 0) ))))
102 #define cma__sched_prio_fore(tcb) cma__sched_prio_fore_var (tcb)
103 #define cma__sched_prio_back(tcb) ((tcb)->sched.fixed_prio \
104 ? cma__sched_prio_back_fix (tcb) : cma__sched_prio_back_var (tcb) )
105 #define cma__sched_prio_rt(tcb) ((tcb)->sched.priority)
106 #define cma__sched_prio_idle(tcb) ((tcb)->sched.priority)
108 #define cma__sched_prio_back_fix(tcb) \
109 (cma__g_prio_bg_min + (cma__g_prio_bg_max - cma__g_prio_bg_min) \
110 * ((tcb)->sched.priority + cma__c_prio_o_al - cma__c_prio_o_bg) \
114 * FIX-ME: Enable after modeling (if we like it)
117 # define cma__sched_prio_fore_var(tcb) \
118 ((cma__g_prio_fg_max + cma__g_prio_fg_min)/2)
119 # define cma__sched_prio_back_var(tcb) \
120 ((cma__g_prio_bg_max + cma__g_prio_bg_min)/2)
122 # define cma__sched_prio_back_var(tcb) cma__sched_prio_fore_var (tcb)
126 * Re-scale, since the division removes the scale factor.
127 * Scale and multiply before dividing to avoid loss of precision.
129 # define cma__sched_prio_fore_var(tcb) \
130 ((cma__g_vp_count * cma__scale_up((tcb)->sched.tot_time)) \
131 / (tcb)->sched.cpu_time)
134 * Re-scale, since the division removes the scale factor.
135 * Scale and multiply before dividing to avoid loss of precision.
136 * Left shift the numerator to multiply by two.
138 # define cma__sched_prio_fore_var(tcb) \
139 (((cma__g_vp_count * cma__scale_up((tcb)->sched.tot_time) \
140 * (tcb)->sched.priority * cma__g_init_frac_sum) << 1) \
141 / ((tcb)->sched.cpu_time * (tcb)->sched.priority * cma__g_init_frac_sum \
142 + (tcb)->sched.tot_time))
147 * Update weighted-averaged, scaled tick counters
149 #define cma__sched_update_time(ave, new) \
150 (ave) = (ave) - ((cma__scale_dn((ave)) - (new)) << (cma__c_prio_scale - 4))
152 #define cma__sched_parameterize(tcb, policy) { \
154 case cma_c_sched_fifo : { \
155 (tcb)->sched.rtb = cma_c_true; \
156 (tcb)->sched.spp = cma_c_true; \
157 (tcb)->sched.fixed_prio = cma_c_true; \
158 (tcb)->sched.class = cma__c_class_rt; \
161 case cma_c_sched_rr : { \
162 (tcb)->sched.rtb = cma_c_false; \
163 (tcb)->sched.spp = cma_c_true; \
164 (tcb)->sched.fixed_prio = cma_c_true; \
165 (tcb)->sched.class = cma__c_class_rt; \
168 case cma_c_sched_throughput : { \
169 (tcb)->sched.rtb = cma_c_false; \
170 (tcb)->sched.spp = cma_c_false; \
171 (tcb)->sched.fixed_prio = cma_c_false; \
172 (tcb)->sched.class = cma__c_class_fore; \
175 case cma_c_sched_background : { \
176 (tcb)->sched.rtb = cma_c_false; \
177 (tcb)->sched.spp = cma_c_false; \
178 (tcb)->sched.fixed_prio = cma_c_false; \
179 (tcb)->sched.class = cma__c_class_back; \
182 case cma_c_sched_ada_low : { \
183 (tcb)->sched.rtb = cma_c_false; \
184 (tcb)->sched.spp = cma_c_true; \
185 (tcb)->sched.fixed_prio = cma_c_true; \
186 (tcb)->sched.class = cma__c_class_back; \
189 case cma_c_sched_idle : { \
190 (tcb)->sched.rtb = cma_c_false; \
191 (tcb)->sched.spp = cma_c_false; \
192 (tcb)->sched.fixed_prio = cma_c_false; \
193 (tcb)->sched.class = cma__c_class_idle; \
197 cma__bugcheck ("cma__sched_parameterize: bad scheduling Policy"); \
210 typedef enum CMA__T_SCHED_CLASS
{
215 } cma__t_sched_class
;
222 * Minimuma and maximum prioirities, for foreground and background threads,
223 * as of the last time the scheduler ran. (Scaled once.)
225 extern cma_t_integer cma__g_prio_fg_min
;
226 extern cma_t_integer cma__g_prio_fg_max
;
227 extern cma_t_integer cma__g_prio_bg_min
;
228 extern cma_t_integer cma__g_prio_bg_max
;
231 * The "m" values are the slopes of the four sections of linear approximation.
233 * cma__g_prio_m_I = 4*N(I)/cma__g_prio_range (Scaled once.)
235 extern cma_t_integer cma__g_prio_m_0
,
241 * The "b" values are the intercepts of the four sections of linear approx.
244 * cma__g_prio_b_I = -N(I)*(I*prio_max + (4-I)*prio_min)/prio_range + prio_o_I
246 extern cma_t_integer cma__g_prio_b_0
,
252 * The "p" values are the end points of the four sections of linear approx.
254 * cma__g_prio_p_I = cma__g_prio_fg_min + (I/4)*cma__g_prio_range
256 * [cma__g_prio_p_0 is not defined since it is not used (also, it is the same
257 * as cma__g_prio_fg_min).] (Scaled once.)
259 extern cma_t_integer cma__g_prio_p_1
,
264 * Points to the next queue for the dispatcher to check for ready threads.
266 extern cma_t_integer cma__g_next_ready_queue
;
269 * Points to the queues of virtual processors (for preempt victim search)
271 extern cma__t_queue cma__g_run_vps
;
272 extern cma__t_queue cma__g_susp_vps
;
273 extern cma_t_integer cma__g_vp_count
;
276 * INTERNAL INTERFACES