#include <kern/locks.h>
#include <sys/errno.h>
+#include <kperf/kperf.h>
+#include <kperf/buffer.h>
+#include <kperf/context.h>
+#include <kperf/sample.h>
+#include <kperf/action.h>
+#include <kperf/kperf_kpc.h>
#include <kern/kpc.h>
+#if defined (__arm64__)
+#include <arm/cpu_data_internal.h>
+#elif defined (__arm__)
+#include <arm/cpu_data_internal.h>
+#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;
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)
{
/* 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;
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,
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];
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)
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)
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();
}