Trying to disable Processor idle states (C states) on Windows PC

我的梦境 提交于 2019-12-04 05:26:56

You can use SetThreadExecutionState function which enables the application to inform the system that it is in use.

EDIT: After a little research and testing I came to a solution or I think I did. You're on the right track for Windows XP. If you read the documentation for the PROCESSOR_POWER_POLICY structure , you'll notice you can disable each C-states that offends you:

Policy[0].AllowPromotion = 0; // Disable's C1 (usually C1 won't cause problems, so you should leave it alone.)
Policy[1].AllowPromotion = 0; // Disable's C2
Policy[2].AllowPromotion = 0; // Disable's C3


In Vista and Windows7 you can't use this interface instead you have to do this:

GUID *scheme;
PowerGetActiveScheme(NULL, &scheme); 
PowerWriteACValueIndex(NULL, scheme, &GUID_PROCESSOR_SETTINGS_SUBGROUP,  &GUID_PROCESSOR_IDLE_DISABLE, 1); 
PowerSetActiveScheme(NULL, scheme);


I haven't found a way to disable individual C states on Vista and Windows 7. If you need some sample codes please email me I can help you out.

This seems to be working for me:

void PowerState(bool bEnable)
{
    // CPU idle state
    unsigned int ActPwrSch;
    MACHINE_PROCESSOR_POWER_POLICY Policy;
    if (GetActivePwrScheme(&ActPwrSch))
    {
        if (ReadProcessorPwrScheme(ActPwrSch, &Policy))
        {
            Policy.ProcessorPolicyAc.Policy[0].AllowPromotion = bEnable ? 1: 0; // C1
            Policy.ProcessorPolicyAc.Policy[1].AllowPromotion = bEnable ? 1: 0; // C2
            Policy.ProcessorPolicyAc.Policy[2].AllowPromotion = bEnable ? 1: 0; // C3
            if (WriteProcessorPwrScheme(ActPwrSch, &Policy))
                SetActivePwrScheme(ActPwrSch, 0, 0);
        }
    }
    OSVERSIONINFO osvi;
    memset(&osvi, 0, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osvi);
    // For Vista and above
    if (osvi.dwMajorVersion >= 6)
    {
        static const GUID processor_idle_disable_guid = {0x5d76a2ca, 0xe8c0, 0x402f, 0xa1, 0x33, 0x21, 0x58, 0x49, 0x2d, 0x58, 0xad};
        GUID *scheme;
        PowerGetActiveScheme(NULL, &scheme);
        PowerWriteACValueIndex(NULL, scheme, &GUID_PROCESSOR_SETTINGS_SUBGROUP, &processor_idle_disable_guid, bEnable ? 0 :  1);
        PowerSetActiveScheme(NULL, scheme);
    }
}

Surely a TSR running a mathematical calculation every 5 minutes will prevent an idle state? Alternatively you can purchase a cheap hardware or software mouse emulator that sends a mouse move signal at defined intervals.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!