-
-
Notifications
You must be signed in to change notification settings - Fork 467
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
Fixed get count threads for multiprocessor system with NUMA architecture #1514
Conversation
|
src/xrCore/Threading/TaskManager.cpp
Outdated
@@ -213,12 +213,63 @@ void CalcIterations() | |||
ttapi_dwFastIter = u32((iterations * frequency) / ((end - start) * 50000)); | |||
} | |||
|
|||
// Lainon: This implementation supports both conventional single-cpu PC configurations | |||
// and multi-cpu system on NUMA architecture | |||
size_t NUMAHardwareConcurrency() noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be defined in _math.h
and _math.cpp
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 7218c71
src/xrCore/_math.cpp
Outdated
@@ -236,7 +237,11 @@ void _initialize_cpu() | |||
listFeature("AltiVec", SDL_HasAltiVec()); | |||
|
|||
Msg("* CPU features: %s", features); | |||
#if defined(XR_PLATFORM_WINDOWS) | |||
Msg("* CPU threads: %d", NUMAHardwareConcurrency()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to just name this function something like GetThreadsCounts
and place it into CPU namespace in _math.h
and use it instead of std::thread::hardware_concurrency());
– that means we also should create a Linux, etc. version of this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 7218c71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish people were saying "physical/logical cores", not "threads". It's so confusing and grows people illiterate IMHO.
|
9c47638
to
7218c71
Compare
src/xrCore/_math.cpp
Outdated
if (concurrency == 0) | ||
return std::thread::hardware_concurrency(); | ||
else | ||
return concurrency; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (concurrency == 0) | |
return std::thread::hardware_concurrency(); | |
else | |
return concurrency; | |
return concurrency == 0 ? std::thread::hardware_concurrency() : concurrency; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 7dc0960
7218c71
to
7dc0960
Compare
@Xottab-DUTY you can do a code review |
143d1ca
to
118d39d
Compare
@Xottab-DUTY, if (!IsNUMA())
return single_cpu_concurrency();
if (GetLogicalProcessorInformationEx(RelationAll, nullptr, &length) != FALSE)
{
return single_cpu_concurrency();
} bool IsNUMA() noexcept
{
ULONG HighestNodeNumber;
return !(!GetNumaHighestNodeNumber(&HighestNodeNumber) || HighestNodeNumber == 0);
} |
Platform-specific code is generally unwanted if we can use standard C++ functionality and/or SDL. |
Fixed very old problem that only on any Windows NT and modern Windows Server 😆
https://developercommunity.visualstudio.com/t/hardware-concurrency-returns-an-incorrect-result/350854
https://stackoverflow.com/questions/31209256/reliable-way-to-programmatically-get-the-number-of-hardware-threads-on-windows
Why this commit is useful not only for server configurations, now a very cheap PC configuration is building from Xeon E54xx, X34xx, E3-xxxx, E5-xxxx, E7-xxx, any Silver, any Gold, any Platinum series, cheapest on LGA 2011v3 socket two-socket board with NUMA support is cheap on Aliexpress, Baidu or Alibaba.
https://aliexpress.ru/item/1005004510711777.html