Add cpu load, thanks masa for the help!
This commit is contained in:
@@ -66,11 +66,12 @@
|
||||
#define HOSSVC_HAS_TC (hosversionAtLeast(5,0,0))
|
||||
#define NVGPU_GPU_IOCTL_PMU_GET_GPU_LOAD 0x80044715
|
||||
|
||||
#define systemtickfrequency 19200000
|
||||
#define systemtickfrequencyF 19200000.0f
|
||||
#define CPU_TICK_WAIT (1'000'000'000 / 60)
|
||||
constexpr u64 CpuTimeOutNs = 500'000'000;
|
||||
constexpr double Systemtickfrequency = 19200000.0 * (static_cast<double>(CpuTimeOutNs) / 1'000'000'000.0);
|
||||
|
||||
Result nvCheck = 1;
|
||||
|
||||
LEvent threadexit;
|
||||
Thread gpuLThread;
|
||||
Thread cpuCore0Thread;
|
||||
Thread cpuCore1Thread;
|
||||
@@ -91,10 +92,11 @@ BatteryChargeInfo info;
|
||||
static SysClkSocType g_socType = SysClkSocType_Erista;
|
||||
static HorizonOCConsoleType g_consoleType = HorizonOCConsoleType_Iowa;
|
||||
|
||||
std::atomic<uint64_t> idletick0{systemtickfrequency};
|
||||
std::atomic<uint64_t> idletick1{systemtickfrequency};
|
||||
std::atomic<uint64_t> idletick2{systemtickfrequency};
|
||||
std::atomic<uint64_t> idletick3{systemtickfrequency};
|
||||
u64 idletick0 = 0;
|
||||
u64 idletick1 = 0;
|
||||
u64 idletick2 = 0;
|
||||
// u64 idletick3 = 0;
|
||||
|
||||
u32 cpu0, cpu1, cpu2, cpu3, cpuAvg;
|
||||
u16 cpuSpeedo0, cpuSpeedo2, socSpeedo0; // CPU, GPU, SOC
|
||||
u32 speedoBracket;
|
||||
@@ -164,16 +166,16 @@ PcvModuleId Board::GetPcvModuleId(SysClkModule sysclkModule)
|
||||
return pcvModuleId;
|
||||
}
|
||||
|
||||
void CheckCore(void* idletick_ptr) {
|
||||
std::atomic<uint64_t>* idletick = (std::atomic<uint64_t>*)idletick_ptr;
|
||||
while (true) {
|
||||
uint64_t idletick_a;
|
||||
uint64_t idletick_b;
|
||||
svcGetInfo(&idletick_b, InfoType_IdleTickCount, INVALID_HANDLE, -1);
|
||||
svcSleepThread(CPU_TICK_WAIT);
|
||||
svcGetInfo(&idletick_a, InfoType_IdleTickCount, INVALID_HANDLE, -1);
|
||||
idletick->store(idletick_a - idletick_b, std::memory_order_release);
|
||||
}
|
||||
void CheckCore(void *idletickPtr) {
|
||||
u64* idletick = static_cast<u64 *>(idletickPtr);
|
||||
while(true) {
|
||||
u64 idletickA;
|
||||
u64 idletickB;
|
||||
svcGetInfo(&idletickB, InfoType_IdleTickCount, INVALID_HANDLE, -1);
|
||||
svcWaitForAddress(&threadexit, ArbitrationType_WaitIfEqual, 0, CpuTimeOutNs);
|
||||
svcGetInfo(&idletickA, InfoType_IdleTickCount, INVALID_HANDLE, -1);
|
||||
*idletick = idletickA - idletickB;
|
||||
}
|
||||
}
|
||||
|
||||
void gpuLoadThread(void*) {
|
||||
@@ -205,7 +207,6 @@ void miscThreadFunc(void*) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Board::Initialize()
|
||||
{
|
||||
Result rc = 0;
|
||||
@@ -253,17 +254,17 @@ void Board::Initialize()
|
||||
|
||||
threadCreate(&gpuLThread, gpuLoadThread, NULL, NULL, 0x1000, 0x3F, -2);
|
||||
threadStart(&gpuLThread);
|
||||
|
||||
threadCreate(&cpuCore0Thread, CheckCore, &idletick0, NULL, 0x500, 0x10, 0);
|
||||
threadCreate(&cpuCore1Thread, CheckCore, &idletick1, NULL, 0x500, 0x10, 1);
|
||||
threadCreate(&cpuCore2Thread, CheckCore, &idletick2, NULL, 0x500, 0x10, 2);
|
||||
threadCreate(&cpuCore3Thread, CheckCore, &idletick3, NULL, 0x500, 0x10, 3);
|
||||
threadCreate(&miscThread, miscThreadFunc, NULL, NULL, 0x1000, 0x3F, 3);
|
||||
leventClear(&threadexit);
|
||||
threadCreate(&cpuCore0Thread, CheckCore, &idletick0, NULL, 0x1000, 0x10, 0);
|
||||
threadCreate(&cpuCore1Thread, CheckCore, &idletick1, NULL, 0x1000, 0x10, 1);
|
||||
threadCreate(&cpuCore2Thread, CheckCore, &idletick2, NULL, 0x1000, 0x10, 2);
|
||||
// threadCreate(&cpuCore3Thread, CheckCore, &idletick3, NULL, 0x1000, 0x10, 3);
|
||||
threadCreate(&miscThread, miscThreadFunc, NULL, NULL, 0x1000, 0x10, 3);
|
||||
|
||||
threadStart(&cpuCore0Thread);
|
||||
threadStart(&cpuCore1Thread);
|
||||
threadStart(&cpuCore2Thread);
|
||||
threadStart(&cpuCore3Thread);
|
||||
// threadStart(&cpuCore3Thread);
|
||||
threadStart(&miscThread);
|
||||
batteryInfoInitialize();
|
||||
|
||||
@@ -393,7 +394,7 @@ void Board::Exit()
|
||||
threadClose(&cpuCore0Thread);
|
||||
threadClose(&cpuCore1Thread);
|
||||
threadClose(&cpuCore2Thread);
|
||||
threadClose(&cpuCore3Thread);
|
||||
// threadClose(&cpuCore3Thread);
|
||||
threadClose(&miscThread);
|
||||
|
||||
pwmChannelSessionClose(&g_ICon);
|
||||
@@ -776,6 +777,15 @@ std::int32_t Board::GetPowerMw(SysClkPowerSensor sensor)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 GetMaxCpuLoad() {
|
||||
float cpuUsage0 = std::clamp(((Systemtickfrequency - idletick0) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0);
|
||||
float cpuUsage1 = std::clamp(((Systemtickfrequency - idletick1) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0);
|
||||
float cpuUsage2 = std::clamp(((Systemtickfrequency - idletick2) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0);
|
||||
// float cpuUsage3 = std::clamp(((Systemtickfrequency - idletick3) / static_cast<double>(Systemtickfrequency)) * 1000.0, 0.0, 1000.0);
|
||||
|
||||
return std::round(std::max({cpuUsage0, cpuUsage1, cpuUsage2}));
|
||||
}
|
||||
|
||||
std::uint32_t Board::GetPartLoad(SysClkPartLoad loadSource)
|
||||
{
|
||||
switch(loadSource)
|
||||
@@ -786,8 +796,8 @@ std::uint32_t Board::GetPartLoad(SysClkPartLoad loadSource)
|
||||
return t210EmcLoadCpu();
|
||||
case HocClkPartLoad_GPU:
|
||||
return GPU_Load_u;
|
||||
case HocClkPartLoad_CPUAvg:
|
||||
return idletick0;
|
||||
case HocClkPartLoad_CPUMax:
|
||||
return GetMaxCpuLoad();
|
||||
case HocClkPartLoad_BAT:
|
||||
batteryInfoGetChargeInfo(&info);
|
||||
return info.RawBatteryCharge;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "process_management.h"
|
||||
#include "clock_manager.h"
|
||||
#include "ipc_service.h"
|
||||
#define INNER_HEAP_SIZE 0x30000
|
||||
#define INNER_HEAP_SIZE 0x34000
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -80,11 +80,11 @@ extern "C"
|
||||
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
|
||||
setsysExit();
|
||||
}
|
||||
|
||||
|
||||
// rc = fanInitialize();
|
||||
// if (R_FAILED(rc))
|
||||
// diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
|
||||
|
||||
|
||||
rc = i2cInitialize();
|
||||
if (R_FAILED(rc))
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
|
||||
@@ -96,7 +96,7 @@ extern "C"
|
||||
// fanExit();
|
||||
i2cExit();
|
||||
fsExit();
|
||||
fsdevUnmountAll();
|
||||
fsdevUnmountAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,6 @@ int main(int argc, char** argv)
|
||||
FileUtils::LogLine("Exit");
|
||||
svcSleepThread(1000000ULL);
|
||||
FileUtils::Exit();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user