diff --git a/data/MangoHud.conf b/data/MangoHud.conf index bdba69541f..922fd11812 100644 --- a/data/MangoHud.conf +++ b/data/MangoHud.conf @@ -79,7 +79,10 @@ gpu_stats # gpu_temp # gpu_junction_temp -# gpu_core_clock +gpu_core_clock +gpu_nvdec_clock +gpu_nvenc_clock +gpu_vic_clock # gpu_mem_temp # gpu_mem_clock # gpu_power @@ -94,7 +97,7 @@ gpu_stats ### Display the current CPU information cpu_stats -# cpu_temp +cpu_temp # cpu_power # cpu_text= # cpu_mhz @@ -103,7 +106,7 @@ cpu_stats # cpu_load_color=39F900,FDFD09,B22222 ### Display the current CPU load & frequency for each core -# core_load +core_load # core_load_change ### Display IO read and write for the app (not system) @@ -112,7 +115,9 @@ cpu_stats ### Display system vram / ram / swap space usage # vram -# ram +ram +ram_clock +ram_bandwidth # swap ### Display per process memory usage @@ -147,9 +152,9 @@ throttling_status #throttling_status_graph ### Display miscellaneous information -# engine_version +engine_version # engine_short_names -# gpu_name +gpu_name # vulkan_driver # wine # exec_name @@ -196,7 +201,7 @@ frame_timing # show_fps_limit ### Display the current resolution -# resolution +resolution ### Display custom text # custom_text= diff --git a/src/cpu.cpp b/src/cpu.cpp index 51c2570b5a..ddfd66e7fb 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -533,8 +533,29 @@ bool CPUStats::GetCpuFile() { } } if (path.empty() || (!file_exists(input) && !find_fallback_input(path, "temp", input))) { - SPDLOG_ERROR("Could not find cpu temp sensor location"); - return false; + std::string type, path, input; + std::string thermal = "/sys/class/thermal/"; + + auto dirs = ls(thermal.c_str()); + for (auto& dir : dirs) { + path = thermal + dir; + type = read_line(path + "/type"); + SPDLOG_DEBUG("thermal: sensor type: {}", type); + + if (type == "CPU-therm") { + input = path + "/temp"; + break; + } else { + path.clear(); + } + } + if (path.empty() || (!file_exists(input) && !find_fallback_input(path, "temp", input))) { + SPDLOG_ERROR("Could not find cpu temp sensor location"); + return false; + } else { + SPDLOG_DEBUG("thermal: using input: {}", input); + m_cpuTempFile = fopen(input.c_str(), "r"); + } } else { SPDLOG_DEBUG("hwmon: using input: {}", input); m_cpuTempFile = fopen(input.c_str(), "r"); diff --git a/src/gpu.cpp b/src/gpu.cpp index 9a8c8f6750..4ee49fb080 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -15,6 +15,8 @@ #include "amdgpu.h" +#include "file_utils.h" + using namespace std::chrono_literals; struct gpuInfo gpu_info {}; @@ -83,6 +85,49 @@ void getNvidiaGpuInfo(const struct overlay_params& params){ #ifdef _WIN32 nvapi_util(); #endif + +// FIXME: generic GPU sensor data +// load +gpu_info.load = std::stoi(read_line("/sys/devices/gpu.0/load")) / 10; + +// temporary strings +std::string type, path, input; + +// temperature +// this runs every reading. needs to be changed to be like cpu.cpp where the location is stored +std::string thermal = "/sys/class/thermal/"; +for (auto& dir : ls(thermal.c_str())) { + path = thermal + dir; + type = read_line(path + "/type"); + if (type == "GPU-therm") { + input = path + "/temp"; + gpu_info.temp = std::stoi(read_line(input)) / 1000; + break; + } else { + path.clear(); + } +} + +// gpu clocks +// this runs every reading. needs to be changed to be like cpu.cpp where the location is stored +std::string devfreq = "/sys/devices/gpu.0/devfreq/"; +for (auto& dir : ls(devfreq.c_str())) { + path = devfreq + dir; + input = path + "/cur_freq"; + gpu_info.CoreClock = std::stoi(read_line(input)) / 1000000 ; + break; +} + +// nvdev/nvenc/vic clocks +if (file_exists("/sys/kernel/debug/clk/nvdec/clk_rate")) { + if (read_line("/sys/kernel/debug/clk/nvdec/clk_state") == "1") gpu_info.NVDECClock = std::stoi(read_line("/sys/kernel/debug/clk/nvdec/clk_rate")) / 1000000 ; else gpu_info.NVDECClock = 0 ; +} +if (file_exists("/sys/kernel/debug/clk/nvenc/clk_rate")) { + if (read_line("/sys/kernel/debug/clk/nvenc/clk_state") == "1") gpu_info.NVENCClock = std::stoi(read_line("/sys/kernel/debug/clk/nvenc/clk_rate")) / 1000000 ; else gpu_info.NVENCClock = 0 ; +} +if (file_exists("/sys/kernel/debug/clk/vic03/clk_rate")) { + if (read_line("/sys/kernel/debug/clk/vic03/clk_state") == "1") gpu_info.VICClock = std::stoi(read_line("/sys/kernel/debug/clk/vic03/clk_rate")) / 1000000 ; else gpu_info.VICClock = 0 ; +} } void getAmdGpuInfo(){ diff --git a/src/gpu.h b/src/gpu.h index c27a36621c..5e6e2f209e 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -34,6 +34,9 @@ struct gpuInfo{ float memoryTotal; int MemClock; int CoreClock; + int NVDECClock; + int NVENCClock; + int VICClock; float powerUsage; float apu_cpu_power; int apu_cpu_temp; diff --git a/src/hud_elements.cpp b/src/hud_elements.cpp index 7e68c5001c..94e5bdd9d5 100644 --- a/src/hud_elements.cpp +++ b/src/hud_elements.cpp @@ -297,6 +297,39 @@ void HudElements::gpu_stats(){ HUDElements.TextColored(HUDElements.colors.text, "mV"); ImGui::PopFont(); } + if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_nvdec_clock]){ + ImGui::TableNextColumn(); + ImGui::TextColored(HUDElements.colors.gpu, "%s", "NVDEC"); + ImGui::TableNextColumn(); + ImguiNextColumnOrNewRow(); + right_aligned_text(text_color, HUDElements.ralign_width, "%i", gpu_info.NVDECClock); + ImGui::SameLine(0, 1.0f); + ImGui::PushFont(HUDElements.sw_stats->font1); + ImGui::Text("MHz"); + ImGui::PopFont(); + } + if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_nvenc_clock]){ + ImGui::TableNextColumn(); + ImGui::TextColored(HUDElements.colors.gpu, "%s", "NVENC"); + ImGui::TableNextColumn(); + ImguiNextColumnOrNewRow(); + right_aligned_text(text_color, HUDElements.ralign_width, "%i", gpu_info.NVENCClock); + ImGui::SameLine(0, 1.0f); + ImGui::PushFont(HUDElements.sw_stats->font1); + ImGui::Text("MHz"); + ImGui::PopFont(); + } + if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gpu_vic_clock]){ + ImGui::TableNextColumn(); + ImGui::TextColored(HUDElements.colors.gpu, "%s", "VIC"); + ImGui::TableNextColumn(); + ImguiNextColumnOrNewRow(); + right_aligned_text(text_color, HUDElements.ralign_width, "%i", gpu_info.VICClock); + ImGui::SameLine(0, 1.0f); + ImGui::PushFont(HUDElements.sw_stats->font1); + ImGui::Text("MHz"); + ImGui::PopFont(); + } } } @@ -545,6 +578,22 @@ void HudElements::ram(){ } } + if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_ram_clock]){ + ImguiNextColumnOrNewRow(); + right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%i", memclock); + ImGui::SameLine(0, 1.0f); + ImGui::PushFont(HUDElements.sw_stats->font1); + ImGui::Text("MHz"); + ImGui::PopFont(); + } + + if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_ram_bandwidth]){ + ImguiNextColumnOrNewRow(); + right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%i", membandwidth); + ImGui::SameLine(0, 1.0f); + ImGui::TextColored(HUDElements.colors.text,"%%"); + } + if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_ram] && HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_swap]){ ImguiNextColumnOrNewRow(); right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%.1f", swapused); @@ -1322,6 +1371,42 @@ void HudElements::graphs(){ HUDElements.TextColored(HUDElements.colors.engine, "%s", "GPU Core Clock"); } + if (value == "gpu_nvdec_clock"){ + for (auto& it : graph_data){ + arr.push_back(float(it.gpu_nvdec_clock)); + } + if (int(arr.back()) > HUDElements.gpu_nvdec_max) + HUDElements.gpu_nvdec_max = arr.back(); + + HUDElements.max = HUDElements.gpu_nvdec_max; + HUDElements.min = 0; + ImGui::TextColored(HUDElements.colors.engine, "%s", "NVDEC Clock"); + } + + if (value == "gpu_nvenc_clock"){ + for (auto& it : graph_data){ + arr.push_back(float(it.gpu_nvenc_clock)); + } + if (int(arr.back()) > HUDElements.gpu_nvenc_max) + HUDElements.gpu_nvenc_max = arr.back(); + + HUDElements.max = HUDElements.gpu_nvenc_max; + HUDElements.min = 0; + ImGui::TextColored(HUDElements.colors.engine, "%s", "NVENC Clock"); + } + + if (value == "gpu_vic_clock"){ + for (auto& it : graph_data){ + arr.push_back(float(it.gpu_vic_clock)); + } + if (int(arr.back()) > HUDElements.gpu_vic_max) + HUDElements.gpu_vic_max = arr.back(); + + HUDElements.max = HUDElements.gpu_vic_max; + HUDElements.min = 0; + ImGui::TextColored(HUDElements.colors.engine, "%s", "VIC Clock"); + } + if (value == "gpu_mem_clock"){ for (auto& it : graph_data){ arr.push_back(float(it.gpu_mem_clock)); diff --git a/src/hud_elements.h b/src/hud_elements.h index f49fa54a3c..e0fab4593f 100644 --- a/src/hud_elements.h +++ b/src/hud_elements.h @@ -42,9 +42,9 @@ class HudElements{ std::vector ordered_functions; std::vector gamescope_debug_latency {}; std::vector gamescope_debug_app {}; - int min, max, gpu_core_max, gpu_mem_max, cpu_temp_max, gpu_temp_max; + int min, max, gpu_core_max, gpu_nvdec_max, gpu_nvenc_max, gpu_vic_max, gpu_mem_max, cpu_temp_max, gpu_temp_max; const std::vector permitted_params = { - "gpu_load", "cpu_load", "gpu_core_clock", "gpu_mem_clock", + "gpu_load", "cpu_load", "gpu_core_clock", "gpu_nvdec_clock", "gpu_nvenc_max", "gpu_vic_max", "gpu_mem_clock", "vram", "ram", "cpu_temp", "gpu_temp" }; std::vector exec_list; diff --git a/src/logging.h b/src/logging.h index 309cdb73e5..c83dbdd45b 100644 --- a/src/logging.h +++ b/src/logging.h @@ -21,6 +21,9 @@ struct logData{ int cpu_temp; int gpu_temp; int gpu_core_clock; + int gpu_nvdec_clock; + int gpu_nvenc_clock; + int gpu_vic_clock; int gpu_mem_clock; int gpu_power; float gpu_vram_used; diff --git a/src/memory.cpp b/src/memory.cpp index c360e97606..4d2aa437a9 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -7,8 +7,11 @@ #include #include +#include "file_utils.h" + struct memory_information mem_info; float memused, memmax, swapused, swapmax; +int memclock, membandwidth; struct process_mem proc_mem {}; FILE *open_file(const char *file, int *reported) { @@ -97,7 +100,11 @@ void update_meminfo(void) { memused = (float(mem_info.memmax) - float(mem_info.memeasyfree)) / (1024 * 1024); memmax = float(mem_info.memmax) / (1024 * 1024); - + + if (file_exists("/sys/kernel/debug/clk/emc/clk_rate")) { + memclock = std::stoi(read_line("/sys/kernel/debug/clk/emc/clk_rate")) / 1000000 ; + membandwidth = std::stoi(read_line("/sys/kernel/actmon_avg_activity/mc_all")) / memclock / 10 ; + } swapused = (float(mem_info.swapmax) - float(mem_info.swapfree)) / (1024 * 1024); swapmax = float(mem_info.swapmax) / (1024 * 1024); diff --git a/src/memory.h b/src/memory.h index 79dd0d3a01..eb4e3d89cf 100644 --- a/src/memory.h +++ b/src/memory.h @@ -6,6 +6,7 @@ #include extern float memused, memmax, swapused, swapmax, rss; +extern int memclock, membandwidth; struct memory_information { /* memory information in kilobytes */ diff --git a/src/overlay.cpp b/src/overlay.cpp index 0b8776d3f7..62ebfe041a 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -164,6 +164,9 @@ void update_hw_info(const struct overlay_params& params, uint32_t vendorID) currentLogData.gpu_load = gpu_info.load; currentLogData.gpu_temp = gpu_info.temp; currentLogData.gpu_core_clock = gpu_info.CoreClock; + currentLogData.gpu_nvdec_clock = gpu_info.NVDECClock; + currentLogData.gpu_nvenc_clock = gpu_info.NVENCClock; + currentLogData.gpu_vic_clock = gpu_info.VICClock; currentLogData.gpu_mem_clock = gpu_info.MemClock; currentLogData.gpu_vram_used = gpu_info.memoryUsed; currentLogData.gpu_power = gpu_info.powerUsage; diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 9727b140da..9d53a80826 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -700,16 +700,25 @@ parse_overlay_env(struct overlay_params *params, static void set_param_defaults(struct overlay_params *params){ params->enabled[OVERLAY_PARAM_ENABLED_fps] = true; params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true; - params->enabled[OVERLAY_PARAM_ENABLED_core_load] = false; + params->enabled[OVERLAY_PARAM_ENABLED_core_load] = true; params->enabled[OVERLAY_PARAM_ENABLED_core_bars] = false; - params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp] = false; + params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp] = true; params->enabled[OVERLAY_PARAM_ENABLED_cpu_power] = false; params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp] = false; params->enabled[OVERLAY_PARAM_ENABLED_gpu_junction_temp] = false; params->enabled[OVERLAY_PARAM_ENABLED_gpu_mem_temp] = false; params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats] = true; params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = true; - params->enabled[OVERLAY_PARAM_ENABLED_ram] = false; + params->enabled[OVERLAY_PARAM_ENABLED_gpu_core_clock] = true; + params->enabled[OVERLAY_PARAM_ENABLED_gpu_nvdec_clock] = true; + params->enabled[OVERLAY_PARAM_ENABLED_gpu_nvenc_clock] = true; + params->enabled[OVERLAY_PARAM_ENABLED_gpu_vic_clock] = true; + params->enabled[OVERLAY_PARAM_ENABLED_engine_version] = true; + params->enabled[OVERLAY_PARAM_ENABLED_gpu_name] = true; + params->enabled[OVERLAY_PARAM_ENABLED_resolution] = true; + params->enabled[OVERLAY_PARAM_ENABLED_ram] = true; + params->enabled[OVERLAY_PARAM_ENABLED_ram_clock] = true; + params->enabled[OVERLAY_PARAM_ENABLED_ram_bandwidth] = true; params->enabled[OVERLAY_PARAM_ENABLED_swap] = false; params->enabled[OVERLAY_PARAM_ENABLED_vram] = false; params->enabled[OVERLAY_PARAM_ENABLED_read_cfg] = false; diff --git a/src/overlay_params.h b/src/overlay_params.h index dbf2683837..985a7b16ed 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -40,6 +40,8 @@ typedef unsigned long KeySym; OVERLAY_PARAM_BOOL(cpu_stats) \ OVERLAY_PARAM_BOOL(gpu_stats) \ OVERLAY_PARAM_BOOL(ram) \ + OVERLAY_PARAM_BOOL(ram_clock) \ + OVERLAY_PARAM_BOOL(ram_bandwidth) \ OVERLAY_PARAM_BOOL(swap) \ OVERLAY_PARAM_BOOL(vram) \ OVERLAY_PARAM_BOOL(procmem) \ @@ -52,6 +54,9 @@ typedef unsigned long KeySym; OVERLAY_PARAM_BOOL(io_write) \ OVERLAY_PARAM_BOOL(gpu_mem_clock) \ OVERLAY_PARAM_BOOL(gpu_core_clock) \ + OVERLAY_PARAM_BOOL(gpu_nvdec_clock) \ + OVERLAY_PARAM_BOOL(gpu_nvenc_clock) \ + OVERLAY_PARAM_BOOL(gpu_vic_clock) \ OVERLAY_PARAM_BOOL(gpu_power) \ OVERLAY_PARAM_BOOL(arch) \ OVERLAY_PARAM_BOOL(media_player) \