2 * Copyright (c) 2000-2018 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@
28 #include <mach/mach_types.h>
29 #include <mach/machine/vm_param.h>
30 #include <mach/task.h>
32 #include <kern/kern_types.h>
33 #include <kern/ledger.h>
34 #include <kern/processor.h>
35 #include <kern/thread.h>
36 #include <kern/task.h>
39 #include <ipc/ipc_port.h>
40 #include <ipc/ipc_object.h>
41 #include <vm/vm_map.h>
42 #include <vm/vm_kern.h>
44 #include <vm/vm_protos.h> /* last */
45 #include <sys/resource.h>
46 #include <sys/signal.h>
49 #include <kern/monotonic.h>
50 #include <machine/monotonic.h>
51 #endif /* MONOTONIC */
53 #include <machine/limits.h>
55 #undef thread_should_halt
57 /* BSD KERN COMPONENT INTERFACE */
59 extern unsigned int not_in_kdp
; /* Skip acquiring locks if we're in kdp */
61 thread_t
get_firstthread(task_t
);
62 int get_task_userstop(task_t
);
63 int get_thread_userstop(thread_t
);
64 boolean_t
current_thread_aborted(void);
65 void task_act_iterate_wth_args(task_t
, void (*)(thread_t
, void *), void *);
66 kern_return_t
get_signalact(task_t
, thread_t
*, int);
67 int fill_task_rusage(task_t task
, rusage_info_current
*ri
);
68 int fill_task_io_rusage(task_t task
, rusage_info_current
*ri
);
69 int fill_task_qos_rusage(task_t task
, rusage_info_current
*ri
);
70 void fill_task_monotonic_rusage(task_t task
, rusage_info_current
*ri
);
71 uint64_t get_task_logical_writes(task_t task
);
72 void fill_task_billed_usage(task_t task
, rusage_info_current
*ri
);
73 void task_bsdtask_kill(task_t
);
75 extern uint64_t get_dispatchqueue_serialno_offset_from_proc(void *p
);
76 extern uint64_t proc_uniqueid(void *p
);
77 extern int proc_pidversion(void *p
);
80 extern void psignal(void *, int);
87 get_bsdtask_info(task_t t
)
93 task_bsdtask_kill(task_t t
)
95 void * bsd_info
= get_bsdtask_info(t
);
96 if (bsd_info
!= NULL
) {
97 psignal(bsd_info
, SIGKILL
);
104 get_bsdthreadtask_info(thread_t th
)
106 return th
->task
!= TASK_NULL
? th
->task
->bsd_info
: NULL
;
113 set_bsdtask_info(task_t t
, void * v
)
122 get_bsdthread_info(thread_t th
)
127 #if defined(__x86_64__)
129 * Returns non-zero if the thread has a non-NULL task
130 * and that task has an LDT.
133 thread_task_has_ldt(thread_t th
)
135 return th
->task
&& th
->task
->i386_ldt
!= 0;
137 #endif /* __x86_64__ */
142 int get_thread_lock_count(thread_t th
); /* forced forward */
144 get_thread_lock_count(thread_t th
)
146 return th
->mutex_count
;
150 * XXX: wait for BSD to fix signal code
151 * Until then, we cannot block here. We know the task
152 * can't go away, so we make sure it is still active after
153 * retrieving the first thread for extra safety.
156 get_firstthread(task_t task
)
158 thread_t thread
= (thread_t
)(void *)queue_first(&task
->threads
);
160 if (queue_end(&task
->threads
, (queue_entry_t
)thread
)) {
161 thread
= THREAD_NULL
;
174 thread_t
*result_out
,
177 kern_return_t result
= KERN_SUCCESS
;
178 thread_t inc
, thread
= THREAD_NULL
;
188 for (inc
= (thread_t
)(void *)queue_first(&task
->threads
);
189 !queue_end(&task
->threads
, (queue_entry_t
)inc
);) {
190 thread_mtx_lock(inc
);
192 (inc
->sched_flags
& TH_SFLAG_ABORTED_MASK
) != TH_SFLAG_ABORT
) {
196 thread_mtx_unlock(inc
);
198 inc
= (thread_t
)(void *)queue_next(&inc
->task_threads
);
202 *result_out
= thread
;
207 act_set_astbsd(thread
);
210 thread_mtx_unlock(thread
);
212 result
= KERN_FAILURE
;
227 kern_return_t result
= KERN_FAILURE
;
238 for (inc
= (thread_t
)(void *)queue_first(&task
->threads
);
239 !queue_end(&task
->threads
, (queue_entry_t
)inc
);) {
241 thread_mtx_lock(inc
);
244 (inc
->sched_flags
& TH_SFLAG_ABORTED_MASK
) != TH_SFLAG_ABORT
) {
245 result
= KERN_SUCCESS
;
249 thread_mtx_unlock(inc
);
253 inc
= (thread_t
)(void *)queue_next(&inc
->task_threads
);
256 if (result
== KERN_SUCCESS
) {
258 act_set_astbsd(thread
);
261 thread_mtx_unlock(thread
);
270 get_task_ledger(task_t t
)
276 * This is only safe to call from a thread executing in
277 * in the task's context or if the task is locked. Otherwise,
278 * the map could be switched for the task (and freed) before
279 * we go to return it here.
282 get_task_map(task_t t
)
288 get_task_map_reference(task_t t
)
302 vm_map_reference_swap(m
);
311 get_task_ipcspace(task_t t
)
317 get_task_numactivethreads(task_t task
)
320 int num_active_thr
= 0;
323 for (inc
= (thread_t
)(void *)queue_first(&task
->threads
);
324 !queue_end(&task
->threads
, (queue_entry_t
)inc
); inc
= (thread_t
)(void *)queue_next(&inc
->task_threads
)) {
330 return num_active_thr
;
334 get_task_numacts(task_t t
)
336 return t
->thread_count
;
339 /* does this machine need 64bit register set for signal handler */
341 is_64signalregset(void)
343 if (task_has_64Bit_data(current_task())) {
351 * Swap in a new map for the task/thread pair; the old map reference is
352 * returned. Also does a pmap switch if thread provided is current thread.
355 swap_task_map(task_t task
, thread_t thread
, vm_map_t map
)
358 boolean_t doswitch
= (thread
== current_thread()) ? TRUE
: FALSE
;
360 if (task
!= thread
->task
) {
361 panic("swap_task_map");
365 mp_disable_preemption();
368 thread
->map
= task
->map
= map
;
369 vm_commit_pagezero_status(map
);
372 PMAP_SWITCH_USER(thread
, map
, cpu_number());
374 mp_enable_preemption();
377 #if defined(__x86_64__) && NCOPY_WINDOWS > 0
378 inval_copy_windows(thread
);
386 * This is only safe to call from a thread executing in
387 * in the task's context or if the task is locked. Otherwise,
388 * the map could be switched for the task (and freed) before
389 * we go to return it here.
392 get_task_pmap(task_t t
)
401 get_task_resident_size(task_t task
)
405 map
= (task
== kernel_task
) ? kernel_map
: task
->map
;
406 return (uint64_t)pmap_resident_count(map
->pmap
) * PAGE_SIZE_64
;
410 get_task_compressed(task_t task
)
414 map
= (task
== kernel_task
) ? kernel_map
: task
->map
;
415 return (uint64_t)pmap_compressed(map
->pmap
) * PAGE_SIZE_64
;
419 get_task_resident_max(task_t task
)
423 map
= (task
== kernel_task
) ? kernel_map
: task
->map
;
424 return (uint64_t)pmap_resident_max(map
->pmap
) * PAGE_SIZE_64
;
428 get_task_purgeable_size(task_t task
)
431 ledger_amount_t credit
, debit
;
432 uint64_t volatile_size
= 0;
434 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.purgeable_volatile
, &credit
, &debit
);
435 if (ret
!= KERN_SUCCESS
) {
439 volatile_size
+= (credit
- debit
);
441 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.purgeable_volatile_compressed
, &credit
, &debit
);
442 if (ret
!= KERN_SUCCESS
) {
446 volatile_size
+= (credit
- debit
);
448 return volatile_size
;
455 get_task_phys_footprint(task_t task
)
458 ledger_amount_t credit
, debit
;
460 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.phys_footprint
, &credit
, &debit
);
461 if (KERN_SUCCESS
== ret
) {
462 return credit
- debit
;
468 #if CONFIG_LEDGER_INTERVAL_MAX
473 get_task_phys_footprint_interval_max(task_t task
, int reset
)
478 ret
= ledger_get_interval_max(task
->ledger
, task_ledgers
.phys_footprint
, &max
, reset
);
480 if (KERN_SUCCESS
== ret
) {
486 #endif /* CONFIG_LEDGER_INTERVAL_MAX */
492 get_task_phys_footprint_lifetime_max(task_t task
)
497 ret
= ledger_get_lifetime_max(task
->ledger
, task_ledgers
.phys_footprint
, &max
);
499 if (KERN_SUCCESS
== ret
) {
510 get_task_phys_footprint_limit(task_t task
)
515 ret
= ledger_get_limit(task
->ledger
, task_ledgers
.phys_footprint
, &max
);
516 if (KERN_SUCCESS
== ret
) {
524 get_task_internal(task_t task
)
527 ledger_amount_t credit
, debit
;
529 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.internal
, &credit
, &debit
);
530 if (KERN_SUCCESS
== ret
) {
531 return credit
- debit
;
538 get_task_internal_compressed(task_t task
)
541 ledger_amount_t credit
, debit
;
543 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.internal_compressed
, &credit
, &debit
);
544 if (KERN_SUCCESS
== ret
) {
545 return credit
- debit
;
552 get_task_purgeable_nonvolatile(task_t task
)
555 ledger_amount_t credit
, debit
;
557 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.purgeable_nonvolatile
, &credit
, &debit
);
558 if (KERN_SUCCESS
== ret
) {
559 return credit
- debit
;
566 get_task_purgeable_nonvolatile_compressed(task_t task
)
569 ledger_amount_t credit
, debit
;
571 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.purgeable_nonvolatile_compressed
, &credit
, &debit
);
572 if (KERN_SUCCESS
== ret
) {
573 return credit
- debit
;
580 get_task_alternate_accounting(task_t task
)
583 ledger_amount_t credit
, debit
;
585 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.alternate_accounting
, &credit
, &debit
);
586 if (KERN_SUCCESS
== ret
) {
587 return credit
- debit
;
594 get_task_alternate_accounting_compressed(task_t task
)
597 ledger_amount_t credit
, debit
;
599 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.alternate_accounting_compressed
, &credit
, &debit
);
600 if (KERN_SUCCESS
== ret
) {
601 return credit
- debit
;
608 get_task_page_table(task_t task
)
611 ledger_amount_t credit
, debit
;
613 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.page_table
, &credit
, &debit
);
614 if (KERN_SUCCESS
== ret
) {
615 return credit
- debit
;
622 get_task_iokit_mapped(task_t task
)
625 ledger_amount_t credit
, debit
;
627 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.iokit_mapped
, &credit
, &debit
);
628 if (KERN_SUCCESS
== ret
) {
629 return credit
- debit
;
636 get_task_network_nonvolatile(task_t task
)
639 ledger_amount_t credit
, debit
;
641 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.network_nonvolatile
, &credit
, &debit
);
642 if (KERN_SUCCESS
== ret
) {
643 return credit
- debit
;
650 get_task_network_nonvolatile_compressed(task_t task
)
653 ledger_amount_t credit
, debit
;
655 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.network_nonvolatile_compressed
, &credit
, &debit
);
656 if (KERN_SUCCESS
== ret
) {
657 return credit
- debit
;
664 get_task_wired_mem(task_t task
)
667 ledger_amount_t credit
, debit
;
669 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.wired_mem
, &credit
, &debit
);
670 if (KERN_SUCCESS
== ret
) {
671 return credit
- debit
;
679 get_task_cpu_time(task_t task
)
682 ledger_amount_t credit
, debit
;
684 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.cpu_time
, &credit
, &debit
);
685 if (KERN_SUCCESS
== ret
) {
686 return credit
- debit
;
696 get_threadtask(thread_t th
)
708 return vm_map_min(map
);
718 return vm_map_max(map
);
730 get_vmsubmap_entries(
732 vm_object_offset_t start
,
733 vm_object_offset_t end
)
735 int total_entries
= 0;
736 vm_map_entry_t entry
;
741 entry
= vm_map_first_entry(map
);
742 while ((entry
!= vm_map_to_entry(map
)) && (entry
->vme_start
< start
)) {
743 entry
= entry
->vme_next
;
746 while ((entry
!= vm_map_to_entry(map
)) && (entry
->vme_start
< end
)) {
747 if (entry
->is_sub_map
) {
749 get_vmsubmap_entries(VME_SUBMAP(entry
),
757 entry
= entry
->vme_next
;
762 return total_entries
;
769 int total_entries
= 0;
770 vm_map_entry_t entry
;
775 entry
= vm_map_first_entry(map
);
777 while (entry
!= vm_map_to_entry(map
)) {
778 if (entry
->is_sub_map
) {
780 get_vmsubmap_entries(VME_SUBMAP(entry
),
788 entry
= entry
->vme_next
;
793 return total_entries
;
795 #endif /* CONFIG_COREDUMP */
807 return task
->user_stop_count
;
817 return th
->user_stop_count
;
824 get_task_pidsuspended(
827 return task
->pidsuspended
;
847 return (th
->sched_flags
& TH_SFLAG_ABORTED_MASK
) == TH_SFLAG_ABORT
;
851 * This routine is like thread_should_abort() above. It checks to
852 * see if the current thread is aborted. But unlike above, it also
853 * checks to see if thread is safely aborted. If so, it returns
854 * that fact, and clears the condition (safe aborts only should
855 * have a single effect, and a poll of the abort status
859 current_thread_aborted(
862 thread_t th
= current_thread();
865 if ((th
->sched_flags
& TH_SFLAG_ABORTED_MASK
) == TH_SFLAG_ABORT
&&
866 (th
->options
& TH_OPT_INTMASK
) != THREAD_UNINT
) {
869 if (th
->sched_flags
& TH_SFLAG_ABORTSAFELY
) {
872 if (th
->sched_flags
& TH_SFLAG_ABORTSAFELY
) {
873 th
->sched_flags
&= ~TH_SFLAG_ABORTED_MASK
;
885 task_act_iterate_wth_args(
887 void (*func_callback
)(thread_t
, void *),
894 for (inc
= (thread_t
)(void *)queue_first(&task
->threads
);
895 !queue_end(&task
->threads
, (queue_entry_t
)inc
);) {
896 (void) (*func_callback
)(inc
, func_arg
);
897 inc
= (thread_t
)(void *)queue_next(&inc
->task_threads
);
904 #include <sys/bsdtask_info.h>
907 fill_taskprocinfo(task_t task
, struct proc_taskinfo_internal
* ptinfo
)
910 task_absolutetime_info_data_t tinfo
;
912 uint32_t cswitch
= 0, numrunning
= 0;
913 uint32_t syscalls_unix
= 0;
914 uint32_t syscalls_mach
= 0;
918 map
= (task
== kernel_task
)? kernel_map
: task
->map
;
920 ptinfo
->pti_virtual_size
= map
->size
;
921 ptinfo
->pti_resident_size
=
922 (mach_vm_size_t
)(pmap_resident_count(map
->pmap
))
925 ptinfo
->pti_policy
= ((task
!= kernel_task
)?
926 POLICY_TIMESHARE
: POLICY_RR
);
928 tinfo
.threads_user
= tinfo
.threads_system
= 0;
929 tinfo
.total_user
= task
->total_user_time
;
930 tinfo
.total_system
= task
->total_system_time
;
932 queue_iterate(&task
->threads
, thread
, thread_t
, task_threads
) {
936 if (thread
->options
& TH_OPT_IDLE_THREAD
) {
943 if ((thread
->state
& TH_RUN
) == TH_RUN
) {
946 cswitch
+= thread
->c_switch
;
947 tval
= timer_grab(&thread
->user_timer
);
948 tinfo
.threads_user
+= tval
;
949 tinfo
.total_user
+= tval
;
951 tval
= timer_grab(&thread
->system_timer
);
953 if (thread
->precise_user_kernel_time
) {
954 tinfo
.threads_system
+= tval
;
955 tinfo
.total_system
+= tval
;
957 /* system_timer may represent either sys or user */
958 tinfo
.threads_user
+= tval
;
959 tinfo
.total_user
+= tval
;
962 syscalls_unix
+= thread
->syscalls_unix
;
963 syscalls_mach
+= thread
->syscalls_mach
;
965 thread_unlock(thread
);
969 ptinfo
->pti_total_system
= tinfo
.total_system
;
970 ptinfo
->pti_total_user
= tinfo
.total_user
;
971 ptinfo
->pti_threads_system
= tinfo
.threads_system
;
972 ptinfo
->pti_threads_user
= tinfo
.threads_user
;
974 ptinfo
->pti_faults
= task
->faults
;
975 ptinfo
->pti_pageins
= task
->pageins
;
976 ptinfo
->pti_cow_faults
= task
->cow_faults
;
977 ptinfo
->pti_messages_sent
= task
->messages_sent
;
978 ptinfo
->pti_messages_received
= task
->messages_received
;
979 ptinfo
->pti_syscalls_mach
= task
->syscalls_mach
+ syscalls_mach
;
980 ptinfo
->pti_syscalls_unix
= task
->syscalls_unix
+ syscalls_unix
;
981 ptinfo
->pti_csw
= task
->c_switch
+ cswitch
;
982 ptinfo
->pti_threadnum
= task
->thread_count
;
983 ptinfo
->pti_numrunning
= numrunning
;
984 ptinfo
->pti_priority
= task
->priority
;
990 fill_taskthreadinfo(task_t task
, uint64_t thaddr
, bool thuniqueid
, struct proc_threadinfo_internal
* ptinfo
, void * vpp
, int *vidp
)
994 mach_msg_type_number_t count
;
995 thread_basic_info_data_t basic_info
;
1001 for (thact
= (thread_t
)(void *)queue_first(&task
->threads
);
1002 !queue_end(&task
->threads
, (queue_entry_t
)thact
);) {
1003 addr
= (thuniqueid
) ? thact
->thread_id
: thact
->machine
.cthread_self
;
1004 if (addr
== thaddr
) {
1005 count
= THREAD_BASIC_INFO_COUNT
;
1006 if ((kret
= thread_info_internal(thact
, THREAD_BASIC_INFO
, (thread_info_t
)&basic_info
, &count
)) != KERN_SUCCESS
) {
1010 ptinfo
->pth_user_time
= ((basic_info
.user_time
.seconds
* (integer_t
)NSEC_PER_SEC
) + (basic_info
.user_time
.microseconds
* (integer_t
)NSEC_PER_USEC
));
1011 ptinfo
->pth_system_time
= ((basic_info
.system_time
.seconds
* (integer_t
)NSEC_PER_SEC
) + (basic_info
.system_time
.microseconds
* (integer_t
)NSEC_PER_USEC
));
1013 ptinfo
->pth_cpu_usage
= basic_info
.cpu_usage
;
1014 ptinfo
->pth_policy
= basic_info
.policy
;
1015 ptinfo
->pth_run_state
= basic_info
.run_state
;
1016 ptinfo
->pth_flags
= basic_info
.flags
;
1017 ptinfo
->pth_sleep_time
= basic_info
.sleep_time
;
1018 ptinfo
->pth_curpri
= thact
->sched_pri
;
1019 ptinfo
->pth_priority
= thact
->base_pri
;
1020 ptinfo
->pth_maxpriority
= thact
->max_priority
;
1022 if ((vpp
!= NULL
) && (thact
->uthread
!= NULL
)) {
1023 bsd_threadcdir(thact
->uthread
, vpp
, vidp
);
1025 bsd_getthreadname(thact
->uthread
, ptinfo
->pth_name
);
1029 thact
= (thread_t
)(void *)queue_next(&thact
->task_threads
);
1039 fill_taskthreadlist(task_t task
, void * buffer
, int thcount
, bool thuniqueid
)
1046 uptr
= (uint64_t *)buffer
;
1050 for (thact
= (thread_t
)(void *)queue_first(&task
->threads
);
1051 !queue_end(&task
->threads
, (queue_entry_t
)thact
);) {
1052 thaddr
= (thuniqueid
) ? thact
->thread_id
: thact
->machine
.cthread_self
;
1055 if (numthr
>= thcount
) {
1058 thact
= (thread_t
)(void *)queue_next(&thact
->task_threads
);
1063 return (int)(numthr
* sizeof(uint64_t));
1067 get_numthreads(task_t task
)
1069 return task
->thread_count
;
1073 * Gather the various pieces of info about the designated task,
1074 * and collect it all into a single rusage_info.
1077 fill_task_rusage(task_t task
, rusage_info_current
*ri
)
1079 struct task_power_info powerinfo
;
1081 assert(task
!= TASK_NULL
);
1084 task_power_info_locked(task
, &powerinfo
, NULL
, NULL
);
1085 ri
->ri_pkg_idle_wkups
= powerinfo
.task_platform_idle_wakeups
;
1086 ri
->ri_interrupt_wkups
= powerinfo
.task_interrupt_wakeups
;
1087 ri
->ri_user_time
= powerinfo
.total_user
;
1088 ri
->ri_system_time
= powerinfo
.total_system
;
1090 ledger_get_balance(task
->ledger
, task_ledgers
.phys_footprint
,
1091 (ledger_amount_t
*)&ri
->ri_phys_footprint
);
1092 ledger_get_balance(task
->ledger
, task_ledgers
.phys_mem
,
1093 (ledger_amount_t
*)&ri
->ri_resident_size
);
1094 ledger_get_balance(task
->ledger
, task_ledgers
.wired_mem
,
1095 (ledger_amount_t
*)&ri
->ri_wired_size
);
1097 ri
->ri_pageins
= task
->pageins
;
1104 fill_task_billed_usage(task_t task __unused
, rusage_info_current
*ri
)
1106 bank_billed_balance_safe(task
, &ri
->ri_billed_system_time
, &ri
->ri_billed_energy
);
1107 bank_serviced_balance_safe(task
, &ri
->ri_serviced_system_time
, &ri
->ri_serviced_energy
);
1111 fill_task_io_rusage(task_t task
, rusage_info_current
*ri
)
1113 assert(task
!= TASK_NULL
);
1116 if (task
->task_io_stats
) {
1117 ri
->ri_diskio_bytesread
= task
->task_io_stats
->disk_reads
.size
;
1118 ri
->ri_diskio_byteswritten
= (task
->task_io_stats
->total_io
.size
- task
->task_io_stats
->disk_reads
.size
);
1120 /* I/O Stats unavailable */
1121 ri
->ri_diskio_bytesread
= 0;
1122 ri
->ri_diskio_byteswritten
= 0;
1129 fill_task_qos_rusage(task_t task
, rusage_info_current
*ri
)
1133 assert(task
!= TASK_NULL
);
1136 /* Rollup QoS time of all the threads to task */
1137 queue_iterate(&task
->threads
, thread
, thread_t
, task_threads
) {
1138 if (thread
->options
& TH_OPT_IDLE_THREAD
) {
1142 thread_update_qos_cpu_time(thread
);
1144 ri
->ri_cpu_time_qos_default
= task
->cpu_time_eqos_stats
.cpu_time_qos_default
;
1145 ri
->ri_cpu_time_qos_maintenance
= task
->cpu_time_eqos_stats
.cpu_time_qos_maintenance
;
1146 ri
->ri_cpu_time_qos_background
= task
->cpu_time_eqos_stats
.cpu_time_qos_background
;
1147 ri
->ri_cpu_time_qos_utility
= task
->cpu_time_eqos_stats
.cpu_time_qos_utility
;
1148 ri
->ri_cpu_time_qos_legacy
= task
->cpu_time_eqos_stats
.cpu_time_qos_legacy
;
1149 ri
->ri_cpu_time_qos_user_initiated
= task
->cpu_time_eqos_stats
.cpu_time_qos_user_initiated
;
1150 ri
->ri_cpu_time_qos_user_interactive
= task
->cpu_time_eqos_stats
.cpu_time_qos_user_interactive
;
1157 fill_task_monotonic_rusage(task_t task
, rusage_info_current
*ri
)
1160 if (!mt_core_supported
) {
1164 assert(task
!= TASK_NULL
);
1166 uint64_t counts
[MT_CORE_NFIXED
] = { 0 };
1167 mt_fixed_task_counts(task
, counts
);
1168 #ifdef MT_CORE_INSTRS
1169 ri
->ri_instructions
= counts
[MT_CORE_INSTRS
];
1170 #endif /* defined(MT_CORE_INSTRS) */
1171 ri
->ri_cycles
= counts
[MT_CORE_CYCLES
];
1172 #else /* MONOTONIC */
1173 #pragma unused(task, ri)
1174 #endif /* !MONOTONIC */
1178 get_task_logical_writes(task_t task
)
1180 assert(task
!= TASK_NULL
);
1181 struct ledger_entry_info lei
;
1184 ledger_get_entry_info(task
->ledger
, task_ledgers
.logical_writes
, &lei
);
1187 return lei
.lei_balance
;
1191 get_task_dispatchqueue_serialno_offset(task_t task
)
1193 uint64_t dq_serialno_offset
= 0;
1195 if (task
->bsd_info
) {
1196 dq_serialno_offset
= get_dispatchqueue_serialno_offset_from_proc(task
->bsd_info
);
1199 return dq_serialno_offset
;
1203 get_task_uniqueid(task_t task
)
1205 if (task
->bsd_info
) {
1206 return proc_uniqueid(task
->bsd_info
);
1213 get_task_version(task_t task
)
1215 if (task
->bsd_info
) {
1216 return proc_pidversion(task
->bsd_info
);
1224 get_task_crash_label(task_t task
)
1226 return task
->crash_label
;