diff --git a/README.md b/README.md index 31569db8..ca00c839 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This project will not be actively maintained by me and I'm looking for collabora - **Modded sys-clk and ReverseNX**(-Tools and -RT) - **No need to change clocks manually** after toggling modes in ReverseNX - Auto-Boost CPU for faster game loading - - Profile-aware clock override for all games + - Global clock override for all profiles - System Settings - Disable background services, less heat and power consumption in standby mode - Game recording and SysDVR streaming @ 60fps with high video bitrate @@ -43,7 +43,7 @@ This project will not be actively maintained by me and I'm looking for collabora - Only 1331.2 and MAX MHz could be selected in sys-clk. - Apply thermal paste on RAM chips and test with emuNAND before long-term usage. - DRAM Timing Table Adjustment: - - 2131.2 MHz is stable for Micron chips with ~24.8GiB/s throughput. (theoretical bandwidth: 31.76GiB/s @ 2131.2 MHz) + - 2131.2 MHz should be stable for some Micron chips with ~24.8GiB/s throughput without overvolting. (theoretical bandwidth: 31.76GiB/s @ 2131.2 MHz) - 1862.4 MHz is stable for all. (~23.0 GB/s) - See [issue #5](https://github.com/KazushiMe/Switch-OC-Suite/issues/5) for more info on DRAM OC and timings @@ -79,26 +79,6 @@ This project will not be actively maintained by me and I'm looking for collabora - Enable CPU Boost (1963.5 MHz) if CPU Core#3 (System Core) is stressed, especially when the game is loading assets from eMMC/SD card. - Auto-Boost will be enabled only when charger is connected. (>90% w/ PD charger or >95% w/ unsupported charger) - To **disable this feature**, simply remove `boost.flag` in `/config/sys-clk/ `. - - Profile-aware clock override for all games - - Add `[A111111111111111]` title config in `/config/sys-clk/config.ini` to set frequency override globally: - ```ini - [A111111111111111] - docked_cpu= - docked_gpu= - docked_mem= - handheld_charging_cpu= - handheld_charging_gpu= - handheld_charging_mem= - handheld_charging_usb_cpu= - handheld_charging_usb_gpu= - handheld_charging_usb_mem= - handheld_charging_official_cpu= - handheld_charging_official_gpu= - handheld_charging_official_mem= - handheld_cpu= - handheld_gpu= - handheld_mem= - ``` - Disable background services, less heat and power consumption in standby mode - **Remove** the "Disable Background service" part in `/atmosphere/config/system_settings.ini` if you **use Nintendo Online services**. diff --git a/Source/Atmosphere/stratosphere/loader/source/ldr_oc_patch.hpp b/Source/Atmosphere/stratosphere/loader/source/ldr_oc_patch.hpp index 10b18378..af610aad 100644 --- a/Source/Atmosphere/stratosphere/loader/source/ldr_oc_patch.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/ldr_oc_patch.hpp @@ -264,6 +264,7 @@ namespace pcv { #include "mtc_timing_table.hpp" + #if 0 #define ADJUST_PROP(TARGET, REF) (REF + ((GetEmcClock()-1331200)*(TARGET-REF))/(1600000-1331200)) #define ADJUST_PARAM_ROUND2_ALL_REG(TARGET_TABLE, REF_TABLE, PARAM) \ @@ -316,6 +317,95 @@ namespace pcv { /* For latency allowance */ #define ADJUST_INVERSE(TARGET) ((TARGET*1000) / (GetEmcClock()/1600)) + #endif + + #define ADJUST_PARAM(PARAM) PARAM = GetEmcClock()*PARAM/1600000; + + #define ADJUST_PARAM_TABLE(TABLE, PARAM) ADJUST_PARAM(TABLE->PARAM) + + #define ADJUST_PARAM_ALL_REG(TABLE, PARAM) \ + ADJUST_PARAM_TABLE(TABLE, burst_regs.PARAM) \ + ADJUST_PARAM_TABLE(TABLE, shadow_regs_ca_train.PARAM) \ + ADJUST_PARAM_TABLE(TABLE, shadow_regs_rdwr_train.PARAM) + + void AdjustMtcTable(MarikoMtcTable* table) + { + /* Official Tegra X1 TRM, sign up for nvidia developer program (free) to download: + * https://developer.nvidia.com/embedded/dlc/tegra-x1-technical-reference-manual + * Section 18.11: MC Registers + * + * Retail Mariko: 200FBGA 16Gb DDP LPDDR4X SDRAM x 2 + * x16/Ch, 1Ch/die, Double-die, 2Ch, 1CS(rank), 8Gb density per die + * 64Mb x 16DQ x 8banks x 2channels = 2048MB (x32DQ) per package + * + * Devkit Mariko: 200FBGA 32Gb DDP LPDDR4X SDRAM x 2 + * x16/Ch, 1Ch/die, Quad-die, 2Ch, 2CS(rank), 8Gb density per die + * X1+ EMC can R/W to both ranks at the same time, resulting in doubled DQ + * 64Mb x 32DQ x 8banks x 2channels = 4096MB (x64DQ) per package + * + * If you have access to LPDDR4(X) specs or datasheets (from manufacturers or Google), + * you'd better calculate timings yourself rather than relying on following algorithm. + */ + + ADJUST_PARAM_ALL_REG(table, emc_rc); + ADJUST_PARAM_ALL_REG(table, emc_rfc); + ADJUST_PARAM_ALL_REG(table, emc_rfcpb); + ADJUST_PARAM_ALL_REG(table, emc_ras); + ADJUST_PARAM_ALL_REG(table, emc_rp); + ADJUST_PARAM_ALL_REG(table, emc_r2w); + ADJUST_PARAM_ALL_REG(table, emc_w2r); + ADJUST_PARAM_ALL_REG(table, emc_r2p); + ADJUST_PARAM_ALL_REG(table, emc_w2p); + ADJUST_PARAM_ALL_REG(table, emc_trtm); + ADJUST_PARAM_ALL_REG(table, emc_twtm); + ADJUST_PARAM_ALL_REG(table, emc_tratm); + ADJUST_PARAM_ALL_REG(table, emc_twatm); + ADJUST_PARAM_ALL_REG(table, emc_rd_rcd); + ADJUST_PARAM_ALL_REG(table, emc_wr_rcd); + ADJUST_PARAM_ALL_REG(table, emc_rrd); + + ADJUST_PARAM_ALL_REG(table, emc_refresh); + ADJUST_PARAM_ALL_REG(table, emc_pre_refresh_req_cnt); + + ADJUST_PARAM_ALL_REG(table, emc_pdex2wr); + ADJUST_PARAM_ALL_REG(table, emc_pdex2rd); + ADJUST_PARAM_ALL_REG(table, emc_act2pden); + ADJUST_PARAM_ALL_REG(table, emc_rw2pden); + ADJUST_PARAM_ALL_REG(table, emc_cke2pden); + ADJUST_PARAM_ALL_REG(table, emc_pdex2mrr); + + ADJUST_PARAM_ALL_REG(table, emc_txsr); + ADJUST_PARAM_ALL_REG(table, emc_txsrdll); + ADJUST_PARAM_ALL_REG(table, emc_tcke); + ADJUST_PARAM_ALL_REG(table, emc_tckesr); + ADJUST_PARAM_ALL_REG(table, emc_tpd); + ADJUST_PARAM_ALL_REG(table, emc_tfaw); + ADJUST_PARAM_ALL_REG(table, emc_trpab); + ADJUST_PARAM_ALL_REG(table, emc_tclkstop); + ADJUST_PARAM_ALL_REG(table, emc_trefbw); + + ADJUST_PARAM_ALL_REG(table, emc_pmacro_dll_cfg_2); + + ADJUST_PARAM_TABLE(table, dram_timings.rl); + + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_rcd); + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_rp); + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_rc); + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_ras); + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_faw); + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_wap2pre); + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_r2w); + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_w2r); + ADJUST_PARAM_TABLE(table, burst_mc_regs.mc_emem_arb_timing_rfcpb); + + ADJUST_PARAM_TABLE(table, la_scale_regs.mc_mll_mpcorer_ptsa_rate); + ADJUST_PARAM_TABLE(table, la_scale_regs.mc_ptsa_grant_decrement); + + ADJUST_PARAM_TABLE(table, min_mrs_wait); + ADJUST_PARAM_TABLE(table, latency); + } + + #if 0 void AdjustMtcTable(MarikoMtcTable* target_table, MarikoMtcTable* ref_table) { /* Official Tegra X1 TRM, sign up for nvidia developer program (free) to download: */ @@ -659,6 +749,7 @@ namespace pcv { #endif } + #endif /* Unlock the second sub-partition for retail Mariko, and double the bandwidth (~60GB/s) * https://github.com/CTCaer/hekate/blob/01b6e645b3cb69ddf28cc9eff40c4b35bf03dbd4/bdk/mem/sdram.h#L30 diff --git a/Source/Atmosphere/stratosphere/loader/source/ldr_patcher.cpp b/Source/Atmosphere/stratosphere/loader/source/ldr_patcher.cpp index b429c711..0731c78d 100644 --- a/Source/Atmosphere/stratosphere/loader/source/ldr_patcher.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/ldr_patcher.cpp @@ -179,11 +179,6 @@ namespace ams::ldr { /* Patch max GPU voltage on Mariko */ std::memcpy(reinterpret_cast(mapped_nso + pcv::GpuVoltageLimitOffsets[i]), &pcv::NewGpuVoltageLimit, sizeof(pcv::NewGpuVoltageLimit)); - /* Patch RAM Clock */ - for (u32 j = 0; j < sizeof(pcv::EmcFreqOffsets[i])/sizeof(u32); j++) { - std::memcpy(reinterpret_cast(mapped_nso + pcv::EmcFreqOffsets[i][j]), &EmcClock, sizeof(EmcClock)); - } - /* Calculate DIVM and DIVN (clock DIVisors) */ /* Assume oscillator (PLLMB_IN) is 38.4 MHz */ /* PLLMB_OUT = PLLMB_IN / DIVM * DIVN */ @@ -196,16 +191,27 @@ namespace ams::ldr { if (i >= 2) { for (u32 j = 0; j < sizeof(pcv::MtcTable_1600[i-2])/sizeof(u32); j++) { - pcv::MarikoMtcTable* mtc_table_1600 = reinterpret_cast(mapped_nso + pcv::MtcTable_1600[i-2][j]); - pcv::MarikoMtcTable* mtc_table_1331 = reinterpret_cast(mapped_nso + pcv::MtcTable_1600[i-2][j] - pcv::MtcTableOffset); + pcv::MarikoMtcTable* mtc_table_new = reinterpret_cast(mapped_nso + pcv::MtcTable_1600[i-2][j]); + pcv::MarikoMtcTable* mtc_table_old = reinterpret_cast(mapped_nso + pcv::MtcTable_1600[i-2][j] - pcv::MtcTableOffset); - pcv::AdjustMtcTable(mtc_table_1600, mtc_table_1331); + #ifdef REPLACE_1331 + /* Replace 1331 MHz with 1600 MHz */ + std::memcpy(reinterpret_cast(mtc_table_old), reinterpret_cast(mtc_table_new), sizeof(pcv::MarikoMtcTable)); + #endif + + /* Generate new table for OC MHz */ + pcv::AdjustMtcTable(mtc_table_new); /* Patch clock divisors */ mtc_table_1600->pllmb_divm = divm; mtc_table_1600->pllmb_divn = divn; } } + + /* Patch RAM Clock */ + for (u32 j = 0; j < sizeof(pcv::EmcFreqOffsets[i])/sizeof(u32); j++) { + std::memcpy(reinterpret_cast(mapped_nso + pcv::EmcFreqOffsets[i][j]), &EmcClock, sizeof(EmcClock)); + } } } diff --git a/Source/sys-clk-OC/common/include/sysclk/clocks.h b/Source/sys-clk-OC/common/include/sysclk/clocks.h index 8a52dbf8..2ffeb8bb 100644 --- a/Source/sys-clk-OC/common/include/sysclk/clocks.h +++ b/Source/sys-clk-OC/common/include/sysclk/clocks.h @@ -67,11 +67,9 @@ typedef struct bool systemCoreBoostCPU; bool systemCoreCheckStuck; - ReverseNXMode reverseNXToolMode; - ReverseNXMode reverseNXRTMode; + ReverseNXMode reverseNXMode; uint64_t tickWaitTimeMs; - // int16_t systemCoreStuckCount; uint32_t maxMEMFreq; } SysClkOcExtra; diff --git a/Source/sys-clk-OC/manager/src/advanced_settings_tab.cpp b/Source/sys-clk-OC/manager/src/advanced_settings_tab.cpp index 9b11f643..4e213af6 100644 --- a/Source/sys-clk-OC/manager/src/advanced_settings_tab.cpp +++ b/Source/sys-clk-OC/manager/src/advanced_settings_tab.cpp @@ -20,6 +20,8 @@ #include "advanced_settings_tab.h" +#include "app_profile_frame.h" + #include "utils.h" #include @@ -94,10 +96,25 @@ AdvancedSettingsTab::AdvancedSettingsTab() this->addView(cpuFreqListItem); this->addView(gpuFreqListItem); - //this->addView(memFreqListItem); + this->addView(memFreqListItem); + + // Permanent overrides + this->addView(new brls::Header("Permanent overrides")); + + // Add the ListItem to Permanent override + Title* permTitle = (Title*) malloc(sizeof(Title)); + permTitle->tid = 0xA111111111111111; + + brls::ListItem *listItem = new brls::ListItem(std::string("Permanent Override")); + listItem->getClickEvent()->subscribe([permTitle](View* view) { + AppProfileFrame* profileFrame = new AppProfileFrame(permTitle); + brls::Application::pushView(profileFrame, brls::ViewAnimation::SLIDE_LEFT); + }); + this->addView(listItem); // Config - this->addView(new brls::Header("Configuration")); + // Broken, only accepting single digit + // this->addView(new brls::Header("Configuration")); // Logging // TODO: add a logger view and put the button to enter it here @@ -105,57 +122,57 @@ AdvancedSettingsTab::AdvancedSettingsTab() // Config entries // TODO: add constraints to the swkbd if possible (min / max) - sysclkIpcGetConfigValues(&this->configValues); + // sysclkIpcGetConfigValues(&this->configValues); - for (int i = 0; i < SysClkConfigValue_EnumMax; i++) - { - SysClkConfigValue config = (SysClkConfigValue) i; + // for (int i = 0; i < SysClkConfigValue_EnumMax; i++) + // { + // SysClkConfigValue config = (SysClkConfigValue) i; - std::string label = std::string(sysclkFormatConfigValue(config, true)); - std::string description = this->getDescriptionForConfig(config); - uint64_t defaultValue = configValues.values[config]; + // std::string label = std::string(sysclkFormatConfigValue(config, true)); + // std::string description = this->getDescriptionForConfig(config); + // uint64_t defaultValue = configValues.values[config]; - brls::IntegerInputListItem* configItem = new brls::IntegerInputListItem(label, defaultValue, label, description); + // brls::IntegerInputListItem* configItem = new brls::IntegerInputListItem(label, defaultValue, label, description); - configItem->setReduceDescriptionSpacing(true); + // configItem->setReduceDescriptionSpacing(true); - configItem->getClickEvent()->subscribe([this, configItem, config](View* view) - { - try - { - int value = std::stoi(configItem->getValue()); + // configItem->getClickEvent()->subscribe([this, configItem, config](View* view) + // { + // try + // { + // int value = std::stoi(configItem->getValue()); - // Validate the value - if (value < 0) - { - brls::Application::notify("\uE5CD Couldn't save configuration: invalid value (is negative)"); - configItem->setValue(std::to_string(this->configValues.values[config])); - return; - } + // // Validate the value + // if (value < 0) + // { + // brls::Application::notify("\uE5CD Couldn't save configuration: invalid value (is negative)"); + // configItem->setValue(std::to_string(this->configValues.values[config])); + // return; + // } - uint64_t uvalue = (uint64_t) value; + // uint64_t uvalue = (uint64_t) value; - if (!sysclkValidConfigValue(config, uvalue)) - { - brls::Application::notify("\uE5CD Couldn't save configuration: invalid value"); - configItem->setValue(std::to_string(this->configValues.values[config])); - return; - } + // if (!sysclkValidConfigValue(config, uvalue)) + // { + // brls::Application::notify("\uE5CD Couldn't save configuration: invalid value"); + // configItem->setValue(std::to_string(this->configValues.values[config])); + // return; + // } - // Save the config - this->configValues.values[config] = uvalue; - sysclkIpcSetConfigValues(&this->configValues); + // // Save the config + // this->configValues.values[config] = uvalue; + // sysclkIpcSetConfigValues(&this->configValues); - brls::Application::notify("\uE14B Configuration saved"); - } - catch(const std::exception& e) - { - brls::Logger::error("Unable to parse config value %s: %s", configItem->getValue().c_str(), e.what()); - } - }); + // brls::Application::notify("\uE14B Configuration saved"); + // } + // catch(const std::exception& e) + // { + // brls::Logger::error("Unable to parse config value %s: %s", configItem->getValue().c_str(), e.what()); + // } + // }); - this->addView(configItem); - } + // this->addView(configItem); + // } } std::string AdvancedSettingsTab::getDescriptionForConfig(SysClkConfigValue config) diff --git a/Source/sys-clk-OC/manager/src/app_profile_frame.cpp b/Source/sys-clk-OC/manager/src/app_profile_frame.cpp index 4ad95451..f6b121a3 100644 --- a/Source/sys-clk-OC/manager/src/app_profile_frame.cpp +++ b/Source/sys-clk-OC/manager/src/app_profile_frame.cpp @@ -30,7 +30,9 @@ AppProfileFrame::AppProfileFrame(Title* title) : ThumbnailFrame(), title(title) { - this->setTitle("Edit application profile"); + bool isPermanent = (title->tid == 0xA111111111111111); + + this->setTitle(isPermanent ? "Edit Permanent Override" : "Edit application profile"); this->setIcon(new brls::MaterialIcon("\uE315")); // Get the freqs @@ -40,9 +42,12 @@ AppProfileFrame::AppProfileFrame(Title* title) : ThumbnailFrame(), title(title) errorResult("sysclkIpcGetProfiles", rc); // Setup the right sidebar - this->getSidebar()->setThumbnail(title->icon, sizeof(title->icon)); - this->getSidebar()->setTitle(std::string(title->name)); - this->getSidebar()->setSubtitle(formatTid(title->tid)); + if (!isPermanent) + { + this->getSidebar()->setThumbnail(title->icon, sizeof(title->icon)); + this->getSidebar()->setTitle(std::string(title->name)); + this->getSidebar()->setSubtitle(formatTid(title->tid)); + } this->getSidebar()->getButton()->setState(brls::ButtonState::DISABLED); this->getSidebar()->getButton()->getClickEvent()->subscribe([this, title](brls::View* view) diff --git a/Source/sys-clk-OC/manager/src/logo.cpp b/Source/sys-clk-OC/manager/src/logo.cpp index 5f4e0c02..4b81879b 100644 --- a/Source/sys-clk-OC/manager/src/logo.cpp +++ b/Source/sys-clk-OC/manager/src/logo.cpp @@ -21,7 +21,7 @@ #include "logo.h" Logo::Logo(LogoStyle style) { - this->logoLabel = new brls::Label(brls::LabelStyle::LIST_ITEM, "sys-clk", style == LogoStyle::ABOUT); + this->logoLabel = new brls::Label(brls::LabelStyle::LIST_ITEM, "sys-clk-OC", style == LogoStyle::ABOUT); this->logoLabel->setParent(this); int logoFont = brls::Application::findFont(LOGO_FONT_NAME); diff --git a/Source/sys-clk-OC/overlay/data/logo_rgba.bin b/Source/sys-clk-OC/overlay/data/logo_rgba.bin deleted file mode 100644 index d5b9ced7..00000000 Binary files a/Source/sys-clk-OC/overlay/data/logo_rgba.bin and /dev/null differ diff --git a/Source/sys-clk-OC/overlay/src/ui/elements/base_frame.h b/Source/sys-clk-OC/overlay/src/ui/elements/base_frame.h index 0d4d9ecc..756fa7dc 100644 --- a/Source/sys-clk-OC/overlay/src/ui/elements/base_frame.h +++ b/Source/sys-clk-OC/overlay/src/ui/elements/base_frame.h @@ -16,7 +16,7 @@ class BaseFrame : public tsl::elm::HeaderOverlayFrame { public: - BaseFrame(BaseGui* gui) : tsl::elm::HeaderOverlayFrame() { + BaseFrame(BaseGui* gui) : tsl::elm::HeaderOverlayFrame(130) { // headerHeight this->gui = gui; } diff --git a/Source/sys-clk-OC/overlay/src/ui/gui/app_profile_gui.cpp b/Source/sys-clk-OC/overlay/src/ui/gui/app_profile_gui.cpp index 16a9b1f0..547fe646 100644 --- a/Source/sys-clk-OC/overlay/src/ui/gui/app_profile_gui.cpp +++ b/Source/sys-clk-OC/overlay/src/ui/gui/app_profile_gui.cpp @@ -92,7 +92,7 @@ void AppProfileGui::update() { BaseMenuGui::update(); - if(this->context && this->applicationId != this->context->applicationId) + if(this->context && this->applicationId != 0xA111111111111111 && this->applicationId != this->context->applicationId) { tsl::changeTo( "Application changed\n\n" diff --git a/Source/sys-clk-OC/overlay/src/ui/gui/base_gui.cpp b/Source/sys-clk-OC/overlay/src/ui/gui/base_gui.cpp index 9b427c68..a5c00c86 100644 --- a/Source/sys-clk-OC/overlay/src/ui/gui/base_gui.cpp +++ b/Source/sys-clk-OC/overlay/src/ui/gui/base_gui.cpp @@ -11,25 +11,19 @@ #include "base_gui.h" #include "../elements/base_frame.h" -#include "logo_rgba_bin.h" +// #include "logo_rgba_bin.h" -#define LOGO_WIDTH 110 -#define LOGO_HEIGHT 39 -#define LOGO_X 18 -#define LOGO_Y 21 +#define LOGO_LABEL_X 18 +#define LOGO_LABEL_Y 26 +#define LOGO_LABEL_FONT_SIZE 23 -#define LOGO_LABEL_X (LOGO_X + LOGO_WIDTH + 6) -#define LOGO_LABEL_Y 50 -#define LOGO_LABEL_FONT_SIZE 28 - -#define VERSION_X (LOGO_LABEL_X + 110) +#define VERSION_X 246 #define VERSION_Y LOGO_LABEL_Y -#define VERSION_FONT_SIZE 15 +#define VERSION_FONT_SIZE 16 void BaseGui::preDraw(tsl::gfx::Renderer* renderer) { - renderer->drawBitmap(LOGO_X, LOGO_Y, LOGO_WIDTH, LOGO_HEIGHT, logo_rgba_bin); - renderer->drawString("overlay", false, LOGO_LABEL_X, LOGO_LABEL_Y, LOGO_LABEL_FONT_SIZE, TEXT_COLOR); + renderer->drawString("Sys-clk-OC overlay", false, LOGO_LABEL_X, LOGO_LABEL_Y, LOGO_LABEL_FONT_SIZE, TEXT_COLOR); renderer->drawString(TARGET_VERSION, false, VERSION_X, VERSION_Y, VERSION_FONT_SIZE, DESC_COLOR); } diff --git a/Source/sys-clk-OC/overlay/src/ui/gui/base_menu_gui.cpp b/Source/sys-clk-OC/overlay/src/ui/gui/base_menu_gui.cpp index 45e159bf..ead4ac3e 100644 --- a/Source/sys-clk-OC/overlay/src/ui/gui/base_menu_gui.cpp +++ b/Source/sys-clk-OC/overlay/src/ui/gui/base_menu_gui.cpp @@ -34,12 +34,12 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) { char buf[32]; - renderer->drawString("App ID: ", false, 20, 90, SMALL_TEXT_SIZE, DESC_COLOR); + renderer->drawString("App ID: ", false, 20, 55, SMALL_TEXT_SIZE, DESC_COLOR); snprintf(buf, sizeof(buf), "%016lX", context->applicationId); - renderer->drawString(buf, false, 81, 90, SMALL_TEXT_SIZE, VALUE_COLOR); + renderer->drawString(buf, false, 81, 55, SMALL_TEXT_SIZE, VALUE_COLOR); - renderer->drawString("Profile: ", false, 246, 90, SMALL_TEXT_SIZE, DESC_COLOR); - renderer->drawString(sysclkFormatProfile(context->profile, true), false, 302, 90, SMALL_TEXT_SIZE, VALUE_COLOR); + renderer->drawString("Profile: ", false, 246, 55, SMALL_TEXT_SIZE, DESC_COLOR); + renderer->drawString(sysclkFormatProfile(context->profile, true), false, 302, 55, SMALL_TEXT_SIZE, VALUE_COLOR); static struct { @@ -54,12 +54,12 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) for(unsigned int i = 0; i < SysClkModule_EnumMax; i++) { std::uint32_t hz = this->context->freqs[freqOffsets[i].m]; - snprintf(buf, sizeof(buf), "%u.%u Mhz", hz / 1000000, hz / 100000 - hz / 1000000 * 10); - renderer->drawString(buf, false, freqOffsets[i].x, 115, SMALL_TEXT_SIZE, VALUE_COLOR); + snprintf(buf, sizeof(buf), "%u.%u MHz", hz / 1000000, hz / 100000 - hz / 1000000 * 10); + renderer->drawString(buf, false, freqOffsets[i].x, 80, SMALL_TEXT_SIZE, VALUE_COLOR); } - renderer->drawString("CPU:", false, 20, 115, SMALL_TEXT_SIZE, DESC_COLOR); - renderer->drawString("GPU:", false, 162, 115, SMALL_TEXT_SIZE, DESC_COLOR); - renderer->drawString("MEM:", false, 295, 115, SMALL_TEXT_SIZE, DESC_COLOR); + renderer->drawString("CPU:", false, 20, 80, SMALL_TEXT_SIZE, DESC_COLOR); + renderer->drawString("GPU:", false, 162, 80, SMALL_TEXT_SIZE, DESC_COLOR); + renderer->drawString("MEM:", false, 295, 80, SMALL_TEXT_SIZE, DESC_COLOR); static struct { @@ -71,14 +71,14 @@ void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) { SysClkThermalSensor_Skin, 268 }, }; - renderer->drawString("SOC:", false, 20, 140, SMALL_TEXT_SIZE, DESC_COLOR); - renderer->drawString("PCB:", false, 125, 140, SMALL_TEXT_SIZE, DESC_COLOR); - renderer->drawString("Skin:", false, 230, 140, SMALL_TEXT_SIZE, DESC_COLOR); + renderer->drawString("SOC:", false, 20, 105, SMALL_TEXT_SIZE, DESC_COLOR); + renderer->drawString("PCB:", false, 125, 105, SMALL_TEXT_SIZE, DESC_COLOR); + renderer->drawString("Skin:", false, 230, 105, SMALL_TEXT_SIZE, DESC_COLOR); for(unsigned int i = 0; i < SysClkModule_EnumMax; i++) { std::uint32_t millis = this->context->temps[tempOffsets[i].s]; snprintf(buf, sizeof(buf), "%u.%u °C", millis / 1000, (millis - millis / 1000 * 1000) / 100); - renderer->drawString(buf, false, tempOffsets[i].x, 140, SMALL_TEXT_SIZE, VALUE_COLOR); + renderer->drawString(buf, false, tempOffsets[i].x, 105, SMALL_TEXT_SIZE, VALUE_COLOR); } } } diff --git a/Source/sys-clk-OC/overlay/src/ui/gui/main_gui.cpp b/Source/sys-clk-OC/overlay/src/ui/gui/main_gui.cpp index 4e5e649d..44605e28 100644 --- a/Source/sys-clk-OC/overlay/src/ui/gui/main_gui.cpp +++ b/Source/sys-clk-OC/overlay/src/ui/gui/main_gui.cpp @@ -13,6 +13,7 @@ #include "fatal_gui.h" #include "app_profile_gui.h" #include "global_override_gui.h" +// #include "misc_gui.h" void MainGui::listUI() { @@ -54,6 +55,30 @@ void MainGui::listUI() return false; }); this->listElement->addItem(globalOverrideItem); + + tsl::elm::ListItem* globalPermanentOverrideItem = new tsl::elm::ListItem("Permanent overrides"); + globalPermanentOverrideItem->setClickListener([this](u64 keys) { + if((keys & HidNpadButton_A) == HidNpadButton_A && this->context) + { + AppProfileGui::changeTo(0xA111111111111111); + return true; + } + + return false; + }); + this->listElement->addItem(globalPermanentOverrideItem); + + // tsl::elm::ListItem* miscItem = new tsl::elm::ListItem("Miscellaneous"); + // miscItem->setClickListener([this](u64 keys) { + // if((keys & HidNpadButton_A) == HidNpadButton_A && this->context) + // { + // tsl::changeTo(); + // return true; + // } + + // return false; + // }); + // this->listElement->addItem(miscItem); } void MainGui::refresh() diff --git a/Source/sys-clk-OC/sysmodule/src/clock_manager.cpp b/Source/sys-clk-OC/sysmodule/src/clock_manager.cpp index cc903892..f34e54bd 100644 --- a/Source/sys-clk-OC/sysmodule/src/clock_manager.cpp +++ b/Source/sys-clk-OC/sysmodule/src/clock_manager.cpp @@ -59,12 +59,11 @@ ClockManager::ClockManager() this->oc = new SysClkOcExtra; this->oc->systemCoreBoostCPU = false; - this->oc->systemCoreCheckStuck = false; - this->oc->reverseNXToolMode = ReverseNX_NotFound; - this->oc->reverseNXRTMode = ReverseNX_NotFound; + // this->oc->systemCoreCheckStuck = false; + // this->oc->systemCoreStuckCount = 0; + this->oc->reverseNXMode = ReverseNX_NotFound; this->oc->tickWaitTimeMs = 0; this->oc->maxMEMFreq = 1600'000'000; - // this->oc->systemCoreStuckCount = 0; } ClockManager::~ClockManager() @@ -82,13 +81,12 @@ bool ClockManager::IsCpuBoostMode() bool ClockManager::IsReverseNXEnabled() { - return (this->oc->reverseNXRTMode || this->oc->reverseNXToolMode); + return (this->oc->reverseNXMode); } bool ClockManager::IsReverseNXDocked() { - return (this->oc->reverseNXRTMode == ReverseNX_Docked - || this->oc->reverseNXToolMode == ReverseNX_Docked); + return (this->oc->reverseNXMode == ReverseNX_Docked); } void ClockManager::SetRunning(bool running) @@ -227,14 +225,14 @@ void ClockManager::WaitForNextTick() break; } - bool systemCoreBoostCPU_PrevState = this->oc->systemCoreBoostCPU; + bool systemCoreBoostCPUPrevState = this->oc->systemCoreBoostCPU; this->oc->systemCoreBoostCPU = (freePerc <= systemCoreBoostFreeThreshold); - if (systemCoreBoostCPU_PrevState && !this->oc->systemCoreBoostCPU) + if (systemCoreBoostCPUPrevState && !this->oc->systemCoreBoostCPU) { Clocks::SetHz(SysClkModule_CPU, GetHz(SysClkModule_CPU)); } - else if (!systemCoreBoostCPU_PrevState && this->oc->systemCoreBoostCPU) + else if (!systemCoreBoostCPUPrevState && this->oc->systemCoreBoostCPU) { Clocks::SetHz(SysClkModule_CPU, CPU_BOOST_FREQ); } @@ -245,54 +243,56 @@ void ClockManager::WaitForNextTick() } /* Signal that systemCore is not busy */ - // this->oc->systemCoreStuckCount = 0; + // { + // std::scoped_lock lock{this->systemCoreStuckCountMutex}; + // this->oc->systemCoreStuckCount = 0; + // } } /* Tricky part, see IpcService implementation of calling static member function */ -// I don't see any use of this @ 1020 MHz (only useful at lowest freq), -// and downclock below 1020 MHz won't save battery. (same volt @ 600mV) -/*void ClockManager::CheckSystemCoreStuck(void *arg) -{ - ClockManager* clkMgr = (ClockManager*)arg; - while (clkMgr->oc->systemCoreCheckStuck) - { - svcSleepThread(clkMgr->oc->tickWaitTimeMs * 1000000ULL); +// void ClockManager::CheckSystemCoreStuck(void *arg) +// { +// ClockManager* clkMgr = (ClockManager*)arg; +// while (clkMgr->oc->systemCoreCheckStuck) +// { +// svcSleepThread(clkMgr->oc->tickWaitTimeMs * 1000000ULL); - if (clkMgr->context->freqs[SysClkModule_CPU] >= clkMgr->CPU_BOOST_FREQ) - continue; +// if (clkMgr->context->freqs[SysClkModule_CPU] >= clkMgr->CPU_BOOST_FREQ) +// continue; - // Core #0,1,2 will check if Core#3 is stuck (threshold count = 2*3 = 6) - // ! Add mutex ! - if (clkMgr->oc->systemCoreStuckCount++ > 6) - { - // Signal that current core will take over to boost CPU and wait some time to recheck - clkMgr->oc->systemCoreStuckCount = -6; - Clocks::SetHz(SysClkModule_CPU, clkMgr->CPU_BOOST_FREQ); - } - } -}*/ +// // Core #0,1,2 will check if Core#3 is stuck (threshold count = 2*3 = 6) +// { +// std::scoped_lock lock{clkMgr->systemCoreStuckCountMutex}; +// if (++clkMgr->oc->systemCoreStuckCount > 6) +// { +// clkMgr->oc->systemCoreStuckCount = -6; +// Clocks::SetHz(SysClkModule_CPU, clkMgr->CPU_BOOST_FREQ); +// } +// } +// } +// } -/*void ClockManager::StartCheckSystemCore() -{ - this->oc->systemCoreCheckStuck = true; - threadCreate(&this->t_CheckSystemCoreStuck_0, this->CheckSystemCoreStuck, NULL, NULL, 0x1000, 0x20, 0); - threadCreate(&this->t_CheckSystemCoreStuck_1, this->CheckSystemCoreStuck, NULL, NULL, 0x1000, 0x20, 1); - threadCreate(&this->t_CheckSystemCoreStuck_2, this->CheckSystemCoreStuck, NULL, NULL, 0x1000, 0x20, 2); - threadStart(&this->t_CheckSystemCoreStuck_0); - threadStart(&this->t_CheckSystemCoreStuck_1); - threadStart(&this->t_CheckSystemCoreStuck_2); -}*/ +// void ClockManager::StartCheckSystemCore() +// { +// this->oc->systemCoreCheckStuck = true; +// threadCreate(&this->t_CheckSystemCoreStuck_0, this->CheckSystemCoreStuck, this, NULL, 0x1000, 0x20, 0); +// threadCreate(&this->t_CheckSystemCoreStuck_1, this->CheckSystemCoreStuck, this, NULL, 0x1000, 0x20, 1); +// threadCreate(&this->t_CheckSystemCoreStuck_2, this->CheckSystemCoreStuck, this, NULL, 0x1000, 0x20, 2); +// threadStart(&this->t_CheckSystemCoreStuck_0); +// threadStart(&this->t_CheckSystemCoreStuck_1); +// threadStart(&this->t_CheckSystemCoreStuck_2); +// } -/*void ClockManager::StopCheckSystemCore() -{ - this->oc->systemCoreCheckStuck = false; - threadWaitForExit(&this->t_CheckSystemCoreStuck_0); - threadWaitForExit(&this->t_CheckSystemCoreStuck_1); - threadWaitForExit(&this->t_CheckSystemCoreStuck_2); - threadClose(&this->t_CheckSystemCoreStuck_0); - threadClose(&this->t_CheckSystemCoreStuck_1); - threadClose(&this->t_CheckSystemCoreStuck_2); -}*/ +// void ClockManager::StopCheckSystemCore() +// { +// this->oc->systemCoreCheckStuck = false; +// threadWaitForExit(&this->t_CheckSystemCoreStuck_0); +// threadWaitForExit(&this->t_CheckSystemCoreStuck_1); +// threadWaitForExit(&this->t_CheckSystemCoreStuck_2); +// threadClose(&this->t_CheckSystemCoreStuck_0); +// threadClose(&this->t_CheckSystemCoreStuck_1); +// threadClose(&this->t_CheckSystemCoreStuck_2); +// } SysClkProfile ClockManager::ReverseNXProfileHandler() { @@ -351,13 +351,7 @@ ReverseNXMode ClockManager::ReverseNXFileHandler(bool checkTool, const char* fil if (!memcmp(&this->context->applicationId, &tidBuffer, sizeof(tidBuffer))) { - /* If user toggles -RT overlay, mode set by -Tool remains invalid until the game restarts */ - this->oc->reverseNXToolMode = ReverseNX_NotValid; - - ReverseNXMode getMode = static_cast(ctrlBuffer); - this->oc->reverseNXRTMode = getMode; - - return getMode; + return static_cast(ctrlBuffer); } } @@ -388,7 +382,7 @@ void ClockManager::CheckReverseNXTool() } } - this->oc->reverseNXToolMode = getMode; + this->oc->reverseNXMode = getMode; } bool ClockManager::RefreshContext() @@ -412,8 +406,8 @@ bool ClockManager::RefreshContext() hasChanged = true; shouldAdjustProfile = true; - /* Clear ReverseNX-RT state and recheck -Tool patches*/ - this->oc->reverseNXRTMode = ReverseNX_SystemDefault; + /* Clear ReverseNX state and recheck -Tool patches*/ + this->oc->reverseNXMode = ReverseNX_SystemDefault; CheckReverseNXTool(); } @@ -426,24 +420,25 @@ bool ClockManager::RefreshContext() shouldAdjustProfile = true; } - /* Check ReverseNX-RT once per tick */ + /* Check ReverseNX-RT */ { ReverseNXMode getMode = ReverseNXFileHandler(false, FILE_REVERSENX_RT_CONF_PATH); if (getMode) { - this->oc->reverseNXRTMode = getMode; + this->oc->reverseNXMode = getMode; shouldAdjustProfile = true; } if (getMode == ReverseNX_RTResetToDefault) { - this->oc->reverseNXRTMode = ReverseNX_SystemDefault; + this->oc->reverseNXMode = ReverseNX_SystemDefault; } + } - if (shouldAdjustProfile) - { - this->context->profile = ReverseNXProfileHandler(); - } + /* Adjust nominal profile when tid, real profile or -RT profile change */ + if (shouldAdjustProfile) + { + this->context->profile = ReverseNXProfileHandler(); } /* Update PerformanceConfigurationId */ diff --git a/Source/sys-clk-OC/sysmodule/src/clock_manager.h b/Source/sys-clk-OC/sysmodule/src/clock_manager.h index 8f6ab08a..7060afec 100644 --- a/Source/sys-clk-OC/sysmodule/src/clock_manager.h +++ b/Source/sys-clk-OC/sysmodule/src/clock_manager.h @@ -59,6 +59,7 @@ class ClockManager void CheckReverseNXTool(); + // LockableMutex systemCoreStuckCountMutex; // Thread t_CheckSystemCoreStuck_0, t_CheckSystemCoreStuck_1, t_CheckSystemCoreStuck_2; // static void CheckSystemCoreStuck(void *arg); diff --git a/Source/sys-clk-OC/sysmodule/src/errors.h b/Source/sys-clk-OC/sysmodule/src/errors.h index 264b6260..e9631124 100644 --- a/Source/sys-clk-OC/sysmodule/src/errors.h +++ b/Source/sys-clk-OC/sysmodule/src/errors.h @@ -13,7 +13,12 @@ #include #include +#ifdef DEBUG #define ERROR_THROW(format, ...) Errors::ThrowException(format "\n in %s:%u", ##__VA_ARGS__, __FILE__, __LINE__) +#else +#define ERROR_THROW(format, ...) Errors::ThrowException(format, ##__VA_ARGS__) +#endif + #define ERROR_RESULT_THROW(rc, format, ...) ERROR_THROW(format "\n RC: [0x%x] %04d-%04d", ##__VA_ARGS__, rc, R_MODULE(rc), R_DESCRIPTION(rc)) #define ASSERT_RESULT_OK(rc, format, ...) \ if (R_FAILED(rc)) \