From patchwork Wed Jan 3 04:18:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Jinchao X-Patchwork-Id: 184604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4828106dyb; Tue, 2 Jan 2024 20:34:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiuaNRqEa/2o92nkevUrLo8mydnVtJMx0SAQWNA7setU+By7n2gYmBOOsVgGa2lni3aaRD X-Received: by 2002:a05:6402:1c83:b0:556:b290:5bc1 with SMTP id cy3-20020a0564021c8300b00556b2905bc1mr489698edb.24.1704256496777; Tue, 02 Jan 2024 20:34:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704256496; cv=none; d=google.com; s=arc-20160816; b=R7v3Potv/Abk+B49cDXQJ8F0XtQt28n3ctKEepHdj1n6cbU6I+INaCClS3sa3pmQE7 JQYldDJ1009jYoTFIn6ni9KjgMi4wAxLCiKDEOpzOxuuD9XqUoVsV8OAOkklkXeCE7+N pWE9lJTCxe3zbdilNgaKCYz6RrIdWfU5mRmqQiudZ5/bV+zuMPZZw8AmfDPfAJ5YeGhb /NfMBciWH9GljbRs/V408ZjEfuL3zIVUa2/aLTWmUGlezV5KutbYH4tb5a4NxI0NTdyc rWeSs19Sntpi0sIm/3vZoYOMPweaBG+5RAxkagWTJuO0b5JiiCYK/arnhZ+HBm/JBAR5 8JZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date; bh=bqClvV2P0czyZMsFCnU64D+UDftEZJpLB9zo9Kp2oek=; fh=f40UFx4PIoN5VHjot5Te0Vsnl2epc2I3Vpkjl2f6MCo=; b=wy43GuMI9+HguSWqQytGZD5M/u6+7Uj+aN/n69vU1sJOIoyQ4zt5ChyQhpx1PiJnCb a3ROgci3mbvuZZt/YzTCSYhHq/jp82A+eQ+l5Nl/N3BUE08fQsnCUiUMwUnrtBOhUDPv QAur8csXXXzrWWtUSApPzXPhw66j9aQ0MCU4JrkbtFfArLez4o2Ptqi73B/KHvxbfBFP Vit76FnrOHj39rKoayrhQK+R43DaEPZD8duEWQ0TwiT3Iv4sknJkUHBZ6W7llH9Z8+n/ QGpxvKH+4RECQDhXPEch5CWNaLgcyTCjNGBsg+Ou8d2dvejQ1W7JIWMGUfisLspzCWX9 0Giw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-15153-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15153-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b11-20020a056402350b00b005537ce7b66fsi12039861edd.189.2024.01.02.20.34.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 20:34:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15153-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-15153-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15153-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 656821F239D9 for ; Wed, 3 Jan 2024 04:34:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFE451799A; Wed, 3 Jan 2024 04:34:41 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from wxsgout04.xfusion.com (wxsgout03.xfusion.com [36.139.52.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80FA0171C4 for ; Wed, 3 Jan 2024 04:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xfusion.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xfusion.com Received: from wuxshcsitd00600.xfusion.com (unknown [10.32.133.213]) by wxsgout04.xfusion.com (SkyGuard) with ESMTPS id 4T4bw92tcmzB13y6; Wed, 3 Jan 2024 12:14:49 +0800 (CST) Received: from localhost (10.82.147.3) by wuxshcsitd00600.xfusion.com (10.32.133.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 3 Jan 2024 12:18:31 +0800 Date: Wed, 3 Jan 2024 12:18:31 +0800 From: Wang Jinchao To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , CC: , Subject: [PATCH] sched/fair: Optimize min_vruntime update on unchanged vruntime Message-ID: <202401031216+0800-wangjinchao@xfusion.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-ClientProxiedBy: wuxshcsitd00601.xfusion.com (10.32.135.241) To wuxshcsitd00600.xfusion.com (10.32.133.213) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787042460643062445 X-GMAIL-MSGID: 1787042460643062445 When (!(curr && curr->on_rq) && !se) is true, there is no need to update min_vruntime. Simplify the if-else logic accordingly. Signed-off-by: Wang Jinchao --- kernel/sched/fair.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d7a3c63a2171..a4afdeee515d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -755,21 +755,16 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq) struct sched_entity *se = __pick_first_entity(cfs_rq); struct sched_entity *curr = cfs_rq->curr; - u64 vruntime = cfs_rq->min_vruntime; + u64 vruntime = U64_MAX; - if (curr) { - if (curr->on_rq) - vruntime = curr->vruntime; - else - curr = NULL; - } + if (curr && curr->on_rq) + vruntime = curr->vruntime; + if (se) + vruntime = min_vruntime(vruntime, se->vruntime); - if (se) { - if (!curr) - vruntime = se->vruntime; - else - vruntime = min_vruntime(vruntime, se->vruntime); - } + /* no need to update if vruntime is unchanged */ + if (vruntime == U64_MAX) + return; /* ensure we never gain time by being placed backwards. */ u64_u32_store(cfs_rq->min_vruntime,