1214501Srpaulo/*
2214501Srpaulo * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
3214501Srpaulo *
4214501Srpaulo * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5214501Srpaulo *
6214501Srpaulo * This file contains Original Code and/or Modifications of Original Code
7214501Srpaulo * as defined in and that are subject to the Apple Public Source License
8214501Srpaulo * Version 2.0 (the 'License'). You may not use this file except in
9214501Srpaulo * compliance with the License. The rights granted to you under the License
10214501Srpaulo * may not be used to create, or enable the creation or redistribution of,
11214501Srpaulo * unlawful or unlicensed copies of an Apple operating system, or to
12214501Srpaulo * circumvent, violate, or enable the circumvention or violation of, any
13214501Srpaulo * terms of an Apple operating system software license agreement.
14214501Srpaulo *
15214501Srpaulo * Please obtain a copy of the License at
16214501Srpaulo * http://www.opensource.apple.com/apsl/ and read it before using this file.
17214501Srpaulo *
18252190Srpaulo * The Original Code and all software distributed under the License are
19214501Srpaulo * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20214501Srpaulo * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21214501Srpaulo * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22214501Srpaulo * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23214501Srpaulo * Please see the License for the specific language governing rights and
24214501Srpaulo * limitations under the License.
25214501Srpaulo *
26214501Srpaulo * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27214501Srpaulo */
28214501Srpaulo/*
29214501Srpaulo * @OSF_COPYRIGHT@
30214501Srpaulo */
31214501Srpaulo/*
32214501Srpaulo * Mach Operating System
33214501Srpaulo * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
34214501Srpaulo * All Rights Reserved.
35214501Srpaulo *
36214501Srpaulo * Permission to use, copy, modify and distribute this software and its
37214501Srpaulo * documentation is hereby granted, provided that both the copyright
38214501Srpaulo * notice and this permission notice appear in all copies of the
39214501Srpaulo * software, derivative works or modified versions, and any portions
40214501Srpaulo * thereof, and that both notices appear in supporting documentation.
41214501Srpaulo *
42252190Srpaulo * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43214501Srpaulo * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44214501Srpaulo * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45252190Srpaulo *
46214501Srpaulo * Carnegie Mellon requests users of this software to return to
47214501Srpaulo *
48214501Srpaulo *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
49214501Srpaulo *  School of Computer Science
50214501Srpaulo *  Carnegie Mellon University
51214501Srpaulo *  Pittsburgh PA 15213-3890
52214501Srpaulo *
53214501Srpaulo * any improvements or extensions that they make and grant Carnegie Mellon
54214501Srpaulo * the rights to redistribute these changes.
55214501Srpaulo */
56214501Srpaulo/*
57214501Srpaulo */
58214501Srpaulo
59214501Srpaulo/*
60214501Srpaulo *	File:	mach/host_info.h
61214501Srpaulo *
62214501Srpaulo *	Definitions for host_info call.
63214501Srpaulo */
64214501Srpaulo
65214501Srpaulo#ifndef	_MACH_HOST_INFO_H_
66214501Srpaulo#define	_MACH_HOST_INFO_H_
67214501Srpaulo
68214501Srpaulo#include <mach/message.h>
69214501Srpaulo#include <mach/vm_statistics.h>
70214501Srpaulo#include <mach/machine.h>
71214501Srpaulo#include <mach/machine/vm_types.h>
72214501Srpaulo#include <mach/time_value.h>
73214501Srpaulo
74#include <sys/cdefs.h>
75
76/*
77 *	Generic information structure to allow for expansion.
78 */
79typedef integer_t	*host_info_t;		/* varying array of int. */
80typedef integer_t	*host_info64_t;		/* varying array of int. */
81
82#define	HOST_INFO_MAX	(1024)		/* max array size */
83typedef integer_t	host_info_data_t[HOST_INFO_MAX];
84
85#define KERNEL_VERSION_MAX (512)
86typedef char	kernel_version_t[KERNEL_VERSION_MAX];
87
88#define KERNEL_BOOT_INFO_MAX (4096)
89typedef char	kernel_boot_info_t[KERNEL_BOOT_INFO_MAX];
90
91/*
92 *	Currently defined information.
93 */
94/* host_info() */
95typedef	integer_t	host_flavor_t;
96#define HOST_BASIC_INFO		1	/* basic info */
97#define HOST_SCHED_INFO		3	/* scheduling info */
98#define HOST_RESOURCE_SIZES	4	/* kernel struct sizes */
99#define HOST_PRIORITY_INFO	5	/* priority information */
100#define HOST_SEMAPHORE_TRAPS	7	/* Has semaphore traps */
101#define HOST_MACH_MSG_TRAP	8	/* Has mach_msg_trap */
102
103#ifdef MACH_KERNEL_PRIVATE
104struct host_basic_info_old {
105	integer_t	max_cpus;	/* max number of cpus possible */
106	uint32_t	avail_cpus;	/* number of cpus now available */
107	natural_t	memory_size;	/* size of memory in bytes */
108	cpu_type_t	cpu_type;	/* cpu type */
109	cpu_subtype_t	cpu_subtype;	/* cpu subtype */
110};
111
112typedef	struct host_basic_info_old	host_basic_info_data_old_t;
113typedef struct host_basic_info_old	*host_basic_info_old_t;
114#define HOST_BASIC_INFO_OLD_COUNT ((mach_msg_type_number_t) \
115		(sizeof(host_basic_info_data_old_t)/sizeof(integer_t)))
116#endif
117
118#pragma pack(4)
119
120struct host_basic_info {
121	integer_t		max_cpus;		/* max number of CPUs possible */
122	integer_t		avail_cpus;		/* number of CPUs now available */
123	natural_t		memory_size;		/* size of memory in bytes, capped at 2 GB */
124	cpu_type_t		cpu_type;		/* cpu type */
125	cpu_subtype_t		cpu_subtype;		/* cpu subtype */
126	cpu_threadtype_t	cpu_threadtype;		/* cpu threadtype */
127	integer_t		physical_cpu;		/* number of physical CPUs now available */
128	integer_t		physical_cpu_max;	/* max number of physical CPUs possible */
129	integer_t		logical_cpu;		/* number of logical cpu now available */
130	integer_t		logical_cpu_max;	/* max number of physical CPUs possible */
131	uint64_t		max_mem;		/* actual size of physical memory */
132};
133
134#pragma pack()
135
136typedef	struct host_basic_info	host_basic_info_data_t;
137typedef struct host_basic_info	*host_basic_info_t;
138#define HOST_BASIC_INFO_COUNT ((mach_msg_type_number_t) \
139		(sizeof(host_basic_info_data_t)/sizeof(integer_t)))
140
141struct host_sched_info {
142	integer_t	min_timeout;	/* minimum timeout in milliseconds */
143	integer_t	min_quantum;	/* minimum quantum in milliseconds */
144};
145
146typedef	struct host_sched_info	host_sched_info_data_t;
147typedef struct host_sched_info	*host_sched_info_t;
148#define HOST_SCHED_INFO_COUNT ((mach_msg_type_number_t) \
149		(sizeof(host_sched_info_data_t)/sizeof(integer_t)))
150
151struct kernel_resource_sizes {
152	natural_t	task;
153        natural_t	thread;
154        natural_t	port;
155        natural_t	memory_region;
156        natural_t	memory_object;
157};
158
159typedef struct kernel_resource_sizes	kernel_resource_sizes_data_t;
160typedef struct kernel_resource_sizes	*kernel_resource_sizes_t;
161#define HOST_RESOURCE_SIZES_COUNT ((mach_msg_type_number_t) \
162		(sizeof(kernel_resource_sizes_data_t)/sizeof(integer_t)))
163
164struct host_priority_info {
165    	integer_t	kernel_priority;
166    	integer_t	system_priority;
167    	integer_t	server_priority;
168    	integer_t	user_priority;
169    	integer_t	depress_priority;
170    	integer_t	idle_priority;
171    	integer_t	minimum_priority;
172	integer_t	maximum_priority;
173};
174
175typedef struct host_priority_info	host_priority_info_data_t;
176typedef struct host_priority_info	*host_priority_info_t;
177#define HOST_PRIORITY_INFO_COUNT ((mach_msg_type_number_t) \
178		(sizeof(host_priority_info_data_t)/sizeof(integer_t)))
179
180/* host_statistics() */
181#define	HOST_LOAD_INFO		1	/* System loading stats */
182#define HOST_VM_INFO		2	/* Virtual memory stats */
183#define HOST_CPU_LOAD_INFO	3	/* CPU load stats */
184
185/* host_statistics64() */
186#define HOST_VM_INFO64		4	/* 64-bit virtual memory stats */
187#define HOST_EXTMOD_INFO64	5	/* External modification stats */
188#define HOST_EXPIRED_TASK_INFO        6        /* Statistics for expired tasks */
189
190struct host_load_info {
191	integer_t	avenrun[3];	/* scaled by LOAD_SCALE */
192	integer_t	mach_factor[3];	/* scaled by LOAD_SCALE */
193};
194
195typedef struct host_load_info	host_load_info_data_t;
196typedef struct host_load_info	*host_load_info_t;
197#define	HOST_LOAD_INFO_COUNT ((mach_msg_type_number_t) \
198		(sizeof(host_load_info_data_t)/sizeof(integer_t)))
199
200/* in <mach/vm_statistics.h> */
201/* vm_statistics64 */
202#define	HOST_VM_INFO64_COUNT ((mach_msg_type_number_t) \
203		(sizeof(vm_statistics64_data_t)/sizeof(integer_t)))
204
205/* size of the latest version of the structure */
206#define HOST_VM_INFO64_LATEST_COUNT HOST_VM_INFO64_COUNT
207
208/* in <mach/vm_statistics.h> */
209/* vm_extmod_statistics */
210#define HOST_EXTMOD_INFO64_COUNT ((mach_msg_type_number_t) \
211	    (sizeof(vm_extmod_statistics_data_t)/sizeof(integer_t)))
212
213/* size of the latest version of the structure */
214#define HOST_EXTMOD_INFO64_LATEST_COUNT HOST_EXTMOD_INFO64_COUNT
215
216/* vm_statistics */
217#define	HOST_VM_INFO_COUNT ((mach_msg_type_number_t) \
218		(sizeof(vm_statistics_data_t)/sizeof(integer_t)))
219
220/* size of the latest version of the structure */
221#define HOST_VM_INFO_LATEST_COUNT HOST_VM_INFO_COUNT
222#define	HOST_VM_INFO_REV2_COUNT HOST_VM_INFO_LATEST_COUNT
223/* previous versions: adjust the size according to what was added each time */
224#define	HOST_VM_INFO_REV1_COUNT /* added "speculative_count" (1 int) */	\
225	((mach_msg_type_number_t) \
226	 (HOST_VM_INFO_REV2_COUNT - 1))
227#define	HOST_VM_INFO_REV0_COUNT /* added "purgable" info (2 ints) */ 	\
228	((mach_msg_type_number_t) \
229	 (HOST_VM_INFO_REV1_COUNT - 2))
230
231struct host_cpu_load_info {		/* number of ticks while running... */
232	natural_t	cpu_ticks[CPU_STATE_MAX]; /* ... in the given mode */
233};
234
235typedef struct host_cpu_load_info	host_cpu_load_info_data_t;
236typedef struct host_cpu_load_info	*host_cpu_load_info_t;
237#define HOST_CPU_LOAD_INFO_COUNT ((mach_msg_type_number_t) \
238		(sizeof (host_cpu_load_info_data_t) / sizeof (integer_t)))
239
240#ifdef PRIVATE
241/*
242 * CPU Statistics information
243 */
244struct _processor_statistics_np  {
245	int32_t			ps_cpuid;
246
247	uint32_t		ps_csw_count;
248	uint32_t		ps_preempt_count;
249	uint32_t		ps_preempted_rt_count;
250	uint32_t		ps_preempted_by_rt_count;
251
252	uint32_t		ps_rt_sched_count;
253
254	uint32_t		ps_interrupt_count;
255	uint32_t		ps_ipi_count;
256	uint32_t		ps_timer_pop_count;
257
258	uint64_t		ps_runq_count_sum __attribute((aligned(8)));
259
260	uint32_t		ps_idle_transitions;
261	uint32_t		ps_quantum_timer_expirations;
262};
263
264#endif /* PRIVATE */
265
266#ifdef KERNEL_PRIVATE
267
268extern kern_return_t	set_sched_stats_active(
269					boolean_t active);
270
271extern kern_return_t	get_sched_statistics(
272					struct _processor_statistics_np *out,
273					uint32_t *count);
274#endif  /* KERNEL_PRIVATE */
275
276
277#endif	/* _MACH_HOST_INFO_H_ */
278