sched_policy.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: LGPL-2.1
  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. bool show_prefix = arg->show_string_prefix;
  18. const char *prefix = "SCHED_";
  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. policy &= SCHED_POLICY_MASK;
  26. if (policy <= SCHED_DEADLINE)
  27. printed = scnprintf(bf, size, "%s%s", show_prefix ? prefix : "", policies[policy]);
  28. else
  29. printed = scnprintf(bf, size, "%#x", policy);
  30. #define P_POLICY_FLAG(n) \
  31. if (flags & SCHED_##n) { \
  32. printed += scnprintf(bf + printed, size - printed, "|%s%s", show_prefix ? prefix : "", #n); \
  33. flags &= ~SCHED_##n; \
  34. }
  35. P_POLICY_FLAG(RESET_ON_FORK);
  36. #undef P_POLICY_FLAG
  37. if (flags)
  38. printed += scnprintf(bf + printed, size - printed, "|%#x", flags);
  39. return printed;
  40. }
  41. #define SCA_SCHED_POLICY syscall_arg__scnprintf_sched_policy