X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/39236c6e673c41db228275375ab7fdb0f837b292..527f99514973766e9c0382a4d8550dfb00f54939:/bsd/kern/kern_overrides.c diff --git a/bsd/kern/kern_overrides.c b/bsd/kern/kern_overrides.c index e2055aae6..8e70d80f0 100644 --- a/bsd/kern/kern_overrides.c +++ b/bsd/kern/kern_overrides.c @@ -39,12 +39,11 @@ #include #include #include -#include #include #include #include -#include +#include #include #include @@ -67,6 +66,12 @@ static int64_t cpu_throttle_assert_cnt; /* Wait Channel for system override */ static uint64_t sys_override_wait; +/* Global variable to indicate if system_override is enabled */ +int sys_override_enabled; + +/* Sysctl definition for sys_override_enabled */ +SYSCTL_INT(_debug, OID_AUTO, sys_override_enabled, CTLFLAG_RW | CTLFLAG_LOCKED, &sys_override_enabled, 0, ""); + /* Forward Declarations */ static void enable_system_override(uint64_t flags); static void disable_system_override(uint64_t flags); @@ -85,6 +90,7 @@ init_system_override() sys_override_mtx_attr = lck_attr_alloc_init(); lck_mtx_init(&sys_override_lock, sys_override_mtx_grp, sys_override_mtx_attr); io_throttle_assert_cnt = cpu_throttle_assert_cnt = 0; + sys_override_enabled = 1; } /* system call implementation */ @@ -100,12 +106,30 @@ system_override(__unused struct proc *p, struct system_override_args * uap, __un goto out; } - /* Check to see if some flags are specified. Zero flags are invalid. */ - if ((flags == 0) || ((flags & ~SYS_OVERRIDE_FLAGS_MASK) != 0)) { + /* Check to see if some flags are specified. */ + if ((flags & ~SYS_OVERRIDE_FLAGS_MASK) != 0) { error = EINVAL; goto out; } + if (flags == SYS_OVERRIDE_DISABLE) { + + printf("Process %s [%d] disabling system_override()\n", current_proc()->p_comm, current_proc()->p_pid); + + lck_mtx_lock(&sys_override_lock); + + if (io_throttle_assert_cnt > 0) + sys_override_io_throttle(THROTTLE_IO_ENABLE); + if (cpu_throttle_assert_cnt > 0) + sys_override_cpu_throttle(CPU_THROTTLE_ENABLE); + + sys_override_enabled = 0; + + lck_mtx_unlock(&sys_override_lock); + + goto out; + } + lck_mtx_lock(&sys_override_lock); enable_system_override(flags); @@ -129,22 +153,22 @@ enable_system_override(uint64_t flags) { if (flags & SYS_OVERRIDE_IO_THROTTLE) { - if (io_throttle_assert_cnt == 0) { + if ((io_throttle_assert_cnt == 0) && sys_override_enabled) { /* Disable I/O Throttling */ printf("Process %s [%d] disabling system-wide I/O Throttling\n", current_proc()->p_comm, current_proc()->p_pid); - KERNEL_DEBUG_CONSTANT(FSDBG_CODE(DBG_THROTTLE, IO_THROTTLE_DISABLE) | DBG_FUNC_START, current_proc()->p_pid, 0, 0, 0, 0); sys_override_io_throttle(THROTTLE_IO_DISABLE); } + KERNEL_DEBUG_CONSTANT(FSDBG_CODE(DBG_THROTTLE, IO_THROTTLE_DISABLE) | DBG_FUNC_START, current_proc()->p_pid, 0, 0, 0, 0); io_throttle_assert_cnt++; } if (flags & SYS_OVERRIDE_CPU_THROTTLE) { - if (cpu_throttle_assert_cnt == 0) { + if ((cpu_throttle_assert_cnt == 0) && sys_override_enabled) { /* Disable CPU Throttling */ printf("Process %s [%d] disabling system-wide CPU Throttling\n", current_proc()->p_comm, current_proc()->p_pid); - KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED, MACH_CPU_THROTTLE_DISABLE) | DBG_FUNC_START, current_proc()->p_pid, 0, 0, 0, 0); sys_override_cpu_throttle(CPU_THROTTLE_DISABLE); } + KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED, MACH_CPU_THROTTLE_DISABLE) | DBG_FUNC_START, current_proc()->p_pid, 0, 0, 0, 0); cpu_throttle_assert_cnt++; } @@ -161,9 +185,9 @@ disable_system_override(uint64_t flags) if (flags & SYS_OVERRIDE_IO_THROTTLE) { assert(io_throttle_assert_cnt > 0); io_throttle_assert_cnt--; - if (io_throttle_assert_cnt == 0) { + KERNEL_DEBUG_CONSTANT(FSDBG_CODE(DBG_THROTTLE, IO_THROTTLE_DISABLE) | DBG_FUNC_END, current_proc()->p_pid, 0, 0, 0, 0); + if ((io_throttle_assert_cnt == 0) && sys_override_enabled) { /* Enable I/O Throttling */ - 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(THROTTLE_IO_ENABLE); } } @@ -171,9 +195,9 @@ disable_system_override(uint64_t flags) if (flags & SYS_OVERRIDE_CPU_THROTTLE) { assert(cpu_throttle_assert_cnt > 0); cpu_throttle_assert_cnt--; - if (cpu_throttle_assert_cnt == 0) { + KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_SCHED, MACH_CPU_THROTTLE_DISABLE) | DBG_FUNC_END, current_proc()->p_pid, 0, 0, 0, 0); + if ((cpu_throttle_assert_cnt == 0) && sys_override_enabled) { /* Enable CPU Throttling */ - 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(CPU_THROTTLE_ENABLE); } }