]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/kpc.h
xnu-4570.1.46.tar.gz
[apple/xnu.git] / osfmk / kern / kpc.h
index 461dd6704082d3d59e8e5b94617c208b24c99827..aa2db20a11d5422b8443e6842959cfdfd8273b7f 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2012 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- * 
+ *
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
  * unlawful or unlicensed copies of an Apple operating system, or to
  * circumvent, violate, or enable the circumvention or violation of, any
  * terms of an Apple operating system software license agreement.
- * 
+ *
  * Please obtain a copy of the License at
  * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
+ *
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  * Please see the License for the specific language governing rights and
  * limitations under the License.
- * 
+ *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
-#ifndef __KERN_KPC_H__
-#define __KERN_KPC_H__
+#ifndef KERN_KPC_H
+#define KERN_KPC_H
 
 /* Kernel interfaces to KPC PMC infrastructure. */
 
 #include <machine/machine_kpc.h>
 #include <kern/thread.h> /* thread_* */
 
+__BEGIN_DECLS
+
 /* cross-platform class constants */
 #define KPC_CLASS_FIXED         (0)
 #define KPC_CLASS_CONFIGURABLE  (1)
@@ -87,6 +89,7 @@ typedef void (*kpc_pm_handler_t)(boolean_t);
  */
 struct cpu_data;
 extern boolean_t kpc_register_cpu(struct cpu_data *cpu_data);
+extern void kpc_unregister_cpu(struct cpu_data *cpu_data);
 
 /* bootstrap */
 extern void kpc_init(void);
@@ -159,8 +162,24 @@ extern int kpc_threads_counting;
 /* AST callback for KPC */
 extern void kpc_thread_ast_handler( thread_t thread );
 
-/* context switch accounting between two threads */
-extern void kpc_switch_context( thread_t old_thread, thread_t new_thread );
+#ifdef MACH_KERNEL_PRIVATE
+
+/* context switch callback for KPC */
+
+extern boolean_t kpc_off_cpu_active;
+
+extern void kpc_off_cpu_internal(thread_t thread);
+extern void kpc_off_cpu_update(void);
+
+static inline void
+kpc_off_cpu(thread_t thread)
+{
+       if (__improbable(kpc_off_cpu_active)) {
+               kpc_off_cpu_internal(thread);
+       }
+}
+
+#endif /* defined(MACH_KERNEL_PRIVATE) */
 
 /* acquire/release the counters used by the Power Manager */
 extern int kpc_force_all_ctrs( task_t task, int val );
@@ -194,6 +213,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
@@ -218,6 +238,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?
  *
@@ -323,4 +353,6 @@ struct kpc_driver
        int      (*set_period)(uint32_t classes, uint64_t *period);
 };
 
-#endif /* __KERN_KPC_H__ */
+__END_DECLS
+
+#endif /* !definde(KERN_KPC_H) */