sched_policy.c 1.1 KB

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