linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Chen <chensong_2000@189.cn>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.com, vschneid@redhat.com
Cc: linux-kernel@vger.kernel.org, Song Chen <chensong_2000@189.cn>
Subject: [PATCH] kernel/sched/core: adjust rt_priority accordingly when prio is changed
Date: Wed,  1 Feb 2023 18:01:20 +0800	[thread overview]
Message-ID: <1675245680-2811-1-git-send-email-chensong_2000@189.cn> (raw)

When a high priority process is acquiring a rtmutex which is held by a
low priority process, the latter's priority will be boosted up by calling
rt_mutex_setprio->__setscheduler_prio.

However, p->prio is changed but p->rt_priority is not, as a result, the
equation between prio and rt_priority is broken, which is:

	prio = MAX_RT_PRIO - 1 - rt_priority

It's confusing to the user when it calls sched_getparam, which only
returns rt_priority.

This patch addresses this issue by adjusting rt_priority according to
the new value of prio, what's more, it also returns normal_prio for
CFS processes instead of just a zero.

Signed-off-by: Song Chen <chensong_2000@189.cn>
---
 kernel/sched/core.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index bb1ee6d7bdde..1c2c4ada08cc 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6933,14 +6933,16 @@ EXPORT_SYMBOL(default_wake_function);
 
 static void __setscheduler_prio(struct task_struct *p, int prio)
 {
+	p->prio = prio;
+
 	if (dl_prio(prio))
 		p->sched_class = &dl_sched_class;
-	else if (rt_prio(prio))
+	else if (rt_prio(prio)) {
+		p->rt_priority = MAX_RT_PRIO - 1 - prio;
 		p->sched_class = &rt_sched_class;
+	}
 	else
 		p->sched_class = &fair_sched_class;
-
-	p->prio = prio;
 }
 
 #ifdef CONFIG_RT_MUTEXES
@@ -8058,6 +8060,8 @@ SYSCALL_DEFINE2(sched_getparam, pid_t, pid, struct sched_param __user *, param)
 
 	if (task_has_rt_policy(p))
 		lp.sched_priority = p->rt_priority;
+	else
+		lp.sched_priority = normal_prio(p);
 	rcu_read_unlock();
 
 	/*
-- 
2.25.1


             reply	other threads:[~2023-02-01 10:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01 10:01 Song Chen [this message]
2023-02-01 15:56 ` [PATCH] kernel/sched/core: adjust rt_priority accordingly when prio is changed Steven Rostedt

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=1675245680-2811-1-git-send-email-chensong_2000@189.cn \
    --to=chensong_2000@189.cn \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).