From patchwork Wed Feb 1 10:01:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Chen X-Patchwork-Id: 51264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp187516wrn; Wed, 1 Feb 2023 02:07:50 -0800 (PST) X-Google-Smtp-Source: AK7set8C1WTfbwlX0fuMdH/LEoo2a0Lwx5K1ViMYxSSfQWMWDyHSfjFqCu/q7/q29BPOPyLDVQon X-Received: by 2002:a17:907:1607:b0:878:46ed:6a29 with SMTP id hb7-20020a170907160700b0087846ed6a29mr2430597ejc.3.1675246070494; Wed, 01 Feb 2023 02:07:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675246070; cv=none; d=google.com; s=arc-20160816; b=ySm1D7VLLnPd3K7LL32BxiGt5D2w6kl99Ud7seOgzkIa9XRUALnmIWiwvVTKPDaU6Z IsW1y7VPJYo8Y0Pkx3c9TruO344PhxOYSFKwtA5/raRx4yPlwbo615rluke7MLPOGBQ8 +S4932NM0oBF/ogj3wG0cT3XMevWyN18NeX4N6bvTPZCsO5+5Xz+1AMaClbtkFTBikK3 4jl+yIXiRIJECZu5OjisYaNbMZVoqEmnKtn31XXXjno5bbgRIbK3GZiIn+h9da4yUNb0 Ww9zN/EOfMgEELXd9S0HJjIpPq2HcED8DUjRDDCQaNkuocdYnMUMLUoYqNgr4FUuZf9H D9Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=pRToZecHvxfaxGUxpkk0qJe+Gduj7HsRb5J5nitRgmU=; b=E0v1sltE+PukfNMuTBmvWhAayAtPkPEOaXwYIF03FocDANaHZVGT69WivuPZIvKI+L sq5iBLE7Uik1sLkU80uGBlL7UTFGkAUBw2KgT6q/5QTrWcaIfSdkWCp8Ce4204VfpkD0 2XXV7PGWaP2YTDFUJwEKllsxhcd0K+m2IYspPqixSQMpy/B7EsgvNzo0NGpLMQ/Za8Mb 2GxTTLxoBK/KrTPxeX+KHbpsXgt448QWIUvkbLQBZ8Igi4117h4/6T2M5u86I5jHSzKv NXiJB6WXdOrL7RRoYnwQaUivldBOrPN3AzisRYHRQtHsVKz+/Rq39P4RTIKziI2j1UkQ Rqbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ka6-20020a170907920600b0087ba20a814esi17444901ejb.643.2023.02.01.02.07.27; Wed, 01 Feb 2023 02:07:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229567AbjBAKBE (ORCPT + 99 others); Wed, 1 Feb 2023 05:01:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232303AbjBAKAz (ORCPT ); Wed, 1 Feb 2023 05:00:55 -0500 Received: from 189.cn (ptr.189.cn [183.61.185.102]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3A4AE32517 for ; Wed, 1 Feb 2023 02:00:52 -0800 (PST) HMM_SOURCE_IP: 10.64.8.31:49242.919551229 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id C7CAB1002AE; Wed, 1 Feb 2023 18:00:49 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-5cf44cb88-lf9qz with ESMTP id 2a85ec2559e34408a72b32d4ebc4d7fa for mingo@redhat.com; Wed, 01 Feb 2023 18:00:50 CST X-Transaction-ID: 2a85ec2559e34408a72b32d4ebc4d7fa X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 Sender: chensong_2000@189.cn From: Song Chen 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 Subject: [PATCH] kernel/sched/core: adjust rt_priority accordingly when prio is changed Date: Wed, 1 Feb 2023 18:01:20 +0800 Message-Id: <1675245680-2811-1-git-send-email-chensong_2000@189.cn> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756622823427379363?= X-GMAIL-MSGID: =?utf-8?q?1756622823427379363?= 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 --- 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(); /*