mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-08-06 13:18:31 +02:00
Support setting the platform profile
The platform profile lives in /sys/firmware/acpi/platform_profile. The desiredprof and defaultprof options correspond to the values for the platform profile set when gamescope begins and ends, respectively. HACK: The platform profile may restrict what values the governor can take, so we choose to set the governor before the platform profile in order to store the correct default governor, and restore the platform profile before the governor. This is done to maximize correctness after restoration, but it can cause issues if the previous platform profile restricts the governor. TODO: Save all the state we care about before any of it is changed. In thsi case, we should set (and restore) the platform profile before the governor.
This commit is contained in:

committed by
afayaz-feral

parent
81d26c79b4
commit
e75f2c3942
@@ -88,6 +88,9 @@ struct GameModeConfig {
|
||||
char defaultgov[CONFIG_VALUE_MAX];
|
||||
char desiredgov[CONFIG_VALUE_MAX];
|
||||
|
||||
char defaultprof[CONFIG_VALUE_MAX];
|
||||
char desiredprof[CONFIG_VALUE_MAX];
|
||||
|
||||
char igpu_desiredgov[CONFIG_VALUE_MAX];
|
||||
float igpu_power_threshold;
|
||||
|
||||
@@ -265,6 +268,10 @@ static int inih_handler(void *user, const char *section, const char *name, const
|
||||
valid = get_string_value(value, self->values.defaultgov);
|
||||
} else if (strcmp(name, "desiredgov") == 0) {
|
||||
valid = get_string_value(value, self->values.desiredgov);
|
||||
} else if (strcmp(name, "defaultprof") == 0) {
|
||||
valid = get_string_value(value, self->values.defaultprof);
|
||||
} else if (strcmp(name, "desiredprof") == 0) {
|
||||
valid = get_string_value(value, self->values.desiredprof);
|
||||
} else if (strcmp(name, "igpu_desiredgov") == 0) {
|
||||
valid = get_string_value(value, self->values.igpu_desiredgov);
|
||||
} else if (strcmp(name, "igpu_power_threshold") == 0) {
|
||||
@@ -691,13 +698,29 @@ void config_get_default_governor(GameModeConfig *self, char governor[CONFIG_VALU
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the chosen desired governor
|
||||
* Get the chosen desired platform profile
|
||||
*/
|
||||
void config_get_desired_governor(GameModeConfig *self, char governor[CONFIG_VALUE_MAX])
|
||||
{
|
||||
memcpy_locked_config(self, governor, self->values.desiredgov, sizeof(self->values.desiredgov));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the chosen default platform profile
|
||||
*/
|
||||
void config_get_default_profile(GameModeConfig *self, char profile[CONFIG_VALUE_MAX])
|
||||
{
|
||||
memcpy_locked_config(self, profile, self->values.defaultprof, sizeof(self->values.defaultprof));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the chosen desired governor
|
||||
*/
|
||||
void config_get_desired_profile(GameModeConfig *self, char profile[CONFIG_VALUE_MAX])
|
||||
{
|
||||
memcpy_locked_config(self, profile, self->values.desiredprof, sizeof(self->values.desiredprof));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the chosen iGPU desired governor
|
||||
*/
|
||||
|
@@ -102,6 +102,8 @@ bool config_get_inhibit_screensaver(GameModeConfig *self);
|
||||
long config_get_script_timeout(GameModeConfig *self);
|
||||
void config_get_default_governor(GameModeConfig *self, char governor[CONFIG_VALUE_MAX]);
|
||||
void config_get_desired_governor(GameModeConfig *self, char governor[CONFIG_VALUE_MAX]);
|
||||
void config_get_default_profile(GameModeConfig *self, char profile[CONFIG_VALUE_MAX]);
|
||||
void config_get_desired_profile(GameModeConfig *self, char profile[CONFIG_VALUE_MAX]);
|
||||
void config_get_igpu_desired_governor(GameModeConfig *self, char governor[CONFIG_VALUE_MAX]);
|
||||
float config_get_igpu_power_threshold(GameModeConfig *self);
|
||||
void config_get_soft_realtime(GameModeConfig *self, char softrealtime[CONFIG_VALUE_MAX]);
|
||||
|
@@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "common-helpers.h"
|
||||
#include "common-logging.h"
|
||||
#include "common-power.h"
|
||||
#include "common-profile.h"
|
||||
|
||||
#include "gamemode.h"
|
||||
#include "gamemode-config.h"
|
||||
@@ -71,6 +72,11 @@ enum GameModeGovernor {
|
||||
GAME_MODE_GOVERNOR_IGPU_DESIRED,
|
||||
};
|
||||
|
||||
enum GameModeProfile {
|
||||
GAME_MODE_PROFILE_DEFAULT,
|
||||
GAME_MODE_PROFILE_DESIRED,
|
||||
};
|
||||
|
||||
struct GameModeContext {
|
||||
pthread_rwlock_t rwlock; /**<Guard access to the client list */
|
||||
_Atomic int refcount; /**<Allow cycling the game mode */
|
||||
@@ -82,6 +88,9 @@ struct GameModeContext {
|
||||
|
||||
enum GameModeGovernor current_govenor;
|
||||
|
||||
char initial_profile[64];
|
||||
enum GameModeProfile current_profile;
|
||||
|
||||
struct GameModeGPUInfo *stored_gpu; /**<Stored GPU info for the current GPU */
|
||||
struct GameModeGPUInfo *target_gpu; /**<Target GPU info for the current GPU */
|
||||
|
||||
@@ -319,6 +328,59 @@ static int game_mode_set_governor(GameModeContext *self, enum GameModeGovernor g
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int game_mode_set_profile(GameModeContext *self, enum GameModeProfile prof)
|
||||
{
|
||||
if (self->current_profile == prof) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (self->current_profile == GAME_MODE_PROFILE_DEFAULT) {
|
||||
/* Read the initial platform profile so we can revert it correctly */
|
||||
const char *initial_state = get_profile_state();
|
||||
if (initial_state == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* store the initial platform profile */
|
||||
strncpy(self->initial_profile, initial_state, sizeof(self->initial_profile) - 1);
|
||||
self->initial_profile[sizeof(self->initial_profile) - 1] = '\0';
|
||||
LOG_MSG("platform profile was initially set to [%s]\n", initial_state);
|
||||
}
|
||||
|
||||
const char *prof_str = NULL;
|
||||
char prof_config_str[CONFIG_VALUE_MAX] = { 0 };
|
||||
switch (prof) {
|
||||
case GAME_MODE_PROFILE_DEFAULT:
|
||||
config_get_default_profile(self->config, prof_config_str);
|
||||
prof_str = prof_config_str[0] != '\0' ? prof_config_str : self->initial_profile;
|
||||
break;
|
||||
|
||||
case GAME_MODE_PROFILE_DESIRED:
|
||||
config_get_desired_profile(self->config, prof_config_str);
|
||||
prof_str = prof_config_str[0] != '\0' ? prof_config_str : "performance";
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(!"Invalid platform profile requested");
|
||||
}
|
||||
|
||||
const char *const exec_args[] = {
|
||||
"pkexec", LIBEXECDIR "/platprofctl", "set", prof_str, NULL,
|
||||
};
|
||||
|
||||
LOG_MSG("Requesting update of platform profile to %s\n", prof_str);
|
||||
int ret = run_external_process(exec_args, NULL, -1);
|
||||
if (ret != 0) {
|
||||
LOG_ERROR("Failed to update platform profile\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Update the current govenor only if we succeed at setting govenors. */
|
||||
self->current_profile = prof;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void game_mode_enable_igpu_optimization(GameModeContext *self)
|
||||
{
|
||||
float threshold = config_get_igpu_power_threshold(self->config);
|
||||
@@ -424,6 +486,8 @@ static void game_mode_context_enter(GameModeContext *self)
|
||||
game_mode_enable_igpu_optimization(self);
|
||||
}
|
||||
|
||||
game_mode_set_profile(self, GAME_MODE_PROFILE_DESIRED);
|
||||
|
||||
/* Inhibit the screensaver */
|
||||
if (config_get_inhibit_screensaver(self->config)) {
|
||||
game_mode_destroy_idle_inhibitor(self->idle_inhibitor);
|
||||
@@ -471,6 +535,8 @@ static void game_mode_context_leave(GameModeContext *self)
|
||||
|
||||
game_mode_disable_splitlock(self, false);
|
||||
|
||||
game_mode_set_profile(self, GAME_MODE_PROFILE_DEFAULT);
|
||||
|
||||
game_mode_set_governor(self, GAME_MODE_GOVERNOR_DEFAULT);
|
||||
|
||||
game_mode_disable_igpu_optimization(self);
|
||||
|
Reference in New Issue
Block a user