mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 13:37:22 +00:00
[client] cpuinfo: implement CPU socket count for Windows
This commit is contained in:
parent
a40a964b30
commit
2099161b7e
@ -48,13 +48,13 @@ static bool getCPUModel(char * model, size_t modelSize)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool getCoreCount(int * cores, int * procs)
|
static bool getCoreCount(int * cores, int * procs, int * sockets)
|
||||||
{
|
{
|
||||||
if (!cores && !procs)
|
if (!cores && !procs)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
DWORD cb = 0;
|
DWORD cb = 0;
|
||||||
GetLogicalProcessorInformationEx(RelationProcessorCore, NULL, &cb);
|
GetLogicalProcessorInformationEx(RelationAll, NULL, &cb);
|
||||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to call GetLogicalProcessorInformationEx", GetLastError());
|
DEBUG_WINERROR("Failed to call GetLogicalProcessorInformationEx", GetLastError());
|
||||||
@ -62,7 +62,7 @@ static bool getCoreCount(int * cores, int * procs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BYTE buffer[cb];
|
BYTE buffer[cb];
|
||||||
if (!GetLogicalProcessorInformationEx(RelationProcessorCore,
|
if (!GetLogicalProcessorInformationEx(RelationAll,
|
||||||
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) buffer, &cb))
|
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) buffer, &cb))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to call GetLogicalProcessorInformationEx", GetLastError());
|
DEBUG_WINERROR("Failed to call GetLogicalProcessorInformationEx", GetLastError());
|
||||||
@ -75,19 +75,32 @@ static bool getCoreCount(int * cores, int * procs)
|
|||||||
if (procs)
|
if (procs)
|
||||||
*procs = 0;
|
*procs = 0;
|
||||||
|
|
||||||
|
if (sockets)
|
||||||
|
*sockets = 0;
|
||||||
|
|
||||||
DWORD offset = 0;
|
DWORD offset = 0;
|
||||||
while (offset < cb)
|
while (offset < cb)
|
||||||
{
|
{
|
||||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX lpi =
|
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX lpi =
|
||||||
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) (buffer + offset);
|
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) (buffer + offset);
|
||||||
if (lpi->Relationship == RelationProcessorCore)
|
switch (lpi->Relationship)
|
||||||
{
|
{
|
||||||
|
case RelationProcessorCore:
|
||||||
if (cores)
|
if (cores)
|
||||||
++*cores;
|
++*cores;
|
||||||
|
|
||||||
if (procs)
|
if (procs)
|
||||||
for (int i = 0; i < lpi->Processor.GroupCount; ++i)
|
for (int i = 0; i < lpi->Processor.GroupCount; ++i)
|
||||||
*procs += __builtin_popcount(lpi->Processor.GroupMask[i].Mask);
|
*procs += __builtin_popcount(lpi->Processor.GroupMask[i].Mask);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RelationProcessorPackage:
|
||||||
|
if (sockets)
|
||||||
|
++*sockets;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
offset += lpi->Size;
|
offset += lpi->Size;
|
||||||
}
|
}
|
||||||
@ -98,8 +111,5 @@ static bool getCoreCount(int * cores, int * procs)
|
|||||||
bool lgCPUInfo(char * model, size_t modelSize, int * procs, int * cores,
|
bool lgCPUInfo(char * model, size_t modelSize, int * procs, int * cores,
|
||||||
int * sockets)
|
int * sockets)
|
||||||
{
|
{
|
||||||
if (sockets)
|
return getCPUModel(model, modelSize) && getCoreCount(cores, procs, sockets);
|
||||||
*sockets = 1;
|
|
||||||
|
|
||||||
return getCPUModel(model, modelSize) && getCoreCount(cores, procs);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user