I am writing an audio device driver that should handle device interrupts in real time. When the CPU enters state C3, interrupts are delayed, causing problems with the driver. Is there a way in which a driver can tell the operating system not to enter idle C states?
I found that unoccupied C-states can be disconnected from user space:
const DWORD DISABLED = 1; const DWORD ENABLED = 0; GUID *scheme; PowerGetActiveScheme(NULL, &scheme); PowerWriteACValueIndex(NULL, scheme, &GUID_PROCESSOR_SETTINGS_SUBGROUP, &GUID_PROCESSOR_IDLE_DISABLE, DISABLED); PowerSetActiveScheme(NULL, scheme);
However, this is a global parameter that can be overwritten by the user or another application (for example, when the user changes the Power Plan).
I need something like PoRegisterSystemState, but not for S and P states, but for C states. (ref: https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/preventing-system-power-state-changes )
Is there any way to achieve this?
=====
It turns out there is no supported way to disable unoccupied C-states from kernel space, and there is no service in user space to provide a common API for this. The way to manage C-states is to "Processor power control" in the "Change advanced power settings" dialog box, through the registry or through the C API PowerWriteACValueIndex / PowerWriteDCValueIndex.
The initial problem was delaying interrupts in all states except C1, so I needed to disable both C2, C3, and deeper idle states. The problem with disabling all unoccupied C-states, including C1 (as shown in the PowerWriteACValueIndex code example (NULL, schema and GUID_PROCESSOR_SETTINGS_SUBGROUP, and GUID_PROCESSOR_IDLE_DISABLE, DISABLED)), is that CPU usage is reported as 100%, and some applications ( .
The solution to my problem is to disable all the unoccupied state of C1, which can be done by setting the following values ββin Power Power Management: - Scaling the threshold of the processor β Disable scaling; - A simple processor protection level β 100%; - Threshold of lowering the threshold of the processor β 100%.
Perhaps I will create a service that does just that and uses the PowerWriteACValueIndex / PowerWriteDCValueIndex API.