summaryrefslogtreecommitdiff
path: root/tools/tracing/rtla/src/utils.h
blob: 5571afd3b549863922df3d71e8c68a732867c0c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: GPL-2.0
#include <stdint.h>
#include <time.h>

/*
 * '18446744073709551615\0'
 */
#define BUFF_U64_STR_SIZE	24
#define MAX_PATH		1024

#define container_of(ptr, type, member)({			\
	const typeof(((type *)0)->member) *__mptr = (ptr);	\
	(type *)((char *)__mptr - offsetof(type, member)) ; })

extern int config_debug;
void debug_msg(const char *fmt, ...);
void err_msg(const char *fmt, ...);

long parse_seconds_duration(char *val);
void get_duration(time_t start_time, char *output, int output_size);

int parse_cpu_list(char *cpu_list, char **monitored_cpus);
long long get_llong_from_str(char *start);

static inline void
update_min(unsigned long long *a, unsigned long long *b)
{
	if (*a > *b)
		*a = *b;
}

static inline void
update_max(unsigned long long *a, unsigned long long *b)
{
	if (*a < *b)
		*a = *b;
}

static inline void
update_sum(unsigned long long *a, unsigned long long *b)
{
	*a += *b;
}

struct sched_attr {
	uint32_t size;
	uint32_t sched_policy;
	uint64_t sched_flags;
	int32_t sched_nice;
	uint32_t sched_priority;
	uint64_t sched_runtime;
	uint64_t sched_deadline;
	uint64_t sched_period;
};

int parse_prio(char *arg, struct sched_attr *sched_param);
int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr);
int set_cpu_dma_latency(int32_t latency);