Check if amdgpu gpu_metrics can be read and do some sanity-checks

pull/724/head
jackun 2 years ago
parent f4081d46f5
commit 3ee1048acf

@ -1,9 +1,37 @@
#include <spdlog/spdlog.h>
#include "amdgpu.h"
#include "gpu.h"
#include "cpu.h"
std::string metrics_path = "";
bool amdgpu_check_metrics(const std::string& path)
{
metrics_table_header header {};
std::ifstream in(path, std::ios_base::binary);
if (!in.read((char*)&header, sizeof(header)))
{
SPDLOG_DEBUG("Failed to read '{}': {}", path, in.eof() ? "End of file" : strerror(errno));
return false;
}
switch (header.structure_size)
{
case 80: // v1_0, not naturally aligned
case 96: // v1_1
case 104: // v1_2
case sizeof(gpu_metrics_v1_3): // v2.0, v2.1
case sizeof(gpu_metrics_v2_2):
if (header.format_revision == 1 || header.format_revision == 2)
return true;
default:
break;
}
SPDLOG_WARN("Unsupported gpu_metrics version: {}.{}", header.format_revision, header.content_revision);
return false;
}
void amdgpu_get_metrics()
{
if (!metrics_path.empty()){

@ -139,5 +139,6 @@ struct gpu_metrics_v2_2 {
uint64_t indep_throttle_status;
};
bool amdgpu_check_metrics(const std::string& path);
extern void amdgpu_get_metrics();
extern std::string metrics_path;
extern std::string metrics_path;

@ -663,7 +663,7 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para
}
std::string gpu_metrics_path = path + "/device/gpu_metrics";
if (file_exists(gpu_metrics_path)) {
if (amdgpu_check_metrics(gpu_metrics_path)) {
gpu_metrics_exists = true;
metrics_path = gpu_metrics_path;
SPDLOG_DEBUG("Using gpu_metrics of {}", path);

Loading…
Cancel
Save