Skip to content

Commit 5130cd8

Browse files
committed
Better sched_runtime handling
1 parent e03876e commit 5130cd8

5 files changed

Lines changed: 22 additions & 42 deletions

File tree

src/cpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Backend::Backend(QObject* parent) : QObject(parent) {
4646
initPcieAspm();
4747
init_workqueue_affinity_scope();
4848

49-
setSchedRuntime(util::get_sched_runtime(0, 0) * 0.000001);
49+
setSchedRuntime(util::get_sched_runtime(0) * 0.000001);
5050
}
5151

5252
auto Backend::useSchedBatch() const -> bool {

src/fastgame_apply.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int {
235235
auto use_realtime_wineserver = root.get<bool>("cpu.use-realtime-wineserver", false);
236236
int niceness = root.get<int>("cpu.niceness", 0);
237237
int autogroup_niceness = root.get<int>("cpu.autogroup-niceness", 0);
238-
double sched_runtime = root.get<double>("cpu.sched-runtime", util::get_sched_runtime(0, 0));
238+
double sched_runtime = root.get<double>("cpu.sched-runtime", util::get_sched_runtime(0));
239239

240240
update_system_setting("/proc/sys/kernel/watchdog", root.get<bool>("cpu.enable-watchdog", true));
241241

@@ -413,10 +413,10 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int {
413413
update_system_setting("/proc/" + util::to_string(game_pid) + "/autogroup", autogroup_niceness);
414414

415415
if (use_batch_scheduler) {
416-
util::set_sched_runtime(game_pid, sched_runtime, SCHED_BATCH, niceness, 0);
416+
util::set_sched_runtime(game_pid, sched_runtime, SCHED_BATCH, niceness);
417417

418418
} else {
419-
util::set_sched_runtime(game_pid, sched_runtime, SCHED_OTHER, niceness, 0);
419+
util::set_sched_runtime(game_pid, sched_runtime, SCHED_OTHER, niceness);
420420
}
421421

422422
if (enable_realtime_io_priority) {
@@ -443,9 +443,9 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int {
443443
if (use_batch_scheduler) {
444444
util::set_process_scheduler(child_pid, SCHED_BATCH, 0);
445445

446-
util::set_sched_runtime(child_pid, sched_runtime, SCHED_BATCH, niceness, 0);
446+
util::set_sched_runtime(child_pid, sched_runtime, SCHED_BATCH, niceness);
447447
} else {
448-
util::set_sched_runtime(child_pid, sched_runtime, SCHED_OTHER, niceness, 0);
448+
util::set_sched_runtime(child_pid, sched_runtime, SCHED_OTHER, niceness);
449449
}
450450

451451
setpriority(PRIO_PROCESS, child_pid, niceness);

src/fastgame_launcher.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ auto main(int argc, char* argv[]) -> int {
7575

7676
util::apply_cpu_affinity(0, cpu_affinity);
7777

78-
double sched_runtime = root.get<double>("cpu.sched-runtime", util::get_sched_runtime(0, 0));
78+
double sched_runtime = root.get<double>("cpu.sched-runtime", util::get_sched_runtime(0));
7979

8080
if (root.get<bool>("cpu.use-batch-scheduler")) {
8181
util::set_process_scheduler(0, SCHED_BATCH, 0);
8282

83-
util::set_sched_runtime(0, sched_runtime, SCHED_BATCH, 0, 0);
83+
util::set_sched_runtime(0, sched_runtime, SCHED_BATCH, 0);
8484
} else {
85-
util::set_sched_runtime(0, sched_runtime, SCHED_OTHER, 0, 0);
85+
util::set_sched_runtime(0, sched_runtime, SCHED_OTHER, 0);
8686
}
8787

8888
int timer_slack_ns = root.get<int>("cpu.timer-slack", 50000);

src/util.cpp

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "util.hpp"
22
#include <bits/types/struct_sched_param.h>
33
#include <fcntl.h>
4+
#include <linux/sched/types.h>
45
#include <qdebug.h>
56
#include <qlogging.h>
67
#include <sched.h>
@@ -24,23 +25,6 @@
2425

2526
namespace util {
2627

27-
struct sched_attr {
28-
uint32_t size; /* Size of this structure */
29-
uint32_t sched_policy; /* Policy (SCHED_*) */
30-
uint64_t sched_flags; /* Flags */
31-
int32_t sched_nice; /* Nice value (SCHED_OTHER, SCHED_BATCH) */
32-
uint32_t sched_priority; /* Static priority (SCHED_FIFO, SCHED_RR) */
33-
34-
/* For SCHED_DEADLINE */
35-
uint64_t sched_runtime;
36-
uint64_t sched_deadline;
37-
uint64_t sched_period;
38-
39-
/* Utilization hints */
40-
uint32_t sched_util_min;
41-
uint32_t sched_util_max;
42-
};
43-
4428
static auto prepare_debug_message(const std::string& message, source_location location) -> std::string {
4529
auto file_path = std::filesystem::path{location.file_name()};
4630

@@ -199,29 +183,29 @@ void set_process_scheduler(const int& pid, const int& policy_index, const int& p
199183
sched_setscheduler(pid, policy_index, &policy_params);
200184
}
201185

202-
void set_sched_runtime(const int& pid,
203-
const double& value,
204-
const int& policy_index,
205-
const int& nice,
206-
const uint& flags) {
207-
sched_attr attr = {};
186+
void set_sched_runtime(const int& pid, const double& value, const int& policy_index, const int& nice) {
187+
struct sched_attr attr = {};
208188

209189
attr.size = sizeof(sched_attr);
210190
attr.sched_policy = policy_index;
211191
attr.sched_runtime = value * 1000 * 1000; // ms in nanoseconds
212192
attr.sched_nice = nice;
213193

214-
if (syscall(SYS_sched_setattr, pid, &attr, flags) != 0) {
194+
if (syscall(SYS_sched_setattr, pid, &attr, 0) != 0) {
215195
perror("sched_setattr");
216196
}
217197
}
218198

219-
auto get_sched_runtime(const int& pid, const uint& flags) -> uint64_t {
220-
sched_attr attr = {};
199+
auto get_sched_runtime(const int& pid) -> uint64_t {
200+
struct sched_attr attr = {};
221201

222202
attr.size = sizeof(sched_attr);
223203

224-
syscall(SYS_sched_getattr, pid, &attr, attr.size, flags);
204+
if (syscall(SYS_sched_getattr, pid, &attr, attr.size, 0) != 0) {
205+
perror("sched_getattr");
206+
207+
return 0;
208+
}
225209

226210
return attr.sched_runtime;
227211
}

src/util.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,9 @@ void clear_cpu_affinity(const int& pid);
3939

4040
void set_process_scheduler(const int& pid, const int& policy_index, const int& priority);
4141

42-
void set_sched_runtime(const int& pid,
43-
const double& value,
44-
const int& policy_index,
45-
const int& nice,
46-
const uint& flags);
42+
void set_sched_runtime(const int& pid, const double& value, const int& policy_index, const int& nice);
4743

48-
auto get_sched_runtime(const int& pid, const uint& flags) -> uint64_t;
44+
auto get_sched_runtime(const int& pid) -> uint64_t;
4945

5046
auto card_is_amdgpu(const int& card_index) -> bool;
5147

0 commit comments

Comments
 (0)