From 146f9a766e8ef4647329161c1c0ce659d809144d Mon Sep 17 00:00:00 2001 From: Ty Lamontagne Date: Tue, 22 Jun 2021 17:36:14 -0400 Subject: [PATCH] System: Check active power profile on application launch --- pcsx2/System.cpp | 4 +++ pcsx2/System.h | 3 ++ pcsx2/pcsx2.vcxproj | 3 +- pcsx2/pcsx2.vcxproj.filters | 3 ++ pcsx2/windows/WinPowerProfile.cpp | 48 +++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 pcsx2/windows/WinPowerProfile.cpp diff --git a/pcsx2/System.cpp b/pcsx2/System.cpp index ed48143969..fe5aacfe78 100644 --- a/pcsx2/System.cpp +++ b/pcsx2/System.cpp @@ -266,6 +266,10 @@ void SysLogMachineCaps() #endif Console.Newline(); + +#ifdef _WIN32 + CheckIsUserOnHighPerfPowerPlan(); +#endif } template< typename CpuType > diff --git a/pcsx2/System.h b/pcsx2/System.h index ef456b1b0c..21717bcaa0 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -215,3 +215,6 @@ namespace Msgbox extern int Assertion( const wxString& text, const wxString& stacktrace ); } +#ifdef _WIN32 +extern void CheckIsUserOnHighPerfPowerPlan(); +#endif diff --git a/pcsx2/pcsx2.vcxproj b/pcsx2/pcsx2.vcxproj index 0cbbd4bb30..77a1a41fdc 100644 --- a/pcsx2/pcsx2.vcxproj +++ b/pcsx2/pcsx2.vcxproj @@ -65,7 +65,7 @@ Yes comctl32.lib;ws2_32.lib;shlwapi.lib;winmm.lib;rpcrt4.lib;iphlpapi.lib;dsound.lib;%(AdditionalDependencies) - dxguid.lib;dinput8.lib;hid.lib;d3dcompiler.lib;d3d11.lib;dxgi.lib;strmiids.lib;opengl32.lib;comsuppw.lib;%(AdditionalDependencies) + dxguid.lib;dinput8.lib;hid.lib;PowrProf.lib;d3dcompiler.lib;d3d11.lib;dxgi.lib;strmiids.lib;opengl32.lib;comsuppw.lib;%(AdditionalDependencies) @@ -681,6 +681,7 @@ + true diff --git a/pcsx2/pcsx2.vcxproj.filters b/pcsx2/pcsx2.vcxproj.filters index 41d078b122..5bf088079b 100644 --- a/pcsx2/pcsx2.vcxproj.filters +++ b/pcsx2/pcsx2.vcxproj.filters @@ -824,6 +824,9 @@ AppHost\Win32 + + AppHost\Win32 + AppHost\Linux diff --git a/pcsx2/windows/WinPowerProfile.cpp b/pcsx2/windows/WinPowerProfile.cpp new file mode 100644 index 0000000000..07a8d0de7c --- /dev/null +++ b/pcsx2/windows/WinPowerProfile.cpp @@ -0,0 +1,48 @@ +/* PCSX2 - PS2 Emulator for PCs +* Copyright (C) 2002-2021 PCSX2 Dev Team +* +* PCSX2 is free software: you can redistribute it and/or modify it under the terms +* of the GNU Lesser General Public License as published by the Free Software Found- +* ation, either version 3 of the License, or (at your option) any later version. +* +* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +* PURPOSE. See the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along with PCSX2. +* If not, see . +*/ + +#include "PrecompiledHeader.h" +#include + +// Checks the current active power plan +// If the power plan isn't named 'high performance', put a little message in the console +// This function fails silently +void CheckIsUserOnHighPerfPowerPlan() +{ + GUID* pPwrGUID; + DWORD ret = PowerGetActiveScheme(NULL, &pPwrGUID); + if (ret != ERROR_SUCCESS) + return; + + UCHAR aBuffer[2048]; + DWORD aBufferSize = sizeof(aBuffer); + ret = PowerReadFriendlyName(NULL, pPwrGUID, &NO_SUBGROUP_GUID, NULL, aBuffer, &aBufferSize); + if (ret != ERROR_SUCCESS) + goto cleanup; + + DWORD acMax = 0,acMin = 0,dcMax = 0,dcMin = 0; + + if (PowerReadACValueIndex(NULL, pPwrGUID, &GUID_PROCESSOR_SETTINGS_SUBGROUP, &GUID_PROCESSOR_THROTTLE_MAXIMUM, &acMax) || + PowerReadACValueIndex(NULL, pPwrGUID, &GUID_PROCESSOR_SETTINGS_SUBGROUP, &GUID_PROCESSOR_THROTTLE_MINIMUM, &acMin) || + PowerReadDCValueIndex(NULL, pPwrGUID, &GUID_PROCESSOR_SETTINGS_SUBGROUP, &GUID_PROCESSOR_THROTTLE_MAXIMUM, &dcMax) || + PowerReadDCValueIndex(NULL, pPwrGUID, &GUID_PROCESSOR_SETTINGS_SUBGROUP, &GUID_PROCESSOR_THROTTLE_MINIMUM, &dcMin)) + goto cleanup; + + Console.WriteLn("The current power profile is '%S'.\nThe current min / max processor states\nAC: %d%% / %d%%\nBattery: %d%% / %d%%\n", aBuffer,acMin,acMax,dcMin,dcMax); + +cleanup: + LocalFree(pPwrGUID); + return; +}