Skip to content
Open
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
11 changes: 11 additions & 0 deletions skeleton/SYSTEM/tg5040/bin/auto_governor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# auto_governor.sh - ondemand governor, min freq to one step below max
# All cpu*/cpufreq entries point at this same shared policy0 path.
CPU_PATH=/sys/devices/system/cpu/cpufreq/policy0
[ -f "$CPU_PATH/scaling_available_frequencies" ] || exit 0
FREQS=$(cat "$CPU_PATH/scaling_available_frequencies" | tr ' ' '\n' | grep -v '^$' | sort -n)
MIN_FREQ=$(echo "$FREQS" | head -1)
SECOND_MAX=$(echo "$FREQS" | tail -2 | head -1)
echo ondemand > "$CPU_PATH/scaling_governor" 2>/dev/null || true
echo "$MIN_FREQ" > "$CPU_PATH/scaling_min_freq"
echo "$SECOND_MAX" > "$CPU_PATH/scaling_max_freq"
11 changes: 11 additions & 0 deletions skeleton/SYSTEM/tg5040/bin/performance_governor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# performance_governor.sh - schedutil governor, min freq to max freq
# All cpu*/cpufreq entries point at this same shared policy0 path.
CPU_PATH=/sys/devices/system/cpu/cpufreq/policy0
[ -f "$CPU_PATH/scaling_available_frequencies" ] || exit 0
FREQS=$(cat "$CPU_PATH/scaling_available_frequencies" | tr ' ' '\n' | grep -v '^$' | sort -n)
MIN_FREQ=$(echo "$FREQS" | head -1)
MAX_FREQ=$(echo "$FREQS" | tail -1)
echo schedutil > "$CPU_PATH/scaling_governor" 2>/dev/null || true
echo "$MIN_FREQ" > "$CPU_PATH/scaling_min_freq"
echo "$MAX_FREQ" > "$CPU_PATH/scaling_max_freq"
13 changes: 13 additions & 0 deletions skeleton/SYSTEM/tg5040/bin/powersave_governor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# powersave_governor.sh - conservative governor, min freq to midpoint max
# All cpu*/cpufreq entries point at this same shared policy0 path.
CPU_PATH=/sys/devices/system/cpu/cpufreq/policy0
[ -f "$CPU_PATH/scaling_available_frequencies" ] || exit 0
FREQS=$(cat "$CPU_PATH/scaling_available_frequencies" | tr ' ' '\n' | grep -v '^$' | sort -n)
COUNT=$(echo "$FREQS" | wc -l)
MID=$(( (COUNT + 1) / 2 ))
MIN_FREQ=$(echo "$FREQS" | head -1)
MID_FREQ=$(echo "$FREQS" | sed -n "${MID}p")
echo conservative > "$CPU_PATH/scaling_governor" 2>/dev/null || true
echo "$MIN_FREQ" > "$CPU_PATH/scaling_min_freq"
echo "$MID_FREQ" > "$CPU_PATH/scaling_max_freq"
5 changes: 1 addition & 4 deletions skeleton/SYSTEM/tg5040/paks/MinUI.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ fi
# start stock gpio input daemon
trimui_inputd &

echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
CPU_PATH=/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
CPU_SPEED_PERF=2000000
echo $CPU_SPEED_PERF > $CPU_PATH
sh "$SYSTEM_PATH/bin/auto_governor.sh"

keymon.elf & # &> $SDCARD_PATH/keymon.txt &
batmon.elf & # &> $SDCARD_PATH/batmon.txt &
Expand Down
11 changes: 11 additions & 0 deletions skeleton/SYSTEM/tg5050/bin/auto_governor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# auto_governor.sh - ondemand governor, min freq to one step below max
# All cpu*/cpufreq entries point at this same shared policy0 path.
CPU_PATH=/sys/devices/system/cpu/cpufreq/policy0
[ -f "$CPU_PATH/scaling_available_frequencies" ] || exit 0
FREQS=$(cat "$CPU_PATH/scaling_available_frequencies" | tr ' ' '\n' | grep -v '^$' | sort -n)
MIN_FREQ=$(echo "$FREQS" | head -1)
SECOND_MAX=$(echo "$FREQS" | tail -2 | head -1)
echo ondemand > "$CPU_PATH/scaling_governor" 2>/dev/null || true
echo "$MIN_FREQ" > "$CPU_PATH/scaling_min_freq"
echo "$SECOND_MAX" > "$CPU_PATH/scaling_max_freq"
11 changes: 11 additions & 0 deletions skeleton/SYSTEM/tg5050/bin/performance_governor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# performance_governor.sh - schedutil governor, min freq to max freq
# All cpu*/cpufreq entries point at this same shared policy0 path.
CPU_PATH=/sys/devices/system/cpu/cpufreq/policy0
[ -f "$CPU_PATH/scaling_available_frequencies" ] || exit 0
FREQS=$(cat "$CPU_PATH/scaling_available_frequencies" | tr ' ' '\n' | grep -v '^$' | sort -n)
MIN_FREQ=$(echo "$FREQS" | head -1)
MAX_FREQ=$(echo "$FREQS" | tail -1)
echo schedutil > "$CPU_PATH/scaling_governor" 2>/dev/null || true
echo "$MIN_FREQ" > "$CPU_PATH/scaling_min_freq"
echo "$MAX_FREQ" > "$CPU_PATH/scaling_max_freq"
13 changes: 13 additions & 0 deletions skeleton/SYSTEM/tg5050/bin/powersave_governor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# powersave_governor.sh - conservative governor, min freq to midpoint max
# All cpu*/cpufreq entries point at this same shared policy0 path.
CPU_PATH=/sys/devices/system/cpu/cpufreq/policy0
[ -f "$CPU_PATH/scaling_available_frequencies" ] || exit 0
FREQS=$(cat "$CPU_PATH/scaling_available_frequencies" | tr ' ' '\n' | grep -v '^$' | sort -n)
COUNT=$(echo "$FREQS" | wc -l)
MID=$(( (COUNT + 1) / 2 ))
MIN_FREQ=$(echo "$FREQS" | head -1)
MID_FREQ=$(echo "$FREQS" | sed -n "${MID}p")
echo conservative > "$CPU_PATH/scaling_governor" 2>/dev/null || true
echo "$MIN_FREQ" > "$CPU_PATH/scaling_min_freq"
echo "$MID_FREQ" > "$CPU_PATH/scaling_max_freq"
16 changes: 1 addition & 15 deletions skeleton/SYSTEM/tg5050/paks/MinUI.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,7 @@ echo 0 > /sys/class/led_anim/max_scale
# start gpio input daemon
trimui_inputd &

echo userspace > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor
echo 408000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq
echo 2160000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq

BIG_PATH=/sys/devices/system/cpu/cpu4/cpufreq/scaling_setspeed
CPU_SPEED_PERF=2160000
echo $CPU_SPEED_PERF > $BIG_PATH

echo schedutil > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo 408000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 2000000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

#LITTLE_PATH=/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
#CPU_SPEED_PERF_LITTLE=2000000
#echo $CPU_SPEED_PERF_LITTLE > $LITTLE_PATH
sh "$SYSTEM_PATH/bin/auto_governor.sh"

echo performance > /sys/devices/platform/soc@3000000/1800000.gpu/devfreq/1800000.gpu/governor

Expand Down
45 changes: 44 additions & 1 deletion workspace/all/common/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,49 @@ int currentshadertexh = 0;

int should_rotate = 0;

static pthread_mutex_t perf_cpu_monitor_mutex = PTHREAD_MUTEX_INITIALIZER;
static int perf_cpu_monitor_enabled = 0;
static int perf_cpu_monitor_running = 0;

void Perf_setCPUMonitorEnabled(int enabled)
{
pthread_mutex_lock(&perf_cpu_monitor_mutex);
perf_cpu_monitor_enabled = enabled;
pthread_mutex_unlock(&perf_cpu_monitor_mutex);
}

int Perf_isCPUMonitorEnabled(void)
{
int enabled;

pthread_mutex_lock(&perf_cpu_monitor_mutex);
enabled = perf_cpu_monitor_enabled;
pthread_mutex_unlock(&perf_cpu_monitor_mutex);

return enabled;
}

int Perf_tryBeginCPUMonitor(void)
{
int should_run = 0;

pthread_mutex_lock(&perf_cpu_monitor_mutex);
if (perf_cpu_monitor_enabled && !perf_cpu_monitor_running) {
perf_cpu_monitor_running = 1;
should_run = 1;
}
pthread_mutex_unlock(&perf_cpu_monitor_mutex);

return should_run;
}

void Perf_endCPUMonitor(void)
{
pthread_mutex_lock(&perf_cpu_monitor_mutex);
perf_cpu_monitor_running = 0;
pthread_mutex_unlock(&perf_cpu_monitor_mutex);
}

FALLBACK_IMPLEMENTATION void PLAT_pinToCores(int core_type)
{
// no-op
Expand Down Expand Up @@ -4393,4 +4436,4 @@ FALLBACK_IMPLEMENTATION void PLAT_bluetoothStreamBegin(int buffersize) {}
FALLBACK_IMPLEMENTATION void PLAT_bluetoothStreamEnd() {}
FALLBACK_IMPLEMENTATION void PLAT_bluetoothStreamQuit() {}
FALLBACK_IMPLEMENTATION int PLAT_bluetoothVolume() { return 100; }
FALLBACK_IMPLEMENTATION void PLAT_bluetoothSetVolume(int vol) {}
FALLBACK_IMPLEMENTATION void PLAT_bluetoothSetVolume(int vol) {}
7 changes: 5 additions & 2 deletions workspace/all/common/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ extern int currentshaderdsth;
extern int currentshadertexw;
extern int currentshadertexh;
extern int should_rotate;
extern volatile int useAutoCpu;

enum {
ASSET_WHITE_PILL,
ASSET_BLACK_PILL,
Expand Down Expand Up @@ -679,6 +677,11 @@ int PLAT_supportsDeepSleep(void);
int PLAT_deepSleep(void);
void PLAT_powerOff(int reboot);

void Perf_setCPUMonitorEnabled(int enabled);
int Perf_isCPUMonitorEnabled(void);
int Perf_tryBeginCPUMonitor(void);
void Perf_endCPUMonitor(void);

void *PLAT_cpu_monitor(void *arg);
void PLAT_setCPUSpeed(int speed); // enum
void PLAT_setCustomCPUSpeed(int speed);
Expand Down
102 changes: 55 additions & 47 deletions workspace/all/minarch/minarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int rewind_cfg_granularity = MINARCH_DEFAULT_REWIND_GRANULARITY;
static int rewind_cfg_audio = MINARCH_DEFAULT_REWIND_AUDIO;
static int rewind_cfg_compress = 1;
static int rewind_cfg_lz4_acceleration = MINARCH_DEFAULT_REWIND_LZ4_ACCELERATION;
static int overclock = 3; // auto
static int overclock = 0; // auto
static int has_custom_controllers = 0;
static int gamepad_type = 0; // index in gamepad_labels/gamepad_values

Expand Down Expand Up @@ -2490,10 +2490,9 @@ static char* button_labels[] = {
NULL,
};
static char* overclock_labels[] = {
"Powersave",
"Normal",
"Performance",
"Auto",
"Performance",
"Powersave",
NULL,
};

Expand Down Expand Up @@ -2640,10 +2639,10 @@ static struct Config {
[FE_OPT_OVERCLOCK] = {
.key = "minarch_cpu_speed",
.name = "CPU Speed",
.desc = "Over- or underclock the CPU to prioritize\npure performance or power savings.",
.default_value = 3,
.value = 3,
.count = 4,
.desc = "Choose how the CPU scales.\nAuto is recommended for most users.",
.default_value = 0,
.value = 0,
.count = 3,
.values = overclock_labels,
.labels = overclock_labels,
},
Expand Down Expand Up @@ -2990,30 +2989,44 @@ static int Config_getValue(char* cfg, const char* key, char* out_value, int* loc



static void setOverclock(int i) {
overclock = i;
switch (i) {
case 0: {
useAutoCpu = 0;
PWR_setCPUSpeed(CPU_SPEED_POWERSAVE);
break;
}
case 1: {
useAutoCpu = 0;
PWR_setCPUSpeed(CPU_SPEED_NORMAL);
break;
}
case 2: {
useAutoCpu = 0;
PWR_setCPUSpeed(CPU_SPEED_PERFORMANCE);
break;
}
case 3: {
PWR_setCPUSpeed(CPU_SPEED_NORMAL);
useAutoCpu = 1;
break;
}
static void run_governor_script(const char* script_name) {
const char* system_path = getenv("SYSTEM_PATH");
if (!system_path) {
LOG_info("WARNING: SYSTEM_PATH not set, cannot run governor script\n");
return;
}
char cmd[512];
int n = snprintf(cmd, sizeof(cmd), "sh \"%s/bin/%s\"", system_path, script_name);
if (n < 0 || n >= (int)sizeof(cmd)) {
LOG_info("WARNING: SYSTEM_PATH too long for governor script path\n");
return;
}
int ret = system(cmd);
if (ret != 0) LOG_info("WARNING: governor script '%s' exited with status %d\n", script_name, ret);
}

static void updateCPUMonitor(void) {
Perf_setCPUMonitorEnabled(show_debug);
if (!show_debug) return;

pthread_t cpucheckthread;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (pthread_create(&cpucheckthread, &attr, PLAT_cpu_monitor, NULL) != 0) {
LOG_info("WARNING: failed to start CPU monitor thread\n");
Perf_setCPUMonitorEnabled(0);
}
pthread_attr_destroy(&attr);
}

static void setOverclock(int i) {
overclock = i;
switch (i) {
case 0: run_governor_script("auto_governor.sh"); break;
case 1: run_governor_script("performance_governor.sh"); break;
case 2: run_governor_script("powersave_governor.sh"); break;
}
}
static void Config_syncFrontend(char* key, int value) {
int i = -1;
Expand Down Expand Up @@ -3080,7 +3093,9 @@ static void Config_syncFrontend(char* key, int value) {
i = FE_OPT_OVERCLOCK;
}
else if (exactMatch(key,config.frontend.options[FE_OPT_DEBUG].key)) {
show_debug = value;
int prev_show_debug = show_debug;
show_debug = value;
if (prev_show_debug != show_debug) updateCPUMonitor();
i = FE_OPT_DEBUG;
}
else if (exactMatch(key,config.frontend.options[FE_OPT_MAXFF].key)) {
Expand Down Expand Up @@ -6270,8 +6285,6 @@ void Menu_beforeSleep() {
RTC_write();
State_autosave();
putFile(AUTO_RESUME_PATH, game.path + strlen(SDCARD_PATH));

PWR_setCPUSpeed(CPU_SPEED_MENU);
}
void Menu_afterSleep() {
unlink(AUTO_RESUME_PATH);
Expand Down Expand Up @@ -8503,7 +8516,6 @@ static void Menu_loop(void) {
SRAM_write();
RTC_write();
if (!HAS_POWER_BUTTON) PWR_enableSleep();
PWR_setCPUSpeed(CPU_SPEED_MENU); // set Hz directly

GFX_setEffect(EFFECT_NONE);

Expand Down Expand Up @@ -8966,23 +8978,16 @@ int main(int argc , char* argv[]) {
//else
// LOG_info("asoundrc does not exist at %s\n", asoundpath);

pthread_t cpucheckthread;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&cpucheckthread, &attr, PLAT_cpu_monitor, NULL);
pthread_attr_destroy(&attr);
if(argc < 2)
return EXIT_FAILURE;

setOverclock(2); // start up in performance mode, faster init
setOverclock(1); // start up in performance mode, faster init
PWR_pinToCores(CPU_CORE_PERFORMANCE); // thread affinity

char core_path[MAX_PATH];
char rom_path[MAX_PATH];
char rom_path[MAX_PATH];
char tag_name[MAX_PATH];

if(argc < 2)
return EXIT_FAILURE;

strcpy(core_path, argv[1]);
strcpy(rom_path, argv[2]);
getEmuName(rom_path, tag_name);
Expand Down Expand Up @@ -9186,6 +9191,9 @@ int main(int argc , char* argv[]) {

finish:

Perf_setCPUMonitorEnabled(0);
run_governor_script("auto_governor.sh"); // restore auto governor on return to menu

// Unload game and shutdown RetroAchievements before Core_quit
RA_unloadGame();
RA_quit();
Expand Down
5 changes: 0 additions & 5 deletions workspace/all/nextui/nextui.c
Original file line number Diff line number Diff line change
Expand Up @@ -2269,11 +2269,6 @@ int main (int argc, char *argv[]) {
int had_bt = PLAT_btIsConnected();
int had_sink = GetAudioSink();

pthread_t cpucheckthread = 0;
if (pthread_create(&cpucheckthread, NULL, PLAT_cpu_monitor, NULL) == 0) {
pthread_detach(cpucheckthread);
}

int selected_row = top->selected - top->start;
float targetY;
float previousY;
Expand Down
1 change: 0 additions & 1 deletion workspace/desktop/platform/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ void PLAT_powerOff(int reboot) {

///////////////////////////////

volatile int useAutoCpu = 0;
void PLAT_setCPUSpeed(int speed) {
// buh
}
Expand Down
Loading
Loading