Skip to contentSkip to conversation

Can't change priority via sys_sched_setscheduler()?

DISCUSSION Malcolm Rowe 1 participant 1 message Apr 28, 2006

lore
Share & tools
lore
#0 lore raw

Sorry, this is probably a silly question, but what's the correct way to adjust (reduce, in my case) the priority of a SCHED_NORMAL/SCHED_OTHER pthread?

glibc translates calls to pthread_setschedprio and pthread_setschedparam into sys_sched_setparam and sys_sched_setscheduler respectively, which both end up at sched_setscheduler(), which does:

        /*
         * Valid priorities for SCHED_FIFO and SCHED_RR are
         * 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL and
         * SCHED_BATCH is 0.
         */
        if (param->sched_priority < 0 ||
            (p->mm && param->sched_priority > MAX_USER_RT_PRIO-1) ||
            (!p->mm && param->sched_priority > MAX_RT_PRIO-1))
                return -EINVAL;
        if ((policy == SCHED_NORMAL || policy == SCHED_BATCH)
                                        != (param->sched_priority == 0))
                return -EINVAL;

So calls to (for example)
struct sched_param sp = {9}; pthread_setschedparam(scthread, SCHED_OTHER, &sp);

Will fail with EINVAL. Yet calls to setpriority(PRIO_PROCESS, 0, 9) within the thread will work as expected.

I suspect I'm missing something - what is it?

Thanks,
Malcolm
(please cc: me, I'm not subscribed)