Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / trace / beauty / sched_policy.c
blob68aa59eeed8dcf3ff8ad2b62ee5d9f5225ca0b18
1 // SPDX-License-Identifier: LGPL-2.1
2 #include <sched.h>
4 /*
5 * Not defined anywhere else, probably, just to make sure we
6 * catch future flags
7 */
8 #define SCHED_POLICY_MASK 0xff
10 #ifndef SCHED_DEADLINE
11 #define SCHED_DEADLINE 6
12 #endif
13 #ifndef SCHED_RESET_ON_FORK
14 #define SCHED_RESET_ON_FORK 0x40000000
15 #endif
17 static size_t syscall_arg__scnprintf_sched_policy(char *bf, size_t size,
18 struct syscall_arg *arg)
20 bool show_prefix = arg->show_string_prefix;
21 const char *prefix = "SCHED_";
22 const char *policies[] = {
23 "NORMAL", "FIFO", "RR", "BATCH", "ISO", "IDLE", "DEADLINE",
25 size_t printed;
26 int policy = arg->val,
27 flags = policy & ~SCHED_POLICY_MASK;
29 policy &= SCHED_POLICY_MASK;
30 if (policy <= SCHED_DEADLINE)
31 printed = scnprintf(bf, size, "%s%s", show_prefix ? prefix : "", policies[policy]);
32 else
33 printed = scnprintf(bf, size, "%#x", policy);
35 #define P_POLICY_FLAG(n) \
36 if (flags & SCHED_##n) { \
37 printed += scnprintf(bf + printed, size - printed, "|%s%s", show_prefix ? prefix : "", #n); \
38 flags &= ~SCHED_##n; \
41 P_POLICY_FLAG(RESET_ON_FORK);
42 #undef P_POLICY_FLAG
44 if (flags)
45 printed += scnprintf(bf + printed, size - printed, "|%#x", flags);
47 return printed;
50 #define SCA_SCHED_POLICY syscall_arg__scnprintf_sched_policy