Skip to content

Commit

Permalink
[QoS] Tweak SetCurrentThreadQualityOfService on Windows
Browse files Browse the repository at this point in the history
In this change, SetCurrentThreadQualityOfService:

- No longer uses GetProcAddress to find SetThreadInformation, as this
  function was added in Windows 8. This removes unneeded contention on
  the loader lock along with the associated complexity.
- No longer checks the OS version before use; instead, we trust that
  versions of Windows prior to Windows 10, version 1709 will ignore a
  call to SetThreadInformation with an unsupported
  THREAD_INFORMATION_CLASS. The motivation for this is that the OS check
  was implicated in renderer startup hangs, as it requires resolving a
  delayload to reach the Windows registry. The OS version check is now
  only done to suppress the debug log message in case of failure, as
  failure is expected on versions of Windows prior to 1709.

Bug: 1278628, 1482568
Change-Id: Ib73251a316c245aad75cc19cc785d9a5398d50c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4976221
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Will Harris <[email protected]>
Commit-Queue: Will Harris <[email protected]>
Auto-Submit: Greg Thompson <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1215530}
  • Loading branch information
GregTho authored and Chromium LUCI CQ committed Oct 26, 2023
1 parent 56c848e commit e90ffab
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions base/threading/platform_thread_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,16 +465,7 @@ void SetCurrentThreadPriority(ThreadType thread_type,
}

void SetCurrentThreadQualityOfService(ThreadType thread_type) {
// QoS and power throttling were introduced in Win10 1709
if (win::GetVersion() < win::Version::WIN10_RS3) {
return;
}

static const auto set_thread_information_fn =
reinterpret_cast<decltype(&::SetThreadInformation)>(::GetProcAddress(
::GetModuleHandle(L"kernel32.dll"), "SetThreadInformation"));
DCHECK(set_thread_information_fn);

// QoS and power throttling were introduced in Win10 1709.
bool desire_ecoqos = false;
switch (thread_type) {
case ThreadType::kBackground:
Expand All @@ -497,10 +488,11 @@ void SetCurrentThreadQualityOfService(ThreadType thread_type) {
.StateMask =
desire_ecoqos ? THREAD_POWER_THROTTLING_EXECUTION_SPEED : 0ul,
};
[[maybe_unused]] const BOOL success = set_thread_information_fn(
[[maybe_unused]] const BOOL success = ::SetThreadInformation(
::GetCurrentThread(), ::ThreadPowerThrottling,
&thread_power_throttling_state, sizeof(thread_power_throttling_state));
DPLOG_IF(ERROR, !success)
// Failure is expected on versions of Windows prior to RS3.
DPLOG_IF(ERROR, !success && win::GetVersion() >= win::Version::WIN10_RS3)
<< "Failed to set EcoQoS to " << std::boolalpha << desire_ecoqos;
}

Expand Down

0 comments on commit e90ffab

Please sign in to comment.