2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
62 * Non-ipc host functions.
65 #include <mach/mach_types.h>
66 #include <mach/boolean.h>
67 #include <mach/host_info.h>
68 #include <mach/host_special_ports.h>
69 #include <mach/kern_return.h>
70 #include <mach/machine.h>
71 #include <mach/port.h>
72 #include <mach/processor_info.h>
73 #include <mach/vm_param.h>
74 #include <mach/processor.h>
75 #include <mach/mach_host_server.h>
76 #include <mach/host_priv_server.h>
77 #include <mach/vm_map.h>
78 #include <mach/task_info.h>
80 #include <machine/commpage.h>
81 #include <machine/cpu_capabilities.h>
83 #include <kern/kern_types.h>
84 #include <kern/assert.h>
85 #include <kern/kalloc.h>
86 #include <kern/host.h>
87 #include <kern/host_statistics.h>
88 #include <kern/ipc_host.h>
89 #include <kern/misc_protos.h>
90 #include <kern/sched.h>
91 #include <kern/processor.h>
92 #include <kern/mach_node.h> // mach_node_port_changed()
94 #include <vm/vm_map.h>
95 #include <vm/vm_purgeable_internal.h>
96 #include <vm/vm_pageout.h>
100 #include <atm/atm_internal.h>
104 #include <security/mac_mach_internal.h>
107 #include <pexpert/pexpert.h>
109 host_data_t realhost
;
111 vm_extmod_statistics_data_t host_extmod_statistics
;
114 host_processors(host_priv_t host_priv
, processor_array_t
* out_array
, mach_msg_type_number_t
* countp
)
116 processor_t processor
, *tp
;
118 unsigned int count
, i
;
120 if (host_priv
== HOST_PRIV_NULL
)
121 return (KERN_INVALID_ARGUMENT
);
123 assert(host_priv
== &realhost
);
125 count
= processor_count
;
128 addr
= kalloc((vm_size_t
)(count
* sizeof(mach_port_t
)));
130 return (KERN_RESOURCE_SHORTAGE
);
132 tp
= (processor_t
*)addr
;
133 *tp
++ = processor
= processor_list
;
136 simple_lock(&processor_list_lock
);
138 for (i
= 1; i
< count
; i
++)
139 *tp
++ = processor
= processor
->processor_list
;
141 simple_unlock(&processor_list_lock
);
145 *out_array
= (processor_array_t
)addr
;
147 /* do the conversion that Mig should handle */
148 tp
= (processor_t
*)addr
;
149 for (i
= 0; i
< count
; i
++)
150 ((mach_port_t
*)tp
)[i
] = (mach_port_t
)convert_processor_to_port(tp
[i
]);
152 return (KERN_SUCCESS
);
156 host_info(host_t host
, host_flavor_t flavor
, host_info_t info
, mach_msg_type_number_t
* count
)
158 if (host
== HOST_NULL
)
159 return (KERN_INVALID_ARGUMENT
);
162 case HOST_BASIC_INFO
: {
163 host_basic_info_t basic_info
;
167 * Basic information about this host.
169 if (*count
< HOST_BASIC_INFO_OLD_COUNT
)
170 return (KERN_FAILURE
);
172 basic_info
= (host_basic_info_t
)info
;
174 basic_info
->memory_size
= machine_info
.memory_size
;
175 basic_info
->max_cpus
= machine_info
.max_cpus
;
176 basic_info
->avail_cpus
= processor_avail_count
;
177 master_id
= master_processor
->cpu_id
;
178 basic_info
->cpu_type
= slot_type(master_id
);
179 basic_info
->cpu_subtype
= slot_subtype(master_id
);
181 if (*count
>= HOST_BASIC_INFO_COUNT
) {
182 basic_info
->cpu_threadtype
= slot_threadtype(master_id
);
183 basic_info
->physical_cpu
= machine_info
.physical_cpu
;
184 basic_info
->physical_cpu_max
= machine_info
.physical_cpu_max
;
185 basic_info
->logical_cpu
= machine_info
.logical_cpu
;
186 basic_info
->logical_cpu_max
= machine_info
.logical_cpu_max
;
187 basic_info
->max_mem
= machine_info
.max_mem
;
189 *count
= HOST_BASIC_INFO_COUNT
;
191 *count
= HOST_BASIC_INFO_OLD_COUNT
;
194 return (KERN_SUCCESS
);
197 case HOST_SCHED_INFO
: {
198 host_sched_info_t sched_info
;
199 uint32_t quantum_time
;
203 * Return scheduler information.
205 if (*count
< HOST_SCHED_INFO_COUNT
)
206 return (KERN_FAILURE
);
208 sched_info
= (host_sched_info_t
)info
;
210 quantum_time
= SCHED(initial_quantum_size
)(THREAD_NULL
);
211 absolutetime_to_nanoseconds(quantum_time
, &quantum_ns
);
213 sched_info
->min_timeout
= sched_info
->min_quantum
= (uint32_t)(quantum_ns
/ 1000 / 1000);
215 *count
= HOST_SCHED_INFO_COUNT
;
217 return (KERN_SUCCESS
);
220 case HOST_RESOURCE_SIZES
: {
222 * Return sizes of kernel data structures
224 if (*count
< HOST_RESOURCE_SIZES_COUNT
)
225 return (KERN_FAILURE
);
227 /* XXX Fail until ledgers are implemented */
228 return (KERN_INVALID_ARGUMENT
);
231 case HOST_PRIORITY_INFO
: {
232 host_priority_info_t priority_info
;
234 if (*count
< HOST_PRIORITY_INFO_COUNT
)
235 return (KERN_FAILURE
);
237 priority_info
= (host_priority_info_t
)info
;
239 priority_info
->kernel_priority
= MINPRI_KERNEL
;
240 priority_info
->system_priority
= MINPRI_KERNEL
;
241 priority_info
->server_priority
= MINPRI_RESERVED
;
242 priority_info
->user_priority
= BASEPRI_DEFAULT
;
243 priority_info
->depress_priority
= DEPRESSPRI
;
244 priority_info
->idle_priority
= IDLEPRI
;
245 priority_info
->minimum_priority
= MINPRI_USER
;
246 priority_info
->maximum_priority
= MAXPRI_RESERVED
;
248 *count
= HOST_PRIORITY_INFO_COUNT
;
250 return (KERN_SUCCESS
);
254 * Gestalt for various trap facilities.
256 case HOST_MACH_MSG_TRAP
:
257 case HOST_SEMAPHORE_TRAPS
: {
259 return (KERN_SUCCESS
);
262 case HOST_CAN_HAS_DEBUGGER
: {
263 host_can_has_debugger_info_t can_has_debugger_info
;
265 if (*count
< HOST_CAN_HAS_DEBUGGER_COUNT
)
266 return (KERN_FAILURE
);
268 can_has_debugger_info
= (host_can_has_debugger_info_t
)info
;
269 can_has_debugger_info
->can_has_debugger
= PE_i_can_has_debugger(NULL
);
270 *count
= HOST_CAN_HAS_DEBUGGER_COUNT
;
275 case HOST_VM_PURGABLE
: {
276 if (*count
< HOST_VM_PURGABLE_COUNT
)
277 return (KERN_FAILURE
);
279 vm_purgeable_stats((vm_purgeable_info_t
)info
, NULL
);
281 *count
= HOST_VM_PURGABLE_COUNT
;
282 return (KERN_SUCCESS
);
285 case HOST_DEBUG_INFO_INTERNAL
: {
286 #if DEVELOPMENT || DEBUG
287 if (*count
< HOST_DEBUG_INFO_INTERNAL_COUNT
)
288 return (KERN_FAILURE
);
290 host_debug_info_internal_t debug_info
= (host_debug_info_internal_t
)info
;
291 bzero(debug_info
, sizeof(host_debug_info_internal_data_t
));
292 *count
= HOST_DEBUG_INFO_INTERNAL_COUNT
;
294 #if CONFIG_COALITIONS
295 debug_info
->config_coalitions
= 1;
298 debug_info
->config_bank
= 1;
301 debug_info
->config_atm
= 1;
304 debug_info
->config_csr
= 1;
306 return (KERN_SUCCESS
);
307 #else /* DEVELOPMENT || DEBUG */
308 return (KERN_NOT_SUPPORTED
);
312 default: return (KERN_INVALID_ARGUMENT
);
317 host_statistics(host_t host
, host_flavor_t flavor
, host_info_t info
, mach_msg_type_number_t
* count
)
321 if (host
== HOST_NULL
)
322 return (KERN_INVALID_HOST
);
325 case HOST_LOAD_INFO
: {
326 host_load_info_t load_info
;
328 if (*count
< HOST_LOAD_INFO_COUNT
)
329 return (KERN_FAILURE
);
331 load_info
= (host_load_info_t
)info
;
333 bcopy((char *)avenrun
, (char *)load_info
->avenrun
, sizeof avenrun
);
334 bcopy((char *)mach_factor
, (char *)load_info
->mach_factor
, sizeof mach_factor
);
336 *count
= HOST_LOAD_INFO_COUNT
;
337 return (KERN_SUCCESS
);
341 processor_t processor
;
342 vm_statistics64_t stat
;
343 vm_statistics64_data_t host_vm_stat
;
344 vm_statistics_t stat32
;
345 mach_msg_type_number_t original_count
;
347 if (*count
< HOST_VM_INFO_REV0_COUNT
)
348 return (KERN_FAILURE
);
350 processor
= processor_list
;
351 stat
= &PROCESSOR_DATA(processor
, vm_stat
);
352 host_vm_stat
= *stat
;
354 if (processor_count
> 1) {
355 simple_lock(&processor_list_lock
);
357 while ((processor
= processor
->processor_list
) != NULL
) {
358 stat
= &PROCESSOR_DATA(processor
, vm_stat
);
360 host_vm_stat
.zero_fill_count
+= stat
->zero_fill_count
;
361 host_vm_stat
.reactivations
+= stat
->reactivations
;
362 host_vm_stat
.pageins
+= stat
->pageins
;
363 host_vm_stat
.pageouts
+= stat
->pageouts
;
364 host_vm_stat
.faults
+= stat
->faults
;
365 host_vm_stat
.cow_faults
+= stat
->cow_faults
;
366 host_vm_stat
.lookups
+= stat
->lookups
;
367 host_vm_stat
.hits
+= stat
->hits
;
370 simple_unlock(&processor_list_lock
);
373 stat32
= (vm_statistics_t
)info
;
375 stat32
->free_count
= VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_free_count
+ vm_page_speculative_count
);
376 stat32
->active_count
= VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_active_count
);
378 if (vm_page_local_q
) {
379 for (i
= 0; i
< vm_page_local_q_count
; i
++) {
382 lq
= &vm_page_local_q
[i
].vpl_un
.vpl
;
384 stat32
->active_count
+= VM_STATISTICS_TRUNCATE_TO_32_BIT(lq
->vpl_count
);
387 stat32
->inactive_count
= VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_inactive_count
);
388 stat32
->wire_count
= VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_wire_count
+ vm_page_throttled_count
+ vm_lopage_free_count
);
389 stat32
->zero_fill_count
= VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat
.zero_fill_count
);
390 stat32
->reactivations
= VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat
.reactivations
);
391 stat32
->pageins
= VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat
.pageins
);
392 stat32
->pageouts
= VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat
.pageouts
);
393 stat32
->faults
= VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat
.faults
);
394 stat32
->cow_faults
= VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat
.cow_faults
);
395 stat32
->lookups
= VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat
.lookups
);
396 stat32
->hits
= VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat
.hits
);
399 * Fill in extra info added in later revisions of the
400 * vm_statistics data structure. Fill in only what can fit
401 * in the data structure the caller gave us !
403 original_count
= *count
;
404 *count
= HOST_VM_INFO_REV0_COUNT
; /* rev0 already filled in */
405 if (original_count
>= HOST_VM_INFO_REV1_COUNT
) {
406 /* rev1 added "purgeable" info */
407 stat32
->purgeable_count
= VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_purgeable_count
);
408 stat32
->purges
= VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_purged_count
);
409 *count
= HOST_VM_INFO_REV1_COUNT
;
412 if (original_count
>= HOST_VM_INFO_REV2_COUNT
) {
413 /* rev2 added "speculative" info */
414 stat32
->speculative_count
= VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_speculative_count
);
415 *count
= HOST_VM_INFO_REV2_COUNT
;
418 /* rev3 changed some of the fields to be 64-bit*/
420 return (KERN_SUCCESS
);
423 case HOST_CPU_LOAD_INFO
: {
424 processor_t processor
;
425 host_cpu_load_info_t cpu_load_info
;
427 if (*count
< HOST_CPU_LOAD_INFO_COUNT
)
428 return (KERN_FAILURE
);
430 #define GET_TICKS_VALUE(state, ticks) \
431 MACRO_BEGIN cpu_load_info->cpu_ticks[(state)] += (uint32_t)(ticks / hz_tick_interval); \
433 #define GET_TICKS_VALUE_FROM_TIMER(processor, state, timer) \
434 MACRO_BEGIN GET_TICKS_VALUE(state, timer_grab(&PROCESSOR_DATA(processor, timer))); \
437 cpu_load_info
= (host_cpu_load_info_t
)info
;
438 cpu_load_info
->cpu_ticks
[CPU_STATE_USER
] = 0;
439 cpu_load_info
->cpu_ticks
[CPU_STATE_SYSTEM
] = 0;
440 cpu_load_info
->cpu_ticks
[CPU_STATE_IDLE
] = 0;
441 cpu_load_info
->cpu_ticks
[CPU_STATE_NICE
] = 0;
443 simple_lock(&processor_list_lock
);
445 for (processor
= processor_list
; processor
!= NULL
; processor
= processor
->processor_list
) {
447 uint64_t idle_time_snapshot1
, idle_time_snapshot2
;
448 uint64_t idle_time_tstamp1
, idle_time_tstamp2
;
450 /* See discussion in processor_info(PROCESSOR_CPU_LOAD_INFO) */
452 GET_TICKS_VALUE_FROM_TIMER(processor
, CPU_STATE_USER
, user_state
);
453 if (precise_user_kernel_time
) {
454 GET_TICKS_VALUE_FROM_TIMER(processor
, CPU_STATE_SYSTEM
, system_state
);
456 /* system_state may represent either sys or user */
457 GET_TICKS_VALUE_FROM_TIMER(processor
, CPU_STATE_USER
, system_state
);
460 idle_state
= &PROCESSOR_DATA(processor
, idle_state
);
461 idle_time_snapshot1
= timer_grab(idle_state
);
462 idle_time_tstamp1
= idle_state
->tstamp
;
464 if (PROCESSOR_DATA(processor
, current_state
) != idle_state
) {
465 /* Processor is non-idle, so idle timer should be accurate */
466 GET_TICKS_VALUE_FROM_TIMER(processor
, CPU_STATE_IDLE
, idle_state
);
467 } else if ((idle_time_snapshot1
!= (idle_time_snapshot2
= timer_grab(idle_state
))) ||
468 (idle_time_tstamp1
!= (idle_time_tstamp2
= idle_state
->tstamp
))) {
469 /* Idle timer is being updated concurrently, second stamp is good enough */
470 GET_TICKS_VALUE(CPU_STATE_IDLE
, idle_time_snapshot2
);
473 * Idle timer may be very stale. Fortunately we have established
474 * that idle_time_snapshot1 and idle_time_tstamp1 are unchanging
476 idle_time_snapshot1
+= mach_absolute_time() - idle_time_tstamp1
;
478 GET_TICKS_VALUE(CPU_STATE_IDLE
, idle_time_snapshot1
);
481 simple_unlock(&processor_list_lock
);
483 *count
= HOST_CPU_LOAD_INFO_COUNT
;
485 return (KERN_SUCCESS
);
488 case HOST_EXPIRED_TASK_INFO
: {
489 if (*count
< TASK_POWER_INFO_COUNT
) {
490 return (KERN_FAILURE
);
493 task_power_info_t tinfo
= (task_power_info_t
)info
;
495 tinfo
->task_interrupt_wakeups
= dead_task_statistics
.task_interrupt_wakeups
;
496 tinfo
->task_platform_idle_wakeups
= dead_task_statistics
.task_platform_idle_wakeups
;
498 tinfo
->task_timer_wakeups_bin_1
= dead_task_statistics
.task_timer_wakeups_bin_1
;
500 tinfo
->task_timer_wakeups_bin_2
= dead_task_statistics
.task_timer_wakeups_bin_2
;
502 tinfo
->total_user
= dead_task_statistics
.total_user_time
;
503 tinfo
->total_system
= dead_task_statistics
.total_system_time
;
505 return (KERN_SUCCESS
);
507 default: return (KERN_INVALID_ARGUMENT
);
511 extern uint32_t c_segment_pages_compressed
;
514 host_statistics64(host_t host
, host_flavor_t flavor
, host_info64_t info
, mach_msg_type_number_t
* count
)
518 if (host
== HOST_NULL
)
519 return (KERN_INVALID_HOST
);
522 case HOST_VM_INFO64
: /* We were asked to get vm_statistics64 */
524 processor_t processor
;
525 vm_statistics64_t stat
;
526 vm_statistics64_data_t host_vm_stat
;
527 mach_msg_type_number_t original_count
;
528 unsigned int local_q_internal_count
;
529 unsigned int local_q_external_count
;
531 if (*count
< HOST_VM_INFO64_REV0_COUNT
)
532 return (KERN_FAILURE
);
534 processor
= processor_list
;
535 stat
= &PROCESSOR_DATA(processor
, vm_stat
);
536 host_vm_stat
= *stat
;
538 if (processor_count
> 1) {
539 simple_lock(&processor_list_lock
);
541 while ((processor
= processor
->processor_list
) != NULL
) {
542 stat
= &PROCESSOR_DATA(processor
, vm_stat
);
544 host_vm_stat
.zero_fill_count
+= stat
->zero_fill_count
;
545 host_vm_stat
.reactivations
+= stat
->reactivations
;
546 host_vm_stat
.pageins
+= stat
->pageins
;
547 host_vm_stat
.pageouts
+= stat
->pageouts
;
548 host_vm_stat
.faults
+= stat
->faults
;
549 host_vm_stat
.cow_faults
+= stat
->cow_faults
;
550 host_vm_stat
.lookups
+= stat
->lookups
;
551 host_vm_stat
.hits
+= stat
->hits
;
552 host_vm_stat
.compressions
+= stat
->compressions
;
553 host_vm_stat
.decompressions
+= stat
->decompressions
;
554 host_vm_stat
.swapins
+= stat
->swapins
;
555 host_vm_stat
.swapouts
+= stat
->swapouts
;
558 simple_unlock(&processor_list_lock
);
561 stat
= (vm_statistics64_t
)info
;
563 stat
->free_count
= vm_page_free_count
+ vm_page_speculative_count
;
564 stat
->active_count
= vm_page_active_count
;
566 local_q_internal_count
= 0;
567 local_q_external_count
= 0;
568 if (vm_page_local_q
) {
569 for (i
= 0; i
< vm_page_local_q_count
; i
++) {
572 lq
= &vm_page_local_q
[i
].vpl_un
.vpl
;
574 stat
->active_count
+= lq
->vpl_count
;
575 local_q_internal_count
+= lq
->vpl_internal_count
;
576 local_q_external_count
+= lq
->vpl_external_count
;
579 stat
->inactive_count
= vm_page_inactive_count
;
580 stat
->wire_count
= vm_page_wire_count
+ vm_page_throttled_count
+ vm_lopage_free_count
;
581 stat
->zero_fill_count
= host_vm_stat
.zero_fill_count
;
582 stat
->reactivations
= host_vm_stat
.reactivations
;
583 stat
->pageins
= host_vm_stat
.pageins
;
584 stat
->pageouts
= host_vm_stat
.pageouts
;
585 stat
->faults
= host_vm_stat
.faults
;
586 stat
->cow_faults
= host_vm_stat
.cow_faults
;
587 stat
->lookups
= host_vm_stat
.lookups
;
588 stat
->hits
= host_vm_stat
.hits
;
590 stat
->purgeable_count
= vm_page_purgeable_count
;
591 stat
->purges
= vm_page_purged_count
;
593 stat
->speculative_count
= vm_page_speculative_count
;
596 * Fill in extra info added in later revisions of the
597 * vm_statistics data structure. Fill in only what can fit
598 * in the data structure the caller gave us !
600 original_count
= *count
;
601 *count
= HOST_VM_INFO64_REV0_COUNT
; /* rev0 already filled in */
602 if (original_count
>= HOST_VM_INFO64_REV1_COUNT
) {
603 /* rev1 added "throttled count" */
604 stat
->throttled_count
= vm_page_throttled_count
;
605 /* rev1 added "compression" info */
606 stat
->compressor_page_count
= VM_PAGE_COMPRESSOR_COUNT
;
607 stat
->compressions
= host_vm_stat
.compressions
;
608 stat
->decompressions
= host_vm_stat
.decompressions
;
609 stat
->swapins
= host_vm_stat
.swapins
;
610 stat
->swapouts
= host_vm_stat
.swapouts
;
612 * "external page count"
613 * "anonymous page count"
614 * "total # of pages (uncompressed) held in the compressor"
616 stat
->external_page_count
= (vm_page_pageable_external_count
+ local_q_external_count
);
617 stat
->internal_page_count
= (vm_page_pageable_internal_count
+ local_q_internal_count
);
618 stat
->total_uncompressed_pages_in_compressor
= c_segment_pages_compressed
;
619 *count
= HOST_VM_INFO64_REV1_COUNT
;
622 return (KERN_SUCCESS
);
625 case HOST_EXTMOD_INFO64
: /* We were asked to get vm_statistics64 */
627 vm_extmod_statistics_t out_extmod_statistics
;
629 if (*count
< HOST_EXTMOD_INFO64_COUNT
)
630 return (KERN_FAILURE
);
632 out_extmod_statistics
= (vm_extmod_statistics_t
)info
;
633 *out_extmod_statistics
= host_extmod_statistics
;
635 *count
= HOST_EXTMOD_INFO64_COUNT
;
637 return (KERN_SUCCESS
);
640 default: /* If we didn't recognize the flavor, send to host_statistics */
641 return (host_statistics(host
, flavor
, (host_info_t
)info
, count
));
646 * Get host statistics that require privilege.
647 * None for now, just call the un-privileged version.
650 host_priv_statistics(host_priv_t host_priv
, host_flavor_t flavor
, host_info_t info
, mach_msg_type_number_t
* count
)
652 return (host_statistics((host_t
)host_priv
, flavor
, info
, count
));
656 set_sched_stats_active(boolean_t active
)
658 sched_stats_active
= active
;
659 return (KERN_SUCCESS
);
663 get_sched_statistics(struct _processor_statistics_np
* out
, uint32_t * count
)
665 processor_t processor
;
667 if (!sched_stats_active
) {
668 return (KERN_FAILURE
);
671 simple_lock(&processor_list_lock
);
673 if (*count
< (processor_count
+ 1) * sizeof(struct _processor_statistics_np
)) { /* One for RT */
674 simple_unlock(&processor_list_lock
);
675 return (KERN_FAILURE
);
678 processor
= processor_list
;
680 struct processor_sched_statistics
* stats
= &processor
->processor_data
.sched_stats
;
682 out
->ps_cpuid
= processor
->cpu_id
;
683 out
->ps_csw_count
= stats
->csw_count
;
684 out
->ps_preempt_count
= stats
->preempt_count
;
685 out
->ps_preempted_rt_count
= stats
->preempted_rt_count
;
686 out
->ps_preempted_by_rt_count
= stats
->preempted_by_rt_count
;
687 out
->ps_rt_sched_count
= stats
->rt_sched_count
;
688 out
->ps_interrupt_count
= stats
->interrupt_count
;
689 out
->ps_ipi_count
= stats
->ipi_count
;
690 out
->ps_timer_pop_count
= stats
->timer_pop_count
;
691 out
->ps_runq_count_sum
= SCHED(processor_runq_stats_count_sum
)(processor
);
692 out
->ps_idle_transitions
= stats
->idle_transitions
;
693 out
->ps_quantum_timer_expirations
= stats
->quantum_timer_expirations
;
696 processor
= processor
->processor_list
;
699 *count
= (uint32_t)(processor_count
* sizeof(struct _processor_statistics_np
));
701 simple_unlock(&processor_list_lock
);
703 /* And include RT Queue information */
704 bzero(out
, sizeof(*out
));
705 out
->ps_cpuid
= (-1);
706 out
->ps_runq_count_sum
= rt_runq
.runq_stats
.count_sum
;
708 *count
+= (uint32_t)sizeof(struct _processor_statistics_np
);
710 return (KERN_SUCCESS
);
714 host_page_size(host_t host
, vm_size_t
* out_page_size
)
716 if (host
== HOST_NULL
)
717 return (KERN_INVALID_ARGUMENT
);
719 *out_page_size
= PAGE_SIZE
;
721 return (KERN_SUCCESS
);
725 * Return kernel version string (more than you ever
726 * wanted to know about what version of the kernel this is).
728 extern char version
[];
731 host_kernel_version(host_t host
, kernel_version_t out_version
)
733 if (host
== HOST_NULL
)
734 return (KERN_INVALID_ARGUMENT
);
736 (void)strncpy(out_version
, version
, sizeof(kernel_version_t
));
738 return (KERN_SUCCESS
);
742 * host_processor_sets:
744 * List all processor sets on the host.
747 host_processor_sets(host_priv_t host_priv
, processor_set_name_array_t
* pset_list
, mach_msg_type_number_t
* count
)
751 if (host_priv
== HOST_PRIV_NULL
)
752 return (KERN_INVALID_ARGUMENT
);
755 * Allocate memory. Can be pageable because it won't be
756 * touched while holding a lock.
759 addr
= kalloc((vm_size_t
)sizeof(mach_port_t
));
761 return (KERN_RESOURCE_SHORTAGE
);
763 /* do the conversion that Mig should handle */
764 *((ipc_port_t
*)addr
) = convert_pset_name_to_port(&pset0
);
766 *pset_list
= (processor_set_array_t
)addr
;
769 return (KERN_SUCCESS
);
773 * host_processor_set_priv:
775 * Return control port for given processor set.
778 host_processor_set_priv(host_priv_t host_priv
, processor_set_t pset_name
, processor_set_t
* pset
)
780 if (host_priv
== HOST_PRIV_NULL
|| pset_name
== PROCESSOR_SET_NULL
) {
781 *pset
= PROCESSOR_SET_NULL
;
783 return (KERN_INVALID_ARGUMENT
);
788 return (KERN_SUCCESS
);
792 * host_processor_info
794 * Return info about the processors on this host. It will return
795 * the number of processors, and the specific type of info requested
799 host_processor_info(host_t host
,
800 processor_flavor_t flavor
,
801 natural_t
* out_pcount
,
802 processor_info_array_t
* out_array
,
803 mach_msg_type_number_t
* out_array_count
)
805 kern_return_t result
;
806 processor_t processor
;
808 processor_info_t info
;
809 unsigned int icount
, tcount
;
810 unsigned int pcount
, i
;
812 vm_size_t size
, needed
;
815 if (host
== HOST_NULL
)
816 return (KERN_INVALID_ARGUMENT
);
818 result
= processor_info_count(flavor
, &icount
);
819 if (result
!= KERN_SUCCESS
)
822 pcount
= processor_count
;
825 needed
= pcount
* icount
* sizeof(natural_t
);
826 size
= vm_map_round_page(needed
, VM_MAP_PAGE_MASK(ipc_kernel_map
));
827 result
= kmem_alloc(ipc_kernel_map
, &addr
, size
, VM_KERN_MEMORY_IPC
);
828 if (result
!= KERN_SUCCESS
)
829 return (KERN_RESOURCE_SHORTAGE
);
831 info
= (processor_info_t
)addr
;
832 processor
= processor_list
;
835 result
= processor_info(processor
, flavor
, &thost
, info
, &tcount
);
836 if (result
!= KERN_SUCCESS
) {
837 kmem_free(ipc_kernel_map
, addr
, size
);
842 for (i
= 1; i
< pcount
; i
++) {
843 simple_lock(&processor_list_lock
);
844 processor
= processor
->processor_list
;
845 simple_unlock(&processor_list_lock
);
849 result
= processor_info(processor
, flavor
, &thost
, info
, &tcount
);
850 if (result
!= KERN_SUCCESS
) {
851 kmem_free(ipc_kernel_map
, addr
, size
);
858 bzero((char *)addr
+ needed
, size
- needed
);
860 result
= vm_map_unwire(ipc_kernel_map
, vm_map_trunc_page(addr
, VM_MAP_PAGE_MASK(ipc_kernel_map
)),
861 vm_map_round_page(addr
+ size
, VM_MAP_PAGE_MASK(ipc_kernel_map
)), FALSE
);
862 assert(result
== KERN_SUCCESS
);
863 result
= vm_map_copyin(ipc_kernel_map
, (vm_map_address_t
)addr
, (vm_map_size_t
)needed
, TRUE
, ©
);
864 assert(result
== KERN_SUCCESS
);
866 *out_pcount
= pcount
;
867 *out_array
= (processor_info_array_t
)copy
;
868 *out_array_count
= pcount
* icount
;
870 return (KERN_SUCCESS
);
874 * Kernel interface for setting a special port.
877 kernel_set_special_port(host_priv_t host_priv
, int id
, ipc_port_t port
)
882 if (id
== HOST_NODE_PORT
)
883 return (KERN_NOT_SUPPORTED
);
886 host_lock(host_priv
);
887 old_port
= host_priv
->special
[id
];
888 host_priv
->special
[id
] = port
;
889 host_unlock(host_priv
);
892 if (id
== HOST_NODE_PORT
)
893 mach_node_port_changed();
896 if (IP_VALID(old_port
))
897 ipc_port_release_send(old_port
);
898 return (KERN_SUCCESS
);
902 * Kernel interface for retrieving a special port.
905 kernel_get_special_port(host_priv_t host_priv
, int id
, ipc_port_t
* portp
)
907 host_lock(host_priv
);
908 *portp
= host_priv
->special
[id
];
909 host_unlock(host_priv
);
910 return (KERN_SUCCESS
);
914 * User interface for setting a special port.
916 * Only permits the user to set a user-owned special port
917 * ID, rejecting a kernel-owned special port ID.
919 * A special kernel port cannot be set up using this
920 * routine; use kernel_set_special_port() instead.
923 host_set_special_port(host_priv_t host_priv
, int id
, ipc_port_t port
)
925 if (host_priv
== HOST_PRIV_NULL
|| id
<= HOST_MAX_SPECIAL_KERNEL_PORT
|| id
> HOST_MAX_SPECIAL_PORT
)
926 return (KERN_INVALID_ARGUMENT
);
929 if (mac_task_check_set_host_special_port(current_task(), id
, port
) != 0)
930 return (KERN_NO_ACCESS
);
933 return (kernel_set_special_port(host_priv
, id
, port
));
937 * User interface for retrieving a special port.
939 * Note that there is nothing to prevent a user special
940 * port from disappearing after it has been discovered by
941 * the caller; thus, using a special port can always result
942 * in a "port not valid" error.
946 host_get_special_port(host_priv_t host_priv
, __unused
int node
, int id
, ipc_port_t
* portp
)
950 if (host_priv
== HOST_PRIV_NULL
|| id
== HOST_SECURITY_PORT
|| id
> HOST_MAX_SPECIAL_PORT
|| id
< 0)
951 return (KERN_INVALID_ARGUMENT
);
953 host_lock(host_priv
);
954 port
= realhost
.special
[id
];
955 *portp
= ipc_port_copy_send(port
);
956 host_unlock(host_priv
);
958 return (KERN_SUCCESS
);
964 * Return the IO master access port for this host.
967 host_get_io_master(host_t host
, io_master_t
* io_masterp
)
969 if (host
== HOST_NULL
)
970 return (KERN_INVALID_ARGUMENT
);
972 return (host_get_io_master_port(host_priv_self(), io_masterp
));
988 host_security_self(void)
994 host_set_atm_diagnostic_flag(host_priv_t host_priv
, uint32_t diagnostic_flag
)
996 if (host_priv
== HOST_PRIV_NULL
)
997 return (KERN_INVALID_ARGUMENT
);
999 assert(host_priv
== &realhost
);
1002 return (atm_set_diagnostic_config(diagnostic_flag
));
1004 (void)diagnostic_flag
;
1005 return (KERN_NOT_SUPPORTED
);
1010 host_set_multiuser_config_flags(host_priv_t host_priv
, uint32_t multiuser_config
)
1013 (void)multiuser_config
;
1014 return (KERN_NOT_SUPPORTED
);