]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/kpc.h
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / osfmk / kern / kpc.h
index 7c79c69536b4d66e2cf84b6c68c5a24ecdf466f8..743e0d2bd5fcdbc10c426db97360e95fb140c2c7 100644 (file)
@@ -56,20 +56,20 @@ __BEGIN_DECLS
 #define KPC_ALL_CPUS (1u << 31)
 
 /* action id setters/getters */
-#define FIXED_ACTIONID(ctr)                    (kpc_actionid[(ctr)])
-#define CONFIGURABLE_ACTIONID(ctr)             (kpc_actionid[(ctr) + kpc_fixed_count()])
+#define FIXED_ACTIONID(ctr)                     (kpc_actionid[(ctr)])
+#define CONFIGURABLE_ACTIONID(ctr)              (kpc_actionid[(ctr) + kpc_fixed_count()])
 
 /* reload counter setters/getters */
-#define FIXED_RELOAD(ctr)                      (current_cpu_datap()->cpu_kpc_reload[(ctr)])
-#define FIXED_RELOAD_CPU(cpu, ctr)             (cpu_datap(cpu)->cpu_kpc_reload[(ctr)])
-#define CONFIGURABLE_RELOAD(ctr)               (current_cpu_datap()->cpu_kpc_reload[(ctr) + kpc_fixed_count()])
-#define CONFIGURABLE_RELOAD_CPU(cpu, ctr)      (cpu_datap(cpu)->cpu_kpc_reload[(ctr) + kpc_fixed_count()])
+#define FIXED_RELOAD(ctr)                       (current_cpu_datap()->cpu_kpc_reload[(ctr)])
+#define FIXED_RELOAD_CPU(cpu, ctr)              (cpu_datap(cpu)->cpu_kpc_reload[(ctr)])
+#define CONFIGURABLE_RELOAD(ctr)                (current_cpu_datap()->cpu_kpc_reload[(ctr) + kpc_fixed_count()])
+#define CONFIGURABLE_RELOAD_CPU(cpu, ctr)       (cpu_datap(cpu)->cpu_kpc_reload[(ctr) + kpc_fixed_count()])
 
 /* shadow counter setters/getters */
-#define FIXED_SHADOW(ctr)                      (current_cpu_datap()->cpu_kpc_shadow[(ctr)])
-#define FIXED_SHADOW_CPU(cpu, ctr)             (cpu_datap(cpu)->cpu_kpc_shadow[(ctr)])
-#define CONFIGURABLE_SHADOW(ctr)               (current_cpu_datap()->cpu_kpc_shadow[(ctr) + kpc_fixed_count()])
-#define CONFIGURABLE_SHADOW_CPU(cpu, ctr)      (cpu_datap(cpu)->cpu_kpc_shadow[(ctr) + kpc_fixed_count()])
+#define FIXED_SHADOW(ctr)                       (current_cpu_datap()->cpu_kpc_shadow[(ctr)])
+#define FIXED_SHADOW_CPU(cpu, ctr)              (cpu_datap(cpu)->cpu_kpc_shadow[(ctr)])
+#define CONFIGURABLE_SHADOW(ctr)                (current_cpu_datap()->cpu_kpc_shadow[(ctr) + kpc_fixed_count()])
+#define CONFIGURABLE_SHADOW_CPU(cpu, ctr)       (cpu_datap(cpu)->cpu_kpc_shadow[(ctr) + kpc_fixed_count()])
 
 /**
  * Callback for notification when PMCs are acquired/released by a task. The
@@ -91,18 +91,14 @@ struct cpu_data;
 extern boolean_t kpc_register_cpu(struct cpu_data *cpu_data);
 extern void kpc_unregister_cpu(struct cpu_data *cpu_data);
 
+extern bool kpc_supported;
+
 /* bootstrap */
 extern void kpc_init(void);
 
-/* common initialization */
-extern void kpc_common_init(void);
-
 /* Architecture specific initialisation */
 extern void kpc_arch_init(void);
 
-/* Thread counting initialization */
-extern void kpc_thread_init(void);
-
 /* Get the bitmask of available classes */
 extern uint32_t kpc_get_classes(void);
 
@@ -118,12 +114,12 @@ extern int kpc_get_pmu_version(void);
 extern int kpc_set_running(uint32_t classes);
 
 /* Read CPU counters */
-extern int kpc_get_cpu_counters(boolean_t all_cpus, uint32_t classes, 
-                                int *curcpu, uint64_t *buf);
+extern int kpc_get_cpu_counters(boolean_t all_cpus, uint32_t classes,
+    int *curcpu, uint64_t *buf);
 
 /* Read shadow counters */
 extern int kpc_get_shadow_counters( boolean_t all_cpus, uint32_t classes,
-                                    int *curcpu, uint64_t *buf );
+    int *curcpu, uint64_t *buf );
 
 /* Read current thread's counter accumulations */
 extern int kpc_get_curthread_counters(uint32_t *inoutcount, uint64_t *buf);
@@ -155,6 +151,7 @@ extern void kpc_thread_destroy(thread_t thread);
 /* allocate a buffer big enough for all counters */
 extern uint64_t *kpc_counterbuf_alloc(void);
 extern void      kpc_counterbuf_free(uint64_t*);
+extern uint32_t  kpc_get_counterbuf_size(void);
 
 /* whether we're currently accounting into threads */
 extern int kpc_threads_counting;
@@ -200,9 +197,9 @@ extern int kpc_disable_whitelist( int val );
  * This is a deprecated function used by old Power Managers, new Power Managers
  * should use the @em kpc_reserve_pm_counters() function. This function actually
  * calls @em kpc_reserve_pm_counters() with the following arguments:
- *     - handler       = handler
- *     - pmc_mask      = 0x83
- *     - custom_config = TRUE
+ *      - handler      = handler
+ *      - pmc_mask     = 0x83
+ *      - custom_config        = TRUE
  *
  * See @em kpc_reserve_pm_counters() for more details about the return value.
  */
@@ -213,6 +210,7 @@ extern boolean_t kpc_register_pm_handler(void (*handler)(boolean_t));
  *
  * @param handler
  * Notification callback to use when PMCs are acquired/released by a task.
+ * Power management must acknowledge the change using kpc_pm_acknowledge.
  *
  * @param pmc_mask
  * Bitmask of the configurable PMCs used by the Power Manager. The number of bits
@@ -229,7 +227,7 @@ extern boolean_t kpc_register_pm_handler(void (*handler)(boolean_t));
  * Manager can start using the reserved PMCs.
  */
 extern boolean_t kpc_reserve_pm_counters(uint64_t pmc_mask, kpc_pm_handler_t handler,
-                                         boolean_t custom_config);
+    boolean_t custom_config);
 
 /*
  * Unregister the Power Manager as a PMCs user, and release the previously
@@ -237,6 +235,16 @@ extern boolean_t kpc_reserve_pm_counters(uint64_t pmc_mask, kpc_pm_handler_t han
  */
 extern void kpc_release_pm_counters(void);
 
+/*
+ * Acknowledge the callback that PMCs are available to power management.
+ *
+ * @param available_to_pm Whether the counters were made available to power
+ * management in the callback.  Pass in whatever was passed into the handler
+ * function.  After this point, power management is able to use POWER_CLASS
+ * counters.
+ */
+extern void kpc_pm_acknowledge(boolean_t available_to_pm);
+
 /*
  * Is the PMU used by both the power manager and userspace?
  *
@@ -279,9 +287,9 @@ struct kpc_config_remote {
 
 /* handler for mp operations */
 struct kpc_running_remote {
-       uint32_t        classes;                /* classes to run */
-       uint64_t        cfg_target_mask;        /* configurable counters selected */
-       uint64_t        cfg_state_mask;         /* configurable counters new state */
+       uint32_t        classes;                /* classes to run */
+       uint64_t        cfg_target_mask;        /* configurable counters selected */
+       uint64_t        cfg_state_mask;         /* configurable counters new state */
 };
 
 /* handler for mp operations */
@@ -292,26 +300,35 @@ struct kpc_get_counters_remote {
        uint64_t *buf;
 };
 
-extern int kpc_get_all_cpus_counters(uint32_t classes, int *curcpu, uint64_t *buf);
-extern int kpc_get_curcpu_counters(uint32_t classes, int *curcpu, uint64_t *buf);
-extern int kpc_get_fixed_counters(uint64_t *counterv);
-extern int kpc_get_configurable_counters(uint64_t *counterv, uint64_t pmc_mask);
-extern boolean_t kpc_is_running_fixed(void);
-extern boolean_t kpc_is_running_configurable(uint64_t pmc_mask);
-extern uint32_t kpc_fixed_count(void);
-extern uint32_t kpc_configurable_count(void);
-extern uint32_t kpc_fixed_config_count(void);
-extern uint32_t kpc_configurable_config_count(uint64_t pmc_mask);
-extern uint32_t kpc_rawpmu_config_count(void);
-extern int kpc_get_fixed_config(kpc_config_t *configv);
-extern int kpc_get_configurable_config(kpc_config_t *configv, uint64_t pmc_mask);
-extern int kpc_get_rawpmu_config(kpc_config_t *configv);
-extern uint64_t kpc_fixed_max(void);
-extern uint64_t kpc_configurable_max(void);
-extern int kpc_set_config_arch(struct kpc_config_remote *mp_config);
-extern int kpc_set_period_arch(struct kpc_config_remote *mp_config);
-extern void kpc_sample_kperf(uint32_t actionid);
-extern int kpc_set_running_arch(struct kpc_running_remote *mp_config);
+int kpc_get_all_cpus_counters(uint32_t classes, int *curcpu, uint64_t *buf);
+int kpc_get_curcpu_counters(uint32_t classes, int *curcpu, uint64_t *buf);
+int kpc_get_fixed_counters(uint64_t *counterv);
+int kpc_get_configurable_counters(uint64_t *counterv, uint64_t pmc_mask);
+boolean_t kpc_is_running_fixed(void);
+boolean_t kpc_is_running_configurable(uint64_t pmc_mask);
+uint32_t kpc_fixed_count(void);
+uint32_t kpc_configurable_count(void);
+uint32_t kpc_fixed_config_count(void);
+uint32_t kpc_configurable_config_count(uint64_t pmc_mask);
+uint32_t kpc_rawpmu_config_count(void);
+int kpc_get_fixed_config(kpc_config_t *configv);
+int kpc_get_configurable_config(kpc_config_t *configv, uint64_t pmc_mask);
+int kpc_get_rawpmu_config(kpc_config_t *configv);
+uint64_t kpc_fixed_max(void);
+uint64_t kpc_configurable_max(void);
+int kpc_set_config_arch(struct kpc_config_remote *mp_config);
+int kpc_set_period_arch(struct kpc_config_remote *mp_config);
+
+__options_decl(kperf_kpc_flags_t, uint16_t, {
+       KPC_KERNEL_PC = 0x01,
+       KPC_KERNEL_COUNTING = 0x02,
+       KPC_USER_COUNTING = 0x04,
+});
+
+void kpc_sample_kperf(uint32_t actionid, uint32_t counter, uint64_t config,
+    uint64_t count, uintptr_t pc, kperf_kpc_flags_t flags);
+
+int kpc_set_running_arch(struct kpc_running_remote *mp_config);
 
 
 /*
@@ -326,13 +343,12 @@ extern uint64_t kpc_get_configurable_pmc_mask(uint32_t classes);
 
 
 /* Interface for kexts to publish a kpc interface */
-struct kpc_driver
-{
+struct kpc_driver {
        uint32_t (*get_classes)(void);
        uint32_t (*get_running)(void);
        int      (*set_running)(uint32_t classes);
-       int      (*get_cpu_counters)(boolean_t all_cpus, uint32_t classes, 
-                                    int *curcpu, uint64_t *buf);
+       int      (*get_cpu_counters)(boolean_t all_cpus, uint32_t classes,
+           int *curcpu, uint64_t *buf);
        int      (*get_curthread_counters)(uint32_t *inoutcount, uint64_t *buf);
        uint32_t (*get_counter_count)(uint32_t classes);
        uint32_t (*get_config_count)(uint32_t classes);