public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Valentin Schneider <valentin.schneider@arm.com>
To: Hillf Danton <hdanton@sina.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Mike Galbraith <efault@gmx.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mel Gorman <mgorman@techsingularity.net>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Phil Auld <pauld@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH 2/4] sched: set new prio after checking schedule policy
Date: Tue, 28 Apr 2020 17:32:45 +0100	[thread overview]
Message-ID: <jhjh7x3sh8y.mognet@arm.com> (raw)
In-Reply-To: <20200424043650.14940-1-hdanton@sina.com>


On 24/04/20 05:36, Hillf Danton wrote:
> Set newprio the same way as normal_prio() does after checking schedule
> policy and to MAX_PRIO -1 by default.
>
> What is also added is boundary checks for RT and fair priorities.
>
> Cc: Mike Galbraith <efault@gmx.de>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Mel Gorman <mgorman@techsingularity.net>
> Cc: Vincent Guittot <vincent.guittot@linaro.org>
> Cc: Phil Auld <pauld@redhat.com>
> Cc: Valentin Schneider <valentin.schneider@arm.com>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Hillf Danton <hdanton@sina.com>
> ---
>
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -4768,8 +4768,7 @@ static int __sched_setscheduler(struct t
>                               const struct sched_attr *attr,
>                               bool user, bool pi)
>  {
> -	int newprio = dl_policy(attr->sched_policy) ? MAX_DL_PRIO - 1 :
> -		      MAX_RT_PRIO - 1 - attr->sched_priority;
> +	int newprio;
>       int retval, oldprio, oldpolicy = -1, queued, running;
>       int new_effective_prio, policy = attr->sched_policy;
>       const struct sched_class *prev_class;
> @@ -4800,6 +4799,26 @@ recheck:
>               return -EINVAL;
>
>       /*
> +	 * compute newprio after checking policy, see normal_prio();
> +	 * it's used in pi boost below
> +	 */
> +	if (dl_policy(policy)) {
> +		newprio = MAX_DL_PRIO - 1;
> +	}
> +	else if (rt_policy(policy)) {
> +		if (attr->sched_priority > MAX_RT_PRIO - 1)
> +			return -EINVAL;
> +		newprio = MAX_RT_PRIO - 1 - attr->sched_priority;
> +	}
> +	else if (fair_policy(policy)) {
> +		if (attr->sched_nice < MIN_NICE ||
> +		    attr->sched_nice > MAX_NICE)
> +			return -EINVAL;


We can't hit this with the syscall route, since we (silently) clamp those
values in sched_copy_attr(). setpriority() does the same. There's this
comment in sched_copy_attr() that asks whether we should clamp or return an
error; seems like the current consensus is on clamping, but then we might
want to get rid of that comment :)

> +		newprio = NICE_TO_PRIO(attr->sched_nice);

This is new, however AFAICT it doesn't change anything for CFS (or about to
be) tasks since what matters is calling check_class_changed() further
down.

> +	} else
> +		newprio = MAX_PRIO - 1;
> +
> +	/*
>        * Allow unprivileged RT tasks to decrease priority:
>        */
>       if (user && !capable(CAP_SYS_NICE)) {

  parent reply	other threads:[~2020-04-28 16:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200424041832.11364-1-hdanton@sina.com>
     [not found] ` <20200424043041.15084-1-hdanton@sina.com>
2020-04-24 13:55   ` [PATCH 1/4] sched: set p->prio reguardless of p->mm Steven Rostedt
     [not found] ` <20200424043650.14940-1-hdanton@sina.com>
2020-04-28 16:32   ` Valentin Schneider [this message]
     [not found]   ` <20200430121301.3460-1-hdanton@sina.com>
2020-04-30 14:06     ` [PATCH 2/4] sched: set new prio after checking schedule policy Dietmar Eggemann
2020-04-30 14:18       ` Valentin Schneider
2020-04-30 15:13         ` Valentin Schneider

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jhjh7x3sh8y.mognet@arm.com \
    --to=valentin.schneider@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=efault@gmx.de \
    --cc=hdanton@sina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mgorman@techsingularity.net \
    --cc=mingo@kernel.org \
    --cc=pauld@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox