[*] Early Linux SWInfo

This commit is contained in:
Reece Wilson 2022-04-06 07:25:34 +01:00
parent 6271af0ada
commit bfc33e6663
4 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,106 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: SWInfo.Linux.cpp
Date: 2022-4-6
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "SWInfo.hpp"
#include "SWInfo.Linux.hpp"
namespace Aurora::SWInfo
{
static AuString gKernelString;
static AuString gUserlandBrand;
static AuString gUserlandDesktopEnv;
static AuString gBuildString;
static void SetProcVersion()
{
AuIOFS::ReadString("/proc/version", gBuildString);
if (gBuildString.size() && gBuildString[gBuildString.size() - 1] == '\n')
{
gBuildString.pop_back();
}
}
static void SetVersion(OSInformation &osInfo)
{
char *endPtr;
auto versionItr = gBuildString.find("ersion ");
if (versionItr == AuString::npos) return;
if (versionItr > 2)
{
gKernelString = gBuildString.substr(0, versionItr - 2);
}
auto ptr = gBuildString.c_str() + (7 + AuUInt(versionItr));
osInfo.uKernelMajor = strtoll(ptr, &endPtr, 10);
if (errno == ERANGE) return;
if (*endPtr != '.') return;
endPtr++;
osInfo.uKernelMinor = strtoll(endPtr, &endPtr, 10);
if (errno == ERANGE) return;
if (*endPtr != '.') return;
endPtr++;
osInfo.uKernelPatch = strtoll(endPtr, &endPtr, 10);
}
static void ParseOSRel(OSInformation &osInfo)
{
AuString osRel;
if (!AuIOFS::ReadString("/etc/os-release", osRel)) return;
AuReplaceAll(osRel, "\"", "");
AuList<AuString> versionNumbers;
Parse::SplitNewlines(osRel, [&](const AuString &line)
{
if (AuStartsWith(line, "NAME="))
{
gUserlandBrand = line.substr(5);
}
else if (AuStartsWith(line, "VERSION="))
{
versionNumbers.push_back(line.substr(8));
}
else if (AuStartsWith(line, "VERSION_ID="))
{
versionNumbers.push_back(line.substr(11));
}
else if (AuStartsWith(line, "BUILD_ID="))
{
versionNumbers.push_back(line.substr(9));
}
});
// TODO: parse uUserlandMajor, uUserlandMinor, uUserlandPatch
}
static void SetDesktopWindowManager()
{
auto name = getenv("XDG_CURRENT_DESKTOP");
if (name == nullptr) return;
gUserlandDesktopEnv = name;
}
void InitLinuxInfo(OSInformation &osInfo)
{
osInfo = AuMove(OSInformation(&gKernelString, &gUserlandBrand, &gUserlandDesktopEnv, &gBuildString, Aurora::Build::EPlatform::eEnumInvalid));
SetProcVersion();
SetVersion(osInfo);
ParseOSRel(osInfo);
SetDesktopWindowManager();
}
}

View File

@ -0,0 +1,13 @@
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: SWInfo.Linux.hpp
Date: 2022-4-6
Author: Reece
***/
#pragma once
namespace Aurora::SWInfo
{
void InitLinuxInfo(OSInformation &info);
}

View File

@ -12,6 +12,10 @@
#include "SWInfo.NT.hpp"
#endif
#if defined(AURORA_IS_LINUX_DERIVED)
#include "SWInfo.Linux.hpp"
#endif
namespace Aurora::SWInfo
{
static const AuString kDefaultStr;
@ -36,6 +40,10 @@ namespace Aurora::SWInfo
#if defined(AURORA_IS_MODERNNT_DERIVED)
InitNTInfo(gTempInfo);
#endif
#if defined(AURORA_IS_LINUX_DERIVED)
InitLinuxInfo(gTempInfo);
#endif
gTempInfo.ePlatform = Build::kCurrentPlatform;
gInfo = &gTempInfo;

View File

@ -747,6 +747,7 @@ namespace Aurora::Threading::Threads
void OSThread::UpdateAffinity(const HWInfo::CpuBitId &mask)
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
if (this->handle_ == INVALID_HANDLE_VALUE)
@ -754,6 +755,11 @@ namespace Aurora::Threading::Threads
return;
}
if (mask.CpuBitCount() == 0)
{
mask = AuHwInfo::GetCPUInfo().maskAllCores;
}
if ((AuBuild::kCurrentPlatform != AuBuild::EPlatform::ePlatformWin32) || (AuSwInfo::IsWindows10OrGreater()))
{
static BOOL(WINAPI * SetThreadSelectedCpuSets_f)(HANDLE, const ULONG *, ULONG);
@ -796,6 +802,7 @@ namespace Aurora::Threading::Threads
switch (this->throttle_)
{
case EThreadThrottle::eNormal:
mask2 = AuHwInfo::GetCPUInfo().maskAllCores;
break;
case EThreadThrottle::ePerformance:
mask2 = AuHwInfo::GetCPUInfo().maskPCores;
@ -816,6 +823,11 @@ namespace Aurora::Threading::Threads
index++;
}
if (!CPU_COUNT(&cpuset))
{
return;
}
if (pthread_setaffinity_np(this->handle_, sizeof(cpuset), &cpuset) != 0)
{
SysPushErrorHAL("Couldn't set affinity mask");