+ * Helper routines for enabling/disabling system overrides for various mechanisms.
+ * These routines should be called with the sys_override_lock held. Each subsystem
+ * which is hooked into the override service provides two routines:
+ *
+ * - void sys_override_foo_init(void);
+ * Routine to initialize the subsystem or the data needed for the override to work.
+ * This routine is optional and if a subsystem needs it, it should be invoked from
+ * init_system_override().
+ *
+ * - void sys_override_foo(boolean_t enable_override);
+ * Routine to enable/disable the override mechanism for that subsystem. A value of
+ * true indicates that the mechanism should be overridden and the special behavior
+ * should begin. A false value indicates that the subsystem should return to default
+ * behavior. This routine is mandatory and should be invoked as part of the helper
+ * routines if the flags passed in the syscall match the subsystem. Also, this
+ * routine should preferably be idempotent.
+ */
+
+static void
+system_override_callouts(uint64_t flags, boolean_t enable_override)
+{
+ switch (flags) {
+ case SYS_OVERRIDE_IO_THROTTLE:
+ if (enable_override) {
+ KERNEL_DEBUG_CONSTANT(FSDBG_CODE(DBG_THROTTLE, IO_THROTTLE_DISABLE) | DBG_FUNC_START,
+ current_proc()->p_pid, 0, 0, 0, 0);
+ } else {
+ KERNEL_DEBUG_CONSTANT(FSDBG_CODE(DBG_THROTTLE, IO_THROTTLE_DISABLE) | DBG_FUNC_END,
+ current_proc()->p_pid, 0, 0, 0, 0);
+ }
+ sys_override_io_throttle(enable_override);
+ break;
+
+ case SYS_OVERRIDE_CPU_THROTTLE:
+ if (enable_override) {
+ KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED, MACH_CPU_THROTTLE_DISABLE) | DBG_FUNC_START,
+ current_proc()->p_pid, 0, 0, 0, 0);
+ } else {
+ KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED, MACH_CPU_THROTTLE_DISABLE) | DBG_FUNC_END,
+ current_proc()->p_pid, 0, 0, 0, 0);
+ }
+ sys_override_cpu_throttle(enable_override);
+ break;
+
+ case SYS_OVERRIDE_FAST_JETSAM:
+ if (enable_override) {
+ KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_MEMSTAT, BSD_MEMSTAT_FAST_JETSAM) | DBG_FUNC_START,
+ current_proc()->p_pid, 0, 0, 0, 0);
+ } else {
+ KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_MEMSTAT, BSD_MEMSTAT_FAST_JETSAM) | DBG_FUNC_END,
+ current_proc()->p_pid, 0, 0, 0, 0);
+ }
+#if CONFIG_JETSAM
+ memorystatus_fast_jetsam_override(enable_override);
+#endif /* CONFIG_JETSAM */
+ break;
+
+ default:
+ panic("Unknown option to system_override_callouts(): %llu\n", flags);
+ }
+}
+
+/*
+ * system_override_begin(uint64_t flags)
+ *
+ * Routine to start a system override if the assertion count
+ * transitions from 0->1 for a specified mechanism.