X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/39236c6e673c41db228275375ab7fdb0f837b292..cc8bc92ae4a8e9f1a1ab61bf83d34ad8150b3405:/osfmk/kern/kpc_thread.c diff --git a/osfmk/kern/kpc_thread.c b/osfmk/kern/kpc_thread.c index 692aa02fe..248ea3c56 100644 --- a/osfmk/kern/kpc_thread.c +++ b/osfmk/kern/kpc_thread.c @@ -33,11 +33,25 @@ #include #include +#include +#include +#include +#include +#include +#include #include +#if defined (__arm64__) +#include +#elif defined (__arm__) +#include +#endif /* global for whether to read PMCs on context switch */ -int kpc_threads_counting; +int kpc_threads_counting = 0; + +/* whether to call into KPC when a thread goes off CPU */ +boolean_t kpc_off_cpu_active = FALSE; /* current config and number of counters in that config */ static uint32_t kpc_thread_classes = 0; @@ -47,8 +61,6 @@ static lck_grp_attr_t *kpc_thread_lckgrp_attr = NULL; static lck_grp_t *kpc_thread_lckgrp = NULL; static lck_mtx_t kpc_thread_lock; -void kpc_thread_init(void); - void kpc_thread_init(void) { @@ -107,11 +119,12 @@ kpc_set_thread_counting(uint32_t classes) /* and schedule an AST for this thread... */ if( !current_thread()->kpc_buf ) { - current_thread()->t_chud |= T_KPC_ALLOC; + current_thread()->kperf_flags |= T_KPC_ALLOC; act_set_kperf(current_thread()); - } + } } + kpc_off_cpu_update(); lck_mtx_unlock(&kpc_thread_lock); return 0; @@ -125,12 +138,7 @@ kpc_update_thread_counters( thread_t thread ) uint64_t *tmp = NULL; cpu_data_t *cpu = NULL; -/* TODO: Fix this...*/ -#if defined (__x86_64__) cpu = current_cpu_datap(); -#else -#error architecture not yet supported -#endif /* 1. stash current PMCs into latest CPU block */ kpc_get_cpu_counters( FALSE, kpc_thread_classes, @@ -141,13 +149,12 @@ kpc_update_thread_counters( thread_t thread ) for( i = 0; i < kpc_thread_classes_count; i++ ) thread->kpc_buf[i] += cpu->cpu_kpc_buf[1][i] - cpu->cpu_kpc_buf[0][i]; - /* schedule any necessary allocations */ if( !current_thread()->kpc_buf ) { - current_thread()->t_chud |= T_KPC_ALLOC; + current_thread()->kperf_flags |= T_KPC_ALLOC; act_set_kperf(current_thread()); - } + } /* 3. switch the PMC block pointers */ tmp = cpu->cpu_kpc_buf[1]; @@ -155,12 +162,6 @@ kpc_update_thread_counters( thread_t thread ) cpu->cpu_kpc_buf[0] = tmp; } -void -kpc_switch_context( thread_t old, thread_t new __unused ) -{ - kpc_update_thread_counters( old ); -} - /* get counter values for a thread */ int kpc_get_curthread_counters(uint32_t *inoutcount, uint64_t *buf) @@ -191,6 +192,19 @@ kpc_get_curthread_counters(uint32_t *inoutcount, uint64_t *buf) return 0; } +void +kpc_off_cpu_update(void) +{ + kpc_off_cpu_active = kpc_threads_counting; +} + +void +kpc_off_cpu_internal(thread_t thread) +{ + if (kpc_threads_counting) { + kpc_update_thread_counters(thread); + } +} void kpc_thread_create(thread_t thread) @@ -223,6 +237,6 @@ void kpc_thread_ast_handler( thread_t thread ) { /* see if we want an alloc */ - if( thread->t_chud & T_KPC_ALLOC ) + if( thread->kperf_flags & T_KPC_ALLOC ) thread->kpc_buf = kpc_counterbuf_alloc(); }