Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linux): enable lowlatency mode for AMD #3088

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/platform/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,23 @@ namespace platf {
void
restart();

/**
* @brief Set an environment variable.
* @param name The name of the environment variable.
* @param value The value to set the environment variable to.
* @return 0 on success, non-zero on failure.
*/
int
set_env(const std::string &name, const std::string &value);

/**
* @brief Unset an environment variable.
* @param name The name of the environment variable.
* @return 0 on success, non-zero on failure.
*/
int
unset_env(const std::string &name);

struct buffer_descriptor_t {
const char *buffer;
size_t size;
Expand Down
14 changes: 14 additions & 0 deletions src/platform/linux/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ namespace platf {
lifetime::exit_sunshine(0, true);
}

int
set_env(const std::string &name, const std::string &value) {
return setenv(name.c_str(), value.c_str(), 1);
}

int
unset_env(const std::string &name) {
return unsetenv(name.c_str());
}

bool
request_process_group_exit(std::uintptr_t native_handle) {
if (kill(-((pid_t) native_handle), SIGTERM) == 0 || errno == ESRCH) {
Expand Down Expand Up @@ -913,6 +923,10 @@ namespace platf {

std::unique_ptr<deinit_t>
init() {
// enable low latency mode for AMD
// https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30039
set_env("AMD_DEBUG", "lowlatency");

// These are allowed to fail.
gbm::init();

Expand Down
10 changes: 10 additions & 0 deletions src/platform/macos/misc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@
lifetime::exit_sunshine(0, true);
}

int
set_env(const std::string &name, const std::string &value) {
return setenv(name.c_str(), value.c_str(), 1);
}

int
unset_env(const std::string &name) {
return unsetenv(name.c_str());
}

bool
request_process_group_exit(std::uintptr_t native_handle) {
if (killpg((pid_t) native_handle, SIGTERM) == 0 || errno == ESRCH) {
Expand Down
10 changes: 10 additions & 0 deletions src/platform/windows/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,16 @@ namespace platf {
lifetime::exit_sunshine(0, true);
}

int
set_env(const std::string &name, const std::string &value) {
return _putenv_s(name.c_str(), value.c_str());
}

int
unset_env(const std::string &name) {
return _putenv_s(name.c_str(), "");
}

struct enum_wnd_context_t {
std::set<DWORD> process_ids;
bool requested_exit;
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/platform/test_common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @file tests/unit/platform/test_common.cpp
* @brief Test src/platform/common.*.
*/
#include <src/platform/common.h>

#include "../../tests_common.h"

struct SetEnvTest: ::testing::TestWithParam<std::tuple<std::string, std::string, int>> {
protected:
void
TearDown() override {
// Clean up environment variable after each test
const auto &[name, value, expected] = GetParam();
platf::unset_env(name);
}
};

TEST_P(SetEnvTest, SetEnvironmentVariableTests) {
const auto &[name, value, expected] = GetParam();
platf::set_env(name, value);

const char *env_value = std::getenv(name.c_str());
if (expected == 0 && !value.empty()) {
ASSERT_NE(env_value, nullptr);
ASSERT_EQ(std::string(env_value), value);
}
else {
ASSERT_EQ(env_value, nullptr);
}
}

TEST_P(SetEnvTest, UnsetEnvironmentVariableTests) {
const auto &[name, value, expected] = GetParam();
platf::unset_env(name);

const char *env_value = std::getenv(name.c_str());
if (expected == 0) {
ASSERT_EQ(env_value, nullptr);
}
}

INSTANTIATE_TEST_SUITE_P(
SetEnvTests,
SetEnvTest,
::testing::Values(
std::make_tuple("SUNSHINE_UNIT_TEST_ENV_VAR", "test_value_0", 0),
std::make_tuple("SUNSHINE_UNIT_TEST_ENV_VAR", "test_value_1", 0),
std::make_tuple("", "test_value", -1)));
Loading