GNU Linux-libre 4.9.337-gnu1
[releases.git] / tools / perf / trace / beauty / sched_policy.c
1 #include <sched.h>
2
3 /*
4  * Not defined anywhere else, probably, just to make sure we
5  * catch future flags
6  */
7 #define SCHED_POLICY_MASK 0xff
8
9 #ifndef SCHED_DEADLINE
10 #define SCHED_DEADLINE 6
11 #endif
12 #ifndef SCHED_RESET_ON_FORK
13 #define SCHED_RESET_ON_FORK 0x40000000
14 #endif
15
16 static size_t syscall_arg__scnprintf_sched_policy(char *bf, size_t size,
17                                                   struct syscall_arg *arg)
18 {
19         const char *policies[] = {
20                 "NORMAL", "FIFO", "RR", "BATCH", "ISO", "IDLE", "DEADLINE",
21         };
22         size_t printed;
23         int policy = arg->val,
24             flags = policy & ~SCHED_POLICY_MASK;
25
26         policy &= SCHED_POLICY_MASK;
27         if (policy <= SCHED_DEADLINE)
28                 printed = scnprintf(bf, size, "%s", policies[policy]);
29         else
30                 printed = scnprintf(bf, size, "%#x", policy);
31
32 #define P_POLICY_FLAG(n) \
33         if (flags & SCHED_##n) { \
34                 printed += scnprintf(bf + printed, size - printed, "|%s", #n); \
35                 flags &= ~SCHED_##n; \
36         }
37
38         P_POLICY_FLAG(RESET_ON_FORK);
39 #undef P_POLICY_FLAG
40
41         if (flags)
42                 printed += scnprintf(bf + printed, size - printed, "|%#x", flags);
43
44         return printed;
45 }
46
47 #define SCA_SCHED_POLICY syscall_arg__scnprintf_sched_policy