mangoapp: amdgpu: pause the polling thread when it's not needed

pull/1011/head
FlightlessMango 1 year ago
parent 9bc90493be
commit 7853af98d0

@ -14,6 +14,9 @@
std::string metrics_path = "";
struct amdgpu_common_metrics amdgpu_common_metrics;
std::mutex amdgpu_common_metrics_m;
std::mutex amdgpu_m;
std::condition_variable amdgpu_c;
bool amdgpu_run_thread = false;
bool amdgpu_verify_metrics(const std::string& path)
{
@ -233,6 +236,9 @@ void amdgpu_metrics_polling_thread() {
memset(metrics_buffer, 0, sizeof(metrics_buffer));
while (1) {
std::unique_lock<std::mutex> lock(amdgpu_m);
amdgpu_c.wait(lock, []{return amdgpu_run_thread;});
lock.unlock();
#ifndef TEST_ONLY
if (HUDElements.params->no_display && !logger->is_active())
usleep(100000);

@ -6,6 +6,8 @@
#include <unistd.h>
#include <string>
#include "overlay_params.h"
#include <mutex>
#include <condition_variable>
// #include <vector>
#define METRICS_UPDATE_PERIOD_MS 500
@ -188,6 +190,8 @@ struct amdgpu_common_metrics {
bool amdgpu_verify_metrics(const std::string& path);
void amdgpu_get_metrics();
extern std::string metrics_path;
extern std::condition_variable amdgpu_c;
extern bool amdgpu_run_thread;
void amdgpu_get_instant_metrics(struct amdgpu_common_metrics *metrics);
void amdgpu_metrics_polling_thread();
void amdgpu_get_samples_and_copy(struct amdgpu_common_metrics metrics_buffer[METRICS_SAMPLE_COUNT], bool &gpu_load_needs_dividing);

@ -18,6 +18,7 @@
#include "mangoapp_proto.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "amdgpu.h"
#define GLFW_EXPOSE_NATIVE_X11
#include <GLFW/glfw3native.h>
@ -310,6 +311,10 @@ int main(int, char**)
XChangeProperty(x11_display, x11_window, overlay_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&value, 1);
XSync(x11_display, 0);
mangoapp_paused = false;
{
amdgpu_run_thread = true;
amdgpu_c.notify_one();
}
}
{
std::unique_lock<std::mutex> lk(mangoapp_m);
@ -349,6 +354,10 @@ int main(int, char**)
XChangeProperty(x11_display, x11_window, overlay_atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&value, 1);
XSync(x11_display, 0);
mangoapp_paused = true;
{
amdgpu_run_thread = false;
amdgpu_c.notify_one();
}
std::unique_lock<std::mutex> lk(mangoapp_m);
mangoapp_cv.wait(lk, []{return !params.no_display;});
}

Loading…
Cancel
Save