2022-01-26 04:22:12 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: CpuId.Linux.cpp
|
|
|
|
Date: 2022-1-25
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include "HWInfo.hpp"
|
|
|
|
#include "CpuInfo.hpp"
|
|
|
|
#include "CpuInfo.Linux.hpp"
|
|
|
|
|
|
|
|
#if defined(AURORA_IS_BSD_DERIVED)
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Aurora::HWInfo
|
|
|
|
{
|
2022-03-30 21:45:10 +00:00
|
|
|
|
|
|
|
static AuUInt32 ReadUInt(const AuString &path)
|
|
|
|
{
|
|
|
|
AuString contents;
|
|
|
|
if (AuIOFS::ReadString(path, contents))
|
|
|
|
{
|
|
|
|
char *endPtr;
|
|
|
|
auto word = strtoll(contents.c_str(), &endPtr, 10);
|
|
|
|
if (errno == ERANGE) return 0;
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetCaches()
|
|
|
|
{
|
|
|
|
gCpuInfo.dwCacheLine = ReadUInt("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size");
|
|
|
|
gCpuInfo.dwCacheL1 = ReadUInt("/sys/devices/system/cpu/cpu0/cache/index1/size");
|
|
|
|
gCpuInfo.dwCacheL2 = ReadUInt("/sys/devices/system/cpu/cpu0/cache/index2/size");
|
|
|
|
gCpuInfo.dwCacheL3 = ReadUInt("/sys/devices/system/cpu/cpu0/cache/index3/size");
|
|
|
|
}
|
|
|
|
|
2022-01-26 04:22:12 +00:00
|
|
|
void SetCpuTopologyLinux()
|
|
|
|
{
|
2022-02-18 10:46:51 +00:00
|
|
|
gCpuInfo.uSocket = 1;
|
|
|
|
gCpuInfo.uCores = 1;
|
|
|
|
gCpuInfo.uThreads = get_nprocs();
|
2022-01-26 04:22:12 +00:00
|
|
|
|
|
|
|
// TODO: parse /proc/cpuinfo
|
2022-02-18 10:46:51 +00:00
|
|
|
gCpuInfo.bMaskMTHalf = true;
|
2022-03-30 21:45:10 +00:00
|
|
|
|
|
|
|
SetCaches();
|
2022-01-26 04:22:12 +00:00
|
|
|
}
|
|
|
|
}
|