|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Mach Operating System
27: * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28: * All Rights Reserved.
29: *
30: * Permission to use, copy, modify and distribute this software and its
31: * documentation is hereby granted, provided that both the copyright
32: * notice and this permission notice appear in all copies of the
33: * software, derivative works or modified versions, and any portions
34: * thereof, and that both notices appear in supporting documentation.
35: *
36: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39: *
40: * Carnegie Mellon requests users of this software to return to
41: *
42: * Software Distribution Coordinator or [email protected]
43: * School of Computer Science
44: * Carnegie Mellon University
45: * Pittsburgh PA 15213-3890
46: *
47: * any improvements or extensions that they make and grant Carnegie Mellon
48: * the rights to redistribute these changes.
49: */
50: /*
51: * File: kern/mach_factor.c
52: * Author: Avadis Tevanian, Jr.
53: * Date: 1986
54: *
55: * Compute the Mach Factor.
56: */
57:
58: #include <cpus.h>
59:
60: #include <mach/machine.h>
61: #include <mach/processor_info.h>
62: #include <kern/sched.h>
63: #include <kern/processor.h>
64: #include <kern/time_out.h>
65:
66: long avenrun[3] = {0, 0, 0};
67: long mach_factor[3] = {0, 0, 0};
68:
69: /*
70: * Values are scaled by LOAD_SCALE, defined in processor_info.h
71: */
72: static long fract[3] = {
73: 800, /* (4.0/5.0) 5 second average */
74: 966, /* (29.0/30.0) 30 second average */
75: 983, /* (59.0/60.) 1 minute average */
76: };
77:
78: void compute_mach_factor()
79: {
80: register processor_set_t pset;
81: register processor_t processor;
82: register int ncpus;
83: register int nthreads;
84: register long factor_now;
85: register long average_now;
86: register long load_now;
87:
88: simple_lock(&all_psets_lock);
89: pset = (processor_set_t) queue_first(&all_psets);
90: while (!queue_end(&all_psets, (queue_entry_t)pset)) {
91:
92: /*
93: * If no processors, this pset is in suspended animation.
94: * No load calculations are performed.
95: */
96: pset_lock(pset);
97: if((ncpus = pset->processor_count) > 0) {
98:
99: /*
100: * Count number of threads.
101: */
102: nthreads = pset->runq.count;
103: processor = (processor_t) queue_first(&pset->processors);
104: while (!queue_end(&pset->processors,
105: (queue_entry_t)processor)) {
106: nthreads += processor->runq.count;
107: processor =
108: (processor_t) queue_next(&processor->processors);
109: }
110:
111: /*
112: * account for threads on cpus.
113: */
114: nthreads += ncpus - pset->idle_count;
115:
116: /*
117: * The current thread (running this calculation)
118: * doesn't count; it's always in the default pset.
119: */
120: if (pset == &default_pset)
121: nthreads -= 1;
122:
123: if (nthreads > ncpus) {
124: factor_now = (ncpus * LOAD_SCALE) / (nthreads + 1);
125: load_now = (nthreads << SCHED_SHIFT) / ncpus;
126: }
127: else {
128: factor_now = (ncpus - nthreads) * LOAD_SCALE;
129: load_now = SCHED_SCALE;
130: }
131:
132: /*
133: * Load average and mach factor calculations for
134: * those that ask about these things.
135: */
136:
137: average_now = nthreads * LOAD_SCALE;
138:
139: pset->mach_factor =
140: ((pset->mach_factor << 2) + factor_now)/5;
141: pset->load_average =
142: ((pset->load_average << 2) + average_now)/5;
143:
144: /*
145: * And some ugly stuff to keep w happy.
146: */
147: if (pset == &default_pset) {
148: register int i;
149:
150: for (i = 0; i < 3; i++) {
151: mach_factor[i] = ( (mach_factor[i]*fract[i])
152: + (factor_now*(LOAD_SCALE-fract[i])) )
153: / LOAD_SCALE;
154: avenrun[i] = ( (avenrun[i]*fract[i])
155: + (average_now*(LOAD_SCALE-fract[i])) )
156: / LOAD_SCALE;
157: }
158: }
159:
160: /*
161: * sched_load is the only thing used by scheduler.
162: * It is always at least 1 (i.e. SCHED_SCALE).
163: */
164: pset->sched_load = (pset->sched_load + load_now) >> 1;
165: }
166:
167: pset_unlock(pset);
168: pset = (processor_set_t) queue_next(&pset->all_psets);
169: }
170:
171: simple_unlock(&all_psets_lock);
172: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.