summaryrefslogtreecommitdiff
path: root/src/common/wall_clock.h
diff options
context:
space:
mode:
authorZephyron <zephyron@citron-emu.org>2025-04-16 22:02:10 +1000
committerMike Lothian <mike@fireburn.co.uk>2025-05-12 12:46:19 +0100
commitea8bb22148a69ebe19b186073a06b21614913525 (patch)
treeb344da696dacba2c24921e6965c176015b44dedd /src/common/wall_clock.h
parent6a845fd03bdfcf3435f7da840e6af1be6b74fee3 (diff)
feat: add CPU clock rate slider to settings
Implement a slider in the CPU settings tab to adjust the BASE_CLOCK_RATE up to 1,785 MHz (Switch's official maximum clock rate). Default remains at 1,020 MHz. This change: - Adds UI slider and spinbox to configure_cpu.ui with range 500-1785 MHz - Makes BASE_CLOCK_RATE dynamic by reading from settings - Modifies WallClock to handle dynamic clock rate changes - Updates APM controller to properly set the clock rate - Changes clock rate settings category from Core to CPU The user can now easily adjust the CPU clock rate to improve performance or manage thermals and power consumption. Signed-off-by: Zephyron <zephyron@citron-emu.org>
Diffstat (limited to 'src/common/wall_clock.h')
-rw-r--r--src/common/wall_clock.h33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h
index 3a0c43909..8b971c3be 100644
--- a/src/common/wall_clock.h
+++ b/src/common/wall_clock.h
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
+// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
@@ -8,6 +9,7 @@
#include <ratio>
#include "common/common_types.h"
+#include "core/hardware_properties.h"
namespace Common {
@@ -15,7 +17,10 @@ class WallClock {
public:
static constexpr u64 CNTFRQ = 19'200'000; // CNTPCT_EL0 Frequency = 19.2 MHz
static constexpr u64 GPUTickFreq = 614'400'000; // GM20B GPU Tick Frequency = 614.4 MHz
- static constexpr u64 CPUTickFreq = 1'020'000'000; // T210/4 A57 CPU Tick Frequency = 1020.0 MHz
+ // Changed from constexpr to function to get dynamic value from settings
+ static inline u64 CPUTickFreq() {
+ return Core::Hardware::BASE_CLOCK_RATE();
+ } // T210/4 A57 CPU Tick Frequency from settings
virtual ~WallClock() = default;
@@ -76,12 +81,28 @@ protected:
using NsToCNTPCTRatio = std::ratio<CNTFRQ, std::nano::den>;
using NsToGPUTickRatio = std::ratio<GPUTickFreq, std::nano::den>;
- // Cycle Timing
+ // Cycle Timing - using functions for dynamic values
+
+ // Update these to use functions instead of constexpr
+ struct CPUTickToNsRatio {
+ static inline std::intmax_t num = std::nano::den;
+ static inline std::intmax_t den = CPUTickFreq();
+ };
+
+ struct CPUTickToUsRatio {
+ static inline std::intmax_t num = std::micro::den;
+ static inline std::intmax_t den = CPUTickFreq();
+ };
+
+ struct CPUTickToCNTPCTRatio {
+ static inline std::intmax_t num = CNTFRQ;
+ static inline std::intmax_t den = CPUTickFreq();
+ };
- using CPUTickToNsRatio = std::ratio<std::nano::den, CPUTickFreq>;
- using CPUTickToUsRatio = std::ratio<std::micro::den, CPUTickFreq>;
- using CPUTickToCNTPCTRatio = std::ratio<CNTFRQ, CPUTickFreq>;
- using CPUTickToGPUTickRatio = std::ratio<GPUTickFreq, CPUTickFreq>;
+ struct CPUTickToGPUTickRatio {
+ static inline std::intmax_t num = GPUTickFreq;
+ static inline std::intmax_t den = CPUTickFreq();
+ };
};
std::unique_ptr<WallClock> CreateOptimalClock();