[+] Modern Linux cpuinfo
[*] Replace getpid with gettid
This commit is contained in:
parent
8fe83de42f
commit
b97ed198c3
@ -37,6 +37,13 @@ namespace Aurora::HWInfo
|
||||
return 0;
|
||||
}
|
||||
|
||||
static AuString ReadString(const AuString &path)
|
||||
{
|
||||
AuString contents;
|
||||
AuIOFS::ReadString(path, contents);
|
||||
return contents;
|
||||
}
|
||||
|
||||
static void SetCaches()
|
||||
{
|
||||
gCpuInfo.dwCacheLine = ReadUInt("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size");
|
||||
@ -45,15 +52,90 @@ namespace Aurora::HWInfo
|
||||
gCpuInfo.dwCacheL3 = ReadUInt("/sys/devices/system/cpu/cpu0/cache/index3/size");
|
||||
}
|
||||
|
||||
static void SetCpuA()
|
||||
{
|
||||
static const AuString kBasePath = "/sys/devices/system/cpu/";
|
||||
|
||||
AuList<AuString> files;
|
||||
if (!AuIOFS::DirsInDirectory(kBasePath, files))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AuList<AuTuple<AuUInt8, AuString>> cpuThreads;
|
||||
cpuThreads.reserve(files.size());
|
||||
|
||||
std::sort(files.begin(), files.end());
|
||||
|
||||
for (auto & file : files)
|
||||
{
|
||||
if (AuStartsWith(file, "cpu"))
|
||||
{
|
||||
char *endPtr;
|
||||
auto word = strtoll(file.c_str() + 3, &endPtr, 10);
|
||||
if (errno == ERANGE) continue;
|
||||
if (*endPtr != '\x00') continue;
|
||||
|
||||
cpuThreads.push_back(AuMakeTuple(word, file));
|
||||
}
|
||||
}
|
||||
|
||||
bool bIsHyperThreaded {};
|
||||
for (auto &[threadId, coreStr] : cpuThreads)
|
||||
{
|
||||
auto cpuId = CpuBitId(threadId);
|
||||
|
||||
auto coreID = ReadUInt(kBasePath + coreStr + "/topology/core_id");
|
||||
auto cpuList = ReadString(kBasePath + coreStr +"/topology/core_cpus_list");
|
||||
|
||||
auto isHVCore = AuStringContains(cpuList, ",");
|
||||
|
||||
if (!bIsHyperThreaded && isHVCore)
|
||||
{
|
||||
bIsHyperThreaded = true;
|
||||
}
|
||||
|
||||
if (bIsHyperThreaded && !isHVCore)
|
||||
{
|
||||
gCpuInfo.maskECores.Add(cpuId);
|
||||
}
|
||||
else
|
||||
{
|
||||
gCpuInfo.maskPCores.Add(cpuId);
|
||||
gCpuInfo.pCoreTopology.push_back(cpuId);
|
||||
}
|
||||
|
||||
if (coreID == threadId)
|
||||
{
|
||||
auto children = CpuBitId();
|
||||
|
||||
auto cores = AuSplitString(cpuList, ",");
|
||||
for (const auto core : cores)
|
||||
{
|
||||
char *endPtr;
|
||||
auto word = strtoll(core.data(), &endPtr, 10);
|
||||
if (errno == ERANGE) continue;
|
||||
children.Add(CpuBitId(word));
|
||||
}
|
||||
gCpuInfo.coreTopology.push_back(children);
|
||||
gCpuInfo.threadTopology.push_back(children.lower);
|
||||
}
|
||||
|
||||
gCpuInfo.maskAllCores.Add(cpuId);
|
||||
}
|
||||
}
|
||||
|
||||
void SetCpuTopologyLinux()
|
||||
{
|
||||
gCpuInfo.uSocket = 1;
|
||||
gCpuInfo.uCores = 1;
|
||||
gCpuInfo.uThreads = get_nprocs();
|
||||
|
||||
// TODO: parse /proc/cpuinfo
|
||||
gCpuInfo.bMaskMTHalf = true;
|
||||
|
||||
SetCaches();
|
||||
SetCpuA();
|
||||
|
||||
gCpuInfo.uCores = gCpuInfo.coreTopology.size();
|
||||
}
|
||||
}
|
@ -143,10 +143,6 @@ namespace Aurora::HWInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetCpuTopologyNT()
|
||||
|
@ -63,7 +63,7 @@ namespace Aurora::IO::FS
|
||||
{
|
||||
AuUInt read;
|
||||
|
||||
auto file = OpenReadUnique(path);
|
||||
auto file = OpenReadUnique(path, EFileAdvisoryLockLevel::eNoSafety);
|
||||
SysCheckReturn(file, false);
|
||||
|
||||
auto len = file->GetLength();
|
||||
|
@ -247,7 +247,7 @@ namespace Aurora::Processes
|
||||
|
||||
{
|
||||
AU_LOCK_GUARD(gRWLock->AsWritable());
|
||||
AuTryInsert(gPidLookupMap, getpid(), this);
|
||||
AuTryInsert(gPidLookupMap, gettid(), this);
|
||||
}
|
||||
|
||||
this->alive_ = true;
|
||||
|
Loading…
Reference in New Issue
Block a user