2 * Copyright (c) 2000-2010 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);
86 void *get_bsdtask_info(task_t t
)
91 void task_bsdtask_kill(task_t t
)
93 void * bsd_info
= get_bsdtask_info(t
);
94 if (bsd_info
!= NULL
) {
95 psignal(bsd_info
, SIGKILL
);
101 void *get_bsdthreadtask_info(thread_t th
)
103 return(th
->task
!= TASK_NULL
? th
->task
->bsd_info
: NULL
);
109 void set_bsdtask_info(task_t t
,void * v
)
117 void *get_bsdthread_info(thread_t th
)
125 int get_thread_lock_count(thread_t th
); /* forced forward */
126 int get_thread_lock_count(thread_t th
)
128 return(th
->mutex_count
);
132 * XXX: wait for BSD to fix signal code
133 * Until then, we cannot block here. We know the task
134 * can't go away, so we make sure it is still active after
135 * retrieving the first thread for extra safety.
137 thread_t
get_firstthread(task_t task
)
139 thread_t thread
= (thread_t
)(void *)queue_first(&task
->threads
);
141 if (queue_end(&task
->threads
, (queue_entry_t
)thread
))
142 thread
= THREAD_NULL
;
145 return (THREAD_NULL
);
153 thread_t
*result_out
,
156 kern_return_t result
= KERN_SUCCESS
;
157 thread_t inc
, thread
= THREAD_NULL
;
164 return (KERN_FAILURE
);
167 for (inc
= (thread_t
)(void *)queue_first(&task
->threads
);
168 !queue_end(&task
->threads
, (queue_entry_t
)inc
); ) {
169 thread_mtx_lock(inc
);
171 (inc
->sched_flags
& TH_SFLAG_ABORTED_MASK
) != TH_SFLAG_ABORT
) {
175 thread_mtx_unlock(inc
);
177 inc
= (thread_t
)(void *)queue_next(&inc
->task_threads
);
181 *result_out
= thread
;
185 act_set_astbsd(thread
);
187 thread_mtx_unlock(thread
);
190 result
= KERN_FAILURE
;
204 kern_return_t result
= KERN_FAILURE
;
212 return (KERN_FAILURE
);
215 for (inc
= (thread_t
)(void *)queue_first(&task
->threads
);
216 !queue_end(&task
->threads
, (queue_entry_t
)inc
); ) {
218 thread_mtx_lock(inc
);
221 (inc
->sched_flags
& TH_SFLAG_ABORTED_MASK
) != TH_SFLAG_ABORT
) {
222 result
= KERN_SUCCESS
;
226 thread_mtx_unlock(inc
);
230 inc
= (thread_t
)(void *)queue_next(&inc
->task_threads
);
233 if (result
== KERN_SUCCESS
) {
235 act_set_astbsd(thread
);
237 thread_mtx_unlock(thread
);
245 ledger_t
get_task_ledger(task_t t
)
251 * This is only safe to call from a thread executing in
252 * in the task's context or if the task is locked. Otherwise,
253 * the map could be switched for the task (and freed) before
254 * we go to return it here.
256 vm_map_t
get_task_map(task_t t
)
261 vm_map_t
get_task_map_reference(task_t t
)
274 vm_map_reference_swap(m
);
282 ipc_space_t
get_task_ipcspace(task_t t
)
284 return(t
->itk_space
);
287 int get_task_numactivethreads(task_t task
)
290 int num_active_thr
=0;
293 for (inc
= (thread_t
)(void *)queue_first(&task
->threads
);
294 !queue_end(&task
->threads
, (queue_entry_t
)inc
); inc
= (thread_t
)(void *)queue_next(&inc
->task_threads
))
300 return num_active_thr
;
303 int get_task_numacts(task_t t
)
305 return(t
->thread_count
);
308 /* does this machine need 64bit register set for signal handler */
309 int is_64signalregset(void)
311 if (task_has_64BitData(current_task())) {
319 * Swap in a new map for the task/thread pair; the old map reference is
320 * returned. Also does a pmap switch if thread provided is current thread.
323 swap_task_map(task_t task
, thread_t thread
, vm_map_t map
)
326 boolean_t doswitch
= (thread
== current_thread()) ? TRUE
: FALSE
;
328 if (task
!= thread
->task
)
329 panic("swap_task_map");
332 mp_disable_preemption();
335 thread
->map
= task
->map
= map
;
336 vm_commit_pagezero_status(map
);
339 #if defined(__arm__) || defined(__arm64__)
340 PMAP_SWITCH_USER(thread
, map
, cpu_number())
342 pmap_switch(map
->pmap
);
345 mp_enable_preemption();
348 #if (defined(__i386__) || defined(__x86_64__)) && NCOPY_WINDOWS > 0
349 inval_copy_windows(thread
);
357 * This is only safe to call from a thread executing in
358 * in the task's context or if the task is locked. Otherwise,
359 * the map could be switched for the task (and freed) before
360 * we go to return it here.
362 pmap_t
get_task_pmap(task_t t
)
364 return(t
->map
->pmap
);
370 uint64_t get_task_resident_size(task_t task
)
374 map
= (task
== kernel_task
) ? kernel_map
: task
->map
;
375 return((uint64_t)pmap_resident_count(map
->pmap
) * PAGE_SIZE_64
);
378 uint64_t get_task_compressed(task_t task
)
382 map
= (task
== kernel_task
) ? kernel_map
: task
->map
;
383 return((uint64_t)pmap_compressed(map
->pmap
) * PAGE_SIZE_64
);
386 uint64_t get_task_resident_max(task_t task
)
390 map
= (task
== kernel_task
) ? kernel_map
: task
->map
;
391 return((uint64_t)pmap_resident_max(map
->pmap
) * PAGE_SIZE_64
);
394 uint64_t get_task_purgeable_size(task_t task
)
397 ledger_amount_t credit
, debit
;
398 uint64_t volatile_size
= 0;
400 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.purgeable_volatile
, &credit
, &debit
);
401 if (ret
!= KERN_SUCCESS
) {
405 volatile_size
+= (credit
- debit
);
407 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.purgeable_volatile_compressed
, &credit
, &debit
);
408 if (ret
!= KERN_SUCCESS
) {
412 volatile_size
+= (credit
- debit
);
414 return volatile_size
;
420 uint64_t get_task_phys_footprint(task_t task
)
423 ledger_amount_t credit
, debit
;
425 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.phys_footprint
, &credit
, &debit
);
426 if (KERN_SUCCESS
== ret
) {
427 return (credit
- debit
);
436 uint64_t get_task_phys_footprint_recent_max(task_t task
)
441 ret
= ledger_get_recent_max(task
->ledger
, task_ledgers
.phys_footprint
, &max
);
442 if (KERN_SUCCESS
== ret
) {
452 uint64_t get_task_phys_footprint_lifetime_max(task_t task
)
457 ret
= ledger_get_lifetime_max(task
->ledger
, task_ledgers
.phys_footprint
, &max
);
459 if(KERN_SUCCESS
== ret
) {
469 uint64_t get_task_phys_footprint_limit(task_t task
)
474 ret
= ledger_get_limit(task
->ledger
, task_ledgers
.phys_footprint
, &max
);
475 if (KERN_SUCCESS
== ret
) {
482 uint64_t get_task_internal(task_t task
)
485 ledger_amount_t credit
, debit
;
487 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.internal
, &credit
, &debit
);
488 if (KERN_SUCCESS
== ret
) {
489 return (credit
- debit
);
495 uint64_t get_task_internal_compressed(task_t task
)
498 ledger_amount_t credit
, debit
;
500 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.internal_compressed
, &credit
, &debit
);
501 if (KERN_SUCCESS
== ret
) {
502 return (credit
- debit
);
508 uint64_t get_task_purgeable_nonvolatile(task_t task
)
511 ledger_amount_t credit
, debit
;
513 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.purgeable_nonvolatile
, &credit
, &debit
);
514 if (KERN_SUCCESS
== ret
) {
515 return (credit
- debit
);
521 uint64_t get_task_purgeable_nonvolatile_compressed(task_t task
)
524 ledger_amount_t credit
, debit
;
526 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.purgeable_nonvolatile_compressed
, &credit
, &debit
);
527 if (KERN_SUCCESS
== ret
) {
528 return (credit
- debit
);
534 uint64_t get_task_alternate_accounting(task_t task
)
537 ledger_amount_t credit
, debit
;
539 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.alternate_accounting
, &credit
, &debit
);
540 if (KERN_SUCCESS
== ret
) {
541 return (credit
- debit
);
547 uint64_t get_task_alternate_accounting_compressed(task_t task
)
550 ledger_amount_t credit
, debit
;
552 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.alternate_accounting_compressed
, &credit
, &debit
);
553 if (KERN_SUCCESS
== ret
) {
554 return (credit
- debit
);
560 uint64_t get_task_page_table(task_t task
)
563 ledger_amount_t credit
, debit
;
565 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.page_table
, &credit
, &debit
);
566 if (KERN_SUCCESS
== ret
) {
567 return (credit
- debit
);
573 uint64_t get_task_iokit_mapped(task_t task
)
576 ledger_amount_t credit
, debit
;
578 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.iokit_mapped
, &credit
, &debit
);
579 if (KERN_SUCCESS
== ret
) {
580 return (credit
- debit
);
586 uint64_t get_task_cpu_time(task_t task
)
589 ledger_amount_t credit
, debit
;
591 ret
= ledger_get_entries(task
->ledger
, task_ledgers
.cpu_time
, &credit
, &debit
);
592 if (KERN_SUCCESS
== ret
) {
593 return (credit
- debit
);
602 task_t
get_threadtask(thread_t th
)
614 return(vm_map_min(map
));
624 return(vm_map_max(map
));
636 get_vmsubmap_entries(
638 vm_object_offset_t start
,
639 vm_object_offset_t end
)
641 int total_entries
= 0;
642 vm_map_entry_t entry
;
646 entry
= vm_map_first_entry(map
);
647 while((entry
!= vm_map_to_entry(map
)) && (entry
->vme_start
< start
)) {
648 entry
= entry
->vme_next
;
651 while((entry
!= vm_map_to_entry(map
)) && (entry
->vme_start
< end
)) {
652 if(entry
->is_sub_map
) {
654 get_vmsubmap_entries(VME_SUBMAP(entry
),
662 entry
= entry
->vme_next
;
666 return(total_entries
);
673 int total_entries
= 0;
674 vm_map_entry_t entry
;
678 entry
= vm_map_first_entry(map
);
680 while(entry
!= vm_map_to_entry(map
)) {
681 if(entry
->is_sub_map
) {
683 get_vmsubmap_entries(VME_SUBMAP(entry
),
691 entry
= entry
->vme_next
;
695 return(total_entries
);
697 #endif /* CONFIG_COREDUMP */
709 return(task
->user_stop_count
);
719 return(th
->user_stop_count
);
726 get_task_pidsuspended(
729 return (task
->pidsuspended
);
739 return (task
->frozen
);
749 return ((th
->sched_flags
& TH_SFLAG_ABORTED_MASK
) == TH_SFLAG_ABORT
);
753 * This routine is like thread_should_abort() above. It checks to
754 * see if the current thread is aborted. But unlike above, it also
755 * checks to see if thread is safely aborted. If so, it returns
756 * that fact, and clears the condition (safe aborts only should
757 * have a single effect, and a poll of the abort status
761 current_thread_aborted (
764 thread_t th
= current_thread();
767 if ((th
->sched_flags
& TH_SFLAG_ABORTED_MASK
) == TH_SFLAG_ABORT
&&
768 (th
->options
& TH_OPT_INTMASK
) != THREAD_UNINT
)
770 if (th
->sched_flags
& TH_SFLAG_ABORTSAFELY
) {
773 if (th
->sched_flags
& TH_SFLAG_ABORTSAFELY
)
774 th
->sched_flags
&= ~TH_SFLAG_ABORTED_MASK
;
785 task_act_iterate_wth_args(
787 void (*func_callback
)(thread_t
, void *),
794 for (inc
= (thread_t
)(void *)queue_first(&task
->threads
);
795 !queue_end(&task
->threads
, (queue_entry_t
)inc
); ) {
796 (void) (*func_callback
)(inc
, func_arg
);
797 inc
= (thread_t
)(void *)queue_next(&inc
->task_threads
);
804 #include <sys/bsdtask_info.h>
807 fill_taskprocinfo(task_t task
, struct proc_taskinfo_internal
* ptinfo
)
810 task_absolutetime_info_data_t tinfo
;
812 uint32_t cswitch
= 0, numrunning
= 0;
813 uint32_t syscalls_unix
= 0;
814 uint32_t syscalls_mach
= 0;
818 map
= (task
== kernel_task
)? kernel_map
: task
->map
;
820 ptinfo
->pti_virtual_size
= map
->size
;
821 ptinfo
->pti_resident_size
=
822 (mach_vm_size_t
)(pmap_resident_count(map
->pmap
))
825 ptinfo
->pti_policy
= ((task
!= kernel_task
)?
826 POLICY_TIMESHARE
: POLICY_RR
);
828 tinfo
.threads_user
= tinfo
.threads_system
= 0;
829 tinfo
.total_user
= task
->total_user_time
;
830 tinfo
.total_system
= task
->total_system_time
;
832 queue_iterate(&task
->threads
, thread
, thread_t
, task_threads
) {
836 if (thread
->options
& TH_OPT_IDLE_THREAD
)
842 if ((thread
->state
& TH_RUN
) == TH_RUN
)
844 cswitch
+= thread
->c_switch
;
845 tval
= timer_grab(&thread
->user_timer
);
846 tinfo
.threads_user
+= tval
;
847 tinfo
.total_user
+= tval
;
849 tval
= timer_grab(&thread
->system_timer
);
851 if (thread
->precise_user_kernel_time
) {
852 tinfo
.threads_system
+= tval
;
853 tinfo
.total_system
+= tval
;
855 /* system_timer may represent either sys or user */
856 tinfo
.threads_user
+= tval
;
857 tinfo
.total_user
+= tval
;
860 syscalls_unix
+= thread
->syscalls_unix
;
861 syscalls_mach
+= thread
->syscalls_mach
;
863 thread_unlock(thread
);
867 ptinfo
->pti_total_system
= tinfo
.total_system
;
868 ptinfo
->pti_total_user
= tinfo
.total_user
;
869 ptinfo
->pti_threads_system
= tinfo
.threads_system
;
870 ptinfo
->pti_threads_user
= tinfo
.threads_user
;
872 ptinfo
->pti_faults
= task
->faults
;
873 ptinfo
->pti_pageins
= task
->pageins
;
874 ptinfo
->pti_cow_faults
= task
->cow_faults
;
875 ptinfo
->pti_messages_sent
= task
->messages_sent
;
876 ptinfo
->pti_messages_received
= task
->messages_received
;
877 ptinfo
->pti_syscalls_mach
= task
->syscalls_mach
+ syscalls_mach
;
878 ptinfo
->pti_syscalls_unix
= task
->syscalls_unix
+ syscalls_unix
;
879 ptinfo
->pti_csw
= task
->c_switch
+ cswitch
;
880 ptinfo
->pti_threadnum
= task
->thread_count
;
881 ptinfo
->pti_numrunning
= numrunning
;
882 ptinfo
->pti_priority
= task
->priority
;
888 fill_taskthreadinfo(task_t task
, uint64_t thaddr
, int thuniqueid
, struct proc_threadinfo_internal
* ptinfo
, void * vpp
, int *vidp
)
892 mach_msg_type_number_t count
;
893 thread_basic_info_data_t basic_info
;
899 for (thact
= (thread_t
)(void *)queue_first(&task
->threads
);
900 !queue_end(&task
->threads
, (queue_entry_t
)thact
); ) {
901 addr
= (thuniqueid
==0)?thact
->machine
.cthread_self
: thact
->thread_id
;
905 count
= THREAD_BASIC_INFO_COUNT
;
906 if ((kret
= thread_info_internal(thact
, THREAD_BASIC_INFO
, (thread_info_t
)&basic_info
, &count
)) != KERN_SUCCESS
) {
910 ptinfo
->pth_user_time
= ((basic_info
.user_time
.seconds
* (integer_t
)NSEC_PER_SEC
) + (basic_info
.user_time
.microseconds
* (integer_t
)NSEC_PER_USEC
));
911 ptinfo
->pth_system_time
= ((basic_info
.system_time
.seconds
* (integer_t
)NSEC_PER_SEC
) + (basic_info
.system_time
.microseconds
* (integer_t
)NSEC_PER_USEC
));
913 ptinfo
->pth_cpu_usage
= basic_info
.cpu_usage
;
914 ptinfo
->pth_policy
= basic_info
.policy
;
915 ptinfo
->pth_run_state
= basic_info
.run_state
;
916 ptinfo
->pth_flags
= basic_info
.flags
;
917 ptinfo
->pth_sleep_time
= basic_info
.sleep_time
;
918 ptinfo
->pth_curpri
= thact
->sched_pri
;
919 ptinfo
->pth_priority
= thact
->base_pri
;
920 ptinfo
->pth_maxpriority
= thact
->max_priority
;
922 if ((vpp
!= NULL
) && (thact
->uthread
!= NULL
))
923 bsd_threadcdir(thact
->uthread
, vpp
, vidp
);
924 bsd_getthreadname(thact
->uthread
,ptinfo
->pth_name
);
928 thact
= (thread_t
)(void *)queue_next(&thact
->task_threads
);
938 fill_taskthreadlist(task_t task
, void * buffer
, int thcount
)
945 uptr
= (uint64_t *)buffer
;
949 for (thact
= (thread_t
)(void *)queue_first(&task
->threads
);
950 !queue_end(&task
->threads
, (queue_entry_t
)thact
); ) {
951 thaddr
= thact
->machine
.cthread_self
;
954 if (numthr
>= thcount
)
956 thact
= (thread_t
)(void *)queue_next(&thact
->task_threads
);
961 return (int)(numthr
* sizeof(uint64_t));
966 get_numthreads(task_t task
)
968 return(task
->thread_count
);
972 * Gather the various pieces of info about the designated task,
973 * and collect it all into a single rusage_info.
976 fill_task_rusage(task_t task
, rusage_info_current
*ri
)
978 struct task_power_info powerinfo
;
980 assert(task
!= TASK_NULL
);
983 task_power_info_locked(task
, &powerinfo
, NULL
, NULL
);
984 ri
->ri_pkg_idle_wkups
= powerinfo
.task_platform_idle_wakeups
;
985 ri
->ri_interrupt_wkups
= powerinfo
.task_interrupt_wakeups
;
986 ri
->ri_user_time
= powerinfo
.total_user
;
987 ri
->ri_system_time
= powerinfo
.total_system
;
989 ledger_get_balance(task
->ledger
, task_ledgers
.phys_footprint
,
990 (ledger_amount_t
*)&ri
->ri_phys_footprint
);
991 ledger_get_balance(task
->ledger
, task_ledgers
.phys_mem
,
992 (ledger_amount_t
*)&ri
->ri_resident_size
);
993 ledger_get_balance(task
->ledger
, task_ledgers
.wired_mem
,
994 (ledger_amount_t
*)&ri
->ri_wired_size
);
996 ri
->ri_pageins
= task
->pageins
;
1003 fill_task_billed_usage(task_t task __unused
, rusage_info_current
*ri
)
1005 bank_billed_balance_safe(task
, &ri
->ri_billed_system_time
, &ri
->ri_billed_energy
);
1006 bank_serviced_balance_safe(task
, &ri
->ri_serviced_system_time
, &ri
->ri_serviced_energy
);
1010 fill_task_io_rusage(task_t task
, rusage_info_current
*ri
)
1012 assert(task
!= TASK_NULL
);
1015 if (task
->task_io_stats
) {
1016 ri
->ri_diskio_bytesread
= task
->task_io_stats
->disk_reads
.size
;
1017 ri
->ri_diskio_byteswritten
= (task
->task_io_stats
->total_io
.size
- task
->task_io_stats
->disk_reads
.size
);
1019 /* I/O Stats unavailable */
1020 ri
->ri_diskio_bytesread
= 0;
1021 ri
->ri_diskio_byteswritten
= 0;
1028 fill_task_qos_rusage(task_t task
, rusage_info_current
*ri
)
1032 assert(task
!= TASK_NULL
);
1035 /* Rollup Qos time of all the threads to task */
1036 queue_iterate(&task
->threads
, thread
, thread_t
, task_threads
) {
1037 if (thread
->options
& TH_OPT_IDLE_THREAD
)
1040 thread_update_qos_cpu_time(thread
);
1042 ri
->ri_cpu_time_qos_default
= task
->cpu_time_qos_stats
.cpu_time_qos_default
;
1043 ri
->ri_cpu_time_qos_maintenance
= task
->cpu_time_qos_stats
.cpu_time_qos_maintenance
;
1044 ri
->ri_cpu_time_qos_background
= task
->cpu_time_qos_stats
.cpu_time_qos_background
;
1045 ri
->ri_cpu_time_qos_utility
= task
->cpu_time_qos_stats
.cpu_time_qos_utility
;
1046 ri
->ri_cpu_time_qos_legacy
= task
->cpu_time_qos_stats
.cpu_time_qos_legacy
;
1047 ri
->ri_cpu_time_qos_user_initiated
= task
->cpu_time_qos_stats
.cpu_time_qos_user_initiated
;
1048 ri
->ri_cpu_time_qos_user_interactive
= task
->cpu_time_qos_stats
.cpu_time_qos_user_interactive
;
1055 fill_task_monotonic_rusage(task_t task
, rusage_info_current
*ri
)
1058 if (!mt_core_supported
) {
1062 assert(task
!= TASK_NULL
);
1064 uint64_t counts
[MT_CORE_NFIXED
] = {};
1065 mt_fixed_task_counts(task
, counts
);
1066 #ifdef MT_CORE_INSTRS
1067 ri
->ri_instructions
= counts
[MT_CORE_INSTRS
];
1068 #endif /* defined(MT_CORE_INSTRS) */
1069 ri
->ri_cycles
= counts
[MT_CORE_CYCLES
];
1070 #else /* MONOTONIC */
1071 #pragma unused(task, ri)
1072 #endif /* !MONOTONIC */
1076 get_task_logical_writes(task_t task
)
1078 assert(task
!= TASK_NULL
);
1079 struct ledger_entry_info lei
;
1082 ledger_get_entry_info(task
->ledger
, task_ledgers
.logical_writes
, &lei
);
1085 return lei
.lei_balance
;
1089 get_task_dispatchqueue_serialno_offset(task_t task
)
1091 uint64_t dq_serialno_offset
= 0;
1093 if (task
->bsd_info
) {
1094 dq_serialno_offset
= get_dispatchqueue_serialno_offset_from_proc(task
->bsd_info
);
1097 return dq_serialno_offset
;
1101 get_task_uniqueid(task_t task
)
1103 if (task
->bsd_info
) {
1104 return proc_uniqueid(task
->bsd_info
);
1111 get_task_version(task_t task
)
1113 if (task
->bsd_info
) {
1114 return proc_pidversion(task
->bsd_info
);
1122 get_task_crash_label(task_t task
)
1124 return task
->crash_label
;