xref: /openbmc/linux/tools/perf/trace/beauty/sched_policy.c (revision 597473720f4dc69749542bfcfed4a927a43d935e)
1794f594eSArnaldo Carvalho de Melo // SPDX-License-Identifier: LGPL-2.1
2a3bca91fSArnaldo Carvalho de Melo #include <sched.h>
3a3bca91fSArnaldo Carvalho de Melo 
4a3bca91fSArnaldo Carvalho de Melo /*
5a3bca91fSArnaldo Carvalho de Melo  * Not defined anywhere else, probably, just to make sure we
6a3bca91fSArnaldo Carvalho de Melo  * catch future flags
7a3bca91fSArnaldo Carvalho de Melo  */
8a3bca91fSArnaldo Carvalho de Melo #define SCHED_POLICY_MASK 0xff
9a3bca91fSArnaldo Carvalho de Melo 
10a3bca91fSArnaldo Carvalho de Melo #ifndef SCHED_DEADLINE
11a3bca91fSArnaldo Carvalho de Melo #define SCHED_DEADLINE 6
12a3bca91fSArnaldo Carvalho de Melo #endif
13a41af25bSArnaldo Carvalho de Melo #ifndef SCHED_RESET_ON_FORK
14a41af25bSArnaldo Carvalho de Melo #define SCHED_RESET_ON_FORK 0x40000000
15a41af25bSArnaldo Carvalho de Melo #endif
16a3bca91fSArnaldo Carvalho de Melo 
syscall_arg__scnprintf_sched_policy(char * bf,size_t size,struct syscall_arg * arg)17a3bca91fSArnaldo Carvalho de Melo static size_t syscall_arg__scnprintf_sched_policy(char *bf, size_t size,
18a3bca91fSArnaldo Carvalho de Melo 						  struct syscall_arg *arg)
19a3bca91fSArnaldo Carvalho de Melo {
20*c65c83ffSArnaldo Carvalho de Melo 	bool show_prefix = arg->show_string_prefix;
21*c65c83ffSArnaldo Carvalho de Melo 	const char *prefix = "SCHED_";
22a3bca91fSArnaldo Carvalho de Melo 	const char *policies[] = {
23a3bca91fSArnaldo Carvalho de Melo 		"NORMAL", "FIFO", "RR", "BATCH", "ISO", "IDLE", "DEADLINE",
24a3bca91fSArnaldo Carvalho de Melo 	};
25a3bca91fSArnaldo Carvalho de Melo 	size_t printed;
26a3bca91fSArnaldo Carvalho de Melo 	int policy = arg->val,
27a3bca91fSArnaldo Carvalho de Melo 	    flags = policy & ~SCHED_POLICY_MASK;
28a3bca91fSArnaldo Carvalho de Melo 
29a3bca91fSArnaldo Carvalho de Melo 	policy &= SCHED_POLICY_MASK;
30a3bca91fSArnaldo Carvalho de Melo 	if (policy <= SCHED_DEADLINE)
31*c65c83ffSArnaldo Carvalho de Melo 		printed = scnprintf(bf, size, "%s%s", show_prefix ? prefix : "", policies[policy]);
32a3bca91fSArnaldo Carvalho de Melo 	else
33a3bca91fSArnaldo Carvalho de Melo 		printed = scnprintf(bf, size, "%#x", policy);
34a3bca91fSArnaldo Carvalho de Melo 
35a3bca91fSArnaldo Carvalho de Melo #define	P_POLICY_FLAG(n) \
36a3bca91fSArnaldo Carvalho de Melo 	if (flags & SCHED_##n) { \
37*c65c83ffSArnaldo Carvalho de Melo 		printed += scnprintf(bf + printed, size - printed, "|%s%s", show_prefix ? prefix : "",  #n); \
38a3bca91fSArnaldo Carvalho de Melo 		flags &= ~SCHED_##n; \
39a3bca91fSArnaldo Carvalho de Melo 	}
40a3bca91fSArnaldo Carvalho de Melo 
41a3bca91fSArnaldo Carvalho de Melo 	P_POLICY_FLAG(RESET_ON_FORK);
42a3bca91fSArnaldo Carvalho de Melo #undef P_POLICY_FLAG
43a3bca91fSArnaldo Carvalho de Melo 
44a3bca91fSArnaldo Carvalho de Melo 	if (flags)
45a3bca91fSArnaldo Carvalho de Melo 		printed += scnprintf(bf + printed, size - printed, "|%#x", flags);
46a3bca91fSArnaldo Carvalho de Melo 
47a3bca91fSArnaldo Carvalho de Melo 	return printed;
48a3bca91fSArnaldo Carvalho de Melo }
49a3bca91fSArnaldo Carvalho de Melo 
50a3bca91fSArnaldo Carvalho de Melo #define SCA_SCHED_POLICY syscall_arg__scnprintf_sched_policy
51