X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/813fb2f63a553c957e917ede5f119b021d6ce391..b226f5e54a60dc81db17b1260381d7dbfea3cdf1:/osfmk/kern/bsd_kern.c diff --git a/osfmk/kern/bsd_kern.c b/osfmk/kern/bsd_kern.c index e9e601433..b28d396c2 100644 --- a/osfmk/kern/bsd_kern.c +++ b/osfmk/kern/bsd_kern.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2010 Apple Inc. All rights reserved. + * Copyright (c) 2000-2018 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -45,6 +45,13 @@ #include #include +#if MONOTONIC +#include +#include +#endif /* MONOTONIC */ + +#include + #undef thread_should_halt /* BSD KERN COMPONENT INTERFACE */ @@ -60,11 +67,14 @@ kern_return_t get_signalact(task_t , thread_t *, int); int fill_task_rusage(task_t task, rusage_info_current *ri); int fill_task_io_rusage(task_t task, rusage_info_current *ri); int fill_task_qos_rusage(task_t task, rusage_info_current *ri); +void fill_task_monotonic_rusage(task_t task, rusage_info_current *ri); +uint64_t get_task_logical_writes(task_t task); void fill_task_billed_usage(task_t task, rusage_info_current *ri); void task_bsdtask_kill(task_t); extern uint64_t get_dispatchqueue_serialno_offset_from_proc(void *p); extern uint64_t proc_uniqueid(void *p); +extern int proc_pidversion(void *p); #if MACH_BSD extern void psignal(void *, int); @@ -298,7 +308,7 @@ int get_task_numacts(task_t t) /* does this machine need 64bit register set for signal handler */ int is_64signalregset(void) { - if (task_has_64BitData(current_task())) { + if (task_has_64Bit_data(current_task())) { return(1); } @@ -326,7 +336,11 @@ swap_task_map(task_t task, thread_t thread, vm_map_t map) vm_commit_pagezero_status(map); if (doswitch) { +#if defined(__arm__) || defined(__arm64__) + PMAP_SWITCH_USER(thread, map, cpu_number()) +#else pmap_switch(map->pmap); +#endif } mp_enable_preemption(); task_unlock(task); @@ -403,11 +417,11 @@ uint64_t get_task_purgeable_size(task_t task) /* * */ -uint64_t get_task_phys_footprint(task_t task) -{ +uint64_t get_task_phys_footprint(task_t task) +{ kern_return_t ret; ledger_amount_t credit, debit; - + ret = ledger_get_entries(task->ledger, task_ledgers.phys_footprint, &credit, &debit); if (KERN_SUCCESS == ret) { return (credit - debit); @@ -416,16 +430,36 @@ uint64_t get_task_phys_footprint(task_t task) return 0; } +#if CONFIG_LEDGER_INTERVAL_MAX /* * */ -uint64_t get_task_phys_footprint_max(task_t task) -{ +uint64_t get_task_phys_footprint_interval_max(task_t task, int reset) +{ kern_return_t ret; ledger_amount_t max; - - ret = ledger_get_maximum(task->ledger, task_ledgers.phys_footprint, &max); - if (KERN_SUCCESS == ret) { + + ret = ledger_get_interval_max(task->ledger, task_ledgers.phys_footprint, &max, reset); + + if(KERN_SUCCESS == ret) { + return max; + } + + return 0; +} +#endif /* CONFIG_LEDGER_INTERVAL_MAX */ + +/* + * + */ +uint64_t get_task_phys_footprint_lifetime_max(task_t task) +{ + kern_return_t ret; + ledger_amount_t max; + + ret = ledger_get_lifetime_max(task->ledger, task_ledgers.phys_footprint, &max); + + if(KERN_SUCCESS == ret) { return max; } @@ -552,6 +586,46 @@ uint64_t get_task_iokit_mapped(task_t task) return 0; } +uint64_t get_task_network_nonvolatile(task_t task) +{ + kern_return_t ret; + ledger_amount_t credit, debit; + + ret = ledger_get_entries(task->ledger, task_ledgers.network_nonvolatile, &credit, &debit); + if (KERN_SUCCESS == ret) { + return (credit - debit); + } + + return 0; +} + +uint64_t get_task_network_nonvolatile_compressed(task_t task) +{ + kern_return_t ret; + ledger_amount_t credit, debit; + + ret = ledger_get_entries(task->ledger, task_ledgers.network_nonvolatile_compressed, &credit, &debit); + if (KERN_SUCCESS == ret) { + return (credit - debit); + } + + return 0; +} + +uint64_t get_task_wired_mem(task_t task) +{ + kern_return_t ret; + ledger_amount_t credit, debit; + + ret = ledger_get_entries(task->ledger, task_ledgers.wired_mem, &credit, &debit); + if (KERN_SUCCESS == ret) { + return (credit - debit); + } + + return 0; +} + + uint64_t get_task_cpu_time(task_t task) { kern_return_t ret; @@ -854,7 +928,7 @@ fill_taskprocinfo(task_t task, struct proc_taskinfo_internal * ptinfo) } int -fill_taskthreadinfo(task_t task, uint64_t thaddr, int thuniqueid, struct proc_threadinfo_internal * ptinfo, void * vpp, int *vidp) +fill_taskthreadinfo(task_t task, uint64_t thaddr, bool thuniqueid, struct proc_threadinfo_internal * ptinfo, void * vpp, int *vidp) { thread_t thact; int err=0; @@ -867,7 +941,7 @@ fill_taskthreadinfo(task_t task, uint64_t thaddr, int thuniqueid, struct proc_th for (thact = (thread_t)(void *)queue_first(&task->threads); !queue_end(&task->threads, (queue_entry_t)thact); ) { - addr = (thuniqueid==0)?thact->machine.cthread_self: thact->thread_id; + addr = (thuniqueid) ? thact->thread_id : thact->machine.cthread_self; if (addr == thaddr) { @@ -904,7 +978,7 @@ out: } int -fill_taskthreadlist(task_t task, void * buffer, int thcount) +fill_taskthreadlist(task_t task, void * buffer, int thcount, bool thuniqueid) { int numthr=0; thread_t thact; @@ -917,7 +991,7 @@ fill_taskthreadlist(task_t task, void * buffer, int thcount) for (thact = (thread_t)(void *)queue_first(&task->threads); !queue_end(&task->threads, (queue_entry_t)thact); ) { - thaddr = thact->machine.cthread_self; + thaddr = (thuniqueid) ? thact->thread_id : thact->machine.cthread_self; *uptr++ = thaddr; numthr++; if (numthr >= thcount) @@ -971,13 +1045,8 @@ fill_task_rusage(task_t task, rusage_info_current *ri) void fill_task_billed_usage(task_t task __unused, rusage_info_current *ri) { -#if CONFIG_BANK - ri->ri_billed_system_time = bank_billed_time_safe(task); - ri->ri_serviced_system_time = bank_serviced_time_safe(task); -#else - ri->ri_billed_system_time = 0; - ri->ri_serviced_system_time = 0; -#endif + bank_billed_balance_safe(task, &ri->ri_billed_system_time, &ri->ri_billed_energy); + bank_serviced_balance_safe(task, &ri->ri_serviced_system_time, &ri->ri_serviced_energy); } int @@ -1006,25 +1075,59 @@ fill_task_qos_rusage(task_t task, rusage_info_current *ri) assert(task != TASK_NULL); task_lock(task); - /* Rollup Qos time of all the threads to task */ + /* Rollup QoS time of all the threads to task */ queue_iterate(&task->threads, thread, thread_t, task_threads) { if (thread->options & TH_OPT_IDLE_THREAD) continue; thread_update_qos_cpu_time(thread); } - ri->ri_cpu_time_qos_default = task->cpu_time_qos_stats.cpu_time_qos_default; - ri->ri_cpu_time_qos_maintenance = task->cpu_time_qos_stats.cpu_time_qos_maintenance; - ri->ri_cpu_time_qos_background = task->cpu_time_qos_stats.cpu_time_qos_background; - ri->ri_cpu_time_qos_utility = task->cpu_time_qos_stats.cpu_time_qos_utility; - ri->ri_cpu_time_qos_legacy = task->cpu_time_qos_stats.cpu_time_qos_legacy; - ri->ri_cpu_time_qos_user_initiated = task->cpu_time_qos_stats.cpu_time_qos_user_initiated; - ri->ri_cpu_time_qos_user_interactive = task->cpu_time_qos_stats.cpu_time_qos_user_interactive; + ri->ri_cpu_time_qos_default = task->cpu_time_eqos_stats.cpu_time_qos_default; + ri->ri_cpu_time_qos_maintenance = task->cpu_time_eqos_stats.cpu_time_qos_maintenance; + ri->ri_cpu_time_qos_background = task->cpu_time_eqos_stats.cpu_time_qos_background; + ri->ri_cpu_time_qos_utility = task->cpu_time_eqos_stats.cpu_time_qos_utility; + ri->ri_cpu_time_qos_legacy = task->cpu_time_eqos_stats.cpu_time_qos_legacy; + ri->ri_cpu_time_qos_user_initiated = task->cpu_time_eqos_stats.cpu_time_qos_user_initiated; + ri->ri_cpu_time_qos_user_interactive = task->cpu_time_eqos_stats.cpu_time_qos_user_interactive; task_unlock(task); return (0); } +void +fill_task_monotonic_rusage(task_t task, rusage_info_current *ri) +{ +#if MONOTONIC + if (!mt_core_supported) { + return; + } + + assert(task != TASK_NULL); + + uint64_t counts[MT_CORE_NFIXED] = { 0 }; + mt_fixed_task_counts(task, counts); +#ifdef MT_CORE_INSTRS + ri->ri_instructions = counts[MT_CORE_INSTRS]; +#endif /* defined(MT_CORE_INSTRS) */ + ri->ri_cycles = counts[MT_CORE_CYCLES]; +#else /* MONOTONIC */ +#pragma unused(task, ri) +#endif /* !MONOTONIC */ +} + +uint64_t +get_task_logical_writes(task_t task) +{ + assert(task != TASK_NULL); + struct ledger_entry_info lei; + + task_lock(task); + ledger_get_entry_info(task->ledger, task_ledgers.logical_writes, &lei); + + task_unlock(task); + return lei.lei_balance; +} + uint64_t get_task_dispatchqueue_serialno_offset(task_t task) { @@ -1047,16 +1150,20 @@ get_task_uniqueid(task_t task) } } +int +get_task_version(task_t task) +{ + if (task->bsd_info) { + return proc_pidversion(task->bsd_info); + } else { + return INT_MAX; + } +} + #if CONFIG_MACF struct label * get_task_crash_label(task_t task) { return task->crash_label; } - -void -set_task_crash_label(task_t task, struct label *label) -{ - task->crash_label = label; -} #endif