Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: LGPL-2.1
0002 #include <sched.h>
0003 
0004 /*
0005  * Not defined anywhere else, probably, just to make sure we
0006  * catch future flags
0007  */
0008 #define SCHED_POLICY_MASK 0xff
0009 
0010 #ifndef SCHED_DEADLINE
0011 #define SCHED_DEADLINE 6
0012 #endif
0013 #ifndef SCHED_RESET_ON_FORK
0014 #define SCHED_RESET_ON_FORK 0x40000000
0015 #endif
0016 
0017 static size_t syscall_arg__scnprintf_sched_policy(char *bf, size_t size,
0018                           struct syscall_arg *arg)
0019 {
0020     bool show_prefix = arg->show_string_prefix;
0021     const char *prefix = "SCHED_";
0022     const char *policies[] = {
0023         "NORMAL", "FIFO", "RR", "BATCH", "ISO", "IDLE", "DEADLINE",
0024     };
0025     size_t printed;
0026     int policy = arg->val,
0027         flags = policy & ~SCHED_POLICY_MASK;
0028 
0029     policy &= SCHED_POLICY_MASK;
0030     if (policy <= SCHED_DEADLINE)
0031         printed = scnprintf(bf, size, "%s%s", show_prefix ? prefix : "", policies[policy]);
0032     else
0033         printed = scnprintf(bf, size, "%#x", policy);
0034 
0035 #define P_POLICY_FLAG(n) \
0036     if (flags & SCHED_##n) { \
0037         printed += scnprintf(bf + printed, size - printed, "|%s%s", show_prefix ? prefix : "",  #n); \
0038         flags &= ~SCHED_##n; \
0039     }
0040 
0041     P_POLICY_FLAG(RESET_ON_FORK);
0042 #undef P_POLICY_FLAG
0043 
0044     if (flags)
0045         printed += scnprintf(bf + printed, size - printed, "|%#x", flags);
0046 
0047     return printed;
0048 }
0049 
0050 #define SCA_SCHED_POLICY syscall_arg__scnprintf_sched_policy