- IPC service for handling ReverseNX-RT communication, reducing I/O requests

- Set config for "Auto CPU Boost"/"Sync ReverseNX Mode" in overlay

- Apply hardened freq cap to handheld mode (CPU@1963MHz, GPU@921MHz)
This commit is contained in:
KazushiM
2022-02-11 01:37:47 +08:00
parent 94ac52e80b
commit 4ff20f15f1
21 changed files with 266 additions and 324 deletions

View File

@@ -14,8 +14,6 @@ I'd appreciate if someone is willing to contribute or upload latest binaries. Bu
- Overclocking in general (often combined with overvolting and overheating) will _degrade internal components_ - SoC, VRM(Voltage Regulator Module), Battery, etc. - _faster_ than you and the manufacturer have expected. - Overclocking in general (often combined with overvolting and overheating) will _degrade internal components_ - SoC, VRM(Voltage Regulator Module), Battery, etc. - _faster_ than you and the manufacturer have expected.
- There is **no dynamic frequency scaling** in HOS, which makes _overclocking acts differently than PC_ or other mobile devices. The console will be _sticking to what frequency you've set in the long term_, until you close the game or put it into sleep.
- Higher RAM clocks without proper timings could be UNSTABLE and cause graphical glitches / instabilities / filesystem corruption. **Always make backup before usage.** - Higher RAM clocks without proper timings could be UNSTABLE and cause graphical glitches / instabilities / filesystem corruption. **Always make backup before usage.**
@@ -53,6 +51,9 @@ I'd appreciate if someone is willing to contribute or upload latest binaries. Bu
- It has been proved safe without charger (not reaching battery power draw threshold) - It has been proved safe without charger (not reaching battery power draw threshold)
- Unsafe: CPU/GPU @ 2397/1305 MHz - Unsafe: CPU/GPU @ 2397/1305 MHz
- Without chargers, CPU/GPU would be capped @ 1963/921 MHz.
- Without official chargers, GPU would be capped @ 1267 MHz.
- Why **NOT RECOMMENDED**? - Why **NOT RECOMMENDED**?
- See `Current Flow` in sys-clk-OC overlay `Miscellaneous` (on battery) or measure power draw from charger yourself. - See `Current Flow` in sys-clk-OC overlay `Miscellaneous` (on battery) or measure power draw from charger yourself.
@@ -68,24 +69,22 @@ I'd appreciate if someone is willing to contribute or upload latest binaries. Bu
- GPU: 1305 MHz (no overvolting, less than official threshold 1050 mV) - GPU: 1305 MHz (no overvolting, less than official threshold 1050 mV)
- NVIDIA Official Maximum: 1267.2 MHz - NVIDIA Official Maximum: 1267.2 MHz
- ~~Tested with deko3d compute shaders converted from Maxwell SASS assembly. Single-precision floating point (FP32 FFMA) performance maxes out at 1305 MHz.~~ - ~~Tested with deko3d compute shaders converted from Maxwell SASS assembly. Single-precision floating point (FP32 FFMA) performance maxes out at 1305 MHz.~~
- 1305 MHz CANNOT be set without charger connected.
- **Modded sys-clk and ReverseNX**(-RT) - **Modded sys-clk and ReverseNX**(-RT)
- No need to change clocks manually after toggling modes in ReverseNX (Optional)
- To disable this feature, use original version of ReverseNX-RT and remove `/config/sys-clk/ReverseNX_sync.flag`.
- Auto-Boost CPU for faster game loading (Optional)
- Enable CPU Boost (1785 MHz) when CPU Core#3 (System Core) is stressed, especially when the game is loading assets from eMMC/SD card (I/O ops).
- Auto-Boost will be enabled only when charger is connected.
- To disable this feature, remove `/config/sys-clk/boost.flag`.
- Permanent global clock override - Permanent global clock override
- Expected usage: set maximum DRAM clocks for all games and profiles. - Expected usage: set maximum DRAM clocks for all games and profiles.
- View charger & battery info, toggle charging/fast-charging(2A) in overlay - Miscellaneous
- Extend battery life expectancy by maintaining battery charge at 40% - 60% and disabling fast charging if possible. - Auto CPU Boost: For faster game loading
- Known issue: Fast charging toggle will be reset in-game. - Enable CPU Boost (1785 MHz) when CPU Core#3 (System Core) is stressed, especially when the game is loading assets from eMMC/SD card (I/O ops).
- Auto-Boost will be enabled only when charger is connected.
- Sync ReverseNX Mode: No need to change clocks manually after toggling modes in ReverseNX
- View charger & battery info, toggle charging/fast-charging(2A) in overlay
- Extend battery life expectancy by maintaining battery charge at 40% - 60% and disabling fast charging if possible.
- Known issue: Fast charging toggle will be reset in-game.

View File

@@ -8,7 +8,7 @@ index 3e35c18..6b42bc5 100644
*.nro *.nro
+*.DS_Store +*.DS_Store
diff --git a/Overlay/Makefile b/Overlay/Makefile diff --git a/Overlay/Makefile b/Overlay/Makefile
index f881ed9..88fca31 100644 index f881ed9..7184bb0 100644
--- a/Overlay/Makefile --- a/Overlay/Makefile
+++ b/Overlay/Makefile +++ b/Overlay/Makefile
@@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules @@ -38,7 +38,7 @@ include $(DEVKITPRO)/libnx/switch_rules
@@ -16,17 +16,26 @@ index f881ed9..88fca31 100644
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
APP_TITLE := ReverseNX-RT APP_TITLE := ReverseNX-RT
-APP_VERSION := 1.0.1 -APP_VERSION := 1.0.1
+APP_VERSION := 1.0.1-OC +APP_VERSION := 1.0.2-OC
TARGET := ReverseNX-RT-ovl TARGET := ReverseNX-RT-ovl
BUILD := build BUILD := build
@@ -53,7 +53,7 @@ NO_ICON := 1
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
-CFLAGS := -g -Wall -Os -ffunction-sections \
+CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__ -DAPP_VERSION="\"$(APP_VERSION)\""
diff --git a/Overlay/libs/Atmosphere-libs b/Overlay/libs/Atmosphere-libs diff --git a/Overlay/libs/Atmosphere-libs b/Overlay/libs/Atmosphere-libs
index 2d522dc..c4d0335 160000 index 2d522dc..c4d0335 160000
--- a/Overlay/libs/Atmosphere-libs --- a/Overlay/libs/Atmosphere-libs
+++ b/Overlay/libs/Atmosphere-libs +++ b/Overlay/libs/Atmosphere-libs
@@ -1 +1 @@ @@ -1 +1 @@
-Subproject commit 2d522dc6a12b2eb5eb3f103a8c5b5126ca301b1a -Subproject commit 2d522dc6a12b2eb5eb3f103a8c5b5126ca301b1a
+Subproject commit c4d0335b79da7207b49abf1988f45b0168b692f0-dirty +Subproject commit c4d0335b79da7207b49abf1988f45b0168b692f0
diff --git a/Overlay/libs/libtesla b/Overlay/libs/libtesla diff --git a/Overlay/libs/libtesla b/Overlay/libs/libtesla
index 6628524..640629f 160000 index 6628524..640629f 160000
--- a/Overlay/libs/libtesla --- a/Overlay/libs/libtesla
@@ -35,15 +44,15 @@ index 6628524..640629f 160000
-Subproject commit 66285245361a02e5480c7bb7dac9ef6449ae6181 -Subproject commit 66285245361a02e5480c7bb7dac9ef6449ae6181
+Subproject commit 640629f49f9e8997ef0769b21b26f4fc177c736f +Subproject commit 640629f49f9e8997ef0769b21b26f4fc177c736f
diff --git a/Overlay/source/main.cpp b/Overlay/source/main.cpp diff --git a/Overlay/source/main.cpp b/Overlay/source/main.cpp
index cec060c..1a6080e 100644 index cec060c..90c020b 100644
--- a/Overlay/source/main.cpp --- a/Overlay/source/main.cpp
+++ b/Overlay/source/main.cpp +++ b/Overlay/source/main.cpp
@@ -2,8 +2,12 @@ @@ -1,9 +1,12 @@
#define TESLA_INIT_IMPL // If you have more than one file using the tesla header, only define this in the main one
#include <tesla.hpp> // The Tesla Header #include <tesla.hpp> // The Tesla Header
+#include <atomic>
#include "dmntcht.h" #include "dmntcht.h"
+#define PROCESS_MANAGEMENT_QLAUNCH_TID 0x0100000000001000ULL
+
bool def = true; bool def = true;
+bool defChanged = false; +bool defChanged = false;
bool isDocked = false; bool isDocked = false;
@@ -51,54 +60,76 @@ index cec060c..1a6080e 100644
bool PluginRunning = false; bool PluginRunning = false;
bool closed = false; bool closed = false;
Handle debug; Handle debug;
@@ -17,9 +21,16 @@ bool dmntcht = false; @@ -20,6 +23,10 @@ bool plugin = false;
bool SaltySD = false;
bool bak = false;
bool plugin = false;
+bool sysclkComm = false;
+uint8_t sysclkSyncInfoShowTick = 0;
+constexpr uint8_t sysclkSyncChecksPerSec = 10;
+constexpr uint8_t sysclkSyncFramesPerCheck = 60 / sysclkSyncChecksPerSec;
+constexpr uint8_t sysclkSyncInfoShowInitTick = 3 * sysclkSyncFramesPerCheck;
+uint8_t sysclkSyncRetry = 0;
char DockedChar[32]; char DockedChar[32];
char SystemChar[32]; char SystemChar[32];
char PluginChar[36]; char PluginChar[36];
+char SysclkChar[36]; +char SysclkChar[36];
+static Service g_sysclkSrv;
+static std::atomic<std::size_t> g_refCnt;
+bool sysclkComm = false;
bool CheckPort () { bool CheckPort () {
Handle saltysd; Handle saltysd;
@@ -54,6 +65,29 @@ bool isServiceRunning(const char *serviceName) { @@ -54,6 +61,57 @@ bool isServiceRunning(const char *serviceName) {
} }
} }
+u64 GetCurrentApplicationId() +#define SYSCLK_IPC_API_VERSION 1
+#define SYSCLK_IPC_SERVICE_NAME "sysclkOC"
+
+enum SysClkIpcCmd
+{
+ SysClkIpcCmd_GetApiVersion = 0,
+ SysClkIpcCmd_SetReverseNXRTMode = 11,
+};
+
+void sysclkIpcExit(void)
+{
+ if (--g_refCnt == 0)
+ {
+ serviceClose(&g_sysclkSrv);
+ }
+}
+
+Result sysclkIpcInitialize(void)
+{ +{
+ // Copied from sys-clk
+ Result rc = 0; + Result rc = 0;
+ std::uint64_t pid = 0;
+ std::uint64_t tid = 0;
+ rc = pmdmntGetApplicationProcessId(&pid);
+ +
+ if (rc == 0x20f) + g_refCnt++;
+ {
+ return PROCESS_MANAGEMENT_QLAUNCH_TID;
+ }
+ +
+ rc = pminfoGetProgramId(&tid, pid); + if (serviceIsActive(&g_sysclkSrv))
+ return 0;
+ +
+ if (rc == 0x20f) + rc = smGetService(&g_sysclkSrv, SYSCLK_IPC_SERVICE_NAME);
+ {
+ return PROCESS_MANAGEMENT_QLAUNCH_TID;
+ }
+ +
+ return tid; + if (R_FAILED(rc)) sysclkIpcExit();
+
+ return rc;
+}
+
+Result sysclkIpcGetAPIVersion(u32* out_ver)
+{
+ return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetApiVersion, *out_ver);
+}
+
+typedef enum
+{
+ ReverseNX_SystemDefault = 0,
+ ReverseNX_Handheld,
+ ReverseNX_Docked,
+ ReverseNX_RTResetToDefault,
+} ReverseNXMode;
+
+Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode)
+{
+ return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, mode);
+} +}
+ +
class GuiTest : public tsl::Gui { class GuiTest : public tsl::Gui {
public: public:
GuiTest(u8 arg1, u8 arg2, bool arg3) { } GuiTest(u8 arg1, u8 arg2, bool arg3) { }
@@ -88,6 +122,7 @@ public: @@ -88,6 +146,7 @@ public:
else { else {
renderer->drawString(SystemChar, false, x, y+40, 20, renderer->a(0xFFFF)); renderer->drawString(SystemChar, false, x, y+40, 20, renderer->a(0xFFFF));
renderer->drawString(DockedChar, false, x, y+60, 20, renderer->a(0xFFFF)); renderer->drawString(DockedChar, false, x, y+60, 20, renderer->a(0xFFFF));
@@ -106,7 +137,7 @@ index cec060c..1a6080e 100644
} }
} }
}), 100); }), 100);
@@ -95,9 +130,10 @@ public: @@ -95,9 +154,10 @@ public:
if (MAGIC == 0x06BA7E39) { if (MAGIC == 0x06BA7E39) {
auto *clickableListItem = new tsl::elm::ListItem("Change system control"); auto *clickableListItem = new tsl::elm::ListItem("Change system control");
clickableListItem->setClickListener([](u64 keys) { clickableListItem->setClickListener([](u64 keys) {
@@ -118,7 +149,7 @@ index cec060c..1a6080e 100644
if (dmntcht == true) { if (dmntcht == true) {
dmntchtWriteCheatProcessMemory(def_address, &def, 0x1); dmntchtWriteCheatProcessMemory(def_address, &def, 0x1);
dmntchtReadCheatProcessMemory(def_address, &def, 0x1); dmntchtReadCheatProcessMemory(def_address, &def, 0x1);
@@ -120,9 +156,10 @@ public: @@ -120,9 +180,10 @@ public:
auto *clickableListItem2 = new tsl::elm::ListItem("Change mode"); auto *clickableListItem2 = new tsl::elm::ListItem("Change mode");
clickableListItem2->setClickListener([](u64 keys) { clickableListItem2->setClickListener([](u64 keys) {
@@ -130,7 +161,7 @@ index cec060c..1a6080e 100644
if (dmntcht == true) { if (dmntcht == true) {
dmntchtWriteCheatProcessMemory(docked_address, &isDocked, 0x1); dmntchtWriteCheatProcessMemory(docked_address, &isDocked, 0x1);
dmntchtReadCheatProcessMemory(docked_address, &isDocked, 0x1); dmntchtReadCheatProcessMemory(docked_address, &isDocked, 0x1);
@@ -145,7 +182,7 @@ public: @@ -145,7 +206,7 @@ public:
else if (SaltySD == true && plugin == true && check == false) { else if (SaltySD == true && plugin == true && check == false) {
auto *clickableListItem = new tsl::elm::ListItem("(De)activate plugin"); auto *clickableListItem = new tsl::elm::ListItem("(De)activate plugin");
clickableListItem->setClickListener([](u64 keys) { clickableListItem->setClickListener([](u64 keys) {
@@ -139,93 +170,35 @@ index cec060c..1a6080e 100644
if (bak == false) { if (bak == false) {
rename("sdmc:/SaltySD/plugins/ReverseNX-RT.elf", "sdmc:/SaltySD/plugins/ReverseNX-RT.elf.bak"); rename("sdmc:/SaltySD/plugins/ReverseNX-RT.elf", "sdmc:/SaltySD/plugins/ReverseNX-RT.elf.bak");
bak = true; bak = true;
@@ -185,6 +222,40 @@ public: @@ -179,12 +240,22 @@ public:
closed = true;
}
if (PluginRunning == true) {
- if (i > 59) {
+ if (i > 29) {
if (dmntcht == true) dmntchtReadCheatProcessMemory(docked_address, &isDocked, 0x1);
else if (R_SUCCEEDED(svcDebugActiveProcess(&debug, PID))) {
svcReadDebugProcessMemory(&isDocked, debug, docked_address, 0x1); svcReadDebugProcessMemory(&isDocked, debug, docked_address, 0x1);
svcCloseHandle(debug); svcCloseHandle(debug);
} }
+ if (sysclkComm && isDockedChanged && def == false && bak == false) + if (sysclkComm && !bak) {
+ { + if (!def && isDockedChanged) {
+ u64 currentTID = GetCurrentApplicationId(); + isDockedChanged = false;
+ if (currentTID != PROCESS_MANAGEMENT_QLAUNCH_TID) + sysclkIpcSetReverseNXRTMode(isDocked ? ReverseNX_Docked : ReverseNX_Handheld);
+ {
+ FILE* sysclkConf = fopen("/config/sys-clk/ReverseNX-RT.conf", "wb+");
+ if (sysclkConf)
+ {
+ uint8_t ctrlState = isDocked + 1;
+ fwrite(&currentTID, 1, sizeof(currentTID), sysclkConf);
+ fwrite(&ctrlState, 1, sizeof(ctrlState), sysclkConf);
+ fclose(sysclkConf);
+ sysclkSyncInfoShowTick = sysclkSyncInfoShowInitTick;
+ }
+ } + }
+ isDockedChanged = false; + if (def && defChanged) {
+ } + defChanged = false;
+ if (sysclkComm && defChanged && def == true && bak == false) // change from force mode to system-controlled mode + sysclkIpcSetReverseNXRTMode(ReverseNX_RTResetToDefault);
+ {
+ u64 currentTID = GetCurrentApplicationId();
+ if (currentTID != PROCESS_MANAGEMENT_QLAUNCH_TID)
+ {
+ FILE* sysclkConf = fopen("/config/sys-clk/ReverseNX-RT.conf", "wb+");
+ if (sysclkConf)
+ {
+ uint8_t ctrlState = 3; // ReverseNX_RTResetToDefault
+ fwrite(&currentTID, 1, sizeof(currentTID), sysclkConf);
+ fwrite(&ctrlState, 1, sizeof(ctrlState), sysclkConf);
+ fclose(sysclkConf);
+ sysclkSyncInfoShowTick = sysclkSyncInfoShowInitTick;
+ }
+ } + }
+ defChanged = false;
+ } + }
i = 0; i = 0;
} }
else i++; else i++;
@@ -198,11 +269,51 @@ public: @@ -198,11 +269,10 @@ public:
if (bak == false) sprintf(PluginChar, "ReverseNX-RT plugin is activated."); if (bak == false) sprintf(PluginChar, "ReverseNX-RT plugin is activated.");
else sprintf(PluginChar, "ReverseNX-RT plugin is deactivated."); else sprintf(PluginChar, "ReverseNX-RT plugin is deactivated.");
- -
+
+ if (sysclkComm)
+ {
+ if (sysclkSyncInfoShowTick == sysclkSyncInfoShowInitTick)
+ {
+ if (sysclkSyncRetry >= sysclkSyncInfoShowInitTick)
+ {
+ sprintf(SysclkChar, "Sys-clk Profile Sync: Error!");
+ }
+ else if (i % sysclkSyncFramesPerCheck == 0)
+ {
+ /* Check if conf file is detected by sys-clk */
+ FILE* sysclkConf = fopen("/config/sys-clk/ReverseNX-RT.conf", "r");
+ if (sysclkConf)
+ {
+ fclose(sysclkConf);
+ sprintf(SysclkChar, "Sys-clk Profile Sync: Pending...");
+ sysclkSyncRetry++;
+ }
+ else
+ {
+ sprintf(SysclkChar, "Sys-clk Profile Sync: Success!");
+ sysclkSyncRetry = 0;
+ sysclkSyncInfoShowTick--;
+ }
+ }
+ }
+ else if (sysclkSyncInfoShowTick)
+ {
+ if (i % sysclkSyncFramesPerCheck == 0)
+ sysclkSyncInfoShowTick--;
+ }
+ else
+ {
+ sprintf(SysclkChar, "Sys-clk Profile Sync: ON");
+ }
+ }
+ else
+ {
+ sprintf(SysclkChar, "Sys-clk Profile Sync: OFF");
+ }
} }
// Called once every frame to handle inputs not handled by other UI elements // Called once every frame to handle inputs not handled by other UI elements
@@ -234,54 +207,31 @@ index cec060c..1a6080e 100644
return false; // Return true here to singal the inputs have been consumed return false; // Return true here to singal the inputs have been consumed
} }
}; };
@@ -213,6 +324,7 @@ public: @@ -234,6 +304,13 @@ public:
virtual void initServices() override {
smInitialize();
fsdevMountSdmc();
+ pminfoInitialize();
SaltySD = CheckPort();
if (SaltySD == false) return;
@@ -234,6 +346,19 @@ public:
else return; else return;
} }
+ // Check if sys-clk exist + // Initialize sysclkIpc
+ temp = fopen("sdmc:/atmosphere/contents/00FF0000636C6BFF/exefs.nsp", "r"); + if (isServiceRunning(SYSCLK_IPC_SERVICE_NAME)) {
+ if (temp != NULL) + uint32_t apiVer;
+ { + if (R_SUCCEEDED(sysclkIpcInitialize()) && R_SUCCEEDED(sysclkIpcGetAPIVersion(&apiVer)) && apiVer == SYSCLK_IPC_API_VERSION)
+ fclose(temp);
+ temp = fopen("sdmc:/config/sys-clk/ReverseNX_sync.flag", "r");
+ if (temp)
+ {
+ sysclkComm = true; + sysclkComm = true;
+ fclose(temp);
+ }
+ } + }
+ +
if (R_FAILED(pmdmntGetApplicationProcessId(&PID))) remove("sdmc:/SaltySD/ReverseNX-RT.hex"); if (R_FAILED(pmdmntGetApplicationProcessId(&PID))) remove("sdmc:/SaltySD/ReverseNX-RT.hex");
else { else {
check = true; check = true;
@@ -278,12 +403,22 @@ public: @@ -278,10 +355,13 @@ public:
if (def == true) sprintf(SystemChar, "Controlled by system: Yes"); if (def == true) sprintf(SystemChar, "Controlled by system: Yes");
else sprintf(SystemChar, "Controlled by system: No"); else sprintf(SystemChar, "Controlled by system: No");
+ +
+ if (sysclkComm) + sprintf(SysclkChar, "Sys-clk-OC Sync Service: %s", sysclkComm ? "ON" : "OFF");
+ {
+ sprintf(SysclkChar, "Sys-clk Profile Sync: ON");
+ }
+ else
+ {
+ sprintf(SysclkChar, "Sys-clk Profile Sync: OFF");
+ }
} // Called at the start to initialize all services necessary for this Overlay } // Called at the start to initialize all services necessary for this Overlay
virtual void exitServices() override { virtual void exitServices() override {
+ sysclkIpcExit();
dmntchtExit(); dmntchtExit();
if (dmntcht == false) svcCloseHandle(debug); if (dmntcht == false) svcCloseHandle(debug);
+ pminfoExit();
fsdevUnmountDevice("sdmc"); fsdevUnmountDevice("sdmc");
smExit();
} // Callet at the end to clean up all services previously initialized

View File

@@ -77,8 +77,8 @@ To protect the battery from excessive strain, clocks requested from config may b
| | Handheld | Charging (USB) | Charging (Official) | Docked | | | Handheld | Charging (USB) | Charging (Official) | Docked |
|:-------:|:--------:|:--------------:|:-------------------:|:------:| |:-------:|:--------:|:--------------:|:-------------------:|:------:|
| **MEM** | - | - | - | - | | **MEM** | - | - | - | - |
| **CPU** | - | - | - | - | | **CPU** | 1963 | - | - | - |
| **GPU** | 1267 | - | - | - | | **GPU** | 921 | 1267 | - | - |
## Installation ## Installation
@@ -180,6 +180,8 @@ The `[values]` section allows you to alter timings in sys-clk, you should not ne
| Key | Desc | Default | | Key | Desc | Default |
|:-----------------------:|-------------------------------------------------------------------------------|:-------:| |:-----------------------:|-------------------------------------------------------------------------------|:-------:|
|**auto_cpu_boost** | Auto-boost CPU when system Core #3 utilization is high | ON |
|**sync_reversenx_mode** | Sync nominal profile (mode) with ReverseNX (-Tool and -RT) | ON |
|**temp_log_interval_ms** | Defines how often sys-clk log temperatures, in milliseconds (`0` to disable) | 0 ms | |**temp_log_interval_ms** | Defines how often sys-clk log temperatures, in milliseconds (`0` to disable) | 0 ms |
|**csv_write_interval_ms**| Defines how often sys-clk writes to the CSV, in milliseconds (`0` to disable) | 0 ms | |**csv_write_interval_ms**| Defines how often sys-clk writes to the CSV, in milliseconds (`0` to disable) | 0 ms |
|**poll_interval_ms** | Defines how fast sys-clk checks and applies profiles, in milliseconds | 500 ms | |**poll_interval_ms** | Defines how fast sys-clk checks and applies profiles, in milliseconds | 500 ms |

View File

@@ -30,6 +30,7 @@ Result sysclkIpcGetProfiles(u64 tid, SysClkTitleProfileList* out_profiles);
Result sysclkIpcSetProfiles(u64 tid, SysClkTitleProfileList* profiles); Result sysclkIpcSetProfiles(u64 tid, SysClkTitleProfileList* profiles);
Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues); Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues);
Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues); Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues);
Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode);
static inline Result sysclkIpcRemoveOverride(SysClkModule module) static inline Result sysclkIpcRemoveOverride(SysClkModule module)
{ {

View File

@@ -57,6 +57,7 @@ typedef enum
ReverseNX_SystemDefault = 0, ReverseNX_SystemDefault = 0,
ReverseNX_NotFound = 0, ReverseNX_NotFound = 0,
ReverseNX_NotValid = 0, ReverseNX_NotValid = 0,
ReverseNX_GotValue = 0,
ReverseNX_Handheld, ReverseNX_Handheld,
ReverseNX_Docked, ReverseNX_Docked,
ReverseNX_RTResetToDefault, ReverseNX_RTResetToDefault,
@@ -65,11 +66,7 @@ typedef enum
typedef struct typedef struct
{ {
bool systemCoreBoostCPU; bool systemCoreBoostCPU;
bool systemCoreCheckStuck; ReverseNXMode reverseNXMode;
ReverseNXMode reverseNXMode;
uint64_t tickWaitTimeMs;
uint32_t maxMEMFreq; uint32_t maxMEMFreq;
} SysClkOcExtra; } SysClkOcExtra;
@@ -81,7 +78,9 @@ typedef struct
}; };
} SysClkTitleProfileList; } SysClkTitleProfileList;
#define SYSCLK_GPU_HANDHELD_MAX_HZ 1267200000 #define SYSCLK_CPU_HANDHELD_MAX_HZ 1963500000
#define SYSCLK_GPU_HANDHELD_MAX_HZ 921600000
#define SYSCLK_GPU_CHARGING_USB_MAX_HZ 1267200000
extern uint32_t sysclk_g_freq_table_mem_hz[]; extern uint32_t sysclk_g_freq_table_mem_hz[];
extern uint32_t sysclk_g_freq_table_cpu_hz[]; extern uint32_t sysclk_g_freq_table_cpu_hz[];

View File

@@ -17,6 +17,8 @@ typedef enum {
SysClkConfigValue_PollingIntervalMs = 0, SysClkConfigValue_PollingIntervalMs = 0,
SysClkConfigValue_TempLogIntervalMs, SysClkConfigValue_TempLogIntervalMs,
SysClkConfigValue_CsvWriteIntervalMs, SysClkConfigValue_CsvWriteIntervalMs,
SysClkConfigValue_AutoCPUBoost,
SysClkConfigValue_SyncReverseNXMode,
SysClkConfigValue_EnumMax, SysClkConfigValue_EnumMax,
} SysClkConfigValue; } SysClkConfigValue;
@@ -34,6 +36,10 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr
return pretty ? "Temperature logging interval (ms)" : "temp_log_interval_ms"; return pretty ? "Temperature logging interval (ms)" : "temp_log_interval_ms";
case SysClkConfigValue_CsvWriteIntervalMs: case SysClkConfigValue_CsvWriteIntervalMs:
return pretty ? "CSV write interval (ms)" : "csv_write_interval_ms"; return pretty ? "CSV write interval (ms)" : "csv_write_interval_ms";
case SysClkConfigValue_AutoCPUBoost:
return pretty ? "Enable Auto CPU Boost" : "auto_cpu_boost";
case SysClkConfigValue_SyncReverseNXMode:
return pretty ? "Enable ReverseNX Mode Sync" : "sync_reversenx_mode";
default: default:
return NULL; return NULL;
} }
@@ -44,10 +50,13 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
switch(val) switch(val)
{ {
case SysClkConfigValue_PollingIntervalMs: case SysClkConfigValue_PollingIntervalMs:
return 300ULL; return 500ULL;
case SysClkConfigValue_TempLogIntervalMs: case SysClkConfigValue_TempLogIntervalMs:
case SysClkConfigValue_CsvWriteIntervalMs: case SysClkConfigValue_CsvWriteIntervalMs:
return 0ULL; return 0ULL;
case SysClkConfigValue_AutoCPUBoost:
case SysClkConfigValue_SyncReverseNXMode:
return 1ULL;
default: default:
return 0ULL; return 0ULL;
} }
@@ -62,6 +71,9 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in
case SysClkConfigValue_TempLogIntervalMs: case SysClkConfigValue_TempLogIntervalMs:
case SysClkConfigValue_CsvWriteIntervalMs: case SysClkConfigValue_CsvWriteIntervalMs:
return true; return true;
case SysClkConfigValue_AutoCPUBoost:
case SysClkConfigValue_SyncReverseNXMode:
return (input & 0x1) == input;
default: default:
return false; return false;
} }

View File

@@ -13,8 +13,8 @@
#include <stdint.h> #include <stdint.h>
#include "clocks.h" #include "clocks.h"
#define SYSCLK_IPC_API_VERSION 0 #define SYSCLK_IPC_API_VERSION 1
#define SYSCLK_IPC_SERVICE_NAME "sys:clk" #define SYSCLK_IPC_SERVICE_NAME "sysclkOC"
enum SysClkIpcCmd enum SysClkIpcCmd
{ {
@@ -29,6 +29,7 @@ enum SysClkIpcCmd
SysClkIpcCmd_SetOverride = 8, SysClkIpcCmd_SetOverride = 8,
SysClkIpcCmd_GetConfigValues = 9, SysClkIpcCmd_GetConfigValues = 9,
SysClkIpcCmd_SetConfigValues = 10, SysClkIpcCmd_SetConfigValues = 10,
SysClkIpcCmd_SetReverseNXRTMode = 11,
}; };

View File

@@ -114,3 +114,8 @@ Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues)
{ {
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetConfigValues, *configValues); return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetConfigValues, *configValues);
} }
Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode)
{
return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, mode);
}

View File

@@ -205,8 +205,12 @@ void StatusTab::updateWarningForProfile(SysClkProfile profile, bool animated)
case SysClkProfile_Handheld: case SysClkProfile_Handheld:
if (this->warningLabel->isHidden()) if (this->warningLabel->isHidden())
this->warningLabel->show([](){}); this->warningLabel->show([](){});
this->warningLabel->setText("\uE140 Handheld Mode: Max CPU freq: " + formatFreq(SYSCLK_CPU_HANDHELD_MAX_HZ) + ", Max GPU freq: " + formatFreq(SYSCLK_GPU_HANDHELD_MAX_HZ));
this->warningLabel->setText("\uE140 Maximum GPU frequency is " + formatFreq(SYSCLK_GPU_HANDHELD_MAX_HZ) + " because you're in handheld mode."); break;
case SysClkProfile_HandheldChargingUSB:
if (this->warningLabel->isHidden())
this->warningLabel->show([](){});
this->warningLabel->setText("\uE140 USB Charging Mode: Max GPU freq: " + formatFreq(SYSCLK_GPU_CHARGING_USB_MAX_HZ));
break; break;
default: default:
if (!this->warningLabel->isHidden()) if (!this->warningLabel->isHidden())

View File

@@ -14,12 +14,14 @@
MiscGui::MiscGui() MiscGui::MiscGui()
{ {
this->configList = new SysClkConfigValueList {};
this->chargeInfo = new ChargeInfo {}; this->chargeInfo = new ChargeInfo {};
this->i2cInfo = new I2cInfo {}; this->i2cInfo = new I2cInfo {};
} }
MiscGui::~MiscGui() MiscGui::~MiscGui()
{ {
delete this->configList;
delete this->chargeInfo; delete this->chargeInfo;
delete this->i2cInfo; delete this->i2cInfo;
} }
@@ -28,11 +30,36 @@ void MiscGui::preDraw(tsl::gfx::Renderer* render)
{ {
BaseMenuGui::preDraw(render); BaseMenuGui::preDraw(render);
render->drawString(this->infoOutput, false, 40, 300, SMALL_TEXT_SIZE, DESC_COLOR); render->drawString(this->infoOutput, false, 40, 440, SMALL_TEXT_SIZE, DESC_COLOR);
}
tsl::elm::ToggleListItem* MiscGui::addConfigToggle(SysClkConfigValue configVal, std::string labelName) {
tsl::elm::ToggleListItem* toggle = new tsl::elm::ToggleListItem(labelName, this->configList->values[configVal]);
toggle->setStateChangedListener([this, configVal](bool state) {
this->configList->values[configVal] = uint64_t(state);
Result rc = sysclkIpcSetConfigValues(this->configList);
if (R_FAILED(rc))
FatalGui::openWithResultCode("sysclkIpcSetConfigValues", rc);
this->lastContextUpdate = armGetSystemTick();
});
this->listElement->addItem(toggle);
return toggle;
}
void MiscGui::updateConfigToggle(tsl::elm::ToggleListItem *toggle, SysClkConfigValue configVal) {
if (toggle != nullptr) {
toggle->setState(this->configList->values[configVal]);
}
} }
void MiscGui::listUI() void MiscGui::listUI()
{ {
sysclkIpcGetConfigValues(this->configList);
this->cpuBoostToggle = addConfigToggle(SysClkConfigValue_AutoCPUBoost, "Auto CPU Boost");
this->syncModeToggle = addConfigToggle(SysClkConfigValue_SyncReverseNXMode, "Sync ReverseNX Mode");
// Charging // Charging
this->chargingToggle = new tsl::elm::ToggleListItem("Charging", false); this->chargingToggle = new tsl::elm::ToggleListItem("Charging", false);
chargingToggle->setStateChangedListener([this](bool state) { chargingToggle->setStateChangedListener([this](bool state) {
@@ -63,9 +90,14 @@ void MiscGui::listUI()
this->listElement->addItem(this->fastChargingToggle); this->listElement->addItem(this->fastChargingToggle);
} }
void MiscGui::update() void MiscGui::refresh() {
{ BaseMenuGui::refresh();
BaseMenuGui::update();
if (this->context) {
sysclkIpcGetConfigValues(this->configList);
updateConfigToggle(this->cpuBoostToggle, SysClkConfigValue_AutoCPUBoost);
updateConfigToggle(this->syncModeToggle, SysClkConfigValue_SyncReverseNXMode);
}
if (++frameCounter >= 60) if (++frameCounter >= 60)
{ {

View File

@@ -20,7 +20,7 @@ class MiscGui : public BaseMenuGui
~MiscGui(); ~MiscGui();
void preDraw(tsl::gfx::Renderer* render) override; void preDraw(tsl::gfx::Renderer* render) override;
void listUI() override; void listUI() override;
void update() override; void refresh() override;
protected: protected:
typedef enum { typedef enum {
@@ -307,8 +307,12 @@ class MiscGui : public BaseMenuGui
return PsmIsFastCharging() == enable; return PsmIsFastCharging() == enable;
} }
tsl::elm::ToggleListItem *chargingToggle, *fastChargingToggle; tsl::elm::ToggleListItem* addConfigToggle(SysClkConfigValue, std::string);
void updateConfigToggle(tsl::elm::ToggleListItem*, SysClkConfigValue);
tsl::elm::ToggleListItem *cpuBoostToggle, *syncModeToggle, *chargingToggle, *fastChargingToggle;
SysClkConfigValueList* configList;
ChargeInfo* chargeInfo; ChargeInfo* chargeInfo;
I2cInfo* i2cInfo; I2cInfo* i2cInfo;
bool isEnoughPowerSupplied = false; bool isEnoughPowerSupplied = false;

View File

@@ -1,5 +1,5 @@
{ {
"name": "sys:clk", "name": "sysclkOC",
"title_id": "0x00FF0000636C6BFF", "title_id": "0x00FF0000636C6BFF",
"title_id_range_min": "0x00FF0000636C6BFF", "title_id_range_min": "0x00FF0000636C6BFF",
"title_id_range_max": "0x00FF0000636C6BFF", "title_id_range_max": "0x00FF0000636C6BFF",
@@ -18,7 +18,7 @@
"*" "*"
], ],
"service_host": [ "service_host": [
"sys:clk" "sysclkOC"
], ],
"kernel_capabilities": [ "kernel_capabilities": [
{ {

View File

@@ -60,7 +60,6 @@ ClockManager::ClockManager()
this->oc = new SysClkOcExtra; this->oc = new SysClkOcExtra;
this->oc->systemCoreBoostCPU = false; this->oc->systemCoreBoostCPU = false;
this->oc->reverseNXMode = ReverseNX_NotFound; this->oc->reverseNXMode = ReverseNX_NotFound;
this->oc->tickWaitTimeMs = 0;
this->oc->maxMEMFreq = 0; this->oc->maxMEMFreq = 0;
} }
@@ -77,7 +76,7 @@ bool ClockManager::IsCpuBoostMode()
return (confId == 0x92220009 || confId == 0x9222000A); return (confId == 0x92220009 || confId == 0x9222000A);
} }
bool ClockManager::IsReverseNXEnabled() bool ClockManager::IsReverseNXModeValid()
{ {
return (this->oc->reverseNXMode); return (this->oc->reverseNXMode);
} }
@@ -113,7 +112,7 @@ uint32_t ClockManager::GetHz(SysClkModule module)
hz = this->config->GetAutoClockHz(this->context->applicationId, module, this->context->profile); hz = this->config->GetAutoClockHz(this->context->applicationId, module, this->context->profile);
/* Return pre-set hz if ReverseNX is enabled, downclock is disabled when realProfile == Docked */ /* Return pre-set hz if ReverseNX is enabled, downclock is disabled when realProfile == Docked */
if (!hz && IsReverseNXEnabled()) if (!hz && IsReverseNXModeValid())
{ {
switch(module) switch(module)
{ {
@@ -198,10 +197,11 @@ void ClockManager::Tick()
void ClockManager::WaitForNextTick() void ClockManager::WaitForNextTick()
{ {
/* Self-check system core (#3) usage via idleticks at intervals (Not enabled at higher CPU freq or without charger) */ /* Self-check system core (#3) usage via idleticks at intervals (Not enabled at higher CPU freq or without charger) */
this->oc->tickWaitTimeMs = this->GetConfig()->GetConfigValue(SysClkConfigValue_PollingIntervalMs); uint64_t tickWaitTimeMs = this->GetConfig()->GetConfigValue(SysClkConfigValue_PollingIntervalMs);
uint64_t tickWaitTimeNs = this->oc->tickWaitTimeMs * 1000000ULL; uint64_t tickWaitTimeNs = tickWaitTimeMs * 1000000ULL;
if ( FileUtils::IsBoostEnabled() uint64_t isAutoBoostEnabled = this->GetConfig()->GetConfigValue(SysClkConfigValue_AutoCPUBoost);
if ( isAutoBoostEnabled
&& this->context->realProfile != SysClkProfile_Handheld && this->context->realProfile != SysClkProfile_Handheld
&& this->context->enabled && this->context->enabled
&& this->context->freqs[SysClkModule_CPU] <= CPU_BOOST_FREQ) && this->context->freqs[SysClkModule_CPU] <= CPU_BOOST_FREQ)
@@ -214,7 +214,7 @@ void ClockManager::WaitForNextTick()
/* Convert idletick to free% */ /* Convert idletick to free% */
/* If CPU core usage is 0%, then idletick = 19'200'000 per sec */ /* If CPU core usage is 0%, then idletick = 19'200'000 per sec */
uint64_t systemCoreIdleTick = systemCoreIdleTickNext - systemCoreIdleTickPrev; uint64_t systemCoreIdleTick = systemCoreIdleTickNext - systemCoreIdleTickPrev;
uint64_t freeIdleTick = 19'200 * this->oc->tickWaitTimeMs; uint64_t freeIdleTick = 19'200 * tickWaitTimeMs;
uint8_t freePerc = systemCoreIdleTick / (freeIdleTick / 100); uint8_t freePerc = systemCoreIdleTick / (freeIdleTick / 100);
uint8_t systemCoreBoostFreeThreshold = 5; uint8_t systemCoreBoostFreeThreshold = 5;
@@ -244,62 +244,11 @@ void ClockManager::WaitForNextTick()
{ {
svcSleepThread(tickWaitTimeNs); svcSleepThread(tickWaitTimeNs);
} }
/* Signal that systemCore is not busy */
// {
// std::scoped_lock lock{this->systemCoreStuckCountMutex};
// this->oc->systemCoreStuckCount = 0;
// }
} }
/* Tricky part, see IpcService implementation of calling static member function */
// 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;
// // 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, 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);
// }
SysClkProfile ClockManager::ReverseNXProfileHandler() SysClkProfile ClockManager::ReverseNXProfileHandler()
{ {
if (!IsReverseNXEnabled()) if (!IsReverseNXModeValid())
{ {
return this->context->realProfile; return this->context->realProfile;
} }
@@ -318,52 +267,33 @@ SysClkProfile ClockManager::ReverseNXProfileHandler()
return this->context->realProfile; return this->context->realProfile;
} }
ReverseNXMode ClockManager::ReverseNXFileHandler(bool checkTool, const char* filePath) ReverseNXMode ClockManager::ReverseNXFileHandler(const char* filePath)
{ {
FILE *readFile; FILE *readFile;
readFile = fopen(filePath, "rb"); readFile = fopen(filePath, "rb");
if (!readFile) if (!readFile)
{
return ReverseNX_NotFound; return ReverseNX_NotFound;
}
if (checkTool) uint64_t magicDocked = 0xD65F03C0320003E0;
{ uint64_t magicHandheld = 0xD65F03C052A00000;
uint64_t magicDocked = 0xD65F03C0320003E0;
uint64_t magicHandheld = 0xD65F03C052A00000;
uint64_t readBuffer = 0; uint64_t readBuffer = 0;
fread(&readBuffer, 1, sizeof(readBuffer), readFile); fread(&readBuffer, 1, sizeof(readBuffer), readFile);
fclose(readFile); fclose(readFile);
if (!memcmp(&readBuffer, &magicDocked, sizeof(readBuffer))) if (!memcmp(&readBuffer, &magicDocked, sizeof(readBuffer)))
return ReverseNX_Docked; return ReverseNX_Docked;
if (!memcmp(&readBuffer, &magicHandheld, sizeof(readBuffer))) if (!memcmp(&readBuffer, &magicHandheld, sizeof(readBuffer)))
return ReverseNX_Handheld; return ReverseNX_Handheld;
}
else // checkRT
{
uint64_t tidBuffer = 0;
uint8_t ctrlBuffer = 0;
fread(&tidBuffer, 1, sizeof(tidBuffer), readFile);
fread(&ctrlBuffer, 1, sizeof(ctrlBuffer), readFile);
fclose(readFile);
remove(filePath);
if (!memcmp(&this->context->applicationId, &tidBuffer, sizeof(tidBuffer)))
{
return static_cast<ReverseNXMode>(ctrlBuffer);
}
}
return ReverseNX_NotValid; return ReverseNX_NotValid;
} }
void ClockManager::CheckReverseNXTool() void ClockManager::CheckReverseNXTool()
{ {
bool shouldCheckReverseNXTool = FileUtils::IsReverseNXSyncEnabled() && FileUtils::ExistReverseNXTool(); bool shouldCheckReverseNXTool = FileUtils::ExistReverseNXTool();
if (!shouldCheckReverseNXTool) if (!shouldCheckReverseNXTool)
return; return;
@@ -375,13 +305,13 @@ void ClockManager::CheckReverseNXTool()
/* Check global override */ /* Check global override */
snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%s", asmFileName); snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%s", asmFileName);
getMode = ReverseNXFileHandler(true, asmFilePath); getMode = ReverseNXFileHandler(asmFilePath);
if (!getMode) if (!getMode)
{ {
/* Check per-game override */ /* Check per-game override */
snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%016lX/%s", this->context->applicationId, asmFileName); snprintf(asmFilePath, sizeof(asmFilePath), "/SaltySD/patches/%016lX/%s", this->context->applicationId, asmFileName);
getMode = ReverseNXFileHandler(true, asmFilePath); getMode = ReverseNXFileHandler(asmFilePath);
} }
} }
@@ -390,13 +320,9 @@ void ClockManager::CheckReverseNXTool()
bool ClockManager::CheckReverseNXRT() bool ClockManager::CheckReverseNXRT()
{ {
bool shouldCheckReverseNXRT = FileUtils::IsReverseNXSyncEnabled();
if (!shouldCheckReverseNXRT)
return false;
bool shouldAdjustProfile = false; bool shouldAdjustProfile = false;
ReverseNXMode getMode = ReverseNXFileHandler(false, FILE_REVERSENX_RT_CONF_PATH); ReverseNXMode getMode = this->GetConfig()->GetReverseNXRTModeAndClear();
if (getMode) if (getMode)
{ {
this->oc->reverseNXMode = getMode; this->oc->reverseNXMode = getMode;
@@ -415,6 +341,7 @@ bool ClockManager::RefreshContext()
{ {
bool hasChanged = false; bool hasChanged = false;
bool enabled = this->GetConfig()->Enabled(); bool enabled = this->GetConfig()->Enabled();
uint64_t isReverseNXSyncEnabled = this->GetConfig()->GetConfigValue(SysClkConfigValue_SyncReverseNXMode);
if(enabled != this->context->enabled) if(enabled != this->context->enabled)
{ {
this->context->enabled = enabled; this->context->enabled = enabled;
@@ -430,8 +357,10 @@ bool ClockManager::RefreshContext()
hasChanged = true; hasChanged = true;
/* Clear ReverseNX state and recheck -Tool patches*/ /* Clear ReverseNX state and recheck -Tool patches*/
this->oc->reverseNXMode = ReverseNX_SystemDefault; if (isReverseNXSyncEnabled) {
CheckReverseNXTool(); this->oc->reverseNXMode = ReverseNX_SystemDefault;
CheckReverseNXTool();
}
} }
SysClkProfile profile = Clocks::GetCurrentProfile(); SysClkProfile profile = Clocks::GetCurrentProfile();
@@ -460,9 +389,11 @@ bool ClockManager::RefreshContext()
Clocks::ResetToStock(); Clocks::ResetToStock();
/* Check ReverseNX-RT and adjust nominal profile when context changes */ /* Check ReverseNX-RT and adjust nominal profile when context changes */
hasChanged |= CheckReverseNXRT(); if (isReverseNXSyncEnabled) {
if (hasChanged) hasChanged |= CheckReverseNXRT();
this->context->profile = ReverseNXProfileHandler(); if (hasChanged)
this->context->profile = ReverseNXProfileHandler();
}
std::uint32_t hz = 0; std::uint32_t hz = 0;
for (unsigned int module = 0; module < SysClkModule_EnumMax; module++) for (unsigned int module = 0; module < SysClkModule_EnumMax; module++)

View File

@@ -50,20 +50,13 @@ class ClockManager
const uint32_t CPU_BOOST_FREQ = 1785'000'000; const uint32_t CPU_BOOST_FREQ = 1785'000'000;
bool IsCpuBoostMode(); bool IsCpuBoostMode();
bool IsReverseNXEnabled(); bool IsReverseNXModeValid();
bool IsReverseNXDocked(); bool IsReverseNXDocked();
uint32_t GetHz(SysClkModule); uint32_t GetHz(SysClkModule);
SysClkProfile ReverseNXProfileHandler(); SysClkProfile ReverseNXProfileHandler();
ReverseNXMode ReverseNXFileHandler(bool, const char*); ReverseNXMode ReverseNXFileHandler(const char*);
void CheckReverseNXTool(); void CheckReverseNXTool();
bool CheckReverseNXRT(); bool CheckReverseNXRT();
// LockableMutex systemCoreStuckCountMutex;
// Thread t_CheckSystemCoreStuck_0, t_CheckSystemCoreStuck_1, t_CheckSystemCoreStuck_2;
// static void CheckSystemCoreStuck(void *arg);
// void StartCheckSystemCore();
// void StopCheckSystemCore();
}; };

View File

@@ -297,12 +297,19 @@ std::uint32_t Clocks::GetNearestHz(SysClkModule module, SysClkProfile profile, s
std::uint32_t Clocks::GetMaxAllowedHz(SysClkModule module, SysClkProfile profile) std::uint32_t Clocks::GetMaxAllowedHz(SysClkModule module, SysClkProfile profile)
{ {
if(module == SysClkModule_GPU) switch (module) {
{ case SysClkModule_CPU:
if(profile < SysClkProfile_HandheldCharging) if (profile == SysClkProfile_Handheld)
{ return SYSCLK_CPU_HANDHELD_MAX_HZ;
return SYSCLK_GPU_HANDHELD_MAX_HZ; break;
} case SysClkModule_GPU:
if (profile == SysClkProfile_Handheld)
return SYSCLK_GPU_HANDHELD_MAX_HZ;
if (profile == SysClkProfile_HandheldChargingUSB)
return SYSCLK_GPU_CHARGING_USB_MAX_HZ;
break;
default:
break;
} }
return 0; return 0;

View File

@@ -35,6 +35,8 @@ Config::Config(std::string path)
{ {
this->configValues[i] = sysclkDefaultConfigValue((SysClkConfigValue)i); this->configValues[i] = sysclkDefaultConfigValue((SysClkConfigValue)i);
} }
this->reverseNXRTMode = ReverseNX_NotFound;
} }
Config::~Config() Config::~Config()
@@ -480,3 +482,15 @@ bool Config::SetConfigValues(SysClkConfigValueList* configValues, bool immediate
return true; return true;
} }
ReverseNXMode Config::GetReverseNXRTModeAndClear() {
std::scoped_lock lock{this->reverseNXRTMutex};
ReverseNXMode mode = this->reverseNXRTMode;
this->reverseNXRTMode = ReverseNX_GotValue;
return mode;
}
void Config::SetReverseNXRTMode(ReverseNXMode mode) {
std::scoped_lock lock{this->reverseNXRTMutex};
this->reverseNXRTMode = mode;
}

View File

@@ -47,6 +47,8 @@ class Config
const char* GetConfigValueName(SysClkConfigValue val, bool pretty); const char* GetConfigValueName(SysClkConfigValue val, bool pretty);
void GetConfigValues(SysClkConfigValueList* out_configValues); void GetConfigValues(SysClkConfigValueList* out_configValues);
bool SetConfigValues(SysClkConfigValueList* configValues, bool immediate); bool SetConfigValues(SysClkConfigValueList* configValues, bool immediate);
ReverseNXMode GetReverseNXRTModeAndClear();
void SetReverseNXRTMode(ReverseNXMode);
protected: protected:
void Load(); void Load();
void Close(); void Close();
@@ -63,7 +65,9 @@ class Config
time_t mtime; time_t mtime;
LockableMutex configMutex; LockableMutex configMutex;
LockableMutex overrideMutex; LockableMutex overrideMutex;
LockableMutex reverseNXRTMutex;
std::atomic_bool enabled; std::atomic_bool enabled;
std::uint32_t overrideFreqs[SysClkModule_EnumMax]; std::uint32_t overrideFreqs[SysClkModule_EnumMax];
std::uint64_t configValues[SysClkConfigValue_EnumMax]; std::uint64_t configValues[SysClkConfigValue_EnumMax];
ReverseNXMode reverseNXRTMode;
}; };

View File

@@ -18,9 +18,7 @@ static LockableMutex g_log_mutex;
static LockableMutex g_csv_mutex; static LockableMutex g_csv_mutex;
static std::atomic_bool g_has_initialized = false; static std::atomic_bool g_has_initialized = false;
static bool g_log_enabled = false; static bool g_log_enabled = false;
static bool g_boost_enabled = false;
static bool g_reversenx_tool_exist = false; static bool g_reversenx_tool_exist = false;
static bool g_reversenx_sync_enabled = false;
static std::uint64_t g_last_flag_check = 0; static std::uint64_t g_last_flag_check = 0;
extern "C" void __libnx_init_time(void); extern "C" void __libnx_init_time(void);
@@ -136,20 +134,6 @@ void FileUtils::RefreshFlags(bool force)
void FileUtils::InitCheckFlags() void FileUtils::InitCheckFlags()
{ {
FILE *file; FILE *file;
file = fopen(FILE_BOOST_FLAG_PATH, "r");
if (file)
{
g_boost_enabled = true;
fclose(file);
}
file = fopen(FILE_REVERSENX_SYNC_FLAG_PATH, "r");
if (file)
{
g_reversenx_sync_enabled = true;
fclose(file);
}
file = fopen(FILE_SALTYNX_PATH, "r"); file = fopen(FILE_SALTYNX_PATH, "r");
if (file) if (file)
{ {
@@ -158,21 +142,11 @@ void FileUtils::InitCheckFlags()
} }
} }
bool FileUtils::IsBoostEnabled()
{
return g_boost_enabled;
}
bool FileUtils::ExistReverseNXTool() bool FileUtils::ExistReverseNXTool()
{ {
return g_reversenx_tool_exist; return g_reversenx_tool_exist;
} }
bool FileUtils::IsReverseNXSyncEnabled()
{
return g_reversenx_sync_enabled;
}
void FileUtils::InitializeAsync() void FileUtils::InitializeAsync()
{ {
Thread initThread = {0}; Thread initThread = {0};

View File

@@ -22,9 +22,7 @@
#define FILE_CONTEXT_CSV_PATH FILE_CONFIG_DIR "/context.csv" #define FILE_CONTEXT_CSV_PATH FILE_CONFIG_DIR "/context.csv"
#define FILE_LOG_FLAG_PATH FILE_CONFIG_DIR "/log.flag" #define FILE_LOG_FLAG_PATH FILE_CONFIG_DIR "/log.flag"
#define FILE_LOG_FILE_PATH FILE_CONFIG_DIR "/log.txt" #define FILE_LOG_FILE_PATH FILE_CONFIG_DIR "/log.txt"
#define FILE_BOOST_FLAG_PATH FILE_CONFIG_DIR "/boost.flag"
#define FILE_SALTYNX_PATH "/atmosphere/contents/0000000000534C56/flags/boot2.flag" // Just check for SaltyNX boot flag #define FILE_SALTYNX_PATH "/atmosphere/contents/0000000000534C56/flags/boot2.flag" // Just check for SaltyNX boot flag
#define FILE_REVERSENX_SYNC_FLAG_PATH FILE_CONFIG_DIR "/ReverseNX_sync.flag"
#define FILE_REVERSENX_RT_CONF_PATH FILE_CONFIG_DIR "/ReverseNX-RT.conf" #define FILE_REVERSENX_RT_CONF_PATH FILE_CONFIG_DIR "/ReverseNX-RT.conf"
class FileUtils class FileUtils
@@ -34,8 +32,6 @@ class FileUtils
static Result Initialize(); static Result Initialize();
static bool IsInitialized(); static bool IsInitialized();
static bool IsLogEnabled(); static bool IsLogEnabled();
static bool IsBoostEnabled();
static bool IsReverseNXSyncEnabled();
static bool ExistReverseNXTool(); static bool ExistReverseNXTool();
static void InitializeAsync(); static void InitializeAsync();
static void LogLine(const char *format, ...); static void LogLine(const char *format, ...);

View File

@@ -153,6 +153,13 @@ Result IpcService::ServiceHandlerFunc(void* arg, const IpcServerRequest* r, u8*
return ipcSrv->SetConfigValues((SysClkConfigValueList*)r->data.ptr); return ipcSrv->SetConfigValues((SysClkConfigValueList*)r->data.ptr);
} }
break; break;
case SysClkIpcCmd_SetReverseNXRTMode:
if (r->data.size >= sizeof(ReverseNXMode)) {
ReverseNXMode mode = *((ReverseNXMode*)r->data.ptr);
return ipcSrv->SetReverseNXRTMode(mode);
}
break;
} }
return SYSCLK_ERROR(Generic); return SYSCLK_ERROR(Generic);
@@ -289,3 +296,9 @@ Result IpcService::SetConfigValues(SysClkConfigValueList* configValues)
return 0; return 0;
} }
Result IpcService::SetReverseNXRTMode(ReverseNXMode mode) {
Config* config = ClockManager::GetInstance()->GetConfig();
config->SetReverseNXRTMode(mode);
return 0;
}

View File

@@ -36,6 +36,7 @@ class IpcService
Result SetOverride(SysClkIpc_SetOverride_Args* args); Result SetOverride(SysClkIpc_SetOverride_Args* args);
Result GetConfigValues(SysClkConfigValueList* out_configValues); Result GetConfigValues(SysClkConfigValueList* out_configValues);
Result SetConfigValues(SysClkConfigValueList* configValues); Result SetConfigValues(SysClkConfigValueList* configValues);
Result SetReverseNXRTMode(ReverseNXMode mode);
bool running; bool running;
Thread thread; Thread thread;