Extract split lock mitigation into common file

This reduces duplication of the split lock mitigation path.
Additionally, it allows extending the functionality of procsysctl into
also getting the split lock mitigation state.
This commit is contained in:
MithicSpirit
2025-01-28 20:11:46 -05:00
committed by afayaz-feral
parent 2d71be6a94
commit d84c5ded1c
8 changed files with 119 additions and 24 deletions

View File

@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "common-logging.h"
#include "common-power.h"
#include "common-profile.h"
#include "common-splitlock.h"
#include "gamemode.h"
#include "gamemode-config.h"
@@ -220,25 +221,9 @@ void game_mode_context_destroy(GameModeContext *self)
static void game_mode_store_splitlock(GameModeContext *self)
{
FILE *f = fopen("/proc/sys/kernel/split_lock_mitigate", "r");
if (f == NULL) {
if (errno == ENOENT)
return;
LOG_ERROR("Couldn't open /proc/sys/kernel/split_lock_mitigate : %s\n", strerror(errno));
return;
}
char value_str[40];
if (fgets(value_str, sizeof value_str, f) == NULL) {
LOG_ERROR("Couldn't read from /proc/sys/kernel/split_lock_mitigate : %s\n",
strerror(errno));
fclose(f);
return;
}
fclose(f);
self->initial_split_lock_mitigate = strtol(value_str, NULL, 10);
long initial_state = get_splitlock_state();
self->initial_split_lock_mitigate = initial_state;
LOG_MSG("split lock mitigation was initially set to [%ld]\n", initial_state);
}
static int game_mode_disable_splitlock(GameModeContext *self, bool disable)