2 * Copyright (c) 2000-2010, 2015 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@
29 * @OSF_FREE_COPYRIGHT@
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.
60 * Author: Avadis Tevanian, Jr.
62 * This file contains the structure definitions for tasks.
66 * Copyright (c) 1993 The University of Utah and
67 * the Computer Systems Laboratory (CSL). All rights reserved.
69 * Permission to use, copy, modify and distribute this software and its
70 * documentation is hereby granted, provided that both the copyright
71 * notice and this permission notice appear in all copies of the
72 * software, derivative works or modified versions, and any portions
73 * thereof, and that both notices appear in supporting documentation.
75 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
76 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
77 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
79 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
80 * improvements that they make and grant CSL redistribution rights.
84 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
85 * support for mandatory and extensible security protections. This notice
86 * is included in support of clause 2.2 (b) of the Apple Public License,
88 * Copyright (c) 2005 SPARTA, Inc.
94 #include <kern/kern_types.h>
95 #include <mach/mach_types.h>
96 #include <sys/cdefs.h>
98 #ifdef MACH_KERNEL_PRIVATE
100 #include <mach/boolean.h>
101 #include <mach/port.h>
102 #include <mach/time_value.h>
103 #include <mach/message.h>
104 #include <mach/mach_param.h>
105 #include <mach/task_info.h>
106 #include <mach/exception_types.h>
107 #include <mach/vm_statistics.h>
108 #include <machine/task.h>
110 #include <kern/cpu_data.h>
111 #include <kern/queue.h>
112 #include <kern/exception.h>
113 #include <kern/locks.h>
114 #include <security/_label.h>
115 #include <ipc/ipc_port.h>
116 #endif /* MACH_KERNEL_PRIVATE */
118 #ifdef XNU_KERNEL_PRIVATE
120 #include <kern/kern_cdata.h>
121 #include <mach/sfi_class.h>
123 /* defns for task->rsu_controldata */
124 #define TASK_POLICY_CPU_RESOURCE_USAGE 0
125 #define TASK_POLICY_WIREDMEM_RESOURCE_USAGE 1
126 #define TASK_POLICY_VIRTUALMEM_RESOURCE_USAGE 2
127 #define TASK_POLICY_DISK_RESOURCE_USAGE 3
128 #define TASK_POLICY_NETWORK_RESOURCE_USAGE 4
129 #define TASK_POLICY_POWER_RESOURCE_USAGE 5
131 #define TASK_POLICY_RESOURCE_USAGE_COUNT 6
133 #define TASK_POLICY_CPUMON_DISABLE 0xFF
134 #define TASK_POLICY_CPUMON_DEFAULTS 0xFE
136 /* Resource usage/low resource attributes */
137 #define TASK_POLICY_RESOURCE_ATTRIBUTE_NONE 0x00
138 #define TASK_POLICY_RESOURCE_ATTRIBUTE_THROTTLE 0x01
139 #define TASK_POLICY_RESOURCE_ATTRIBUTE_SUSPEND 0x02
140 #define TASK_POLICY_RESOURCE_ATTRIBUTE_TERMINATE 0x03
141 #define TASK_POLICY_RESOURCE_ATTRIBUTE_NOTIFY_KQ 0x04
142 #define TASK_POLICY_RESOURCE_ATTRIBUTE_NOTIFY_EXC 0x05
143 #define TASK_POLICY_RESOURCE_ATTRIBUTE_DEFAULT TASK_POLICY_RESOURCE_ATTRIBUTE_NONE
145 #endif /* XNU_KERNEL_PRIVATE */
147 #ifdef MACH_KERNEL_PRIVATE
150 #include <kern/thread.h>
151 #include <mach/coalition.h>
154 #include <atm/atm_internal.h>
157 struct _cpu_time_qos_stats
{
158 uint64_t cpu_time_qos_default
;
159 uint64_t cpu_time_qos_maintenance
;
160 uint64_t cpu_time_qos_background
;
161 uint64_t cpu_time_qos_utility
;
162 uint64_t cpu_time_qos_legacy
;
163 uint64_t cpu_time_qos_user_initiated
;
164 uint64_t cpu_time_qos_user_interactive
;
168 #include <bank/bank_internal.h>
172 /* Synchronization/destruction information */
173 decl_lck_mtx_data(,lock
) /* Task's lock */
174 uint32_t ref_count
; /* Number of references to me */
175 boolean_t active
; /* Task has not been terminated */
176 boolean_t halting
; /* Task is being halted */
179 vm_map_t map
; /* Address space description */
180 queue_chain_t tasks
; /* global list of tasks */
181 void *user_data
; /* Arbitrary data settable via IPC */
183 #if defined(CONFIG_SCHED_MULTIQ)
184 sched_group_t sched_group
;
185 #endif /* defined(CONFIG_SCHED_MULTIQ) */
187 /* Threads in this task */
188 queue_head_t threads
;
190 processor_set_t pset_hint
;
191 struct affinity_space
*affinity_space
;
194 uint32_t active_thread_count
;
195 int suspend_count
; /* Internal scheduling only */
197 /* User-visible scheduling information */
198 integer_t user_stop_count
; /* outstanding stops */
199 integer_t legacy_stop_count
; /* outstanding legacy stops */
201 integer_t priority
; /* base priority for threads */
202 integer_t max_priority
; /* maximum priority for threads */
204 integer_t importance
; /* priority offset (BSD 'nice' value) */
206 /* Task security and audit tokens */
207 security_token_t sec_token
;
208 audit_token_t audit_token
;
211 uint64_t total_user_time
; /* terminated threads only */
212 uint64_t total_system_time
;
218 decl_lck_mtx_data(,itk_lock_data
)
219 struct ipc_port
*itk_self
; /* not a right, doesn't hold ref */
220 struct ipc_port
*itk_nself
; /* not a right, doesn't hold ref */
221 struct ipc_port
*itk_sself
; /* a send right */
222 struct exception_action exc_actions
[EXC_TYPES_COUNT
];
223 /* a send right each valid element */
224 struct ipc_port
*itk_host
; /* a send right */
225 struct ipc_port
*itk_bootstrap
; /* a send right */
226 struct ipc_port
*itk_seatbelt
; /* a send right */
227 struct ipc_port
*itk_gssd
; /* yet another send right */
228 struct ipc_port
*itk_debug_control
; /* send right for debugmode communications */
229 struct ipc_port
*itk_task_access
; /* and another send right */
230 struct ipc_port
*itk_resume
; /* a receive right to resume this task */
231 struct ipc_port
*itk_registered
[TASK_PORT_REGISTER_MAX
];
232 /* all send rights */
234 struct ipc_space
*itk_space
;
236 /* Synchronizer ownership information */
237 queue_head_t semaphore_list
; /* list of owned semaphores */
238 int semaphores_owned
; /* number of semaphores owned */
242 unsigned int priv_flags
; /* privilege resource flags */
243 #define VM_BACKING_STORE_PRIV 0x1
247 integer_t faults
; /* faults counter */
248 integer_t pageins
; /* pageins counter */
249 integer_t cow_faults
; /* copy on write fault counter */
250 integer_t messages_sent
; /* messages sent counter */
251 integer_t messages_received
; /* messages received counter */
252 integer_t syscalls_mach
; /* mach system call counter */
253 integer_t syscalls_unix
; /* unix system call counter */
254 uint32_t c_switch
; /* total context switches */
255 uint32_t p_switch
; /* total processor switches */
256 uint32_t ps_switch
; /* total pset switches */
258 zinfo_usage_t tkm_zinfo
; /* per-task, per-zone usage statistics */
263 kcdata_descriptor_t corpse_info
;
264 struct vm_shared_region
*shared_region
;
265 volatile uint32_t t_flags
; /* general-purpose task flags protected by task_lock (TL) */
266 #define TF_64B_ADDR 0x00000001 /* task has 64-bit addressing */
267 #define TF_64B_DATA 0x00000002 /* task has 64-bit data registers */
268 #define TF_CPUMON_WARNING 0x00000004 /* task has at least one thread in CPU usage warning zone */
269 #define TF_WAKEMON_WARNING 0x00000008 /* task is in wakeups monitor warning zone */
270 #define TF_TELEMETRY (TF_CPUMON_WARNING | TF_WAKEMON_WARNING) /* task is a telemetry participant */
271 #define TF_GPU_DENIED 0x00000010 /* task is not allowed to access the GPU */
272 #define TF_CORPSE 0x00000020 /* task is a corpse */
273 #define TF_PENDING_CORPSE 0x00000040 /* task corpse has not been reported yet */
275 #define task_has_64BitAddr(task) \
276 (((task)->t_flags & TF_64B_ADDR) != 0)
277 #define task_set_64BitAddr(task) \
278 ((task)->t_flags |= TF_64B_ADDR)
279 #define task_clear_64BitAddr(task) \
280 ((task)->t_flags &= ~TF_64B_ADDR)
281 #define task_has_64BitData(task) \
282 (((task)->t_flags & TF_64B_DATA) != 0)
284 #define task_is_a_corpse(task) \
285 (((task)->t_flags & TF_CORPSE) != 0)
287 #define task_set_corpse(task) \
288 ((task)->t_flags |= TF_CORPSE)
290 #define task_corpse_pending_report(task) \
291 (((task)->t_flags & TF_PENDING_CORPSE) != 0)
293 #define task_set_corpse_pending_report(task) \
294 ((task)->t_flags |= TF_PENDING_CORPSE)
296 #define task_clear_corpse_pending_report(task) \
297 ((task)->t_flags &= ~TF_PENDING_CORPSE)
299 mach_vm_address_t all_image_info_addr
; /* dyld __all_image_info */
300 mach_vm_size_t all_image_info_size
; /* section location and size */
303 #define TASK_PMC_FLAG 0x1 /* Bit in "t_chud" signifying PMC interest */
304 #define TASK_KPC_FORCED_ALL_CTRS 0x2 /* Bit in "t_chud" signifying KPC forced all counters */
306 uint32_t t_chud
; /* CHUD flags, used for Shark */
309 boolean_t pidsuspended
; /* pid_suspend called; no threads can execute */
310 boolean_t frozen
; /* frozen; private resident pages committed to swap */
311 boolean_t changing_freeze_state
; /* in the process of freezing or thawing */
312 uint16_t policy_ru_cpu
:4,
313 policy_ru_cpu_ext
:4,
315 applied_ru_cpu_ext
:4;
316 uint8_t rusage_cpu_flags
;
317 uint8_t rusage_cpu_percentage
; /* Task-wide CPU limit percentage */
318 uint64_t rusage_cpu_interval
; /* Task-wide CPU limit interval */
319 uint8_t rusage_cpu_perthr_percentage
; /* Per-thread CPU limit percentage */
320 uint64_t rusage_cpu_perthr_interval
; /* Per-thread CPU limit interval */
321 uint64_t rusage_cpu_deadline
;
322 thread_call_t rusage_cpu_callt
;
325 struct atm_task_descriptor
*atm_context
; /* pointer to per task atm descriptor */
328 struct bank_task
*bank_context
; /* pointer to per task bank structure */
331 #if IMPORTANCE_INHERITANCE
332 struct ipc_importance_task
*task_imp_base
; /* Base of IPC importance chain */
333 #endif /* IMPORTANCE_INHERITANCE */
335 vm_extmod_statistics_data_t extmod_statistics
;
338 int8_t suspends_outstanding
; /* suspends this task performed in excess of resumes */
341 struct task_requested_policy requested_policy
;
342 struct task_effective_policy effective_policy
;
343 struct task_pended_policy pended_policy
;
346 * Can be merged with imp_donor bits, once the IMPORTANCE_INHERITANCE macro goes away.
348 uint32_t low_mem_notified_warn
:1, /* warning low memory notification is sent to the task */
349 low_mem_notified_critical
:1, /* critical low memory notification is sent to the task */
350 purged_memory_warn
:1, /* purgeable memory of the task is purged for warning level pressure */
351 purged_memory_critical
:1, /* purgeable memory of the task is purged for critical level pressure */
352 low_mem_privileged_listener
:1, /* if set, task would like to know about pressure changes before other tasks on the system */
353 mem_notify_reserved
:27; /* reserved for future use */
355 io_stat_info_t task_io_stats
;
358 * The cpu_time_qos_stats fields are protected by the task lock
360 struct _cpu_time_qos_stats cpu_time_qos_stats
;
362 /* Statistics accumulated for terminated threads from this task */
363 uint32_t task_timer_wakeups_bin_1
;
364 uint32_t task_timer_wakeups_bin_2
;
365 uint64_t task_gpu_ns
;
367 /* # of purgeable volatile VM objects owned by this task: */
368 int task_volatile_objects
;
369 /* # of purgeable but not volatile VM objects owned by this task: */
370 int task_nonvolatile_objects
;
371 boolean_t task_purgeable_disowning
;
372 boolean_t task_purgeable_disowned
;
375 * A task's coalition set is "adopted" in task_create_internal
376 * and unset in task_deallocate_internal, so each array member
377 * can be referenced without the task lock.
378 * Note: these fields are protected by coalition->lock,
381 coalition_t coalition
[COALITION_NUM_TYPES
];
382 queue_chain_t task_coalition
[COALITION_NUM_TYPES
];
383 uint64_t dispatchqueue_offset
;
386 void *hv_task_target
; /* hypervisor virtual machine object associated with this task */
387 #endif /* HYPERVISOR */
390 #define task_lock(task) lck_mtx_lock(&(task)->lock)
391 #define task_lock_assert_owned(task) lck_mtx_assert(&(task)->lock, LCK_MTX_ASSERT_OWNED)
392 #define task_lock_try(task) lck_mtx_try_lock(&(task)->lock)
393 #define task_unlock(task) lck_mtx_unlock(&(task)->lock)
395 #define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr)
396 #define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp)
397 #define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data)
398 #define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data)
400 #define TASK_REFERENCE_LEAK_DEBUG 0
402 #if TASK_REFERENCE_LEAK_DEBUG
403 extern void task_reference_internal(task_t task
);
404 extern uint32_t task_deallocate_internal(task_t task
);
406 #define task_reference_internal(task) \
407 (void)hw_atomic_add(&(task)->ref_count, 1)
409 #define task_deallocate_internal(task) \
410 hw_atomic_sub(&(task)->ref_count, 1)
413 #define task_reference(task) \
415 if ((task) != TASK_NULL) \
416 task_reference_internal(task); \
419 extern kern_return_t
kernel_task_create(
421 vm_offset_t map_base
,
425 /* Initialize task module */
426 extern void task_init(void);
428 /* coalition_init() calls this to initialize ledgers before task_init() */
429 extern void init_task_ledgers(void);
431 #define current_task_fast() (current_thread()->task)
432 #define current_task() current_task_fast()
434 extern lck_attr_t task_lck_attr
;
435 extern lck_grp_t task_lck_grp
;
437 #define QOS_OVERRIDE_MODE_OVERHANG_PEAK 0
438 #define QOS_OVERRIDE_MODE_IGNORE_OVERRIDE 1
439 #define QOS_OVERRIDE_MODE_FINE_GRAINED_OVERRIDE 2
440 #define QOS_OVERRIDE_MODE_FINE_GRAINED_OVERRIDE_BUT_IGNORE_DISPATCH 3
441 #define QOS_OVERRIDE_MODE_FINE_GRAINED_OVERRIDE_BUT_SINGLE_MUTEX_OVERRIDE 4
443 extern uint32_t qos_override_mode
;
445 #else /* MACH_KERNEL_PRIVATE */
449 extern task_t
current_task(void);
451 extern void task_reference(task_t task
);
455 #endif /* MACH_KERNEL_PRIVATE */
459 #ifdef XNU_KERNEL_PRIVATE
461 /* Hold all threads in a task */
462 extern kern_return_t
task_hold(
465 /* Wait for task to stop running, either just to get off CPU or to cease being runnable */
466 extern kern_return_t
task_wait(
468 boolean_t until_not_runnable
);
470 /* Release hold on all threads in a task */
471 extern kern_return_t
task_release(
474 /* Suspend/resume a task where the kernel owns the suspend count */
475 extern kern_return_t
task_suspend_internal( task_t task
);
476 extern kern_return_t
task_resume_internal( task_t task
);
478 /* Suspends a task by placing a hold on its threads */
479 extern kern_return_t
task_pidsuspend(
481 extern kern_return_t
task_pidsuspend_locked(
484 /* Resumes a previously paused task */
485 extern kern_return_t
task_pidresume(
488 extern kern_return_t
task_send_trace_memory(
495 /* Freeze a task's resident pages */
496 extern kern_return_t
task_freeze(
498 uint32_t *purgeable_count
,
499 uint32_t *wired_count
,
500 uint32_t *clean_count
,
501 uint32_t *dirty_count
,
502 uint32_t dirty_budget
,
504 boolean_t walk_only
);
506 /* Thaw a currently frozen task */
507 extern kern_return_t
task_thaw(
510 #endif /* CONFIG_FREEZE */
512 /* Halt all other threads in the current task */
513 extern kern_return_t
task_start_halt(
516 /* Wait for other threads to halt and free halting task resources */
517 extern void task_complete_halt(
520 extern kern_return_t
task_terminate_internal(
523 extern kern_return_t
task_create_internal(
525 coalition_t
*parent_coalitions
,
526 boolean_t inherit_memory
,
528 task_t
*child_task
); /* OUT */
530 extern kern_return_t
task_importance(
532 integer_t importance
);
534 extern void task_power_info_locked(
536 task_power_info_t info
,
537 gpu_energy_data_t gpu_energy
);
539 extern uint64_t task_gpu_utilisation(
542 extern void task_vtimer_set(
546 extern void task_vtimer_clear(
550 extern void task_vtimer_update(
553 uint32_t *microsecs
);
555 #define TASK_VTIMER_USER 0x01
556 #define TASK_VTIMER_PROF 0x02
557 #define TASK_VTIMER_RLIM 0x04
559 extern void task_set_64bit(
563 extern void task_backing_store_privileged(
566 extern void task_set_dyld_info(
568 mach_vm_address_t addr
,
569 mach_vm_size_t size
);
571 /* Get number of activations in a task */
572 extern int get_task_numacts(
575 extern int get_task_numactivethreads(task_t task
);
576 extern kern_return_t
task_collect_crash_info(task_t task
);
578 /* JMM - should just be temporary (implementation in bsd_kern still) */
579 extern void set_bsdtask_info(task_t
,void *);
580 extern vm_map_t
get_task_map_reference(task_t
);
581 extern vm_map_t
swap_task_map(task_t
, thread_t
, vm_map_t
, boolean_t
);
582 extern pmap_t
get_task_pmap(task_t
);
583 extern uint64_t get_task_resident_size(task_t
);
584 extern uint64_t get_task_compressed(task_t
);
585 extern uint64_t get_task_resident_max(task_t
);
586 extern uint64_t get_task_phys_footprint(task_t
);
587 extern uint64_t get_task_phys_footprint_max(task_t
);
588 extern uint64_t get_task_purgeable_size(task_t
);
589 extern uint64_t get_task_cpu_time(task_t
);
590 extern uint64_t get_task_dispatchqueue_offset(task_t
);
592 extern kern_return_t
task_convert_phys_footprint_limit(int, int *);
593 extern kern_return_t
task_set_phys_footprint_limit_internal(task_t
, int, int *, boolean_t
);
594 extern kern_return_t
task_get_phys_footprint_limit(task_t task
, int *limit_mb
);
596 extern boolean_t
is_kerneltask(task_t task
);
598 extern kern_return_t
check_actforsig(task_t task
, thread_t thread
, int setast
);
600 extern kern_return_t
machine_task_get_state(
603 thread_state_t state
,
604 mach_msg_type_number_t
*state_count
);
606 extern kern_return_t
machine_task_set_state(
609 thread_state_t state
,
610 mach_msg_type_number_t state_count
);
612 extern void machine_task_terminate(task_t task
);
614 struct _task_ledger_indices
{
622 int alternate_accounting
;
623 int alternate_accounting_compressed
;
625 int internal_compressed
;
626 int purgeable_volatile
;
627 int purgeable_nonvolatile
;
628 int purgeable_volatile_compressed
;
629 int purgeable_nonvolatile_compressed
;
630 int platform_idle_wakeups
;
631 int interrupt_wakeups
;
633 int sfi_wait_times
[MAX_SFI_CLASS_ID
];
634 #endif /* CONFIG_SCHED_SFI */
636 int cpu_time_billed_to_me
;
637 int cpu_time_billed_to_others
;
640 extern struct _task_ledger_indices task_ledgers
;
642 /* Begin task_policy */
645 #define TASK_POLICY_DISABLE 0x0
646 #define TASK_POLICY_ENABLE 0x1
649 #define TASK_POLICY_INTERNAL 0x0
650 #define TASK_POLICY_EXTERNAL 0x1
651 #define TASK_POLICY_ATTRIBUTE 0x2
654 #define TASK_POLICY_TASK 0x4
655 #define TASK_POLICY_THREAD 0x8
657 /* flavors (also DBG_IMPORTANCE subclasses 0x20 - 0x3F) */
659 /* internal or external, thread or task */
660 #define TASK_POLICY_DARWIN_BG 0x21
661 #define TASK_POLICY_IOPOL 0x22
662 #define TASK_POLICY_IO 0x23
663 #define TASK_POLICY_PASSIVE_IO 0x24
665 /* internal, task only */
666 #define TASK_POLICY_DARWIN_BG_IOPOL 0x27
668 /* task-only attributes */
669 #define TASK_POLICY_TAL 0x28
670 #define TASK_POLICY_BOOST 0x29
671 #define TASK_POLICY_ROLE 0x2A
672 #define TASK_POLICY_SUPPRESSED_CPU 0x2B
673 #define TASK_POLICY_TERMINATED 0x2C
674 #define TASK_POLICY_NEW_SOCKETS_BG 0x2D
675 #define TASK_POLICY_LOWPRI_CPU 0x2E
676 #define TASK_POLICY_LATENCY_QOS 0x2F
677 #define TASK_POLICY_THROUGH_QOS 0x30
678 #define TASK_POLICY_WATCHERS_BG 0x31
680 #define TASK_POLICY_SFI_MANAGED 0x34
681 #define TASK_POLICY_ALL_SOCKETS_BG 0x37
683 #define TASK_POLICY_BASE_LATENCY_AND_THROUGHPUT_QOS 0x39 /* latency as value1, throughput as value2 */
684 #define TASK_POLICY_OVERRIDE_LATENCY_AND_THROUGHPUT_QOS 0x3A /* latency as value1, throughput as value2 */
686 /* thread-only attributes */
687 #define TASK_POLICY_PIDBIND_BG 0x32
688 #define TASK_POLICY_WORKQ_BG 0x33
689 #define TASK_POLICY_QOS 0x35
690 #define TASK_POLICY_QOS_OVERRIDE 0x36
691 #define TASK_POLICY_QOS_AND_RELPRIO 0x38 /* QoS as value1, relative priority as value2 */
693 #define TASK_POLICY_MAX 0x3F
695 /* The main entrance to task policy is this function */
696 extern void proc_set_task_policy(task_t task
, thread_t thread
, int category
, int flavor
, int value
);
697 extern int proc_get_task_policy(task_t task
, thread_t thread
, int category
, int flavor
);
699 /* For attributes that have two scalars as input/output */
700 extern void proc_set_task_policy2(task_t task
, thread_t thread
, int category
, int flavor
, int value1
, int value2
);
701 extern void proc_get_task_policy2(task_t task
, thread_t thread
, int category
, int flavor
, int *value1
, int *value2
);
703 /* For use by kernel threads and others who don't hold a reference on the target thread */
704 extern void proc_set_task_policy_thread(task_t task
, uint64_t tid
, int category
, int flavor
, int value
);
706 extern void proc_set_task_spawnpolicy(task_t task
, int apptype
, int qos_clamp
, int role
,
707 ipc_port_t
* portwatch_ports
, int portwatch_count
);
709 extern void task_set_main_thread_qos(task_t task
, thread_t main_thread
);
711 extern int proc_darwin_role_to_task_role(int darwin_role
, int* task_role
);
712 extern int proc_task_role_to_darwin_role(int task_role
);
715 /* IO Throttle tiers */
716 #define THROTTLE_LEVEL_NONE -1
717 #define THROTTLE_LEVEL_TIER0 0 /* IOPOL_NORMAL, IOPOL_DEFAULT, IOPOL_PASSIVE */
719 #define THROTTLE_LEVEL_THROTTLED 1
720 #define THROTTLE_LEVEL_TIER1 1 /* IOPOL_STANDARD */
721 #define THROTTLE_LEVEL_TIER2 2 /* IOPOL_UTILITY */
722 #define THROTTLE_LEVEL_TIER3 3 /* IOPOL_THROTTLE */
724 #define THROTTLE_LEVEL_START 0
725 #define THROTTLE_LEVEL_END 3
727 #define THROTTLE_LEVEL_COMPRESSOR_TIER0 THROTTLE_LEVEL_TIER0
728 #define THROTTLE_LEVEL_COMPRESSOR_TIER1 THROTTLE_LEVEL_TIER1
729 #define THROTTLE_LEVEL_COMPRESSOR_TIER2 THROTTLE_LEVEL_TIER2
731 #define THROTTLE_LEVEL_PAGEOUT_THROTTLED THROTTLE_LEVEL_TIER2
732 #define THROTTLE_LEVEL_PAGEOUT_UNTHROTTLED THROTTLE_LEVEL_TIER1
735 #define IOSCHED_METADATA_TIER THROTTLE_LEVEL_TIER1
736 #endif /* CONFIG_IOSCHED */
738 extern int proc_apply_workq_bgthreadpolicy(thread_t thread
);
739 extern int proc_restore_workq_bgthreadpolicy(thread_t thread
);
741 extern int proc_get_darwinbgstate(task_t task
, uint32_t *flagsp
);
742 extern boolean_t
proc_task_is_tal(task_t task
);
743 extern int task_get_apptype(task_t
);
744 extern integer_t
task_grab_latency_qos(task_t task
);
745 extern void task_policy_create(task_t task
, int parent_boosted
);
746 extern void thread_policy_create(thread_t thread
);
749 * for IPC importance hooks into task policy
751 typedef struct task_pend_token
{
752 uint32_t tpt_update_sockets
:1,
753 tpt_update_timers
:1,
754 tpt_update_watchers
:1,
755 tpt_update_live_donor
:1,
756 tpt_update_coal_sfi
:1;
757 } *task_pend_token_t
;
759 extern void task_policy_update_complete_unlocked(task_t task
, thread_t thread
, task_pend_token_t pend_token
);
760 extern void task_update_boost_locked(task_t task
, boolean_t boost_active
, task_pend_token_t pend_token
);
761 extern void task_set_boost_locked(task_t task
, boolean_t boost_active
);
764 * Get effective policy
765 * Only for use by relevant subsystem, should never be passed into a setter!
768 extern int proc_get_effective_task_policy(task_t task
, int flavor
);
769 extern int proc_get_effective_thread_policy(thread_t thread
, int flavor
);
771 /* temporary compatibility */
772 int proc_setthread_saved_importance(thread_t thread
, int importance
);
774 int proc_get_task_ruse_cpu(task_t task
, uint32_t *policyp
, uint8_t *percentagep
, uint64_t *intervalp
, uint64_t *deadlinep
);
775 int proc_set_task_ruse_cpu(task_t task
, uint32_t policy
, uint8_t percentage
, uint64_t interval
, uint64_t deadline
, int cpumon_entitled
);
776 int proc_clear_task_ruse_cpu(task_t task
, int cpumon_entitled
);
777 thread_t
task_findtid(task_t
, uint64_t);
778 void set_thread_iotier_override(thread_t
, int policy
);
780 boolean_t
proc_thread_qos_add_override(task_t task
, thread_t thread
, uint64_t tid
, int override_qos
, boolean_t first_override_for_resource
, user_addr_t resource
, int resource_type
);
781 boolean_t
proc_thread_qos_remove_override(task_t task
, thread_t thread
, uint64_t tid
, user_addr_t resource
, int resource_type
);
782 boolean_t
proc_thread_qos_reset_override(task_t task
, thread_t thread
, uint64_t tid
, user_addr_t resource
, int resource_type
);
783 void proc_thread_qos_deallocate(thread_t thread
);
785 #define TASK_RUSECPU_FLAGS_PROC_LIMIT 0x01
786 #define TASK_RUSECPU_FLAGS_PERTHR_LIMIT 0x02
787 #define TASK_RUSECPU_FLAGS_DEADLINE 0x04
788 #define TASK_RUSECPU_FLAGS_FATAL_CPUMON 0x08 /* CPU usage monitor violations are fatal */
789 #define TASK_RUSECPU_FLAGS_FATAL_WAKEUPSMON 0x10 /* wakeups monitor violations are fatal */
790 #define TASK_RUSECPU_FLAGS_PHYS_FOOTPRINT_EXCEPTION 0x20 /* exceeding physical footprint generates EXC_RESOURCE */
792 /* BSD call back functions */
793 extern int proc_apply_resource_actions(void * p
, int type
, int action
);
794 extern int proc_restore_resource_actions(void * p
, int type
, int action
);
795 extern int task_restore_resource_actions(task_t task
, int type
);
797 extern int task_clear_cpuusage(task_t task
, int cpumon_entitled
);
799 extern kern_return_t
task_wakeups_monitor_ctl(task_t task
, uint32_t *rate_hz
, int32_t *flags
);
800 extern kern_return_t
task_cpu_usage_monitor_ctl(task_t task
, uint32_t *flags
);
803 extern void task_importance_mark_donor(task_t task
, boolean_t donating
);
804 extern void task_importance_mark_live_donor(task_t task
, boolean_t donating
);
805 extern void task_importance_mark_receiver(task_t task
, boolean_t receiving
);
806 extern void task_importance_mark_denap_receiver(task_t task
, boolean_t denap
);
807 extern void task_importance_reset(task_t task
);
808 extern void task_atm_reset(task_t task
);
810 #if IMPORTANCE_INHERITANCE
812 extern boolean_t
task_is_importance_donor(task_t task
);
813 extern boolean_t
task_is_marked_importance_donor(task_t task
);
814 extern boolean_t
task_is_marked_live_importance_donor(task_t task
);
816 extern boolean_t
task_is_importance_receiver(task_t task
);
817 extern boolean_t
task_is_marked_importance_receiver(task_t task
);
819 extern boolean_t
task_is_importance_denap_receiver(task_t task
);
820 extern boolean_t
task_is_marked_importance_denap_receiver(task_t task
);
822 extern boolean_t
task_is_importance_receiver_type(task_t task
);
824 extern int task_importance_hold_watchport_assertion(task_t target_task
, uint32_t count
);
825 extern int task_importance_hold_internal_assertion(task_t target_task
, uint32_t count
);
826 extern int task_importance_drop_internal_assertion(task_t target_task
, uint32_t count
);
828 extern int task_importance_hold_file_lock_assertion(task_t target_task
, uint32_t count
);
829 extern int task_importance_drop_file_lock_assertion(task_t target_task
, uint32_t count
);
831 extern int task_importance_hold_legacy_external_assertion(task_t target_task
, uint32_t count
);
832 extern int task_importance_drop_legacy_external_assertion(task_t target_task
, uint32_t count
);
834 #endif /* IMPORTANCE_INHERITANCE */
836 extern int task_low_mem_privileged_listener(task_t task
, boolean_t new_value
, boolean_t
*old_value
);
837 extern boolean_t
task_has_been_notified(task_t task
, int pressurelevel
);
838 extern boolean_t
task_used_for_purging(task_t task
, int pressurelevel
);
839 extern void task_mark_has_been_notified(task_t task
, int pressurelevel
);
840 extern void task_mark_used_for_purging(task_t task
, int pressurelevel
);
841 extern void task_clear_has_been_notified(task_t task
, int pressurelevel
);
842 extern void task_clear_used_for_purging(task_t task
);
843 extern int task_importance_estimate(task_t task
);
845 extern int task_pid(task_t task
);
847 /* End task_policy */
849 extern kern_return_t
task_purge_volatile_memory(task_t task
);
851 extern void task_set_gpu_denied(task_t task
, boolean_t denied
);
852 extern boolean_t
task_is_gpu_denied(task_t task
);
854 #endif /* XNU_KERNEL_PRIVATE */
856 #ifdef KERNEL_PRIVATE
858 extern void *get_bsdtask_info(task_t
);
859 extern void *get_bsdthreadtask_info(thread_t
);
860 extern void task_bsdtask_kill(task_t
);
861 extern vm_map_t
get_task_map(task_t
);
862 extern ledger_t
get_task_ledger(task_t
);
864 extern boolean_t
get_task_pidsuspended(task_t
);
865 extern boolean_t
get_task_frozen(task_t
);
867 /* Convert from a task to a port */
868 extern ipc_port_t
convert_task_to_port(task_t
);
869 extern ipc_port_t
convert_task_name_to_port(task_name_t
);
870 extern ipc_port_t
convert_task_suspension_token_to_port(task_suspension_token_t task
);
872 /* Convert from a port (in this case, an SO right to a task's resume port) to a task. */
873 extern task_suspension_token_t
convert_port_to_task_suspension_token(ipc_port_t port
);
875 extern boolean_t
task_suspension_notify(mach_msg_header_t
*);
877 #endif /* KERNEL_PRIVATE */
879 extern task_t kernel_task
;
881 extern void task_deallocate(
884 extern void task_name_deallocate(
885 task_name_t task_name
);
887 extern void task_suspension_token_deallocate(
888 task_suspension_token_t token
);
891 #endif /* _KERN_TASK_H_ */