int main(void) { struct sched_attr* attr; ALLOCATE_GUARD(attr, 'x'); test_assert(0 == sched_getattr(0, attr, sizeof(*attr), 0)); /* Don't check specific scheduling parameters in case someone is running the rr tests with low priority or something like that */ test_assert(attr->size == sizeof(*attr)); test_assert(attr->flags == 0); VERIFY_GUARD(attr); test_assert(0 == sched_setattr(0, attr, 0)); VERIFY_GUARD(attr); atomic_puts("EXIT-SUCCESS"); return 0; }
static void show_sched_pid_info(struct chrt_ctl *ctl, pid_t pid) { int policy, reset_on_fork = 0, prio = 0; #ifdef SCHED_DEADLINE uint64_t deadline = 0, runtime = 0, period = 0; #endif /* don't display "pid 0" as that is confusing */ if (!pid) pid = getpid(); #ifdef HAVE_SCHED_SETATTR { struct sched_attr sa; if (sched_getattr(pid, &sa, sizeof(sa), 0) != 0) err(EXIT_FAILURE, _("failed to get pid %d's policy"), pid); policy = sa.sched_policy; prio = sa.sched_priority; reset_on_fork = sa.sched_flags & SCHED_FLAG_RESET_ON_FORK; deadline = sa.sched_deadline; runtime = sa.sched_runtime; period = sa.sched_period; } #else /* !HAVE_SCHED_SETATTR */ { struct sched_param sp; policy = sched_getscheduler(pid); if (policy == -1) err(EXIT_FAILURE, _("failed to get pid %d's policy"), pid); if (sched_getparam(pid, &sp) != 0) err(EXIT_FAILURE, _("failed to get pid %d's attributes"), pid); else prio = sp.sched_priority; # ifdef SCHED_RESET_ON_FORK if (policy == (SCHED_FIFO|SCHED_RESET_ON_FORK) || policy == (SCHED_BATCH|SCHED_RESET_ON_FORK)) reset_on_fork = 1; # endif } #endif /* !HAVE_SCHED_SETATTR */ if (ctl->altered) printf(_("pid %d's new scheduling policy: %s"), pid, get_policy_name(policy)); else printf(_("pid %d's current scheduling policy: %s"), pid, get_policy_name(policy)); if (reset_on_fork) printf("|SCHED_RESET_ON_FORK"); putchar('\n'); if (ctl->altered) printf(_("pid %d's new scheduling priority: %d\n"), pid, prio); else printf(_("pid %d's current scheduling priority: %d\n"), pid, prio); #ifdef SCHED_DEADLINE if (policy == SCHED_DEADLINE) { if (ctl->altered) printf(_("pid %d's new runtime/deadline/period parameters: %ju/%ju/%ju\n"), pid, runtime, deadline, period); else printf(_("pid %d's current runtime/deadline/period parameters: %ju/%ju/%ju\n"), pid, runtime, deadline, period); } #endif }