enable boost mode as early as possible during init, and exit boost as late as possible during exit.

This commit is contained in:
ITotalJustice
2025-06-09 12:32:43 +01:00
parent a33d8e1061
commit 6b77cbb0c0
9 changed files with 42 additions and 17 deletions

View File

@@ -192,6 +192,28 @@ public:
} }
} }
static void SetBoostMode(bool enable, bool force = false) {
static Mutex mutex{};
static int ref_count{};
mutexLock(&mutex);
ON_SCOPE_EXIT(mutexUnlock(&mutex));
if (enable) {
ref_count++;
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad);
} else {
if (ref_count) {
ref_count--;
}
}
if (!ref_count || force) {
ref_count = 0;
appletSetCpuBoostMode(ApmCpuBoostMode_Normal);
}
}
static auto GetAccountList() -> std::vector<AccountProfileBase> { static auto GetAccountList() -> std::vector<AccountProfileBase> {
std::vector<AccountProfileBase> out; std::vector<AccountProfileBase> out;

View File

@@ -1283,8 +1283,8 @@ void App::ScanThemeEntries() {
App::App(const char* argv0) { App::App(const char* argv0) {
TimeStamp ts; TimeStamp ts;
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); // boost mode is enabled in userAppInit().
ON_SCOPE_EXIT(appletSetCpuBoostMode(ApmCpuBoostMode_Normal)); ON_SCOPE_EXIT(App::SetBoostMode(false));
g_app = this; g_app = this;
m_start_timestamp = armGetSystemTick(); m_start_timestamp = armGetSystemTick();
@@ -1851,8 +1851,8 @@ void App::DisplayDumpOptions(bool left_side) {
} }
App::~App() { App::~App() {
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); // boost mode is disabled in userAppExit().
ON_SCOPE_EXIT(appletSetCpuBoostMode(ApmCpuBoostMode_Normal)); App::SetBoostMode(true);
log_write("starting to exit\n"); log_write("starting to exit\n");
TimeStamp ts; TimeStamp ts;

View File

@@ -16,7 +16,7 @@ int main(int argc, char** argv) {
extern "C" { extern "C" {
void userAppInit(void) { void userAppInit(void) {
Result rc; sphaira::App::SetBoostMode(true);
// https://github.com/mtheall/ftpd/blob/e27898f0c3101522311f330e82a324861e0e3f7e/source/switch/init.c#L31 // https://github.com/mtheall/ftpd/blob/e27898f0c3101522311f330e82a324861e0e3f7e/source/switch/init.c#L31
const SocketInitConfig socket_config_application = { const SocketInitConfig socket_config_application = {
@@ -47,6 +47,7 @@ void userAppInit(void) {
const auto socket_config = is_application ? socket_config_application : socket_config_applet; const auto socket_config = is_application ? socket_config_application : socket_config_applet;
Result rc;
if (R_FAILED(rc = appletLockExit())) if (R_FAILED(rc = appletLockExit()))
diagAbortWithResult(rc); diagAbortWithResult(rc);
if (R_FAILED(rc = socketInitialize(&socket_config))) if (R_FAILED(rc = socketInitialize(&socket_config)))
@@ -87,6 +88,8 @@ void userAppExit(void) {
if (auto fs = fsdevGetDeviceFileSystem("sdmc:")) { if (auto fs = fsdevGetDeviceFileSystem("sdmc:")) {
fsFsCommit(fs); fsFsCommit(fs);
} }
sphaira::App::SetBoostMode(false);
appletUnlockExit(); appletUnlockExit();
} }

View File

@@ -1170,8 +1170,8 @@ void Menu::SetIndex(s64 index) {
} }
void Menu::ScanHomebrew() { void Menu::ScanHomebrew() {
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); App::SetBoostMode(true);
ON_SCOPE_EXIT(appletSetCpuBoostMode(ApmCpuBoostMode_Normal)); ON_SCOPE_EXIT(App::SetBoostMode(false));
from_json(REPO_PATH, m_entries); from_json(REPO_PATH, m_entries);

View File

@@ -968,8 +968,8 @@ void FsView::UploadFiles() {
} }
auto FsView::Scan(const fs::FsPath& new_path, bool is_walk_up) -> Result { auto FsView::Scan(const fs::FsPath& new_path, bool is_walk_up) -> Result {
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); App::SetBoostMode(true);
ON_SCOPE_EXIT(appletSetCpuBoostMode(ApmCpuBoostMode_Normal)); ON_SCOPE_EXIT(App::SetBoostMode(false));
log_write("new scan path: %s\n", new_path.s); log_write("new scan path: %s\n", new_path.s);
if (!is_walk_up && !m_path.empty() && !m_entries_current.empty()) { if (!is_walk_up && !m_path.empty() && !m_entries_current.empty()) {

View File

@@ -1101,8 +1101,8 @@ void Menu::ScanHomebrew() {
const auto hide_forwarders = m_hide_forwarders.Get(); const auto hide_forwarders = m_hide_forwarders.Get();
TimeStamp ts; TimeStamp ts;
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); App::SetBoostMode(true);
ON_SCOPE_EXIT(appletSetCpuBoostMode(ApmCpuBoostMode_Normal)); ON_SCOPE_EXIT(App::SetBoostMode(false));
FreeEntries(); FreeEntries();
m_entries.reserve(ENTRY_CHUNK_COUNT); m_entries.reserve(ENTRY_CHUNK_COUNT);

View File

@@ -980,8 +980,8 @@ Result Menu::DumpGames(u32 flags) {
R_TRY(GcMountStorage()); R_TRY(GcMountStorage());
const auto do_dump = [this](u32 flags) -> Result { const auto do_dump = [this](u32 flags) -> Result {
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); App::SetBoostMode(true);
ON_SCOPE_EXIT(appletSetCpuBoostMode(ApmCpuBoostMode_Normal)); ON_SCOPE_EXIT(App::SetBoostMode(false));
u32 location_flags = dump::DumpLocationFlag_All; u32 location_flags = dump::DumpLocationFlag_All;

View File

@@ -581,8 +581,8 @@ void Menu::PackListDownload() {
curl::Flags{curl::Flag_Cache}, curl::Flags{curl::Flag_Cache},
curl::StopToken{this->GetToken()}, curl::StopToken{this->GetToken()},
curl::OnComplete{[this, page_index](auto& result){ curl::OnComplete{[this, page_index](auto& result){
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); App::SetBoostMode(true);
ON_SCOPE_EXIT(appletSetCpuBoostMode(ApmCpuBoostMode_Normal)); ON_SCOPE_EXIT(App::SetBoostMode(false));
log_write("got themezer data\n"); log_write("got themezer data\n");
if (!result.success) { if (!result.success) {

View File

@@ -21,7 +21,7 @@ void threadFunc(void* arg) {
ProgressBox::ProgressBox(int image, const std::string& action, const std::string& title, ProgressBoxCallback callback, ProgressBoxDoneCallback done, int cpuid, int prio, int stack_size) { ProgressBox::ProgressBox(int image, const std::string& action, const std::string& title, ProgressBoxCallback callback, ProgressBoxDoneCallback done, int cpuid, int prio, int stack_size) {
if (App::GetApp()->m_progress_boost_mode.Get()) { if (App::GetApp()->m_progress_boost_mode.Get()) {
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad); App::SetBoostMode(true);
} }
SetAction(Button::B, Action{"Back"_i18n, [this](){ SetAction(Button::B, Action{"Back"_i18n, [this](){
@@ -67,7 +67,7 @@ ProgressBox::~ProgressBox() {
FreeImage(); FreeImage();
m_done(m_thread_data.result); m_done(m_thread_data.result);
appletSetCpuBoostMode(ApmCpuBoostMode_Normal); App::SetBoostMode(false);
} }
auto ProgressBox::Update(Controller* controller, TouchInfo* touch) -> void { auto ProgressBox::Update(Controller* controller, TouchInfo* touch) -> void {