Skip to content

Commit

Permalink
cpu: the user can customize the target /dev/cpu_dma_latency value
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmm committed Dec 6, 2024
1 parent 62455b4 commit f426cf9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/contents/ui/Cpu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ Kirigami.ScrollablePage {
}
}

FgSpinBox {
id: cpuDmaLatency

label: i18n("CPU DMA Latency")
from: 0
to: 1e+06
value: FGCpuBackend.cpuDmaLatency
decimals: 0
stepSize: 1
unit: "us"
enabled: useCpuDmaLatency.isChecked
onValueModified: (v) => {
FGCpuBackend.cpuDmaLatency = v;
}
}

FgSpinBox {
id: schedRuntime

Expand Down
10 changes: 10 additions & 0 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ void Backend::setUseCpuDmaLatency(const bool& value) {
Q_EMIT useCpuDmaLatencyChanged();
}

auto Backend::cpuDmaLatency() const -> int {
return _cpuDmaLatency;
}

void Backend::setCpuDmaLatency(const int& value) {
_cpuDmaLatency = value;

Q_EMIT cpuDmaLatencyChanged();
}

auto Backend::frequencyGovernor() -> std::string {
return frequencyGovernorModel.getValue(_frequencyGovernor).toStdString();
}
Expand Down
10 changes: 8 additions & 2 deletions src/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Backend : public QObject {

Q_PROPERTY(bool useCpuDmaLatency READ useCpuDmaLatency WRITE setUseCpuDmaLatency NOTIFY useCpuDmaLatencyChanged)

Q_PROPERTY(int cpuDmaLatency READ cpuDmaLatency WRITE setCpuDmaLatency NOTIFY cpuDmaLatencyChanged)

Q_PROPERTY(int frequencyGovernor MEMBER _frequencyGovernor NOTIFY frequencyGovernorChanged)

Q_PROPERTY(int pcieAspmPolicy MEMBER _pcieAspmPolicy NOTIFY pcieAspmPolicyChanged)
Expand Down Expand Up @@ -52,11 +54,12 @@ class Backend : public QObject {
[[nodiscard]] auto frequencyGovernor() -> std::string;
[[nodiscard]] auto pcieAspmPolicy() -> std::string;
[[nodiscard]] auto workqueueAffinityScope() -> std::string;
[[nodiscard]] auto cpuDmaLatency() const -> int;
[[nodiscard]] auto timerSlack() const -> int;
[[nodiscard]] auto schedRuntime() const -> double;
[[nodiscard]] auto cpuIntensiveThreshold() const -> int;
[[nodiscard]] auto niceness() const -> int;
[[nodiscard]] auto autogroupNiceness() const -> int;
[[nodiscard]] auto schedRuntime() const -> double;
[[nodiscard]] auto gameAffinity() const -> QString;
[[nodiscard]] auto wineServerAffinity() const -> QString;

Expand All @@ -67,11 +70,12 @@ class Backend : public QObject {
void setFrequencyGovernor(const std::string& value);
void setPcieAspmPolicy(const std::string& value);
void setWorkqueueAffinityScope(const std::string& value);
void setSchedRuntime(const double& value);
void setCpuDmaLatency(const int& value);
void setCpuIntensiveThreshold(const int& value);
void setNiceness(const int& value);
void setAutogroupNiceness(const int& value);
void setTimerSlack(const int& value);
void setSchedRuntime(const double& value);
void setGameAffinity(const QString& value);
void setWineServerAffinity(const QString& value);

Expand All @@ -80,6 +84,7 @@ class Backend : public QObject {
void realtimeWineserverChanged();
void enableWatchdogChanged();
void useCpuDmaLatencyChanged();
void cpuDmaLatencyChanged();
void frequencyGovernorChanged();
void pcieAspmPolicyChanged();
void workqueueAffinityScopeChanged();
Expand All @@ -97,6 +102,7 @@ class Backend : public QObject {
bool _enableWatchdog = false;
bool _useCpuDmaLatency = false;

int _cpuDmaLatency = 0;
int _frequencyGovernor;
int _pcieAspmPolicy;
int _workqueueAffinityScope;
Expand Down
2 changes: 1 addition & 1 deletion src/fastgame_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int {
int cpu_dma_latency_fd = -1;

if (root.get<bool>("cpu.use-cpu-dma-latency", false)) {
uint32_t target = 0;
uint32_t target = root.get<uint32_t>("cpu.cpu-dma-latency", 0);

cpu_dma_latency_fd = open("/dev/cpu_dma_latency", O_RDWR);

Expand Down
3 changes: 3 additions & 0 deletions src/presets_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ bool Backend::loadPreset(const QString& name) {

cpuBackend.setUseCpuDmaLatency(root.get<bool>("cpu.use-cpu-dma-latency", cpuBackend.useCpuDmaLatency()));

cpuBackend.setCpuDmaLatency(root.get<int>("cpu.cpu-dma-latency", cpuBackend.cpuDmaLatency()));

cpuBackend.setGameAffinity(
QString::fromStdString(root.get<std::string>("cpu.game-cores", cpuBackend.gameAffinity().toStdString())));

Expand Down Expand Up @@ -456,6 +458,7 @@ bool Backend::save_preset(const QString& name, const std::filesystem::path& outp
root.put("cpu.frequency-governor", cpuBackend.frequencyGovernor());
root.put("cpu.pcie-aspm-policy", cpuBackend.pcieAspmPolicy());
root.put("cpu.use-cpu-dma-latency", cpuBackend.useCpuDmaLatency());
root.put("cpu.cpu-dma-latency", cpuBackend.cpuDmaLatency());
root.put("cpu.use-realtime-wineserver", cpuBackend.realtimeWineserver());
root.put("cpu.enable-watchdog", cpuBackend.enableWatchdog());
root.put("cpu.niceness", cpuBackend.niceness());
Expand Down

0 comments on commit f426cf9

Please sign in to comment.