From patchwork Wed Feb 22 08:03:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuewen Yan X-Patchwork-Id: 60364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp446318wrd; Wed, 22 Feb 2023 00:07:04 -0800 (PST) X-Google-Smtp-Source: AK7set+0+a/R+h8bHxZbdq5Cm+CjBBiToXl7lm6eI8tvgxOKS3e3DzVdrcNWeeF33Xayy3he29DB X-Received: by 2002:aa7:d4c1:0:b0:4ab:4bf9:a10f with SMTP id t1-20020aa7d4c1000000b004ab4bf9a10fmr5579287edr.30.1677053224036; Wed, 22 Feb 2023 00:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677053224; cv=none; d=google.com; s=arc-20160816; b=XS8A5anXG3tAMRr1xaGK/6/VB7lNwbYGuAUBBcMVWzbrgbfuB80cVw4Yg9JmrUZLv/ XJb2O1nUXDFFTHhxz32aVPHTdxNIA+2u0V+OPzg/EmdJwnVLYmP7Kh/neofoeRhQlFph 4ThsTH8TxtZ7xqImUoP4/VKZ2rPQukFxgcZyfbQo79vt8yHpVkm8agq5GN+GRqgaedwH LRsL392PzBsAqGebN7iSMfFq+PfYJHPUrSe2bpOetU3vlr5B7nAaiZErTWwoXTj6LvQV Ram/ZK4pEQ0U1Xh+EY8iuFGTNeo2GVUDwIf7Tt5JBQyM+cXdt3XxDtTbChAaq+SYqW3Y oAdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=+78kfHKoMqJSPFXtedo6pBOzHXI0mYfmApVAtWZ0Nr0=; b=P1PXby2HnOAiH6jz6B8/8/ee2l6vG3I6h06qQbMv1CaDDdXyIx7lELXtqeHuhb0+p7 QSM9Drib9VwIyoqeWqsulugrEhZYImg3LwWk74+L0F6t2pXDlcTxGrtR9xYm37AjKzUH VjPrpMRjF3ISaL8vh6SS7rPymp9xF8jivJvuzFjigo6r60j+MUCEjSLeiv96RQXe+8Sj 4oIFqAObvh/mLHVsr3u0vJwxsHzxpUxWE7S7SimVQX1deidzuIcJPii71CgpQWl9/cXO b3gH1eleiUbgkKyN+2sDo6kQCF32DOAaHowb8T6lefG0qiZE0DBidwYrQ0LTK4l5MZSw lxwQ== 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 q6-20020aa7d446000000b004ad09c397b1si8083326edr.587.2023.02.22.00.06.40; Wed, 22 Feb 2023 00:07:04 -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 S231236AbjBVIDf (ORCPT + 99 others); Wed, 22 Feb 2023 03:03:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbjBVIDe (ORCPT ); Wed, 22 Feb 2023 03:03:34 -0500 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC21013D50 for ; Wed, 22 Feb 2023 00:03:31 -0800 (PST) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTP id 31M83Iws082845; Wed, 22 Feb 2023 16:03:18 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from BJ10918NBW01.spreadtrum.com (10.0.74.60) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 22 Feb 2023 16:03:17 +0800 From: Xuewen Yan To: , , , , CC: , , , , , , , , Subject: [RFC PATCH] sched/fair: update the vruntime to be max vruntime when yield Date: Wed, 22 Feb 2023 16:03:14 +0800 Message-ID: <20230222080314.2146-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.60] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 31M83Iws082845 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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?1758517761862602539?= X-GMAIL-MSGID: =?utf-8?q?1758517761862602539?= When task call the sched_yield, cfs would set the cfs's skip buddy. If there is no other task call the sched_yield syscall, the task would always be skiped when there are tasks in rq. As a result, the task's vruntime would not be updated for long time, and the cfs's min_vruntime is almost not updated. When this scenario happens, when the yield task had wait for a long time, and other tasks run a long time, once there is other task call the sched_yield, the cfs's skip_buddy is covered, at this time, the first task can run normally, but the task's vruntime is small, as a result, the task would always run, because other task's vruntime is big. This would lead to other tasks can not run for a long time. In order to mitigate this, update the yield_task's vruntime to be cfs's max vruntime. This way, the cfs's min vruntime can be updated as the process running. Signed-off-by: Xuewen Yan --- kernel/sched/fair.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index ff4dbbae3b10..a9ff1921fc07 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -670,7 +670,6 @@ static struct sched_entity *__pick_next_entity(struct sched_entity *se) return __node_2_se(next); } -#ifdef CONFIG_SCHED_DEBUG struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq) { struct rb_node *last = rb_last(&cfs_rq->tasks_timeline.rb_root); @@ -681,6 +680,7 @@ struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq) return __node_2_se(last); } +#ifdef CONFIG_SCHED_DEBUG /************************************************************** * Scheduling class statistics methods: */ @@ -7751,8 +7751,18 @@ static void set_next_buddy(struct sched_entity *se) static void set_skip_buddy(struct sched_entity *se) { - for_each_sched_entity(se) - cfs_rq_of(se)->skip = se; + for_each_sched_entity(se) { + struct sched_entity *last; + struct cfs_rq *cfs_rq = cfs_rq_of(se); + + last = __pick_last_entity(cfs_rq); + if (last) { + se->vruntime = last->vruntime; + update_min_vruntime(cfs_rq); + } + + cfs_rq->skip = se; + } } /*