Fix code style
This commit is contained in:
@@ -1277,7 +1277,7 @@ void LinuxPlatform::GetSystemTime(int32& year, int32& month, int32& dayOfWeek, i
|
||||
|
||||
void LinuxPlatform::GetUTCTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond)
|
||||
{
|
||||
// Query for calendar time
|
||||
// Get the calendar time
|
||||
struct timeval time;
|
||||
gettimeofday(&time, nullptr);
|
||||
|
||||
@@ -1315,34 +1315,33 @@ bool LinuxPlatform::Init()
|
||||
}
|
||||
|
||||
// Set info about the CPU
|
||||
cpu_set_t availableCpusMask;
|
||||
CPU_ZERO(&availableCpusMask);
|
||||
if (sched_getaffinity(0, sizeof(availableCpusMask), &availableCpusMask) == 0)
|
||||
cpu_set_t cpus;
|
||||
CPU_ZERO(&cpus);
|
||||
if (sched_getaffinity(0, sizeof(cpus), &cpus) == 0)
|
||||
{
|
||||
int32 numberOfCores = 0;
|
||||
struct CpuInfo
|
||||
{
|
||||
int Core;
|
||||
int Package;
|
||||
} cpuInfos[CPU_SETSIZE];
|
||||
|
||||
Platform::MemoryClear(cpuInfos, sizeof(cpuInfos));
|
||||
int maxCoreId = 0;
|
||||
int maxPackageId = 0;
|
||||
int cpuCountAvailable = 0;
|
||||
int32 Core;
|
||||
int32 Package;
|
||||
} cpusInfo[CPU_SETSIZE];
|
||||
Platform::MemoryClear(cpusInfo, sizeof(cpusInfo));
|
||||
int32 maxCoreId = 0;
|
||||
int32 maxPackageId = 0;
|
||||
int32 cpuCountAvailable = 0;
|
||||
|
||||
for (int32 cpuIdx = 0; cpuIdx < CPU_SETSIZE; cpuIdx++)
|
||||
{
|
||||
if (CPU_ISSET(cpuIdx, &availableCpusMask))
|
||||
if (CPU_ISSET(cpuIdx, &cpus))
|
||||
{
|
||||
cpuCountAvailable++;
|
||||
|
||||
sprintf(fileNameBuffer, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpuIdx);
|
||||
if (FILE* coreIdFile = fopen(fileNameBuffer, "r"))
|
||||
{
|
||||
if (fscanf(coreIdFile, "%d", &cpuInfos[cpuIdx].Core) != 1)
|
||||
if (fscanf(coreIdFile, "%d", &cpusInfo[cpuIdx].Core) != 1)
|
||||
{
|
||||
cpuInfos[cpuIdx].Core = 0;
|
||||
cpusInfo[cpuIdx].Core = 0;
|
||||
}
|
||||
fclose(coreIdFile);
|
||||
}
|
||||
@@ -1350,22 +1349,21 @@ bool LinuxPlatform::Init()
|
||||
sprintf(fileNameBuffer, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpuIdx);
|
||||
if (FILE* packageIdFile = fopen(fileNameBuffer, "r"))
|
||||
{
|
||||
// physical_package_id can be -1 on embedded devices - treat all CPUs as separate in that case.
|
||||
if (fscanf(packageIdFile, "%d", &cpuInfos[cpuIdx].Package) != 1 || cpuInfos[cpuIdx].Package < 0)
|
||||
if (fscanf(packageIdFile, "%d", &cpusInfo[cpuIdx].Package) != 1 || cpusInfo[cpuIdx].Package < 0)
|
||||
{
|
||||
cpuInfos[cpuIdx].Package = cpuInfos[cpuIdx].Core;
|
||||
cpusInfo[cpuIdx].Package = cpusInfo[cpuIdx].Core;
|
||||
}
|
||||
fclose(packageIdFile);
|
||||
}
|
||||
|
||||
maxCoreId = Math::Max(maxCoreId, cpuInfos[cpuIdx].Core);
|
||||
maxPackageId = Math::Max(maxPackageId, cpuInfos[cpuIdx].Package);
|
||||
maxCoreId = Math::Max(maxCoreId, cpusInfo[cpuIdx].Core);
|
||||
maxPackageId = Math::Max(maxPackageId, cpusInfo[cpuIdx].Package);
|
||||
}
|
||||
}
|
||||
|
||||
int coresCount = maxCoreId + 1;
|
||||
int packagesCount = maxPackageId + 1;
|
||||
int pairsCount = packagesCount * coresCount;
|
||||
int32 coresCount = maxCoreId + 1;
|
||||
int32 packagesCount = maxPackageId + 1;
|
||||
int32 pairsCount = packagesCount * coresCount;
|
||||
|
||||
if (coresCount * 2 < cpuCountAvailable)
|
||||
{
|
||||
@@ -1378,9 +1376,9 @@ bool LinuxPlatform::Init()
|
||||
|
||||
for (int32 cpuIdx = 0; cpuIdx < CPU_SETSIZE; cpuIdx++)
|
||||
{
|
||||
if (CPU_ISSET(cpuIdx, &availableCpusMask))
|
||||
if (CPU_ISSET(cpuIdx, &cpus))
|
||||
{
|
||||
pairs[cpuInfos[cpuIdx].Package * coresCount + cpuInfos[cpuIdx].Core] = 1;
|
||||
pairs[cpusInfo[cpuIdx].Package * coresCount + cpusInfo[cpuIdx].Core] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1394,7 +1392,7 @@ bool LinuxPlatform::Init()
|
||||
|
||||
UnixCpu.ProcessorPackageCount = packagesCount;
|
||||
UnixCpu.ProcessorCoreCount = Math::Max(numberOfCores, 1);
|
||||
UnixCpu.LogicalProcessorCount = CPU_COUNT(&availableCpusMask);
|
||||
UnixCpu.LogicalProcessorCount = CPU_COUNT(&cpus);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user