Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4276308rdb; Mon, 11 Dec 2023 14:22:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMyKpqs0H/BOT7oqFGCDX/5tkfRF9Ghd8U+HEdH5l/KtNK543wKcPIWW7wc+tWqeTt+SH1 X-Received: by 2002:a05:6e02:1a4d:b0:35d:59a2:2b4 with SMTP id u13-20020a056e021a4d00b0035d59a202b4mr8811636ilv.84.1702333343344; Mon, 11 Dec 2023 14:22:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702333343; cv=none; d=google.com; s=arc-20160816; b=o+L92kmlv2X/ylIrh57FsTgmfS/3oP6vOfdAwo9IRDZ55kG474jGElxq5zXFUoz6Rh K1bRmNcbUb1H1W6pRlHarN1b/Jcr+iJMEw0aFivx/cv11WCMX2AdDVPigklbVL0bo2K/ y2Nt3Uiz434VSY/MDfcgZi52hJWJ9OPTM0FIJxFdrf0duUCX1LqpfoV9HZ9NEizubCdx KVupUcMN/SEAeiXp2vnmEkMUR/gcKBTX7YlIdh1MeKJlCMFproMXbN6TMLTHxOyBVfWK 8oYPwOxXkMgqji2vJcpO4hM0Cs9QQUgN4Wi7nSTH3SpoUMQzDiy6fv78fD0Gau8mu/7P hrPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=tDsYhfn2Hnu4nCrfkmn7isNe7zQYVbE1gIPEfJLa1B0=; fh=WLhd+93rWsvU6wdOfwU+fP2yylmedUR3XSK/SxFQhzM=; b=Zcd1RxD4xqHlIL++S5jjpxtJvDi/bu+dVNTEOIdDVg9lEUXL1aF9nwVaS1OAjmzBdb jPUNIJEIl9+QXhJN8OS+g9+74la5Akoxjz0mPGgF8ap3W5z/+t/kbbnUsvFIafmr1kG0 Pr8eq5yoQv+PzWmbgUIs85KO6lPD2eXBE0eF2YObOP08KDifNN7ddIAEjgu1uzm2L7NG F11nUmfTBJeU2FsARNS4VwmW0mz2lH0cl7R7u8AxtRgzXsAVgKu0sO9v4HfTL/GMVL5x 2Yhh29wl9+n+roeKM0IZHvt2b3LEhWA1ouh51FllkqMzoXeHLK6R8vKy6wU+DXgWSWsx oN0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mJEkrtfK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id a22-20020a656416000000b005c1b2c911f0si6681130pgv.328.2023.12.11.14.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 14:22:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mJEkrtfK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id ABAC5806235F; Mon, 11 Dec 2023 14:22:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbjLKWWE (ORCPT + 99 others); Mon, 11 Dec 2023 17:22:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjLKWWD (ORCPT ); Mon, 11 Dec 2023 17:22:03 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6660AB for ; Mon, 11 Dec 2023 14:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702333329; x=1733869329; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=NjBAJdZtEPzflWo/C+hNJjt8+fIgGubvNDTl9Bjsb0Q=; b=mJEkrtfKYdBNRoapSXZoRdKnnzArl0FsaMAKiAqmxFLZkls+kK0AyfXF kSOCZe3ywcvmWr0sRNRY6LZy4qq4Gv5RpjZunbJrBi8m0ZY3ZJsP7/l9k ouiWhanRcM/2iN9YU7owb8Lm+qfV8vjHg0h2Gwaldz/75fyBGPU4WVrhu LrS9sGX9YhtfZUkyPUhsn6//Y5Jp/c8zv66WG4yxWPyZ9wOEaE2igjrVA n7vig1QMatbzvIaf7TdUkpSQafQ62dgRsHarMs5u3WtLQ+DVCkpOFhgjw du0o54tQBU1sRQB3qm6+C8iFz3Xt+GhnUnLfIcdUyJCFh3BdQFO6DFIWz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="8080299" X-IronPort-AV: E=Sophos;i="6.04,268,1695711600"; d="scan'208";a="8080299" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 14:22:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="1104646933" X-IronPort-AV: E=Sophos;i="6.04,268,1695711600"; d="scan'208";a="1104646933" Received: from jjschmit-mobl1.amr.corp.intel.com (HELO [10.209.8.245]) ([10.209.8.245]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 14:22:08 -0800 Message-ID: <471d24f71cc531448572e2fc5964f1231e7ef7b3.camel@linux.intel.com> Subject: Re: [PATCH] sched/fair: merge same code in enqueue_task_fair From: Tim Chen To: WangJinchao , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Cc: stone.xulei@xfusion.com Date: Mon, 11 Dec 2023 14:22:07 -0800 In-Reply-To: <202312101719+0800-wangjinchao@xfusion.com> References: <202312101719+0800-wangjinchao@xfusion.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 14:22:20 -0800 (PST) On Sun, 2023-12-10 at 17:21 +0800, WangJinchao wrote: > 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 In the current code, If a se is already on a rq, all the parents would have= already been on rq too. I don't think there's a case where se's on_rq and parent is not for the current code before your patch. Otherwise the child would never get scheduled. I don't think we have seen such bug being reported. >=20 > ```c > cfs_rq->h_nr_running++; > cfs_rq->idle_h_nr_running +=3D idle_h_nr_running; >=20 > if (cfs_rq_is_idle(cfs_rq)) > idle_h_nr_running =3D 1; >=20 > /* end evaluation on encountering a throttled cfs_rq */ > if (cfs_rq_throttled(cfs_rq)) > goto enqueue_throttle; > ``` >=20 > Signed-off-by: WangJinchao > --- > kernel/sched/fair.c | 31 ++++++++----------------------- > 1 file changed, 8 insertions(+), 23 deletions(-) >=20 > 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_stru= ct *p, int flags) > cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT); > =20 > for_each_sched_entity(se) { > - if (se->on_rq) > - break; > cfs_rq =3D cfs_rq_of(se); > - enqueue_entity(cfs_rq, se, flags); > - > - cfs_rq->h_nr_running++; > - cfs_rq->idle_h_nr_running +=3D idle_h_nr_running; > - > - if (cfs_rq_is_idle(cfs_rq)) > - idle_h_nr_running =3D 1; > - > - /* end evaluation on encountering a throttled cfs_rq */ > - if (cfs_rq_throttled(cfs_rq)) > - goto enqueue_throttle; > - > - flags =3D ENQUEUE_WAKEUP; > - } > - > - for_each_sched_entity(se) { > - cfs_rq =3D 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 =3D ENQUEUE_WAKEUP; > + } The code change looks like a reasonable simplification. Logic is the same as the old code, assuming that once a se's on_rq flag is true, all its parents are too. Thanks. Tim > =20 > cfs_rq->h_nr_running++; > cfs_rq->idle_h_nr_running +=3D idle_h_nr_running;