gametechdev / hybriddetect Goto Github PK
View Code? Open in Web Editor NEWHeterogeneous & Homogeneous CPU Detect for Intel Processors
License: MIT License
Heterogeneous & Homogeneous CPU Detect for Intel Processors
License: MIT License
To get this compiled in our program on Windows with clang-cl, I had to make the following changes:
--- HybridDetect.h.orig 2023-10-06 16:01:25.711716800 +0200
+++ HybridDetect.h 2023-10-06 14:29:08.265495000 +0200
@@ -32,12 +32,23 @@
#endif
#ifdef HYBRIDDETECT_OS_WIN
-#include <windows.h>
-#include <Powrprof.h>
+#include <Windows.h>
+#include <powrprof.h>
#include <VersionHelpers.h>
#include <intrin.h>
#include <malloc.h>
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreserved-identifier"
+#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
+#pragma clang diagnostic ignored "-Wsign-conversion"
+#pragma clang diagnostic ignored "-Wsign-compare"
+#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
+#pragma clang diagnostic ignored "-Wunused-parameter"
+#pragma clang diagnostic ignored "-Wshorten-64-to-32"
+#endif
+
#pragma comment(lib, "Powrprof.lib")
#else
typedef unsigned long ULONG;
@@ -81,7 +92,7 @@
//#define ENABLE_SOFTWARE_PROXY
// Enables/Disables Run On API
-//#define ENABLE_RUNON
+#define ENABLE_RUNON
// Enables/Disables ThreadPriority Based on Core-Type
//#define ENABLE_RUNON_PRIORITY
@@ -313,13 +324,13 @@
//unsigned osMajorVersion;
//unsigned osMinorVersion;
//unsigned osBuildNumber;
- const bool IsIntel() const { return !strcmp("GenuineIntel", vendorID); }
- const bool IsAMD() const { return !strcmp("AuthenticAMD", vendorID); }
+ bool IsIntel() const { return !strcmp("GenuineIntel", vendorID); }
+ bool IsAMD() const { return !strcmp("AuthenticAMD", vendorID); }
inline int GetCoreTypeCount(CoreTypes coreType)
{
#ifdef ENABLE_CPU_SETS
- return (int)cpuSets[coreType].size();
+ return (int)cpuSets[(UINT)coreType].size();
#else
std::bitset<64> bits = coreMasks[coreType];
@@ -375,7 +386,7 @@
{
HYBRID_DETECT_TRACE(10, ">>> (0x%.8x)", function);
if (function > CPUIDFunctionMax) return false;
- CPUIDEX(registers.data(), function, extFunction);
+ CPUIDEX(registers.data(), function, extFunction)
HYBRID_DETECT_TRACE(10, "<<<");
return true;
}
@@ -1164,16 +1175,16 @@
#ifdef _DEBUG
// Where are we starting? [Inferno]
- int startedOn = GetCurrentProcessorNumber();
+ //int startedOn = GetCurrentProcessorNumber();
#endif
if (coreID < procInfo.numLogicalCores)
{
std::vector<ULONG> coreSet = { procInfo.cores[coreID].id };
- short succeeded = RunOnCPUSet(procInfo, threadHandle, coreSet, fallbackSet);
+ succeeded = RunOnCPUSet(procInfo, threadHandle, coreSet, fallbackSet);
#ifdef _DEBUG
// Check to see if the core is masked
- int iterations = 0;
+ //int iterations = 0;
int runningOn = -1;
do {
// Surrender time-slice
@@ -1181,7 +1192,7 @@
// Where Are We?
runningOn = GetCurrentProcessorNumber();
// Count Loop Iterations
- iterations++;
+ //iterations++;
// Loop while the current thread is not scheduled on a logical processor matching the affinity mask.
} while (runningOn != coreID);
// Assert In Debug
It would be nice if this compiled out of the box with clang-cl as well, many of my changes here are just hacks.
The package count prints as zero in the default configuration - please consider this patch:
Is there any plans of supporting Linux in this header package as well? At least for detecting and the RunOn() method.
In the docs for SYSTEM_CPU_SET_INFORMATION , MSDN expressly says:
This is a variable-sized structure designed for future expansion. When iterating over this structure, use the size field to determine the offset to the next structure.
However, the way GetLogicalProcessors
iterates through the data returned from GetSystemCpuSetInformation
completely disregards this note:
HybridDetect/HybridDetectConsole/HybridDetect.h
Lines 389 to 392 in 1a99783
While this code works now (although offset + sizeof(SYSTEM_CPU_SET_INFORMATION) <= size
looks really weird to me and I don't understand the intentions behind it!), it will break if Microsoft ever decides to do as they say and expand this structure.
For an example of proper usage of this data, see:
https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/blob/5e42d181f2daf4a244450b1535223d4c71ea5e54/src/common/win32/Threads.cpp#L116-L127
Strangely enough, the code snippet does adhere to the need of checking a Type
field to ensure the data accessed is valid, so the only issue here is the misuse of size.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.