X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/3e170ce000f1506b7b5d2c5c7faec85ceabb573d..cc8bc92ae4a8e9f1a1ab61bf83d34ad8150b3405:/osfmk/kern/kpc_thread.c diff --git a/osfmk/kern/kpc_thread.c b/osfmk/kern/kpc_thread.c index 1ac250c39..248ea3c56 100644 --- a/osfmk/kern/kpc_thread.c +++ b/osfmk/kern/kpc_thread.c @@ -41,10 +41,18 @@ #include #include +#if defined (__arm64__) +#include +#elif defined (__arm__) +#include +#endif /* global for whether to read PMCs on context switch */ 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; static uint32_t kpc_thread_classes_count = 0; @@ -111,12 +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()); - } + } } - kperf_kpc_cswitch_callback_update(); + kpc_off_cpu_update(); lck_mtx_unlock(&kpc_thread_lock); return 0; @@ -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(); }