]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
b0d623f7 | 2 | * Copyright (c) 2000-2009 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
8f6c56a5 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | ||
59 | /* | |
60 | * host.c | |
61 | * | |
62 | * Non-ipc host functions. | |
63 | */ | |
64 | ||
91447636 | 65 | #include <mach/mach_types.h> |
1c79356b | 66 | #include <mach/boolean.h> |
1c79356b | 67 | #include <mach/host_info.h> |
55e303ae | 68 | #include <mach/host_special_ports.h> |
1c79356b A |
69 | #include <mach/kern_return.h> |
70 | #include <mach/machine.h> | |
71 | #include <mach/port.h> | |
1c79356b A |
72 | #include <mach/processor_info.h> |
73 | #include <mach/vm_param.h> | |
91447636 | 74 | #include <mach/processor.h> |
1c79356b | 75 | #include <mach/mach_host_server.h> |
91447636 A |
76 | #include <mach/host_priv_server.h> |
77 | #include <mach/vm_map.h> | |
78 | ||
79 | #include <kern/kern_types.h> | |
80 | #include <kern/assert.h> | |
81 | #include <kern/kalloc.h> | |
82 | #include <kern/host.h> | |
83 | #include <kern/host_statistics.h> | |
84 | #include <kern/ipc_host.h> | |
85 | #include <kern/misc_protos.h> | |
86 | #include <kern/sched.h> | |
87 | #include <kern/processor.h> | |
88 | ||
89 | #include <vm/vm_map.h> | |
90 | ||
1c79356b A |
91 | host_data_t realhost; |
92 | ||
6d2010ae A |
93 | vm_extmod_statistics_data_t host_extmod_statistics; |
94 | ||
1c79356b A |
95 | kern_return_t |
96 | host_processors( | |
91447636 A |
97 | host_priv_t host_priv, |
98 | processor_array_t *out_array, | |
1c79356b A |
99 | mach_msg_type_number_t *countp) |
100 | { | |
91447636 A |
101 | register processor_t processor, *tp; |
102 | void *addr; | |
103 | unsigned int count, i; | |
1c79356b A |
104 | |
105 | if (host_priv == HOST_PRIV_NULL) | |
91447636 | 106 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
107 | |
108 | assert(host_priv == &realhost); | |
109 | ||
91447636 A |
110 | count = processor_count; |
111 | assert(count != 0); | |
1c79356b A |
112 | |
113 | addr = kalloc((vm_size_t) (count * sizeof(mach_port_t))); | |
114 | if (addr == 0) | |
91447636 | 115 | return (KERN_RESOURCE_SHORTAGE); |
1c79356b A |
116 | |
117 | tp = (processor_t *) addr; | |
91447636 A |
118 | *tp++ = processor = processor_list; |
119 | ||
120 | if (count > 1) { | |
121 | simple_lock(&processor_list_lock); | |
122 | ||
123 | for (i = 1; i < count; i++) | |
124 | *tp++ = processor = processor->processor_list; | |
125 | ||
126 | simple_unlock(&processor_list_lock); | |
127 | } | |
1c79356b A |
128 | |
129 | *countp = count; | |
91447636 | 130 | *out_array = (processor_array_t)addr; |
1c79356b A |
131 | |
132 | /* do the conversion that Mig should handle */ | |
133 | ||
134 | tp = (processor_t *) addr; | |
135 | for (i = 0; i < count; i++) | |
136 | ((mach_port_t *) tp)[i] = | |
137 | (mach_port_t)convert_processor_to_port(tp[i]); | |
138 | ||
91447636 | 139 | return (KERN_SUCCESS); |
1c79356b A |
140 | } |
141 | ||
142 | kern_return_t | |
143 | host_info( | |
144 | host_t host, | |
145 | host_flavor_t flavor, | |
146 | host_info_t info, | |
147 | mach_msg_type_number_t *count) | |
148 | { | |
149 | ||
150 | if (host == HOST_NULL) | |
91447636 | 151 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 152 | |
91447636 | 153 | switch (flavor) { |
1c79356b A |
154 | |
155 | case HOST_BASIC_INFO: | |
156 | { | |
157 | register host_basic_info_t basic_info; | |
b0d623f7 | 158 | register int master_id; |
1c79356b A |
159 | |
160 | /* | |
161 | * Basic information about this host. | |
162 | */ | |
91447636 A |
163 | if (*count < HOST_BASIC_INFO_OLD_COUNT) |
164 | return (KERN_FAILURE); | |
1c79356b A |
165 | |
166 | basic_info = (host_basic_info_t) info; | |
167 | ||
1c79356b | 168 | basic_info->memory_size = machine_info.memory_size; |
2d21ac55 A |
169 | basic_info->max_cpus = machine_info.max_cpus; |
170 | basic_info->avail_cpus = processor_avail_count; | |
b0d623f7 A |
171 | master_id = master_processor->cpu_id; |
172 | basic_info->cpu_type = slot_type(master_id); | |
173 | basic_info->cpu_subtype = slot_subtype(master_id); | |
91447636 A |
174 | |
175 | if (*count >= HOST_BASIC_INFO_COUNT) { | |
b0d623f7 | 176 | basic_info->cpu_threadtype = slot_threadtype(master_id); |
91447636 A |
177 | basic_info->physical_cpu = machine_info.physical_cpu; |
178 | basic_info->physical_cpu_max = machine_info.physical_cpu_max; | |
179 | basic_info->logical_cpu = machine_info.logical_cpu; | |
180 | basic_info->logical_cpu_max = machine_info.logical_cpu_max; | |
181 | basic_info->max_mem = machine_info.max_mem; | |
182 | ||
183 | *count = HOST_BASIC_INFO_COUNT; | |
184 | } else { | |
185 | *count = HOST_BASIC_INFO_OLD_COUNT; | |
186 | } | |
1c79356b | 187 | |
91447636 | 188 | return (KERN_SUCCESS); |
1c79356b A |
189 | } |
190 | ||
191 | case HOST_SCHED_INFO: | |
192 | { | |
193 | register host_sched_info_t sched_info; | |
6d2010ae A |
194 | uint32_t quantum_time; |
195 | uint64_t quantum_ns; | |
1c79356b A |
196 | |
197 | /* | |
198 | * Return scheduler information. | |
199 | */ | |
200 | if (*count < HOST_SCHED_INFO_COUNT) | |
91447636 | 201 | return (KERN_FAILURE); |
1c79356b A |
202 | |
203 | sched_info = (host_sched_info_t) info; | |
204 | ||
6d2010ae A |
205 | quantum_time = SCHED(initial_quantum_size)(THREAD_NULL); |
206 | absolutetime_to_nanoseconds(quantum_time, &quantum_ns); | |
207 | ||
91447636 | 208 | sched_info->min_timeout = |
6d2010ae | 209 | sched_info->min_quantum = (uint32_t)(quantum_ns / 1000 / 1000); |
1c79356b A |
210 | |
211 | *count = HOST_SCHED_INFO_COUNT; | |
212 | ||
91447636 | 213 | return (KERN_SUCCESS); |
1c79356b A |
214 | } |
215 | ||
216 | case HOST_RESOURCE_SIZES: | |
217 | { | |
218 | /* | |
219 | * Return sizes of kernel data structures | |
220 | */ | |
221 | if (*count < HOST_RESOURCE_SIZES_COUNT) | |
91447636 | 222 | return (KERN_FAILURE); |
1c79356b A |
223 | |
224 | /* XXX Fail until ledgers are implemented */ | |
91447636 | 225 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
226 | } |
227 | ||
228 | case HOST_PRIORITY_INFO: | |
229 | { | |
230 | register host_priority_info_t priority_info; | |
231 | ||
232 | if (*count < HOST_PRIORITY_INFO_COUNT) | |
91447636 | 233 | return (KERN_FAILURE); |
1c79356b A |
234 | |
235 | priority_info = (host_priority_info_t) info; | |
236 | ||
0b4e3aa0 A |
237 | priority_info->kernel_priority = MINPRI_KERNEL; |
238 | priority_info->system_priority = MINPRI_KERNEL; | |
91447636 | 239 | priority_info->server_priority = MINPRI_RESERVED; |
1c79356b A |
240 | priority_info->user_priority = BASEPRI_DEFAULT; |
241 | priority_info->depress_priority = DEPRESSPRI; | |
242 | priority_info->idle_priority = IDLEPRI; | |
91447636 A |
243 | priority_info->minimum_priority = MINPRI_USER; |
244 | priority_info->maximum_priority = MAXPRI_RESERVED; | |
1c79356b A |
245 | |
246 | *count = HOST_PRIORITY_INFO_COUNT; | |
247 | ||
91447636 | 248 | return (KERN_SUCCESS); |
1c79356b A |
249 | } |
250 | ||
251 | /* | |
9bccf70c | 252 | * Gestalt for various trap facilities. |
1c79356b | 253 | */ |
9bccf70c | 254 | case HOST_MACH_MSG_TRAP: |
1c79356b A |
255 | case HOST_SEMAPHORE_TRAPS: |
256 | { | |
257 | *count = 0; | |
91447636 | 258 | return (KERN_SUCCESS); |
1c79356b A |
259 | } |
260 | ||
261 | default: | |
91447636 | 262 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
263 | } |
264 | } | |
265 | ||
266 | kern_return_t | |
267 | host_statistics( | |
91447636 A |
268 | host_t host, |
269 | host_flavor_t flavor, | |
270 | host_info_t info, | |
1c79356b A |
271 | mach_msg_type_number_t *count) |
272 | { | |
b0d623f7 | 273 | uint32_t i; |
1c79356b A |
274 | |
275 | if (host == HOST_NULL) | |
91447636 | 276 | return (KERN_INVALID_HOST); |
1c79356b A |
277 | |
278 | switch(flavor) { | |
279 | ||
91447636 A |
280 | case HOST_LOAD_INFO: |
281 | { | |
282 | host_load_info_t load_info; | |
1c79356b A |
283 | |
284 | if (*count < HOST_LOAD_INFO_COUNT) | |
91447636 | 285 | return (KERN_FAILURE); |
1c79356b A |
286 | |
287 | load_info = (host_load_info_t) info; | |
288 | ||
289 | bcopy((char *) avenrun, | |
91447636 | 290 | (char *) load_info->avenrun, sizeof avenrun); |
1c79356b | 291 | bcopy((char *) mach_factor, |
91447636 | 292 | (char *) load_info->mach_factor, sizeof mach_factor); |
1c79356b A |
293 | |
294 | *count = HOST_LOAD_INFO_COUNT; | |
91447636 A |
295 | return (KERN_SUCCESS); |
296 | } | |
297 | ||
298 | case HOST_VM_INFO: | |
299 | { | |
300 | register processor_t processor; | |
b0d623f7 A |
301 | register vm_statistics64_t stat; |
302 | vm_statistics64_data_t host_vm_stat; | |
303 | vm_statistics_t stat32; | |
2d21ac55 | 304 | mach_msg_type_number_t original_count; |
1c79356b | 305 | |
91447636 A |
306 | if (*count < HOST_VM_INFO_REV0_COUNT) |
307 | return (KERN_FAILURE); | |
1c79356b | 308 | |
91447636 A |
309 | processor = processor_list; |
310 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
1c79356b | 311 | host_vm_stat = *stat; |
91447636 A |
312 | |
313 | if (processor_count > 1) { | |
314 | simple_lock(&processor_list_lock); | |
315 | ||
316 | while ((processor = processor->processor_list) != NULL) { | |
317 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
318 | ||
319 | host_vm_stat.zero_fill_count += stat->zero_fill_count; | |
320 | host_vm_stat.reactivations += stat->reactivations; | |
1c79356b A |
321 | host_vm_stat.pageins += stat->pageins; |
322 | host_vm_stat.pageouts += stat->pageouts; | |
323 | host_vm_stat.faults += stat->faults; | |
324 | host_vm_stat.cow_faults += stat->cow_faults; | |
325 | host_vm_stat.lookups += stat->lookups; | |
326 | host_vm_stat.hits += stat->hits; | |
327 | } | |
91447636 A |
328 | |
329 | simple_unlock(&processor_list_lock); | |
1c79356b | 330 | } |
1c79356b | 331 | |
b0d623f7 A |
332 | stat32 = (vm_statistics_t) info; |
333 | ||
334 | stat32->free_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_free_count + vm_page_speculative_count); | |
335 | stat32->active_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_active_count); | |
336 | ||
337 | if (vm_page_local_q) { | |
338 | for (i = 0; i < vm_page_local_q_count; i++) { | |
339 | struct vpl *lq; | |
340 | ||
341 | lq = &vm_page_local_q[i].vpl_un.vpl; | |
342 | ||
343 | stat32->active_count += VM_STATISTICS_TRUNCATE_TO_32_BIT(lq->vpl_count); | |
344 | } | |
345 | } | |
346 | stat32->inactive_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_inactive_count); | |
347 | #if CONFIG_EMBEDDED | |
348 | stat32->wire_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_wire_count); | |
349 | #else | |
0b4c1975 | 350 | stat32->wire_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_wire_count + vm_page_throttled_count + vm_lopage_free_count); |
b0d623f7 A |
351 | #endif |
352 | stat32->zero_fill_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.zero_fill_count); | |
353 | stat32->reactivations = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.reactivations); | |
354 | stat32->pageins = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.pageins); | |
355 | stat32->pageouts = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.pageouts); | |
356 | stat32->faults = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.faults); | |
357 | stat32->cow_faults = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.cow_faults); | |
358 | stat32->lookups = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.lookups); | |
359 | stat32->hits = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.hits); | |
91447636 | 360 | |
2d21ac55 A |
361 | /* |
362 | * Fill in extra info added in later revisions of the | |
363 | * vm_statistics data structure. Fill in only what can fit | |
364 | * in the data structure the caller gave us ! | |
365 | */ | |
366 | original_count = *count; | |
367 | *count = HOST_VM_INFO_REV0_COUNT; /* rev0 already filled in */ | |
368 | if (original_count >= HOST_VM_INFO_REV1_COUNT) { | |
369 | /* rev1 added "purgeable" info */ | |
b0d623f7 A |
370 | stat32->purgeable_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_purgeable_count); |
371 | stat32->purges = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_purged_count); | |
2d21ac55 A |
372 | *count = HOST_VM_INFO_REV1_COUNT; |
373 | } | |
b0d623f7 | 374 | |
2d21ac55 A |
375 | if (original_count >= HOST_VM_INFO_REV2_COUNT) { |
376 | /* rev2 added "speculative" info */ | |
b0d623f7 | 377 | stat32->speculative_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_speculative_count); |
2d21ac55 | 378 | *count = HOST_VM_INFO_REV2_COUNT; |
91447636 A |
379 | } |
380 | ||
b0d623f7 A |
381 | /* rev3 changed some of the fields to be 64-bit*/ |
382 | ||
91447636 A |
383 | return (KERN_SUCCESS); |
384 | } | |
1c79356b | 385 | |
91447636 A |
386 | case HOST_CPU_LOAD_INFO: |
387 | { | |
388 | register processor_t processor; | |
1c79356b | 389 | host_cpu_load_info_t cpu_load_info; |
1c79356b A |
390 | |
391 | if (*count < HOST_CPU_LOAD_INFO_COUNT) | |
91447636 A |
392 | return (KERN_FAILURE); |
393 | ||
b0d623f7 A |
394 | #define GET_TICKS_VALUE(processor, state, timer) \ |
395 | MACRO_BEGIN \ | |
396 | cpu_load_info->cpu_ticks[(state)] += \ | |
397 | (uint32_t)(timer_grab(&PROCESSOR_DATA(processor, timer)) \ | |
398 | / hz_tick_interval); \ | |
91447636 | 399 | MACRO_END |
1c79356b | 400 | |
91447636 | 401 | cpu_load_info = (host_cpu_load_info_t)info; |
1c79356b | 402 | cpu_load_info->cpu_ticks[CPU_STATE_USER] = 0; |
1c79356b A |
403 | cpu_load_info->cpu_ticks[CPU_STATE_SYSTEM] = 0; |
404 | cpu_load_info->cpu_ticks[CPU_STATE_IDLE] = 0; | |
2d21ac55 | 405 | cpu_load_info->cpu_ticks[CPU_STATE_NICE] = 0; |
91447636 | 406 | |
6d2010ae | 407 | simple_lock(&processor_list_lock); |
91447636 | 408 | |
6d2010ae A |
409 | for (processor = processor_list; processor != NULL; processor = processor->processor_list) { |
410 | timer_data_t idle_temp; | |
411 | timer_t idle_state; | |
91447636 | 412 | |
6d2010ae | 413 | GET_TICKS_VALUE(processor, CPU_STATE_USER, user_state); |
316670eb A |
414 | if (precise_user_kernel_time) { |
415 | GET_TICKS_VALUE(processor, CPU_STATE_SYSTEM, system_state); | |
416 | } else { | |
417 | /* system_state may represent either sys or user */ | |
418 | GET_TICKS_VALUE(processor, CPU_STATE_USER, system_state); | |
419 | } | |
6d2010ae A |
420 | |
421 | idle_state = &PROCESSOR_DATA(processor, idle_state); | |
422 | idle_temp = *idle_state; | |
423 | ||
424 | if (PROCESSOR_DATA(processor, current_state) != idle_state || | |
425 | timer_grab(&idle_temp) != timer_grab(idle_state)) | |
2d21ac55 | 426 | GET_TICKS_VALUE(processor, CPU_STATE_IDLE, idle_state); |
6d2010ae A |
427 | else { |
428 | timer_advance(&idle_temp, mach_absolute_time() - idle_temp.tstamp); | |
91447636 | 429 | |
6d2010ae A |
430 | cpu_load_info->cpu_ticks[CPU_STATE_IDLE] += |
431 | (uint32_t)(timer_grab(&idle_temp) / hz_tick_interval); | |
432 | } | |
1c79356b | 433 | } |
6d2010ae | 434 | simple_unlock(&processor_list_lock); |
316670eb | 435 | |
1c79356b | 436 | *count = HOST_CPU_LOAD_INFO_COUNT; |
91447636 A |
437 | |
438 | return (KERN_SUCCESS); | |
439 | } | |
1c79356b A |
440 | |
441 | default: | |
91447636 | 442 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
443 | } |
444 | } | |
445 | ||
b0d623f7 A |
446 | |
447 | kern_return_t | |
448 | host_statistics64( | |
449 | host_t host, | |
450 | host_flavor_t flavor, | |
451 | host_info64_t info, | |
452 | mach_msg_type_number_t *count) | |
453 | { | |
454 | uint32_t i; | |
455 | ||
456 | if (host == HOST_NULL) | |
457 | return (KERN_INVALID_HOST); | |
458 | ||
459 | switch(flavor) { | |
460 | ||
461 | case HOST_VM_INFO64: /* We were asked to get vm_statistics64 */ | |
462 | { | |
463 | register processor_t processor; | |
464 | register vm_statistics64_t stat; | |
465 | vm_statistics64_data_t host_vm_stat; | |
466 | ||
467 | if (*count < HOST_VM_INFO64_COUNT) | |
468 | return (KERN_FAILURE); | |
469 | ||
470 | processor = processor_list; | |
471 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
472 | host_vm_stat = *stat; | |
473 | ||
474 | if (processor_count > 1) { | |
475 | simple_lock(&processor_list_lock); | |
476 | ||
477 | while ((processor = processor->processor_list) != NULL) { | |
478 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
479 | ||
480 | host_vm_stat.zero_fill_count += stat->zero_fill_count; | |
481 | host_vm_stat.reactivations += stat->reactivations; | |
482 | host_vm_stat.pageins += stat->pageins; | |
483 | host_vm_stat.pageouts += stat->pageouts; | |
484 | host_vm_stat.faults += stat->faults; | |
485 | host_vm_stat.cow_faults += stat->cow_faults; | |
486 | host_vm_stat.lookups += stat->lookups; | |
487 | host_vm_stat.hits += stat->hits; | |
488 | } | |
489 | ||
490 | simple_unlock(&processor_list_lock); | |
491 | } | |
492 | ||
493 | stat = (vm_statistics64_t) info; | |
494 | ||
495 | stat->free_count = vm_page_free_count + vm_page_speculative_count; | |
496 | stat->active_count = vm_page_active_count; | |
497 | ||
498 | if (vm_page_local_q) { | |
499 | for (i = 0; i < vm_page_local_q_count; i++) { | |
500 | struct vpl *lq; | |
501 | ||
502 | lq = &vm_page_local_q[i].vpl_un.vpl; | |
503 | ||
504 | stat->active_count += lq->vpl_count; | |
505 | } | |
506 | } | |
507 | stat->inactive_count = vm_page_inactive_count; | |
508 | #if CONFIG_EMBEDDED | |
509 | stat->wire_count = vm_page_wire_count; | |
510 | #else | |
0b4c1975 | 511 | stat->wire_count = vm_page_wire_count + vm_page_throttled_count + vm_lopage_free_count; |
b0d623f7 A |
512 | #endif |
513 | stat->zero_fill_count = host_vm_stat.zero_fill_count; | |
514 | stat->reactivations = host_vm_stat.reactivations; | |
515 | stat->pageins = host_vm_stat.pageins; | |
516 | stat->pageouts = host_vm_stat.pageouts; | |
517 | stat->faults = host_vm_stat.faults; | |
518 | stat->cow_faults = host_vm_stat.cow_faults; | |
519 | stat->lookups = host_vm_stat.lookups; | |
520 | stat->hits = host_vm_stat.hits; | |
521 | ||
522 | /* rev1 added "purgable" info */ | |
523 | stat->purgeable_count = vm_page_purgeable_count; | |
524 | stat->purges = vm_page_purged_count; | |
525 | ||
526 | /* rev2 added "speculative" info */ | |
527 | stat->speculative_count = vm_page_speculative_count; | |
528 | ||
529 | *count = HOST_VM_INFO64_COUNT; | |
530 | ||
531 | return(KERN_SUCCESS); | |
532 | } | |
533 | ||
6d2010ae A |
534 | case HOST_EXTMOD_INFO64: /* We were asked to get vm_statistics64 */ |
535 | { | |
536 | vm_extmod_statistics_t out_extmod_statistics; | |
537 | ||
538 | if (*count < HOST_EXTMOD_INFO64_COUNT) | |
539 | return (KERN_FAILURE); | |
540 | ||
541 | out_extmod_statistics = (vm_extmod_statistics_t) info; | |
542 | *out_extmod_statistics = host_extmod_statistics; | |
543 | ||
544 | *count = HOST_EXTMOD_INFO64_COUNT; | |
545 | ||
546 | return(KERN_SUCCESS); | |
547 | } | |
548 | ||
b0d623f7 A |
549 | default: /* If we didn't recognize the flavor, send to host_statistics */ |
550 | return(host_statistics(host, flavor, (host_info_t) info, count)); | |
551 | } | |
552 | } | |
553 | ||
554 | ||
1c79356b A |
555 | /* |
556 | * Get host statistics that require privilege. | |
557 | * None for now, just call the un-privileged version. | |
558 | */ | |
559 | kern_return_t | |
560 | host_priv_statistics( | |
561 | host_priv_t host_priv, | |
562 | host_flavor_t flavor, | |
563 | host_info_t info, | |
564 | mach_msg_type_number_t *count) | |
565 | { | |
566 | return(host_statistics((host_t)host_priv, flavor, info, count)); | |
567 | } | |
568 | ||
6d2010ae A |
569 | kern_return_t |
570 | set_sched_stats_active( | |
571 | boolean_t active) | |
572 | { | |
573 | sched_stats_active = active; | |
574 | return KERN_SUCCESS; | |
575 | } | |
576 | ||
577 | ||
578 | kern_return_t | |
579 | get_sched_statistics( | |
580 | struct _processor_statistics_np *out, | |
581 | uint32_t *count) | |
582 | { | |
583 | processor_t processor; | |
584 | ||
585 | if (!sched_stats_active) { | |
586 | return KERN_FAILURE; | |
587 | } | |
588 | ||
589 | simple_lock(&processor_list_lock); | |
590 | ||
591 | if (*count < (processor_count + 2) * sizeof(struct _processor_statistics_np)) { /* One for RT, one for FS */ | |
592 | simple_unlock(&processor_list_lock); | |
593 | return KERN_FAILURE; | |
594 | } | |
595 | ||
596 | processor = processor_list; | |
597 | while (processor) { | |
598 | struct processor_sched_statistics *stats = &processor->processor_data.sched_stats; | |
599 | ||
600 | out->ps_cpuid = processor->cpu_id; | |
601 | out->ps_csw_count = stats->csw_count; | |
602 | out->ps_preempt_count = stats->preempt_count; | |
603 | out->ps_preempted_rt_count = stats->preempted_rt_count; | |
604 | out->ps_preempted_by_rt_count = stats->preempted_by_rt_count; | |
605 | out->ps_rt_sched_count = stats->rt_sched_count; | |
606 | out->ps_interrupt_count = stats->interrupt_count; | |
607 | out->ps_ipi_count = stats->ipi_count; | |
608 | out->ps_timer_pop_count = stats->timer_pop_count; | |
609 | out->ps_runq_count_sum = SCHED(processor_runq_stats_count_sum)(processor); | |
610 | out->ps_idle_transitions = stats->idle_transitions; | |
ebb1b9f4 | 611 | out->ps_quantum_timer_expirations = stats->quantum_timer_expirations; |
6d2010ae A |
612 | |
613 | out++; | |
614 | processor = processor->processor_list; | |
615 | } | |
616 | ||
617 | *count = (uint32_t) (processor_count * sizeof(struct _processor_statistics_np)); | |
618 | ||
619 | simple_unlock(&processor_list_lock); | |
620 | ||
621 | /* And include RT Queue information */ | |
622 | bzero(out, sizeof(*out)); | |
623 | out->ps_cpuid = (-1); | |
624 | out->ps_runq_count_sum = rt_runq.runq_stats.count_sum; | |
625 | out++; | |
626 | *count += (uint32_t)sizeof(struct _processor_statistics_np); | |
627 | ||
628 | /* And include Fair Share Queue information at the end */ | |
629 | bzero(out, sizeof(*out)); | |
630 | out->ps_cpuid = (-2); | |
631 | out->ps_runq_count_sum = SCHED(fairshare_runq_stats_count_sum)(); | |
632 | *count += (uint32_t)sizeof(struct _processor_statistics_np); | |
633 | ||
634 | return KERN_SUCCESS; | |
635 | } | |
636 | ||
1c79356b A |
637 | kern_return_t |
638 | host_page_size( | |
639 | host_t host, | |
640 | vm_size_t *out_page_size) | |
641 | { | |
642 | if (host == HOST_NULL) | |
643 | return(KERN_INVALID_ARGUMENT); | |
644 | ||
645 | *out_page_size = PAGE_SIZE; | |
646 | ||
647 | return(KERN_SUCCESS); | |
648 | } | |
649 | ||
650 | /* | |
651 | * Return kernel version string (more than you ever | |
652 | * wanted to know about what version of the kernel this is). | |
653 | */ | |
91447636 | 654 | extern char version[]; |
1c79356b A |
655 | |
656 | kern_return_t | |
657 | host_kernel_version( | |
658 | host_t host, | |
659 | kernel_version_t out_version) | |
660 | { | |
1c79356b A |
661 | |
662 | if (host == HOST_NULL) | |
663 | return(KERN_INVALID_ARGUMENT); | |
664 | ||
665 | (void) strncpy(out_version, version, sizeof(kernel_version_t)); | |
666 | ||
667 | return(KERN_SUCCESS); | |
668 | } | |
669 | ||
670 | /* | |
671 | * host_processor_sets: | |
672 | * | |
673 | * List all processor sets on the host. | |
674 | */ | |
675 | kern_return_t | |
676 | host_processor_sets( | |
677 | host_priv_t host_priv, | |
678 | processor_set_name_array_t *pset_list, | |
679 | mach_msg_type_number_t *count) | |
680 | { | |
91447636 | 681 | void *addr; |
1c79356b A |
682 | |
683 | if (host_priv == HOST_PRIV_NULL) | |
2d21ac55 | 684 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
685 | |
686 | /* | |
687 | * Allocate memory. Can be pageable because it won't be | |
688 | * touched while holding a lock. | |
689 | */ | |
690 | ||
691 | addr = kalloc((vm_size_t) sizeof(mach_port_t)); | |
692 | if (addr == 0) | |
2d21ac55 | 693 | return (KERN_RESOURCE_SHORTAGE); |
1c79356b | 694 | |
1c79356b | 695 | /* do the conversion that Mig should handle */ |
2d21ac55 | 696 | *((ipc_port_t *) addr) = convert_pset_name_to_port(&pset0); |
1c79356b A |
697 | |
698 | *pset_list = (processor_set_array_t)addr; | |
699 | *count = 1; | |
700 | ||
2d21ac55 | 701 | return (KERN_SUCCESS); |
1c79356b A |
702 | } |
703 | ||
704 | /* | |
705 | * host_processor_set_priv: | |
706 | * | |
707 | * Return control port for given processor set. | |
708 | */ | |
709 | kern_return_t | |
710 | host_processor_set_priv( | |
711 | host_priv_t host_priv, | |
712 | processor_set_t pset_name, | |
713 | processor_set_t *pset) | |
714 | { | |
2d21ac55 A |
715 | if (host_priv == HOST_PRIV_NULL || pset_name == PROCESSOR_SET_NULL) { |
716 | *pset = PROCESSOR_SET_NULL; | |
717 | ||
718 | return (KERN_INVALID_ARGUMENT); | |
1c79356b A |
719 | } |
720 | ||
721 | *pset = pset_name; | |
2d21ac55 A |
722 | |
723 | return (KERN_SUCCESS); | |
1c79356b A |
724 | } |
725 | ||
726 | /* | |
727 | * host_processor_info | |
728 | * | |
729 | * Return info about the processors on this host. It will return | |
730 | * the number of processors, and the specific type of info requested | |
731 | * in an OOL array. | |
732 | */ | |
733 | kern_return_t | |
734 | host_processor_info( | |
91447636 A |
735 | host_t host, |
736 | processor_flavor_t flavor, | |
737 | natural_t *out_pcount, | |
738 | processor_info_array_t *out_array, | |
739 | mach_msg_type_number_t *out_array_count) | |
1c79356b | 740 | { |
91447636 A |
741 | kern_return_t result; |
742 | processor_t processor; | |
743 | host_t thost; | |
744 | processor_info_t info; | |
745 | unsigned int icount, tcount; | |
746 | unsigned int pcount, i; | |
747 | vm_offset_t addr; | |
6601e61a | 748 | vm_size_t size, needed; |
91447636 | 749 | vm_map_copy_t copy; |
1c79356b A |
750 | |
751 | if (host == HOST_NULL) | |
91447636 | 752 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 753 | |
91447636 A |
754 | result = processor_info_count(flavor, &icount); |
755 | if (result != KERN_SUCCESS) | |
756 | return (result); | |
1c79356b | 757 | |
91447636 A |
758 | pcount = processor_count; |
759 | assert(pcount != 0); | |
1c79356b | 760 | |
6601e61a A |
761 | needed = pcount * icount * sizeof(natural_t); |
762 | size = round_page(needed); | |
91447636 A |
763 | result = kmem_alloc(ipc_kernel_map, &addr, size); |
764 | if (result != KERN_SUCCESS) | |
765 | return (KERN_RESOURCE_SHORTAGE); | |
766 | ||
767 | info = (processor_info_t) addr; | |
768 | processor = processor_list; | |
769 | tcount = icount; | |
1c79356b | 770 | |
91447636 A |
771 | result = processor_info(processor, flavor, &thost, info, &tcount); |
772 | if (result != KERN_SUCCESS) { | |
1c79356b | 773 | kmem_free(ipc_kernel_map, addr, size); |
91447636 | 774 | return (result); |
1c79356b A |
775 | } |
776 | ||
91447636 A |
777 | if (pcount > 1) { |
778 | for (i = 1; i < pcount; i++) { | |
779 | simple_lock(&processor_list_lock); | |
780 | processor = processor->processor_list; | |
781 | simple_unlock(&processor_list_lock); | |
782 | ||
783 | info += icount; | |
784 | tcount = icount; | |
785 | result = processor_info(processor, flavor, &thost, info, &tcount); | |
786 | if (result != KERN_SUCCESS) { | |
1c79356b | 787 | kmem_free(ipc_kernel_map, addr, size); |
91447636 | 788 | return (result); |
1c79356b | 789 | } |
1c79356b A |
790 | } |
791 | } | |
792 | ||
6601e61a A |
793 | if (size != needed) |
794 | bzero((char *) addr + needed, size - needed); | |
795 | ||
91447636 A |
796 | result = vm_map_unwire(ipc_kernel_map, vm_map_trunc_page(addr), |
797 | vm_map_round_page(addr + size), FALSE); | |
798 | assert(result == KERN_SUCCESS); | |
799 | result = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)addr, | |
800 | (vm_map_size_t)size, TRUE, ©); | |
801 | assert(result == KERN_SUCCESS); | |
1c79356b | 802 | |
91447636 A |
803 | *out_pcount = pcount; |
804 | *out_array = (processor_info_array_t) copy; | |
805 | *out_array_count = pcount * icount; | |
806 | ||
807 | return (KERN_SUCCESS); | |
1c79356b A |
808 | } |
809 | ||
1c79356b | 810 | /* |
55e303ae | 811 | * Kernel interface for setting a special port. |
1c79356b A |
812 | */ |
813 | kern_return_t | |
55e303ae A |
814 | kernel_set_special_port( |
815 | host_priv_t host_priv, | |
816 | int id, | |
817 | ipc_port_t port) | |
1c79356b | 818 | { |
55e303ae A |
819 | ipc_port_t old_port; |
820 | ||
821 | host_lock(host_priv); | |
822 | old_port = host_priv->special[id]; | |
823 | host_priv->special[id] = port; | |
824 | host_unlock(host_priv); | |
825 | if (IP_VALID(old_port)) | |
826 | ipc_port_release_send(old_port); | |
827 | return KERN_SUCCESS; | |
1c79356b A |
828 | } |
829 | ||
830 | /* | |
831 | * User interface for setting a special port. | |
832 | * | |
833 | * Only permits the user to set a user-owned special port | |
834 | * ID, rejecting a kernel-owned special port ID. | |
835 | * | |
836 | * A special kernel port cannot be set up using this | |
837 | * routine; use kernel_set_special_port() instead. | |
838 | */ | |
839 | kern_return_t | |
840 | host_set_special_port( | |
841 | host_priv_t host_priv, | |
842 | int id, | |
843 | ipc_port_t port) | |
844 | { | |
55e303ae A |
845 | if (host_priv == HOST_PRIV_NULL || |
846 | id <= HOST_MAX_SPECIAL_KERNEL_PORT || id > HOST_MAX_SPECIAL_PORT ) { | |
847 | if (IP_VALID(port)) | |
848 | ipc_port_release_send(port); | |
849 | return KERN_INVALID_ARGUMENT; | |
850 | } | |
851 | ||
852 | return kernel_set_special_port(host_priv, id, port); | |
1c79356b A |
853 | } |
854 | ||
855 | ||
856 | /* | |
857 | * User interface for retrieving a special port. | |
858 | * | |
1c79356b A |
859 | * Note that there is nothing to prevent a user special |
860 | * port from disappearing after it has been discovered by | |
861 | * the caller; thus, using a special port can always result | |
862 | * in a "port not valid" error. | |
863 | */ | |
864 | ||
865 | kern_return_t | |
866 | host_get_special_port( | |
867 | host_priv_t host_priv, | |
91447636 | 868 | __unused int node, |
1c79356b A |
869 | int id, |
870 | ipc_port_t *portp) | |
871 | { | |
55e303ae A |
872 | ipc_port_t port; |
873 | ||
874 | if (host_priv == HOST_PRIV_NULL || | |
b0d623f7 | 875 | id == HOST_SECURITY_PORT || id > HOST_MAX_SPECIAL_PORT || id < 0) |
55e303ae A |
876 | return KERN_INVALID_ARGUMENT; |
877 | ||
55e303ae A |
878 | host_lock(host_priv); |
879 | port = realhost.special[id]; | |
880 | *portp = ipc_port_copy_send(port); | |
881 | host_unlock(host_priv); | |
882 | ||
883 | return KERN_SUCCESS; | |
884 | } | |
885 | ||
886 | ||
887 | /* | |
888 | * host_get_io_master | |
889 | * | |
890 | * Return the IO master access port for this host. | |
891 | */ | |
892 | kern_return_t | |
893 | host_get_io_master( | |
894 | host_t host, | |
895 | io_master_t *io_masterp) | |
896 | { | |
897 | if (host == HOST_NULL) | |
898 | return KERN_INVALID_ARGUMENT; | |
899 | ||
900 | return (host_get_io_master_port(host_priv_self(), io_masterp)); | |
1c79356b A |
901 | } |
902 | ||
903 | host_t | |
904 | host_self(void) | |
905 | { | |
906 | return &realhost; | |
907 | } | |
908 | ||
909 | host_priv_t | |
910 | host_priv_self(void) | |
911 | { | |
912 | return &realhost; | |
913 | } | |
914 | ||
915 | host_security_t | |
916 | host_security_self(void) | |
917 | { | |
918 | return &realhost; | |
919 | } | |
920 |