lil refactor

This commit is contained in:
Drath
2025-09-14 21:33:58 +02:00
parent 2ceb08f5ca
commit 329837f92d
5 changed files with 197 additions and 110 deletions

View File

@@ -5,17 +5,21 @@
#include <filesystem>
#include <print>
#include <string>
#include <utils.hpp>
#define N_CPU 16
struct cpu_hwmon_t {
std::string path = "";
bool zenpower = false;
};
// struct cpu_hwmon_t {
// std::string path = "";
// bool zenpower = false;
// };
namespace cpu {
struct sensors {
std::string hwmon = "";
bool zenpower = false;
struct cpu_t {
int tdie = 0;
int tctl = 0;
int tccd1 = 0;
@@ -27,7 +31,12 @@ struct cpu_t {
uint32_t avg_freq = 0;
};
cpu_t getCpu(cpu_hwmon_t hw);
cpu_hwmon_t detectCpuHwmon(std::string pci);
// sensors getCpu(cpu_hwmon_t hw);
// cpu_hwmon_t detectCpuHwmon(std::string pci);
void detectHwmon(sensors* target, std::string pci);
void update(sensors* g);
} // namespace cpu
#endif

View File

@@ -1,24 +1,31 @@
#ifndef GPU_HPP
#define GPU_HPP
/* see which we actually need now */
#include <cstdint>
#include <fstream>
#include <gpu_metrics.hpp>
#include <print>
#include <string>
#include <utils.hpp>
#include <gpu_metrics.hpp>
#define REL_METRICS_PATH "/../../gpu_metrics"
#define MAX_METRICS_LENGTH 512
#define METRICS_IS(m) auto metrics = reinterpret_cast<m*>(raw_metrics)
/* should refactor this struct so its a little cleaner and closer to gpu_metrics */
struct gpu_t {
/* clean abstraction for gpu_metrics or metrics in filesystem in sane units */
namespace gpu {
struct sensors {
std::string hwmon = "";
bool hasGpuMetrics = false;
uint16_t fan_speed = 0;
uint16_t core_clock = 0;
uint16_t mem_clock = 0;
double vcore = 0;
float vcore = 0.0f;
uint16_t power_avg = 0;
uint16_t power_cap = 0;
uint16_t power_max = 0;
@@ -36,8 +43,46 @@ struct gpu_t {
uint8_t umc_usage = 0;
};
std::string detectGpuHwmon(std::string pci);
bool checkForMetrics(std::string hwmon);
gpu_t getGpu(std::string hw, bool hasMetrics);
void detectHwmon(sensors* target, std::string pci);
void update(sensors* g);
#endif
} // namespace gpu
// class ThrottleStatus(IntFlag):
// # linux/drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
// PPT0 = 1 << 0
// PPT1 = 1 << 1
// PPT2 = 1 << 2
// PPT3 = 1 << 3
// SPL = 1 << 4
// FPPT = 1 << 5
// SPPT = 1 << 6
// SPPT_APU = 1 << 7
// TDC_GFX = 1 << 16
// TDC_SOC = 1 << 17
// TDC_MEM = 1 << 18
// TDC_VDD = 1 << 19
// TDC_CVIP = 1 << 20
// EDC_CPU = 1 << 21
// EDC_GFX = 1 << 22
// APCC = 1 << 23
// TEMP_GPU = 1 << 32
// TEMP_CORE = 1 << 33
// TEMP_MEM = 1 << 34
// TEMP_EDGE = 1 << 35
// TEMP_HOTSPOT = 1 << 36
// TEMP_SOC = 1 << 37
// TEMP_VR_GFX = 1 << 38
// TEMP_VR_SOC = 1 << 39
// TEMP_VR_MEM0 = 1 << 40
// TEMP_VR_MEM1 = 1 << 41
// TEMP_LIQUID0 = 1 << 42
// TEMP_LIQUID1 = 1 << 43
// VRHOT0 = 1 << 44
// VRHOT1 = 1 << 45
// PROCHOT_CPU = 1 << 46
// PROCHOT_GFX = 1 << 47
// PPM = 1 << 56
// FIT = 1 << 57
#endif

View File

@@ -13,7 +13,7 @@ https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/amd/include/kgd_pp
#define MAX_XCC 8
#define NUM_XCP 8
namespace gpu {
namespace metrics {
struct metrics_table_header {
uint16_t structure_size;