|
1 | 1 | #include "util.hpp" |
2 | 2 | #include <bits/types/struct_sched_param.h> |
3 | 3 | #include <fcntl.h> |
| 4 | +#include <linux/sched/types.h> |
4 | 5 | #include <qdebug.h> |
5 | 6 | #include <qlogging.h> |
6 | 7 | #include <sched.h> |
|
24 | 25 |
|
25 | 26 | namespace util { |
26 | 27 |
|
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 | | - |
44 | 28 | static auto prepare_debug_message(const std::string& message, source_location location) -> std::string { |
45 | 29 | auto file_path = std::filesystem::path{location.file_name()}; |
46 | 30 |
|
@@ -199,29 +183,29 @@ void set_process_scheduler(const int& pid, const int& policy_index, const int& p |
199 | 183 | sched_setscheduler(pid, policy_index, &policy_params); |
200 | 184 | } |
201 | 185 |
|
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 = {}; |
208 | 188 |
|
209 | 189 | attr.size = sizeof(sched_attr); |
210 | 190 | attr.sched_policy = policy_index; |
211 | 191 | attr.sched_runtime = value * 1000 * 1000; // ms in nanoseconds |
212 | 192 | attr.sched_nice = nice; |
213 | 193 |
|
214 | | - if (syscall(SYS_sched_setattr, pid, &attr, flags) != 0) { |
| 194 | + if (syscall(SYS_sched_setattr, pid, &attr, 0) != 0) { |
215 | 195 | perror("sched_setattr"); |
216 | 196 | } |
217 | 197 | } |
218 | 198 |
|
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 = {}; |
221 | 201 |
|
222 | 202 | attr.size = sizeof(sched_attr); |
223 | 203 |
|
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 | + } |
225 | 209 |
|
226 | 210 | return attr.sched_runtime; |
227 | 211 | } |
|
0 commit comments