From patchwork Sun Dec 10 09:21:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Jinchao X-Patchwork-Id: 176318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6438250vqy; Sun, 10 Dec 2023 01:39:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYi5hlO9MqKMoSAdTHjdefTOBzOk3nCzL00k0PnPCk4BIJbIJ+zzSa1FXsVGabtYjN3d+V X-Received: by 2002:a05:6808:22a6:b0:3ba:380:87ad with SMTP id bo38-20020a05680822a600b003ba038087admr1149414oib.99.1702201169245; Sun, 10 Dec 2023 01:39:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702201169; cv=none; d=google.com; s=arc-20160816; b=Y3C4Fiy3iAh3dUO0DZCBDnvpCDMuC55nfdTN2R3wZG2FHVzgsS5uGF8T3dm0+eW5sh 11Yan99bMveuXngDUjqqKaNLZ8fAhmf/d1FhxzY8FttppOmvZrtX47wT2T8v0yOJ5CwU weXREZ+KwzwBDXwm0kLMmk04TEFRk5Pq7mQJxZYvb/7YWQXjZ+OH2wsT4gd0tztrW5nw Y4DyX0/w4Yfzljj1G+Bl1DKi6kWzbbEGIR+nHW4JH4SQRqCUhZPwHa0j+4+5BHHHMcmQ VUGpVWL5YwF7vIZdD9KF7su9jtMhiy/mvPbFoc53hUHGykQs9ZosEyWLm/r/Rlm3fqLZ 1zfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=M7cLVuXx/fWAzIEUg2Y+b74t8aLXqdFLIbba5aZvwRo=; fh=f40UFx4PIoN5VHjot5Te0Vsnl2epc2I3Vpkjl2f6MCo=; b=iih7DHPkjbiaEEGXX2hiA1EGKCkmqEeektgFY/kLFNPXLwCTEmCtCBdIOgMXPs2f2p yGfZNLk1vMVeqtcqWUvijrOjJwDf7+81s+ww3C3Y+ZoOvrjtLbceWeCDAcSWwvKt/QZR NCs1rQGvHqEGZj+gm7e/5avdOxHb/JhZ4ZfZwy1kLfP0bKuTyu6xOnAgX7cqmB1DFeGl 7Vom9FeRmPCySGUdRj0Vi+bK90egrxokyge7KLMcDeIRS/chlPzVFnotC2Sx8P/6XN2Z 0GDwhzyELI0dPXQP9Ci65/egfUaiwC4yKkZfAuy4xQ2KHnGsZjaQGjW9SjMEFyD+jzNI jgkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id ch9-20020a17090af40900b002886d6c7ea2si4361814pjb.177.2023.12.10.01.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 01:39:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 48E66806B077; Sun, 10 Dec 2023 01:39:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbjLJJjQ (ORCPT + 99 others); Sun, 10 Dec 2023 04:39:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjLJJjP (ORCPT ); Sun, 10 Dec 2023 04:39:15 -0500 X-Greylist: delayed 1069 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 10 Dec 2023 01:39:20 PST Received: from wxsgout04.xfusion.com (wxsgout04.xfusion.com [36.139.87.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B10D0C5 for ; Sun, 10 Dec 2023 01:39:20 -0800 (PST) Received: from wuxshcsitd00600.xfusion.com (unknown [10.32.133.213]) by wxsgout04.xfusion.com (SkyGuard) with ESMTPS id 4Snzn42TQYz9ygN2; Sun, 10 Dec 2023 17:18:00 +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; Sun, 10 Dec 2023 17:21:24 +0800 Date: Sun, 10 Dec 2023 17:21:24 +0800 From: WangJinchao 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: merge same code in enqueue_task_fair Message-ID: <202312101719+0800-wangjinchao@xfusion.com> MIME-Version: 1.0 Content-Disposition: inline X-Originating-IP: [10.82.147.3] X-ClientProxiedBy: wuxshcsitd00603.xfusion.com (10.32.134.231) To wuxshcsitd00600.xfusion.com (10.32.133.213) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 10 Dec 2023 01:39:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784887293053634358 X-GMAIL-MSGID: 1784887293053634358 1. The code below is duplicated in two for loops and need to be consolidated 2. Fix the bug where a se's on_rq is true but its parent is not ```c cfs_rq->h_nr_running++; cfs_rq->idle_h_nr_running += idle_h_nr_running; if (cfs_rq_is_idle(cfs_rq)) idle_h_nr_running = 1; /* end evaluation on encountering a throttled cfs_rq */ if (cfs_rq_throttled(cfs_rq)) goto enqueue_throttle; ``` Signed-off-by: WangJinchao --- kernel/sched/fair.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d7a3c63a2171..e1373bfd4f2e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6681,30 +6681,15 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT); for_each_sched_entity(se) { - if (se->on_rq) - break; cfs_rq = cfs_rq_of(se); - enqueue_entity(cfs_rq, se, flags); - - cfs_rq->h_nr_running++; - cfs_rq->idle_h_nr_running += idle_h_nr_running; - - if (cfs_rq_is_idle(cfs_rq)) - idle_h_nr_running = 1; - - /* end evaluation on encountering a throttled cfs_rq */ - if (cfs_rq_throttled(cfs_rq)) - goto enqueue_throttle; - - flags = ENQUEUE_WAKEUP; - } - - for_each_sched_entity(se) { - cfs_rq = cfs_rq_of(se); - - update_load_avg(cfs_rq, se, UPDATE_TG); - se_update_runnable(se); - update_cfs_group(se); + if (se->on_rq) { + update_load_avg(cfs_rq, se, UPDATE_TG); + se_update_runnable(se); + update_cfs_group(se); + } else { + enqueue_entity(cfs_rq, se, flags); + flags = ENQUEUE_WAKEUP; + } cfs_rq->h_nr_running++; cfs_rq->idle_h_nr_running += idle_h_nr_running;