use std::array instead of c-style bufs
This commit is contained in:
17
src/gpu.cpp
17
src/gpu.cpp
@@ -1,3 +1,4 @@
|
||||
#include <array>
|
||||
#include <gpu.hpp>
|
||||
#include <gpu_metrics.hpp>
|
||||
#include <log.hpp>
|
||||
@@ -24,8 +25,8 @@ void detectHwmon(gpuSensors* target, const std::string& pci) {
|
||||
}
|
||||
|
||||
/* some metrics are missing in gpu_metrics, we always fill them from fs, unused metrics are commented out */
|
||||
void fillMissingMetrics(gpuSensors* g) {
|
||||
static char buf[32];
|
||||
void fillMissingMetrics(gpuSensors* g) {;
|
||||
static std::array<char, 32> buf;
|
||||
utils::fastReadNum<1000>(g->hwmon + "/in0_input", buf, g->vcore);
|
||||
// g->fan_pwm = std::stoi(readFile(g->hwmon + "/pwm1", 4)) * 100 / 256;
|
||||
utils::fastReadNum(g->hwmon + "/fan1_input", buf, g->fan_speed);
|
||||
@@ -37,7 +38,7 @@ void fillMissingMetrics(gpuSensors* g) {
|
||||
|
||||
/* get sensors for pre-vega cards (rx480/580) */
|
||||
void updateFromFs(gpuSensors* g) {
|
||||
static char buf[32];
|
||||
static std::array<char, 32> buf;
|
||||
utils::fastReadNum<1000000>(g->hwmon + "/freq1_input", buf, g->clock_core);
|
||||
utils::fastReadNum<1000000>(g->hwmon + "/freq2_input", buf, g->clock_mem);
|
||||
utils::fastReadNum<1000000>(g->hwmon + "/power1_input", buf, g->power_avg);
|
||||
@@ -47,13 +48,13 @@ void updateFromFs(gpuSensors* g) {
|
||||
|
||||
/* get sensors for vega and newer (rx5700xt, rx7800xt [*]) */
|
||||
void updateFromMetrics(gpuSensors* g) {
|
||||
char raw_metrics[max_metrics_length];
|
||||
if (!utils::readFile(g->hwmon + rel_metrics_path, raw_metrics, sizeof(raw_metrics))) return;
|
||||
std::array<char, max_metrics_length> raw_metrics{};
|
||||
if (!utils::readFile(g->hwmon + rel_metrics_path, raw_metrics)) return;
|
||||
|
||||
switch (const auto header = reinterpret_cast<metrics::metrics_table_header*>(raw_metrics); header->format_revision * 10 + header->content_revision) {
|
||||
switch (const auto header = reinterpret_cast<metrics::metrics_table_header*>(raw_metrics.data()); header->format_revision * 10 + header->content_revision) {
|
||||
/* rx5700xt, rx7800xt */
|
||||
case 13: {
|
||||
const auto metrics = reinterpret_cast<metrics::gpu_metrics_v1_3*>(raw_metrics);
|
||||
const auto metrics = reinterpret_cast<metrics::gpu_metrics_v1_3*>(raw_metrics.data());
|
||||
g->usage_core = metrics->average_gfx_activity;
|
||||
g->usage_umc = metrics->average_umc_activity;
|
||||
g->usage_media = metrics->average_mm_activity;
|
||||
@@ -80,7 +81,7 @@ void updateFromMetrics(gpuSensors* g) {
|
||||
|
||||
/* ryzen 5 5600g */
|
||||
case 22: {
|
||||
const auto metrics = reinterpret_cast<metrics::gpu_metrics_v2_2*>(raw_metrics);
|
||||
const auto metrics = reinterpret_cast<metrics::gpu_metrics_v2_2*>(raw_metrics.data());
|
||||
g->temp_edge = metrics->temperature_gfx / 100;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user