From 1ed88154b13aa0e802b56d8b883aa7ec0ceabe2a Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 22:35:18 +0000 Subject: [PATCH 01/14] editorconfig: drop irrelevant Makefile section There is no such file in-tree and never was. Signed-off-by: Emil Velikov --- .editorconfig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index 36574d32..ea6a8663 100644 --- a/.editorconfig +++ b/.editorconfig @@ -24,7 +24,3 @@ indent_size = 3 [meson.build] indent_size = 2 - -[Makefile] -indent_style = tab -indent_size = 4 From 83ce3ace2dbf582bc0c5be0f649108a12350a705 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sun, 6 Mar 2022 12:43:06 +0000 Subject: [PATCH 02/14] keybinds: move ifdef spaghetti into the header Drop the ifdef and simplify the .cpp file. Signed-off-by: Emil Velikov --- src/keybinds.cpp | 115 ++++++++++++++++------------------------------- src/keybinds.h | 10 +++-- 2 files changed, 45 insertions(+), 80 deletions(-) diff --git a/src/keybinds.cpp b/src/keybinds.cpp index d22da447..04ae5f7e 100644 --- a/src/keybinds.cpp +++ b/src/keybinds.cpp @@ -5,7 +5,6 @@ void check_keybinds(struct overlay_params& params, uint32_t vendorID){ using namespace std::chrono_literals; - bool pressed = false; // FIXME just a placeholder until wayland support auto now = Clock::now(); /* us */ auto elapsedF2 = now - last_f2_press; auto elapsedFpsLimitToggle = now - toggle_fps_limit_press; @@ -20,95 +19,59 @@ void check_keybinds(struct overlay_params& params, uint32_t vendorID){ auto keyPressDelay = 400ms; - if (elapsedF2 >= keyPressDelay){ -#if defined(HAVE_X11) || defined(_WIN32) - pressed = keys_are_pressed(params.toggle_logging); -#else - pressed = false; -#endif - if (pressed) { - last_f2_press = now; - if (logger->is_active()) { + if (elapsedF2 >= keyPressDelay && + keys_are_pressed(params.toggle_logging)) { + last_f2_press = now; + if (logger->is_active()) { logger->stop_logging(); - } else { + } else { logger->start_logging(); - std::thread(update_hw_info, std::ref(params), vendorID) - .detach(); + std::thread(update_hw_info, std::ref(params), vendorID).detach(); benchmark.fps_data.clear(); - } - } + } } - if (elapsedFpsLimitToggle >= keyPressDelay){ -#if defined(HAVE_X11) || defined(_WIN32) - pressed = keys_are_pressed(params.toggle_fps_limit); -#else - pressed = false; -#endif - if (pressed){ - toggle_fps_limit_press = now; - for (size_t i = 0; i < params.fps_limit.size(); i++){ - uint32_t fps_limit = params.fps_limit[i]; - // current fps limit equals vector entry, use next / first - if((fps_limit > 0 && fps_limit_stats.targetFrameTime == std::chrono::duration_cast(std::chrono::duration(1) / params.fps_limit[i])) - || (fps_limit == 0 && fps_limit_stats.targetFrameTime == fps_limit_stats.targetFrameTime.zero())) { - uint32_t newFpsLimit = i+1 == params.fps_limit.size() ? params.fps_limit[0] : params.fps_limit[i+1]; - if(newFpsLimit > 0) { - fps_limit_stats.targetFrameTime = std::chrono::duration_cast(std::chrono::duration(1) / newFpsLimit); - } else { - fps_limit_stats.targetFrameTime = {}; - } - break; + if (elapsedFpsLimitToggle >= keyPressDelay && + keys_are_pressed(params.toggle_fps_limit)) { + toggle_fps_limit_press = now; + for (size_t i = 0; i < params.fps_limit.size(); i++){ + uint32_t fps_limit = params.fps_limit[i]; + // current fps limit equals vector entry, use next / first + if((fps_limit > 0 && fps_limit_stats.targetFrameTime == std::chrono::duration_cast(std::chrono::duration(1) / params.fps_limit[i])) + || (fps_limit == 0 && fps_limit_stats.targetFrameTime == fps_limit_stats.targetFrameTime.zero())) { + uint32_t newFpsLimit = i+1 == params.fps_limit.size() ? params.fps_limit[0] : params.fps_limit[i+1]; + if(newFpsLimit > 0) { + fps_limit_stats.targetFrameTime = std::chrono::duration_cast(std::chrono::duration(1) / newFpsLimit); + } else { + fps_limit_stats.targetFrameTime = {}; } + break; } } } - if (elapsedF12 >= keyPressDelay){ -#if defined(HAVE_X11) || defined(_WIN32) - pressed = keys_are_pressed(params.toggle_hud); -#else - pressed = false; -#endif - if (pressed){ - last_f12_press = now; - params.no_display = !params.no_display; - } + if (elapsedF12 >= keyPressDelay && + keys_are_pressed(params.toggle_hud)) { + last_f12_press = now; + params.no_display = !params.no_display; } - if (elapsedReloadCfg >= keyPressDelay){ -#if defined(HAVE_X11) || defined(_WIN32) - pressed = keys_are_pressed(params.reload_cfg); -#else - pressed = false; -#endif - if (pressed){ - parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG")); - _params = ¶ms; - reload_cfg_press = now; - } + if (elapsedReloadCfg >= keyPressDelay && + keys_are_pressed(params.reload_cfg)) { + parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG")); + _params = ¶ms; + reload_cfg_press = now; } - if (params.permit_upload && elapsedUpload >= keyPressDelay){ -#if defined(HAVE_X11) || defined(_WIN32) - pressed = keys_are_pressed(params.upload_log); -#else - pressed = false; -#endif - if (pressed){ - last_upload_press = now; - logger->upload_last_log(); - } + if (params.permit_upload && elapsedUpload >= keyPressDelay && + keys_are_pressed(params.upload_log)) { + last_upload_press = now; + logger->upload_last_log(); } - if (params.permit_upload && elapsedUpload >= keyPressDelay){ -#if defined(HAVE_X11) || defined(_WIN32) - pressed = keys_are_pressed(params.upload_logs); -#else - pressed = false; -#endif - if (pressed){ - last_upload_press = now; - logger->upload_last_logs(); - } + + if (params.permit_upload && elapsedUpload >= keyPressDelay && + keys_are_pressed(params.upload_logs)) { + last_upload_press = now; + logger->upload_last_logs(); } } diff --git a/src/keybinds.h b/src/keybinds.h index 3aee726a..83dff612 100644 --- a/src/keybinds.h +++ b/src/keybinds.h @@ -13,7 +13,7 @@ typedef unsigned long KeySym; Clock::time_point last_f2_press, toggle_fps_limit_press , last_f12_press, reload_cfg_press, last_upload_press; -#ifdef HAVE_X11 +#if defined(HAVE_X11) bool keys_are_pressed(const std::vector& keys) { if (!init_x11()) @@ -39,9 +39,7 @@ bool keys_are_pressed(const std::vector& keys) { return false; } -#endif //HAVE_X11 - -#ifdef _WIN32 +#elif defined(_WIN32) #include bool keys_are_pressed(const std::vector& keys) { size_t pressed = 0; @@ -57,6 +55,10 @@ bool keys_are_pressed(const std::vector& keys) { return false; } +#else // XXX: Add wayland support +bool keys_are_pressed(const std::vector& keys) { + return false; +} #endif #endif //MANGOHUD_KEYBINDS_H From 7ad24b4c0a97a2f7934b0070e5e0b9f637c3bd51 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 20:05:28 +0000 Subject: [PATCH 03/14] Simplify cpu/mem/os/glxinfo parsing Currently we pipeline a bunch of commands alike cat | grep | sed, there we can do all that job with a single sed invocation - use that. Signed-off-by: Emil Velikov --- src/overlay.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/overlay.cpp b/src/overlay.cpp index d43f9bea..fb4780e4 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -704,13 +704,13 @@ void init_system_info(){ if (ld_preload) unsetenv("LD_PRELOAD"); - ram = exec("cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'"); + ram = exec("sed -n 's/^MemTotal: *\\([0-9]*\\).*/\\1/p' /proc/meminfo"); trim(ram); - cpu = exec("cat /proc/cpuinfo | grep 'model name' | tail -n1 | sed 's/^.*: //' | sed 's/([^)]*)/()/g' | tr -d '(/)'"); + cpu = exec("sed -n 's/^model name.*: \\(.*\\)/\\1/p' /proc/cpuinfo | sed 's/([^)]*)//g' | tail -n1"); trim(cpu); kernel = exec("uname -r"); trim(kernel); - os = exec("cat /etc/*-release | grep 'PRETTY_NAME' | cut -d '=' -f 2-"); + os = exec("sed -n 's/PRETTY_NAME=\\(.*\\)/\\1/p' /etc/*-release"); os.erase(remove(os.begin(), os.end(), '\"' ), os.end()); trim(os); cpusched = read_line("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"); @@ -718,7 +718,7 @@ void init_system_info(){ const char* mangohud_recursion = getenv("MANGOHUD_RECURSION"); if (!mangohud_recursion) { setenv("MANGOHUD_RECURSION", "1", 1); - driver = exec("glxinfo -B | grep 'OpenGL version' | sed 's/^.*: //' | sed 's/([^()]*)//g' | tr -s ' '"); + driver = exec("glxinfo -B | sed -n 's/^OpenGL version.*: \\(.*\\)/\\1/p' | sed 's/([^)]*)//g;s/ / /g'"); trim(driver); unsetenv("MANGOHUD_RECURSION"); } else { From abbe5233ee07b4caf55fa4fc7b9f49a08d250bdc Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 20:11:12 +0000 Subject: [PATCH 04/14] Remove unused X11/drm auth code The code was added back in 2020 and seemingly never built. Just drop it - if needed it can be git reverted at some point. Signed-off-by: Emil Velikov --- src/auth.cpp | 56 ---------------------------------------------------- src/auth.h | 5 ----- src/gpu.cpp | 8 -------- 3 files changed, 69 deletions(-) delete mode 100644 src/auth.cpp delete mode 100644 src/auth.h diff --git a/src/auth.cpp b/src/auth.cpp deleted file mode 100644 index 5d0d5517..00000000 --- a/src/auth.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - Inspired by radeontop -*/ -#include "auth.h" -#include -#include -#include -#include -#include -#include -#include - -/* Try to authenticate the DRM client with help from the X server. */ -bool authenticate_drm_xcb(drm_magic_t magic) { - xcb_connection_t *conn = xcb_connect(NULL, NULL); - if (!conn) { - return false; - } - if (xcb_connection_has_error(conn)) { - xcb_disconnect(conn); - return false; - } - - xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; - xcb_window_t window = screen->root; - - /* Authenticate our client via the X server using the magic. */ - xcb_dri2_authenticate_cookie_t auth_cookie = - xcb_dri2_authenticate(conn, window, magic); - xcb_dri2_authenticate_reply_t *auth_reply = - xcb_dri2_authenticate_reply(conn, auth_cookie, NULL); - free(auth_reply); - - xcb_disconnect(conn); - return true; -} - -bool authenticate_drm(int fd) { - drm_magic_t magic; - - /* Obtain magic for our DRM client. */ - if (drmGetMagic(fd, &magic) < 0) { - return false; - } - - /* Try self-authenticate (if we are somehow the master). */ - if (drmAuthMagic(fd, magic) == 0) { - if (drmDropMaster(fd)) { - perror("MANGOHUD: Failed to drop DRM master"); - fprintf(stderr, "\n\tWARNING: other DRM clients will crash on VT switch\n"); - } - return true; - } - - return authenticate_drm_xcb(magic); -} diff --git a/src/auth.h b/src/auth.h deleted file mode 100644 index 79645e9b..00000000 --- a/src/auth.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include - -bool authenticate_drm_xcb(drm_magic_t magic); -bool authenticate_drm(int fd); diff --git a/src/gpu.cpp b/src/gpu.cpp index a519728a..b838bd94 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -12,7 +12,6 @@ #endif #ifdef HAVE_LIBDRM_AMDGPU -//#include "auth.h" #include #include #include @@ -259,13 +258,6 @@ bool amdgpu_open(const char *path) { } g_libdrm.drmFreeVersion(ver); -/* - if (!authenticate_drm(fd)) { - close(fd); - return false; - } -*/ - uint32_t drm_major, drm_minor; amdgpu_device_handle dev; if (libdrm_amdgpu_ptr->amdgpu_device_initialize(fd, &drm_major, &drm_minor, &dev)){ From 68ce8f81cc767ee5e7adfb38a9fb2e3388e21633 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 20:12:30 +0000 Subject: [PATCH 05/14] Remove libdrm_amdgpu metrics There are two alternatives - hwmon entries and gpu_metrics sysfs file. Signed-off-by: Emil Velikov --- README.md | 1 - build-srt.sh | 2 +- build.sh | 2 +- meson.build | 4 - meson_options.txt | 1 - src/amdgpu.cpp | 2 +- src/gpu.cpp | 174 --------------------------------- src/gpu.h | 5 - src/loaders/loader_libdrm.cpp | 177 ---------------------------------- src/loaders/loader_libdrm.h | 82 ---------------- src/meson.build | 13 --- src/overlay.cpp | 27 +----- 12 files changed, 4 insertions(+), 486 deletions(-) delete mode 100644 src/loaders/loader_libdrm.cpp delete mode 100644 src/loaders/loader_libdrm.h diff --git a/README.md b/README.md index e4f09812..84dc5421 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ Install necessary development packages. - vulkan headers if using `-Duse_system_vulkan=enabled` option with `meson` - libGL/libEGL (libglvnd, mesa-common-dev, mesa-libGL-devel etc) - X11 (libx11-dev) -- libdrm (libdrm-dev) - XNVCtrl (libxnvctrl-dev), optional, use `-Dwith_xnvctrl=disabled` option with `meson` to disable - D-Bus (libdbus-1-dev), optional, use `-Dwith_dbus=disabled` option with `meson` to disable diff --git a/build-srt.sh b/build-srt.sh index 67c299ce..3a317e9f 100755 --- a/build-srt.sh +++ b/build-srt.sh @@ -28,7 +28,7 @@ dependencies() { } echo "# Checking Dependencies" - DEPS=(${LOCAL_CC}-multilib ${LOCAL_CXX}-multilib unzip libdrm-dev) + DEPS=(${LOCAL_CC}-multilib ${LOCAL_CXX}-multilib unzip) install diff --git a/build.sh b/build.sh index a2342cb8..59a7d958 100755 --- a/build.sh +++ b/build.sh @@ -100,7 +100,7 @@ dependencies() { MANAGER_QUERY="rpm -q" MANAGER_INSTALL="zypper install" - DEPS="{gcc-c++,gcc-c++-32bit,libpkgconf-devel,ninja,python3-pip,python3-Mako,libX11-devel,glslang-devel,glibc-devel,glibc-devel-32bit,libstdc++-devel,libstdc++-devel-32bit,Mesa-libGL-devel,dbus-1-devel,libdrm-devel,${PACKMAN_PKGS}}" + DEPS="{gcc-c++,gcc-c++-32bit,libpkgconf-devel,ninja,python3-pip,python3-Mako,libX11-devel,glslang-devel,glibc-devel,glibc-devel-32bit,libstdc++-devel,libstdc++-devel-32bit,Mesa-libGL-devel,dbus-1-devel,${PACKMAN_PKGS}}" dep_install if [[ $(pip3 show meson; echo $?) == 1 ]]; then diff --git a/meson.build b/meson.build index ac30e23e..6c39f400 100644 --- a/meson.build +++ b/meson.build @@ -88,14 +88,10 @@ if is_unixy dep_wayland_client = dependency('wayland-client', required: get_option('with_wayland'), version : '>=1.11') dbus_dep = dependency('dbus-1', required: get_option('with_dbus')).partial_dependency(compile_args : true, includes : true) - dep_libdrm = dependency('libdrm', required: get_option('with_libdrm_amdgpu')).partial_dependency(compile_args : true, includes : true) -# dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>=2.4.79', required: get_option('with_libdrm_amdgpu')).partial_dependency(compile_args : true, includes : true) else dep_x11 = null_dep dep_wayland_client = null_dep dbus_dep = null_dep - dep_libdrm = null_dep -# dep_libdrm_amdgpu = null_dep endif if dep_x11.found() diff --git a/meson_options.txt b/meson_options.txt index b917dfa8..44a841ae 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -13,7 +13,6 @@ option('with_x11', type : 'feature', value : 'enabled') option('with_wayland', type : 'feature', value : 'disabled') option('with_dbus', type : 'feature', value : 'enabled') option('with_dlsym', type : 'feature', value : 'disabled') -option('with_libdrm_amdgpu', type : 'feature', value : 'enabled', description: 'Get amdgpu sensor info through libdrm_amdgpu') option('loglevel', type: 'combo', choices : ['trace', 'debug', 'info', 'warn', 'err', 'critical', 'off'], value : 'info', description: 'Max log level in non-debug build') option('mangoapp', type: 'boolean', value : 'false') option('mangohudctl', type: 'boolean', value : 'false') diff --git a/src/amdgpu.cpp b/src/amdgpu.cpp index aa56e322..f5921421 100644 --- a/src/amdgpu.cpp +++ b/src/amdgpu.cpp @@ -41,4 +41,4 @@ void amdgpu_get_metrics() gpu_info.apu_cpu_temp = cpu_temp / 100; } } -} \ No newline at end of file +} diff --git a/src/gpu.cpp b/src/gpu.cpp index b838bd94..33e287af 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -11,14 +11,6 @@ #include "nvidia_info.h" #endif -#ifdef HAVE_LIBDRM_AMDGPU -#include -#include -#include -#include -#include -#include "loaders/loader_libdrm.h" -#endif #include "amdgpu.h" using namespace std::chrono_literals; @@ -140,169 +132,3 @@ void getAmdGpuInfo(){ gpu_info.memoryUsed = float(value) / (1024 * 1024 * 1024); } } - -#ifdef HAVE_LIBDRM_AMDGPU -#define DRM_ATLEAST_VERSION(ver, maj, min) \ - (ver->version_major > maj || (ver->version_major == maj && ver->version_minor >= min)) - -enum { - GRBM_STATUS = 0x8010, -}; - -static std::unique_ptr libdrm_amdgpu_ptr; - -static int getgrbm_amdgpu(amdgpu_device_handle dev, uint32_t *out) { - return libdrm_amdgpu_ptr->amdgpu_read_mm_registers(dev, GRBM_STATUS / 4, 1, - 0xffffffff, 0, out); -} - -struct amdgpu_handles -{ - amdgpu_device_handle dev; - int fd; - uint32_t version_major, version_minor, gui_percent {0}; - uint32_t ticks = 60, ticks_per_sec = 120; - std::chrono::nanoseconds sleep_interval {}; - - bool quit = false; - std::thread collector; - - amdgpu_handles(amdgpu_device_handle dev_, int fd_, uint32_t major, uint32_t minor) - : dev(dev_) - , fd(fd_) - , version_major(major) - , version_minor(minor) - { - set_sampling_period(500000000 /* 500ms */); - collector = std::thread(&amdgpu_handles::amdgpu_poll, this); - } - - ~amdgpu_handles() - { - quit = true; - if (collector.joinable()) - collector.join(); - libdrm_amdgpu_ptr->amdgpu_device_deinitialize(dev); - close(fd); - } - - void set_sampling_period(uint32_t period) - { - if (period < 10000000) - period = 10000000; /* 10ms */ - ticks = ticks_per_sec * std::chrono::nanoseconds(period) / 1s; - sleep_interval = std::chrono::nanoseconds(period) / ticks; - SPDLOG_DEBUG("ticks: {}, {}ns", ticks, sleep_interval.count()); - } - - void amdgpu_poll() - { - uint32_t stat = 0, gui = 0, curr = 0; - while (!quit) - { - getgrbm_amdgpu(dev, &stat); - if (stat & (1U << 31)) // gui - gui++; - - std::this_thread::sleep_for(sleep_interval); - curr++; - curr %= ticks; - if (!curr) - { - gui_percent = gui * 100 / ticks; - gui = 0; - } - } - } -}; - -typedef std::unique_ptr amdgpu_ptr; -static amdgpu_ptr amdgpu_dev; - -void amdgpu_set_sampling_period(uint32_t period) -{ - if (amdgpu_dev) - amdgpu_dev->set_sampling_period(period); -} - -bool amdgpu_open(const char *path) { - if (!g_libdrm.IsLoaded()) - return false; - - if (!libdrm_amdgpu_ptr) - libdrm_amdgpu_ptr = std::make_unique(); - - if (!libdrm_amdgpu_ptr->IsLoaded()) - return false; - - int fd = open(path, O_RDWR | O_CLOEXEC); - - if (fd < 0) { - SPDLOG_ERROR("Failed to open DRM device: {}", strerror(errno)); - return false; - } - - drmVersionPtr ver = g_libdrm.drmGetVersion(fd); - - if (!ver) { - SPDLOG_ERROR("Failed to query driver version: {}", strerror(errno)); - close(fd); - return false; - } - - if (strcmp(ver->name, "amdgpu") || !DRM_ATLEAST_VERSION(ver, 3, 11)) { - SPDLOG_ERROR("Unsupported driver/version: {} {}.{}.{}", ver->name, ver->version_major, ver->version_minor, ver->version_patchlevel); - close(fd); - g_libdrm.drmFreeVersion(ver); - return false; - } - g_libdrm.drmFreeVersion(ver); - - uint32_t drm_major, drm_minor; - amdgpu_device_handle dev; - if (libdrm_amdgpu_ptr->amdgpu_device_initialize(fd, &drm_major, &drm_minor, &dev)){ - SPDLOG_ERROR("Failed to initialize amdgpu device: {}", strerror(errno)); - close(fd); - return false; - } - - amdgpu_dev = std::make_unique(dev, fd, drm_major, drm_minor); - return true; -} - -void getAmdGpuInfo_libdrm() -{ - uint64_t value = 0; - uint32_t value32 = 0; - - if (!amdgpu_dev || !DRM_ATLEAST_VERSION(amdgpu_dev, 3, 11)) - { - getAmdGpuInfo(); - getAmdGpuInfo_actual = getAmdGpuInfo; - return; - } - - if (!libdrm_amdgpu_ptr->amdgpu_query_info(amdgpu_dev->dev, AMDGPU_INFO_VRAM_USAGE, sizeof(uint64_t), &value)) - gpu_info.memoryUsed = float(value) / (1024 * 1024 * 1024); - - // FIXME probably not correct sensor - if (!libdrm_amdgpu_ptr->amdgpu_query_info(amdgpu_dev->dev, AMDGPU_INFO_MEMORY, sizeof(uint64_t), &value)) - gpu_info.memoryTotal = float(value) / (1024 * 1024 * 1024); - - if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GFX_SCLK, sizeof(uint32_t), &value32)) - gpu_info.CoreClock = value32; - - if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GFX_MCLK, sizeof(uint32_t), &value32)) // XXX Doesn't work on APUs - gpu_info.MemClock = value32; - - //if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GPU_LOAD, sizeof(uint32_t), &value32)) - // gpu_info.load = value32; - gpu_info.load = amdgpu_dev->gui_percent; - - if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GPU_TEMP, sizeof(uint32_t), &value32)) - gpu_info.temp = value32 / 1000; - - if (!libdrm_amdgpu_ptr->amdgpu_query_sensor_info(amdgpu_dev->dev, AMDGPU_INFO_SENSOR_GPU_AVG_POWER, sizeof(uint32_t), &value32)) - gpu_info.powerUsage = value32; -} -#endif diff --git a/src/gpu.h b/src/gpu.h index 09b1a9fc..217c09c4 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -34,11 +34,6 @@ extern struct gpuInfo gpu_info; void getNvidiaGpuInfo(void); void getAmdGpuInfo(void); -#ifdef HAVE_LIBDRM_AMDGPU -void getAmdGpuInfo_libdrm(); -bool amdgpu_open(const char *path); -void amdgpu_set_sampling_period(uint32_t period); -#endif extern decltype(&getAmdGpuInfo) getAmdGpuInfo_actual; bool checkNvidia(const char *pci_dev); extern void nvapi_util(); diff --git a/src/loaders/loader_libdrm.cpp b/src/loaders/loader_libdrm.cpp deleted file mode 100644 index f28525ba..00000000 --- a/src/loaders/loader_libdrm.cpp +++ /dev/null @@ -1,177 +0,0 @@ - -#include "loaders/loader_libdrm.h" -#include -#include - -// Put these sanity checks here so that they fire at most once -// (to avoid cluttering the build output). -#if !defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) && !defined(LIBRARY_LOADER_LIBDRM_H_DT_NEEDED) -#error neither LIBRARY_LOADER_LIBDRM_H_DLOPEN nor LIBRARY_LOADER_LIBDRM_H_DT_NEEDED defined -#endif -#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) && defined(LIBRARY_LOADER_LIBDRM_H_DT_NEEDED) -#error both LIBRARY_LOADER_LIBDRM_H_DLOPEN and LIBRARY_LOADER_LIBDRM_H_DT_NEEDED defined -#endif - -libdrm_loader::libdrm_loader() : loaded_(false) { - Load(); -} - -libdrm_loader::~libdrm_loader() { - CleanUp(loaded_); -} - -bool libdrm_loader::Load() { - if (loaded_) { - return true; - } - -#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) - library = dlopen("libdrm.so.2", RTLD_LAZY); - if (!library) { - SPDLOG_ERROR("Failed to open " MANGOHUD_ARCH " libdrm.so.2: {}", dlerror()); - return false; - } - - drmGetVersion = - reinterpret_castdrmGetVersion)>( - dlsym(library, "drmGetVersion")); - if (!drmGetVersion) { - CleanUp(true); - return false; - } - - drmFreeVersion = - reinterpret_castdrmFreeVersion)>( - dlsym(library, "drmFreeVersion")); - if (!drmFreeVersion) { - CleanUp(true); - return false; - } - - drmCommandWriteRead = - reinterpret_castdrmCommandWriteRead)>( - dlsym(library, "drmCommandWriteRead")); - if (!drmCommandWriteRead) { - CleanUp(true); - return false; - } - -#endif - -#if defined(LIBRARY_LOADER_LIBDRM_H_DT_NEEDED) - drmGetVersion = &::drmGetVersion; - drmFreeVersion = &::drmFreeVersion; - drmCommandWriteRead = &::drmCommandWriteRead; -#endif - - loaded_ = true; - return true; -} - -void libdrm_loader::CleanUp(bool unload) { -#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) - if (unload) { - dlclose(library); - library = nullptr; - } -#endif - loaded_ = false; - drmGetVersion = nullptr; - drmFreeVersion = nullptr; - drmCommandWriteRead = nullptr; - -} - -libdrm_amdgpu_loader::libdrm_amdgpu_loader() : loaded_(false) { - Load(); -} - -libdrm_amdgpu_loader::~libdrm_amdgpu_loader() { - CleanUp(loaded_); -} - -bool libdrm_amdgpu_loader::Load() { - if (loaded_) { - return true; - } - -#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) - library = dlopen("libdrm_amdgpu.so.1", RTLD_LAZY); - if (!library) { - SPDLOG_ERROR("Failed to open " MANGOHUD_ARCH " libdrm_amdgpu.so.1: {}", dlerror()); - CleanUp(true); - return false; - } - - amdgpu_device_initialize = - reinterpret_castamdgpu_device_initialize)>( - dlsym(library, "amdgpu_device_initialize")); - if (!amdgpu_device_initialize) { - CleanUp(true); - return false; - } - - amdgpu_device_deinitialize = - reinterpret_castamdgpu_device_deinitialize)>( - dlsym(library, "amdgpu_device_deinitialize")); - if (!amdgpu_device_deinitialize) { - CleanUp(true); - return false; - } - - amdgpu_query_info = - reinterpret_castamdgpu_query_info)>( - dlsym(library, "amdgpu_query_info")); - if (!amdgpu_query_info) { - CleanUp(true); - return false; - } - - amdgpu_query_sensor_info = - reinterpret_castamdgpu_query_sensor_info)>( - dlsym(library, "amdgpu_query_sensor_info")); - if (!amdgpu_query_sensor_info) { - CleanUp(true); - return false; - } - - amdgpu_read_mm_registers = - reinterpret_castamdgpu_read_mm_registers)>( - dlsym(library, "amdgpu_read_mm_registers")); - if (!amdgpu_read_mm_registers) { - CleanUp(true); - return false; - } - -#endif - -#if defined(LIBRARY_LOADER_LIBDRM_H_DT_NEEDED) - amdgpu_device_initialize = &::amdgpu_device_initialize; - amdgpu_device_deinitialize = &::amdgpu_device_deinitialize; - amdgpu_query_info = &::amdgpu_query_info; - amdgpu_query_sensor_info = &::amdgpu_query_sensor_info; - amdgpu_read_mm_registers = &::amdgpu_read_mm_registers; - -#endif - - loaded_ = true; - return true; -} - -void libdrm_amdgpu_loader::CleanUp(bool unload) { -#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) - if (unload) { - dlclose(library); - library = nullptr; - } -#endif - loaded_ = false; - amdgpu_device_initialize = nullptr; - amdgpu_device_deinitialize = nullptr; - amdgpu_query_info = nullptr; - amdgpu_query_sensor_info = nullptr; - amdgpu_read_mm_registers = nullptr; - -} - -libdrm_loader g_libdrm; diff --git a/src/loaders/loader_libdrm.h b/src/loaders/loader_libdrm.h deleted file mode 100644 index 897e5714..00000000 --- a/src/loaders/loader_libdrm.h +++ /dev/null @@ -1,82 +0,0 @@ - -#ifndef LIBRARY_LOADER_LIBDRM_H -#define LIBRARY_LOADER_LIBDRM_H - -#define LIBRARY_LOADER_LIBDRM_H_DLOPEN - -#include -#include -//#include -//#include - -typedef struct amdgpu_device *amdgpu_device_handle; -int amdgpu_device_initialize(int fd, - uint32_t *major_version, - uint32_t *minor_version, - amdgpu_device_handle *device_handle); -int amdgpu_device_deinitialize(amdgpu_device_handle device_handle); -int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id, - unsigned size, void *value); -int amdgpu_query_sensor_info(amdgpu_device_handle dev, unsigned sensor_type, - unsigned size, void *value); -int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset, - unsigned count, uint32_t instance, uint32_t flags, - uint32_t *values); - -class libdrm_loader { - public: - libdrm_loader(); - ~libdrm_loader(); - - bool Load(); - bool IsLoaded() { return loaded_; } - - decltype(&::drmGetVersion) drmGetVersion; - decltype(&::drmFreeVersion) drmFreeVersion; - decltype(&::drmCommandWriteRead) drmCommandWriteRead; - - private: - void CleanUp(bool unload); - -#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) - void* library; -#endif - - bool loaded_; - - // Disallow copy constructor and assignment operator. - libdrm_loader(const libdrm_loader&); - void operator=(const libdrm_loader&); -}; - -class libdrm_amdgpu_loader { - public: - libdrm_amdgpu_loader(); - ~libdrm_amdgpu_loader(); - - bool Load(); - bool IsLoaded() { return loaded_; } - - decltype(&::amdgpu_device_initialize) amdgpu_device_initialize; - decltype(&::amdgpu_device_deinitialize) amdgpu_device_deinitialize; - decltype(&::amdgpu_query_info) amdgpu_query_info; - decltype(&::amdgpu_query_sensor_info) amdgpu_query_sensor_info; - decltype(&::amdgpu_read_mm_registers) amdgpu_read_mm_registers; - - private: - void CleanUp(bool unload); - -#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) - void* library; -#endif - - bool loaded_; - - // Disallow copy constructor and assignment operator. - libdrm_amdgpu_loader(const libdrm_amdgpu_loader&); - void operator=(const libdrm_amdgpu_loader&); -}; - -extern libdrm_loader g_libdrm; - -#endif // LIBRARY_LOADER_LIBDRM_H diff --git a/src/meson.build b/src/meson.build index ef291efd..582a3809 100644 --- a/src/meson.build +++ b/src/meson.build @@ -152,16 +152,6 @@ if is_unixy 'loaders/loader_dbus.cpp', ) endif - -# if get_option('with_libdrm_amdgpu').enabled() and dep_libdrm.found() and dep_libdrm_amdgpu.found() - if get_option('with_libdrm_amdgpu').enabled() and dep_libdrm.found() - pre_args += '-DHAVE_LIBDRM_AMDGPU' - #if dep_xcb.found() and dep_xcb_dri2.found() - vklayer_files += files( - 'loaders/loader_libdrm.cpp', - ) - #endif - endif endif link_args = cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro', '-Wl,--exclude-libs,ALL', '-lGL']) @@ -190,8 +180,6 @@ vklayer_mesa_overlay = shared_library( vulkan_wsi_deps, dearimgui_dep, spdlog_dep, - dep_libdrm, - #dep_libdrm_amdgpu, dbus_dep, dep_dl, dep_rt, @@ -255,7 +243,6 @@ if get_option('mangoapp') and sizeof_ptr == 8 dep_dl, spdlog_dep, dbus_dep, - dep_libdrm, dep_x11, glfw3_dep, ], diff --git a/src/overlay.cpp b/src/overlay.cpp index fb4780e4..03b12919 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -587,7 +587,6 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para string path; string drm = "/sys/class/drm/"; getAmdGpuInfo_actual = getAmdGpuInfo; - bool using_libdrm = false; auto dirs = ls(drm.c_str(), "card"); for (auto& dir : dirs) { @@ -639,30 +638,6 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para metrics_path = gpu_metrics_path; SPDLOG_DEBUG("Using gpu_metrics"); } -#ifdef HAVE_LIBDRM_AMDGPU - else { - int idx = -1; - //TODO make neater - int res = sscanf(path.c_str(), "/sys/class/drm/card%d", &idx); - std::string dri_path = "/dev/dri/card" + std::to_string(idx); - - if (!params.enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon] && res == 1 && amdgpu_open(dri_path.c_str())) { - vendorID = 0x1002; - using_libdrm = true; - getAmdGpuInfo_actual = getAmdGpuInfo_libdrm; - amdgpu_set_sampling_period(params.fps_sampling_period); - - SPDLOG_DEBUG("Using libdrm"); - - // fall through and open sysfs handles for fallback or check DRM version beforehand - } else if (!params.enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon]) { - SPDLOG_ERROR("Failed to open device '/dev/dri/card{}' with libdrm, falling back to using hwmon sysfs.", idx); - } else if (params.enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon]) { - SPDLOG_DEBUG("Using amdgpu hwmon"); - } - } -#endif - path += "/device"; if (!amdgpu.busy) amdgpu.busy = fopen((path + "/gpu_busy_percent").c_str(), "r"); @@ -689,7 +664,7 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para } // don't bother then - if (!using_libdrm && !amdgpu.busy && !amdgpu.temp && !amdgpu.vram_total && !amdgpu.vram_used) { + if (!amdgpu.busy && !amdgpu.temp && !amdgpu.vram_total && !amdgpu.vram_used) { params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = false; } } From ab684a2f2431d124187242d796e0bcf913f5ced0 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 21:45:09 +0000 Subject: [PATCH 06/14] List regular files with ls(.. LS_FILES) Currently it can give you a regular file, block/char device, fifo or a socket. Signed-off-by: Emil Velikov --- src/file_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file_utils.cpp b/src/file_utils.cpp index 29b1e0b6..77476136 100644 --- a/src/file_utils.cpp +++ b/src/file_utils.cpp @@ -89,7 +89,7 @@ std::vector ls(const char* root, const char* prefix, LS_FLAGS flags continue; if (((flags & LS_DIRS) && S_ISDIR(s.st_mode)) - || ((flags & LS_FILES) && !S_ISDIR(s.st_mode))) { + || ((flags & LS_FILES) && S_ISREG(s.st_mode))) { list.push_back(dp->d_name); } } else if (((flags & LS_DIRS) && dp->d_type == DT_DIR) From ffb9b592f50d326384fb3524f824b0bad01341e7 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 21:53:08 +0000 Subject: [PATCH 07/14] Use a switch in ls() d_type handling Makes the code much easier to read. Signed-off-by: Emil Velikov --- src/file_utils.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/file_utils.cpp b/src/file_utils.cpp index 77476136..4c5dcbb6 100644 --- a/src/file_utils.cpp +++ b/src/file_utils.cpp @@ -78,7 +78,8 @@ std::vector ls(const char* root, const char* prefix, LS_FLAGS flags || !strcmp(dp->d_name, "..")) continue; - if (dp->d_type == DT_LNK) { + switch (dp->d_type) { + case DT_LNK: { struct stat s; std::string path(root); if (path.back() != '/') @@ -92,10 +93,16 @@ std::vector ls(const char* root, const char* prefix, LS_FLAGS flags || ((flags & LS_FILES) && S_ISREG(s.st_mode))) { list.push_back(dp->d_name); } - } else if (((flags & LS_DIRS) && dp->d_type == DT_DIR) - || ((flags & LS_FILES) && dp->d_type == DT_REG) - ) { - list.push_back(dp->d_name); + break; + } + case DT_DIR: + if (flags & LS_DIRS) + list.push_back(dp->d_name); + break; + case DT_REG: + if (flags & LS_FILES) + list.push_back(dp->d_name); + break; } } From d75b4d972bfd7efbda67640157876f53df77f8fe Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 21:54:37 +0000 Subject: [PATCH 08/14] Remove unused LS_FLAGS::LS_ALL Signed-off-by: Emil Velikov --- src/file_utils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/file_utils.h b/src/file_utils.h index 472b1f97..b2103ec4 100644 --- a/src/file_utils.h +++ b/src/file_utils.h @@ -7,7 +7,6 @@ enum LS_FLAGS { - LS_ALL = 0x00, LS_DIRS = 0x01, LS_FILES = 0x02, }; From 2aa49caf52b1037e0fe2ae9bb2fe897daaae5bd6 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 22:08:46 +0000 Subject: [PATCH 09/14] Remove find_folder() API Can be trivially replaced with ls() v2: Move break where it's supposed to. Signed-off-by: Emil Velikov --- src/file_utils.cpp | 28 ---------------------------- src/file_utils.h | 2 -- src/file_utils_win32.cpp | 10 ---------- src/overlay.cpp | 14 +++++++------- 4 files changed, 7 insertions(+), 47 deletions(-) diff --git a/src/file_utils.cpp b/src/file_utils.cpp index 4c5dcbb6..9e3606d8 100644 --- a/src/file_utils.cpp +++ b/src/file_utils.cpp @@ -33,34 +33,6 @@ std::string get_basename(const std::string&& path) } #ifdef __linux__ - -bool find_folder(const char* root, const char* prefix, std::string& dest) -{ - struct dirent* dp; - DIR* dirp = opendir(root); - if (!dirp) { - SPDLOG_ERROR("Error opening directory '{}': {}", root, strerror(errno)); - return false; - } - - // XXX xfs/jfs need stat() for inode type - while ((dp = readdir(dirp))) { - if ((dp->d_type == DT_LNK || dp->d_type == DT_DIR) && starts_with(dp->d_name, prefix)) { - dest = dp->d_name; - closedir(dirp); - return true; - } - } - - closedir(dirp); - return false; -} - -bool find_folder(const std::string& root, const std::string& prefix, std::string& dest) -{ - return find_folder(root.c_str(), prefix.c_str(), dest); -} - std::vector ls(const char* root, const char* prefix, LS_FLAGS flags) { std::vector list; diff --git a/src/file_utils.h b/src/file_utils.h index b2103ec4..03b3d8eb 100644 --- a/src/file_utils.h +++ b/src/file_utils.h @@ -12,8 +12,6 @@ enum LS_FLAGS }; std::string read_line(const std::string& filename); -bool find_folder(const char* root, const char* prefix, std::string& dest); -bool find_folder(const std::string& root, const std::string& prefix, std::string& dest); std::vector ls(const char* root, const char* prefix = nullptr, LS_FLAGS flags = LS_DIRS); bool file_exists(const std::string& path); bool dir_exists(const std::string& path); diff --git a/src/file_utils_win32.cpp b/src/file_utils_win32.cpp index a37a8c14..15e9aac0 100644 --- a/src/file_utils_win32.cpp +++ b/src/file_utils_win32.cpp @@ -3,16 +3,6 @@ #include #include -bool find_folder(const char* root, const char* prefix, std::string& dest) -{ - return false; -} - -bool find_folder(const std::string& root, const std::string& prefix, std::string& dest) -{ - return find_folder(root.c_str(), prefix.c_str(), dest); -} - std::vector ls(const char* root, const char* prefix, LS_FLAGS flags) { std::vector list; diff --git a/src/overlay.cpp b/src/overlay.cpp index 03b12919..0eddd540 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -647,20 +647,20 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para amdgpu.vram_used = fopen((path + "/mem_info_vram_used").c_str(), "r"); path += "/hwmon/"; - string tempFolder; - if (find_folder(path, "hwmon", tempFolder)) { + auto dirs = ls(path.c_str(), "hwmon", LS_DIRS); + for (auto& dir : dirs) { if (!amdgpu.core_clock) - amdgpu.core_clock = fopen((path + tempFolder + "/freq1_input").c_str(), "r"); + amdgpu.core_clock = fopen((path + dir + "/freq1_input").c_str(), "r"); if (!amdgpu.memory_clock) - amdgpu.memory_clock = fopen((path + tempFolder + "/freq2_input").c_str(), "r"); + amdgpu.memory_clock = fopen((path + dir + "/freq2_input").c_str(), "r"); if (!amdgpu.temp) - amdgpu.temp = fopen((path + tempFolder + "/temp1_input").c_str(), "r"); + amdgpu.temp = fopen((path + dir + "/temp1_input").c_str(), "r"); if (!amdgpu.power_usage) - amdgpu.power_usage = fopen((path + tempFolder + "/power1_average").c_str(), "r"); + amdgpu.power_usage = fopen((path + dir + "/power1_average").c_str(), "r"); vendorID = 0x1002; - break; } + break; } // don't bother then From a7e8ae9417722cd9ebbec53468e348c6986ca18e Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 22:00:40 +0000 Subject: [PATCH 10/14] Remove dummy vendorID overwrite in init_gpu_stats() We have already enforced that a few lines above just after parsing the vendor node. Signed-off-by: Emil Velikov --- src/overlay.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/overlay.cpp b/src/overlay.cpp index 0eddd540..d0577f13 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -657,8 +657,6 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para amdgpu.temp = fopen((path + dir + "/temp1_input").c_str(), "r"); if (!amdgpu.power_usage) amdgpu.power_usage = fopen((path + dir + "/power1_average").c_str(), "r"); - - vendorID = 0x1002; } break; } From 5143229bd112e9d4da0a5fcc081d8a7aeed9439c Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 22:05:05 +0000 Subject: [PATCH 11/14] Fix gpu_stats logic check Currently we can get the load and temp stats either from the standalone nodes or from the gpu_metrics (binary) sysfs node. Fix the next to handle that. Signed-off-by: Emil Velikov --- src/overlay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overlay.cpp b/src/overlay.cpp index d0577f13..1eba4991 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -662,7 +662,7 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para } // don't bother then - if (!amdgpu.busy && !amdgpu.temp && !amdgpu.vram_total && !amdgpu.vram_used) { + if (metrics_path.empty() && !amdgpu.busy && !amdgpu.temp && !amdgpu.vram_total && !amdgpu.vram_used) { params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = false; } } From 17bfd6ed0882d0efc5c9bbf46feaf4de72cc6479 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Mar 2022 22:11:45 +0000 Subject: [PATCH 12/14] Skip the standalone nodes, when gpu_metrics is present Currently we open the standalone busy, temp, gpu/memory clock and power_usage nodes, even if gpu_metrics is present. At the same time, we correctly ignore them when doing the read-only. So just avoid opening them all together. Signed-off-by: Emil Velikov --- src/gpu.h | 5 +++-- src/overlay.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/gpu.h b/src/gpu.h index 217c09c4..cd6b14bf 100644 --- a/src/gpu.h +++ b/src/gpu.h @@ -7,10 +7,11 @@ struct amdgpu_files { - FILE *busy; - FILE *temp; FILE *vram_total; FILE *vram_used; + /* The following can be NULL, in that case we're using the gpu_metrics node */ + FILE *busy; + FILE *temp; FILE *core_clock; FILE *memory_clock; FILE *power_usage; diff --git a/src/overlay.cpp b/src/overlay.cpp index 1eba4991..80d28297 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -639,13 +639,16 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para SPDLOG_DEBUG("Using gpu_metrics"); } path += "/device"; - if (!amdgpu.busy) - amdgpu.busy = fopen((path + "/gpu_busy_percent").c_str(), "r"); if (!amdgpu.vram_total) amdgpu.vram_total = fopen((path + "/mem_info_vram_total").c_str(), "r"); if (!amdgpu.vram_used) amdgpu.vram_used = fopen((path + "/mem_info_vram_used").c_str(), "r"); + if (!metrics_path.empty()) + break; + + if (!amdgpu.busy) + amdgpu.busy = fopen((path + "/gpu_busy_percent").c_str(), "r"); path += "/hwmon/"; auto dirs = ls(path.c_str(), "hwmon", LS_DIRS); for (auto& dir : dirs) { From 9c6de0271f668765083a57d8d55e0846b5295f8d Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 12 Mar 2022 18:11:27 +0000 Subject: [PATCH 13/14] overlay: completely remove force_amdgpu_hwmon option No longer applicable, since the libdrm path is gone and hwmon is required - either partially or in full. Signed-off-by: Emil Velikov --- README.md | 1 - src/overlay_params.cpp | 2 -- src/overlay_params.h | 1 - 3 files changed, 4 deletions(-) diff --git a/README.md b/README.md index 84dc5421..6e699a95 100644 --- a/README.md +++ b/README.md @@ -352,7 +352,6 @@ Parameters that are enabled by default have to be explicitly disabled. These (cu | `battery` | Display current battery percent and energy consumption | | `battery_icon` | Display battery icon instead of percent | | `battery_color` | Change the BATT text color | -| `force_amdgpu_hwmon` | Use hwmon sysfs instead of libdrm for amdgpu stats | | `fps_only` | Show FPS without the engine name e.g. DXVK/VULAKAN etc. | | `gamepad_battery` | Display battey of wireless gamepads (xone,xpadneo,ds4) | | `gamepad_battery_icon` | Display gamepad battery percent with icon. *enabled by default | diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 9e80cde7..ae58dc36 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -522,7 +522,6 @@ parse_overlay_env(struct overlay_params *params, params->enabled[OVERLAY_PARAM_ENABLED_gpu_load_change] = 0; params->enabled[OVERLAY_PARAM_ENABLED_cpu_load_change] = 0; params->enabled[OVERLAY_PARAM_ENABLED_fps_only] = 0; - params->enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon] = 0; params->enabled[OVERLAY_PARAM_ENABLED_fps_color_change] = 0; params->enabled[OVERLAY_PARAM_ENABLED_core_load_change] = 0; params->enabled[OVERLAY_PARAM_ENABLED_battery_icon] = 0; @@ -674,7 +673,6 @@ parse_overlay_config(struct overlay_params *params, params->enabled[OVERLAY_PARAM_ENABLED_histogram] = 0; params->enabled[OVERLAY_PARAM_ENABLED_fps_only] = 0; params->enabled[OVERLAY_PARAM_ENABLED_battery_icon] = 0; - params->enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon] = 0; params->enabled[OVERLAY_PARAM_ENABLED_mangoapp_steam] = 0; params->enabled[OVERLAY_PARAM_ENABLED_hide_fsr_sharpness] = 0; params->options.erase("full"); diff --git a/src/overlay_params.h b/src/overlay_params.h index 21f2fe09..2054f109 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -73,7 +73,6 @@ typedef unsigned long KeySym; OVERLAY_PARAM_BOOL(gamemode) \ OVERLAY_PARAM_BOOL(battery) \ OVERLAY_PARAM_BOOL(battery_icon) \ - OVERLAY_PARAM_BOOL(force_amdgpu_hwmon) \ OVERLAY_PARAM_BOOL(fps_only) \ OVERLAY_PARAM_BOOL(fsr) \ OVERLAY_PARAM_BOOL(mangoapp_steam) \ From 816d9f6b98434a8a38d77687a39a0803b7a342b2 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 12 Mar 2022 18:17:29 +0000 Subject: [PATCH 14/14] overlay: rework misleading gpu_busy_percent check Above all, we really don't need the gpu_busy_percent node, if the GPU exposes a gpu_metrics node, Although looking closer, the gpu_busy_percent check is meant for something else - to distinguish between the card node (cardX) and the card output node (cardX-output-foo). To top it all up, the check at the very end implies that we can get a case where gpu_metrics and gpu_busy_perfect is missing ... that's not possible. So instead, drop the early gpu_busy_perfect check and properly mandate it later on. Signed-off-by: Emil Velikov --- src/overlay.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/overlay.cpp b/src/overlay.cpp index 80d28297..cdeae521 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -618,9 +618,6 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para fclose(fp); } - if (!file_exists(path + "/device/gpu_busy_percent")) - continue; - if (pci_bus_parsed && pci_dev) { string pci_device = read_symlink((path + "/device").c_str()); SPDLOG_DEBUG("PCI device symlink: '{}'", pci_device); @@ -647,8 +644,12 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para if (!metrics_path.empty()) break; + // The card output nodes - cardX-output, will point to the card node + // As such the actual metrics nodes will be missing. + amdgpu.busy = fopen((path + "/gpu_busy_percent").c_str(), "r"); if (!amdgpu.busy) - amdgpu.busy = fopen((path + "/gpu_busy_percent").c_str(), "r"); + continue; + path += "/hwmon/"; auto dirs = ls(path.c_str(), "hwmon", LS_DIRS); for (auto& dir : dirs) { @@ -665,7 +666,7 @@ void init_gpu_stats(uint32_t& vendorID, uint32_t reported_deviceID, overlay_para } // don't bother then - if (metrics_path.empty() && !amdgpu.busy && !amdgpu.temp && !amdgpu.vram_total && !amdgpu.vram_used) { + if (metrics_path.empty() && !amdgpu.busy) { params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = false; } }