Skip to content

[Support] [Windows] Conditionally compile the SetThreadInformation calls #151388

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025

Conversation

mstorsjo
Copy link
Member

The declarations for this API are missing in older mingw-w64 headers (versions before v12). This API is also hidden if building with MS WinSDK if targeting versions before Windows 10.

Check whether THREAD_POWER_THROTTLING_CURRENT_VERSION is defined before using this API; this constant is a #define in both WinSDK and mingw-w64.

The declarations for this API are missing in older mingw-w64
headers (versions before v12). This API is also hidden if building
with MS WinSDK if targeting versions before Windows 10.

Check whether THREAD_POWER_THROTTLING_CURRENT_VERSION is defined
before using this API; this constant is a #define in both
WinSDK and mingw-w64.
@llvmbot
Copy link
Member

llvmbot commented Jul 30, 2025

@llvm/pr-subscribers-llvm-support

Author: Martin Storsjö (mstorsjo)

Changes

The declarations for this API are missing in older mingw-w64 headers (versions before v12). This API is also hidden if building with MS WinSDK if targeting versions before Windows 10.

Check whether THREAD_POWER_THROTTLING_CURRENT_VERSION is defined before using this API; this constant is a #define in both WinSDK and mingw-w64.


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

1 Files Affected:

  • (modified) llvm/lib/Support/Windows/Threading.inc (+2)
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 8dd7c88fad34a..b11f216adeba4 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -136,6 +136,7 @@ HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName) {
 } // namespace llvm::sys::windows
 
 SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
+#ifdef THREAD_POWER_THROTTLING_CURRENT_VERSION
   HMODULE kernelM = llvm::sys::windows::loadSystemModuleSecure(L"kernel32.dll");
   if (kernelM) {
     // SetThreadInformation is only available on Windows 8 and later. Since we
@@ -166,6 +167,7 @@ SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
                                : 0);
     }
   }
+#endif
 
   // https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setthreadpriority
   // Begin background processing mode. The system lowers the resource scheduling

@llvmbot
Copy link
Member

llvmbot commented Jul 30, 2025

@llvm/pr-subscribers-platform-windows

Author: Martin Storsjö (mstorsjo)

Changes

The declarations for this API are missing in older mingw-w64 headers (versions before v12). This API is also hidden if building with MS WinSDK if targeting versions before Windows 10.

Check whether THREAD_POWER_THROTTLING_CURRENT_VERSION is defined before using this API; this constant is a #define in both WinSDK and mingw-w64.


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

1 Files Affected:

  • (modified) llvm/lib/Support/Windows/Threading.inc (+2)
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 8dd7c88fad34a..b11f216adeba4 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -136,6 +136,7 @@ HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName) {
 } // namespace llvm::sys::windows
 
 SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
+#ifdef THREAD_POWER_THROTTLING_CURRENT_VERSION
   HMODULE kernelM = llvm::sys::windows::loadSystemModuleSecure(L"kernel32.dll");
   if (kernelM) {
     // SetThreadInformation is only available on Windows 8 and later. Since we
@@ -166,6 +167,7 @@ SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
                                : 0);
     }
   }
+#endif
 
   // https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setthreadpriority
   // Begin background processing mode. The system lowers the resource scheduling

Copy link
Contributor

@Sharjeel-Khan Sharjeel-Khan left a comment

Choose a reason for hiding this comment

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

Thanks, I just tested it locally and this fixed the issue.

@mstorsjo
Copy link
Member Author

CC @timblechmann - will merge this one soon.

@timblechmann
Copy link
Contributor

This API is also hidden if building with MS WinSDK if targeting versions before Windows 10.

makes me wonder if we want to declare/define these defines/struct if not provided by the windows headers? it would allow the use of EcoQoS no matter how llvm is built

@mstorsjo
Copy link
Member Author

This API is also hidden if building with MS WinSDK if targeting versions before Windows 10.

makes me wonder if we want to declare/define these defines/struct if not provided by the windows headers? it would allow the use of EcoQoS no matter how llvm is built

Yes, certainly. Although in practice, I would think most people building with WinSDK end up using the default target version. I think many of those intentionally targeting older versions may be using mingw, where these declarations aren't hidden based on version anyway. (Although that can of course change in the future.) The degradation for those building in that configuration should be quite graceful (behaving like it did before).

Although if you feel strongly about it, I guess you can propose such a patch as well, but it requires a bit more testing, so I'd at least like to land this first, to unbreak @Sharjeel-Khan's builds.

@Sharjeel-Khan
Copy link
Contributor

Yea, our buildbots have been stagnant for 2 days due to the failure. I would also push to land a fix asap to unbreak our builds.

@mstorsjo mstorsjo merged commit 1c60b7d into llvm:main Jul 31, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants