Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Windows: use EcoQoS for ThreadPriority::Background#148797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
timblechmann wants to merge1 commit intollvm:main
base:main
Choose a base branch
Loading
fromtimblechmann:feature/EcoQoS

Conversation

timblechmann
Copy link

The SetThreadInformation API allows threads to be scheduled on the most efficient cores on the most efficient frequency.
Using this API for ThreadPriority::Background should make clangd-based IDEs a little less CPU hungry.

@github-actionsGitHub Actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using@ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by theLLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on theLLVM Discord or on theforums.

@llvmbot
Copy link
Member

llvmbot commentedJul 15, 2025
edited
Loading

@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-llvm-support

Author: Tim Blechmann (timblechmann)

Changes

The SetThreadInformation API allows threads to be scheduled on the most efficient cores on the most efficient frequency.
Using this API for ThreadPriority::Background should make clangd-based IDEs a little less CPU hungry.


Full diff:https://github.com/llvm/llvm-project/pull/148797.diff

1 Files Affected:

  • (modified) llvm/lib/Support/Windows/Threading.inc (+25)
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.incindex d862dbd7f71c9..b52c6dff4e5f4 100644--- a/llvm/lib/Support/Windows/Threading.inc+++ b/llvm/lib/Support/Windows/Threading.inc@@ -107,6 +107,31 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) { }  SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {++  typedef BOOL(WINAPI * SetThreadInformation_t)(+      HANDLE hThread, THREAD_INFORMATION_CLASS ThreadInformationClass,+      _In_reads_bytes_(ThreadInformationSize) PVOID ThreadInformation,+      ULONG ThreadInformationSize);+  static const auto pfnSetThreadInformation =+      (SetThreadInformation_t)GetProcAddress(+          GetModuleHandle(TEXT("kernel32.dll")), "SetThreadInformation");++  if (pfnSetThreadInformation) {+    if (Priority == ThreadPriority::Background) {+      // Use EcoQoS for ThreadPriority::Background available (running on most+      // efficent cores at the most efficient cpu frequency):+      // https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreadinformation+      // https://learn.microsoft.com/en-us/windows/win32/procthread/quality-of-service+      THREAD_POWER_THROTTLING_STATE state;+      memset(&state, 0, sizeof(state));+      state.Version = THREAD_POWER_THROTTLING_CURRENT_VERSION;+      state.ControlMask = THREAD_POWER_THROTTLING_EXECUTION_SPEED;+      state.StateMask = THREAD_POWER_THROTTLING_EXECUTION_SPEED;+      pfnSetThreadInformation(GetCurrentThread(), ThreadPowerThrottling, &state,+                              sizeof(state));+    }+  }+   // https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setthreadpriority   // Begin background processing mode. The system lowers the resource scheduling   // priorities of the thread so that it can perform background work without

The SetThreadInformation API allows threads to be scheduled on the mostefficient cores on the most efficient frequency.Using this API for ThreadPriority::Background should make clangd-basedIDEs a little less CPU hungry.
Copy link
Member

@aganeaaganea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the changes. Just some more minor nits:

@@ -107,6 +107,39 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
}

SetThreadPriorityResultllvm::set_thread_priority(ThreadPriority Priority) {

// SetThreadInformation is only available on Windows 8 and later. so we load
// it at run-time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you please mention explicitely that we want to keep compatibility with Windows 7?

// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreadinformation
// https://learn.microsoft.com/en-us/windows/win32/procthread/quality-of-service
if (Priority == ThreadPriority::Background) {
setThreadInformation(THREAD_POWER_THROTTLING_EXECUTION_SPEED,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For the current requirements, we don't need to be that verbose here, just one value would suffice here (and use it for both control mask and state mask above).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mstorsjomstorsjomstorsjo left review comments

@aganeaaganeaaganea left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@timblechmann@llvmbot@mstorsjo@aganea

[8]ページ先頭

©2009-2025 Movatter.jp