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