Commit | Line | Data |
---|---|---|
b1696371 | 1 | // SPDX-License-Identifier: GPL-2.0 |
272ced25 | 2 | |
b1696371 DBO |
3 | #include <stdint.h> |
4 | #include <time.h> | |
272ced25 | 5 | #include <sched.h> |
b1696371 DBO |
6 | |
7 | /* | |
8 | * '18446744073709551615\0' | |
9 | */ | |
10 | #define BUFF_U64_STR_SIZE 24 | |
dada03db | 11 | #define MAX_PATH 1024 |
14f08c97 | 12 | #define MAX_NICE 20 |
13 | #define MIN_NICE -19 | |
b1696371 DBO |
14 | |
15 | #define container_of(ptr, type, member)({ \ | |
16 | const typeof(((type *)0)->member) *__mptr = (ptr); \ | |
17 | (type *)((char *)__mptr - offsetof(type, member)) ; }) | |
18 | ||
19 | extern int config_debug; | |
20 | void debug_msg(const char *fmt, ...); | |
21 | void err_msg(const char *fmt, ...); | |
22 | ||
23 | long parse_seconds_duration(char *val); | |
24 | void get_duration(time_t start_time, char *output, int output_size); | |
25 | ||
26 | int parse_cpu_list(char *cpu_list, char **monitored_cpus); | |
27 | long long get_llong_from_str(char *start); | |
28 | ||
29 | static inline void | |
30 | update_min(unsigned long long *a, unsigned long long *b) | |
31 | { | |
32 | if (*a > *b) | |
33 | *a = *b; | |
34 | } | |
35 | ||
36 | static inline void | |
37 | update_max(unsigned long long *a, unsigned long long *b) | |
38 | { | |
39 | if (*a < *b) | |
40 | *a = *b; | |
41 | } | |
42 | ||
43 | static inline void | |
44 | update_sum(unsigned long long *a, unsigned long long *b) | |
45 | { | |
46 | *a += *b; | |
47 | } | |
48 | ||
49 | struct sched_attr { | |
50 | uint32_t size; | |
51 | uint32_t sched_policy; | |
52 | uint64_t sched_flags; | |
53 | int32_t sched_nice; | |
54 | uint32_t sched_priority; | |
55 | uint64_t sched_runtime; | |
56 | uint64_t sched_deadline; | |
57 | uint64_t sched_period; | |
58 | }; | |
59 | ||
60 | int parse_prio(char *arg, struct sched_attr *sched_param); | |
272ced25 | 61 | int parse_cpu_set(char *cpu_list, cpu_set_t *set); |
cdca4f4e | 62 | int __set_sched_attr(int pid, struct sched_attr *attr); |
dada03db | 63 | int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr); |
a957cbc0 | 64 | int set_comm_cgroup(const char *comm_prefix, const char *cgroup); |
cdca4f4e | 65 | int set_pid_cgroup(pid_t pid, const char *cgroup); |
7d0dc957 | 66 | int set_cpu_dma_latency(int32_t latency); |
c58a3f8c | 67 | int auto_house_keeping(cpu_set_t *monitored_cpus); |
27e348b2 DBO |
68 | |
69 | #define ns_to_usf(x) (((double)x/1000)) | |
70 | #define ns_to_per(total, part) ((part * 100) / (double)total) |