Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp301373rdb; Thu, 19 Oct 2023 05:11:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIKvdN8GeMwOZniYsRV88eG63vJcTxmZzWM45U3dbpi6VnIk7hIoW9BmL2VBggIFbj5tvq X-Received: by 2002:a17:903:191:b0:1bf:c59:c944 with SMTP id z17-20020a170903019100b001bf0c59c944mr2337824plg.22.1697717460453; Thu, 19 Oct 2023 05:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697717460; cv=none; d=google.com; s=arc-20160816; b=ZzKEZvEh7FT9WHfaHPVUkZkJ2QDoQRcNV8LNxkI/IrR7neJA6oYyc51OgZ1w86O//5 2WbgOKoAqf9OWYeiIQvvQ7pPgNi0Q9ztgXpaNPvITzT4TQvPZ2D+bzRet80iXNnb59RU lQs7wFbBe/amYCTwIfyBB0o1hjQGq5oWNqQ9CpyOmLgPXdWDMPRKh0szlgHkWVTBaSoR SaZzLRcONulD7Gx38xPHWTQFdJoS6KftvbjgFAkfPEpbUZzM7YkpJuPUOjimwBreo8lq cDyk9EsrRIyCjZwFFdt9EMW1Q/S3/ikR00Z+ENll3Bsgb6BspLiF/d9CUW+EOi/QvvXX k3vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=n4tv7L3CKLORBtaOIWt8KkvkWsJtfoDrj0UfoXf86F8=; fh=gWNrWtM1CAyJ4UMYwrg4ryQcoC9zhwA8PnSSNIpWAoU=; b=QF1B5g1hoctFZIkayc5uQQRI/nwqBWJeOjCgyWDcd0lCLCvwp6n/oiO/Ow5Grlxn3n IHvrD7wBuhpcxGgygPeqrJVwRCaNO5z2un5o1EOVKjINhSKrhMZ7GurxUtH0m4JTt81U jqsP8FBK1XqLFlaCSRkXB2DosRHg/2ITdQit+49V2SRlboN60UheMVBzsmMkTSVdZtX5 D4MuZqD8dQkrjvTQ/QBQBbkiO1D2PraCu55mdHkR5WDiVUUsV3QKErjnn8Oi0wW7tiyu zhk6Z9VZCyio6q86e+jVxnOj7XylFYGLmxZB4h7sMJNxy3JqTfKlB12yL04rqvpRiWCv uoVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BkAPGqUJ; 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=linaro.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id y21-20020a1709027c9500b001c88e81a54asi1921883pll.325.2023.10.19.05.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:11:00 -0700 (PDT) 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=@linaro.org header.s=google header.b=BkAPGqUJ; 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=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 5FDFD8116B0E; Thu, 19 Oct 2023 05:10:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345585AbjJSMKj (ORCPT + 99 others); Thu, 19 Oct 2023 08:10:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235469AbjJSMKX (ORCPT ); Thu, 19 Oct 2023 08:10:23 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 058CDD6D for ; Thu, 19 Oct 2023 05:08:59 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-7789aed0e46so60158185a.0 for ; Thu, 19 Oct 2023 05:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697717339; x=1698322139; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=n4tv7L3CKLORBtaOIWt8KkvkWsJtfoDrj0UfoXf86F8=; b=BkAPGqUJblQAKDCwVFa825TZxHuBYXl9QIqdqq6jNhKkZ2CmHCAvfVGBKk+NHkzvQC ggUoQYzDPB9XHNkL3fe/04kKY5Cv0b06Nzdho84PDR2qUyHllTxF/p6pVfMI2GjilJRq 92PsTqJBrUUnAfQBSbRX97fC26TOqbEkw4DK5kegiVixZyXVhky1S1k4EnKlfwA9i+KL LDMMK6T0YMZtu0D1sKOea9JDozRyIcaOR04q7HWsdMvIUcnZzcV21ZPWS5Kr4Wkg7uD2 ggU9YB4jG+f892VFn8auTk+NEzGiAU5OKQcYzuozPA+6jiszvhTyGzynS+nrMotg+gmd ZpPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697717339; x=1698322139; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=n4tv7L3CKLORBtaOIWt8KkvkWsJtfoDrj0UfoXf86F8=; b=ige0CE045SuvxmNd++3DG5ybNHynBKaWKBh7m9LL7s3nDKwbrHXYo0p6kSwedPD4lX SEgio6XcMgPMwFV6dKnYd9FfBxJVqJoW+lzZBc7Q/IEOpj6oaKBf8z75fQIhlkw9iIxt aklWoX8VTfg40y0FOUOIvpZhq5PpiXruY/i3TAzib50RM3WZAtzVk+Z8KNnKSmwpIkzS ZBqVIhnINreEGXTB31MCcsi+KUz6oEP6tAJca67l4M6ZO1WJXNbsgb0jTn5jj6Owzd7P n7W0u51XAwcxCQTKeRRtUIK5SUz1yRZ1oyda02LchcTaS/P5B+iQuSuqCpVY9KfvrdZa a+kg== X-Gm-Message-State: AOJu0YxkAZEc8wZzWpxJGu3zoXMxcjdpMNspzzVfE+2Qz7gUU+SYAB/R gcCziFrpOo0PHDQ0F3HlBbkNQpEUjrRtj/DV0U+bEw== X-Received: by 2002:a05:6214:248e:b0:656:51b9:990e with SMTP id gi14-20020a056214248e00b0065651b9990emr2378325qvb.57.1697717338910; Thu, 19 Oct 2023 05:08:58 -0700 (PDT) MIME-Version: 1.0 References: <20231019033323.54147-1-yangyicong@huawei.com> <20231019033323.54147-4-yangyicong@huawei.com> In-Reply-To: <20231019033323.54147-4-yangyicong@huawei.com> From: Vincent Guittot Date: Thu, 19 Oct 2023 14:08:47 +0200 Message-ID: Subject: Re: [PATCH v11 3/3] sched/fair: Use candidate prev/recent_used CPU if scanning failed for cluster wakeup To: Yicong Yang Cc: peterz@infradead.org, mingo@redhat.com, juri.lelli@redhat.com, dietmar.eggemann@arm.com, tim.c.chen@linux.intel.com, yu.c.chen@intel.com, gautham.shenoy@amd.com, mgorman@suse.de, vschneid@redhat.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, prime.zeng@huawei.com, yangyicong@hisilicon.com, jonathan.cameron@huawei.com, ego@linux.vnet.ibm.com, srikar@linux.vnet.ibm.com, linuxarm@huawei.com, 21cnbao@gmail.com, kprateek.nayak@amd.com, wuyun.abel@bytedance.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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]); Thu, 19 Oct 2023 05:10:51 -0700 (PDT) On Thu, 19 Oct 2023 at 05:36, Yicong Yang wrote: > > From: Yicong Yang > > Chen Yu reports a hackbench regression of cluster wakeup when > hackbench threads equal to the CPU number [1]. Analysis shows > it's because we wake up more on the target CPU even if the > prev_cpu is a good wakeup candidate and leads to the decrease > of the CPU utilization. > > Generally if the task's prev_cpu is idle we'll wake up the task > on it without scanning. On cluster machines we'll try to wake up > the task in the same cluster of the target for better cache > affinity, so if the prev_cpu is idle but not sharing the same > cluster with the target we'll still try to find an idle CPU within > the cluster. This will improve the performance at low loads on > cluster machines. But in the issue above, if the prev_cpu is idle > but not in the cluster with the target CPU, we'll try to scan an > idle one in the cluster. But since the system is busy, we're > likely to fail the scanning and use target instead, even if > the prev_cpu is idle. Then leads to the regression. > > This patch solves this in 2 steps: > o record the prev_cpu/recent_used_cpu if they're good wakeup > candidates but not sharing the cluster with the target. > o on scanning failure use the prev_cpu/recent_used_cpu if > they're recorded as idle > > [1] https://lore.kernel.org/all/ZGzDLuVaHR1PAYDt@chenyu5-mobl1/ > > Reported-by: Chen Yu > Closes: https://lore.kernel.org/all/ZGsLy83wPIpamy6x@chenyu5-mobl1/ > Signed-off-by: Yicong Yang Reviewed-by: Vincent Guittot > --- > kernel/sched/fair.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 02d842df5294..d508d1999ecc 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7346,7 +7346,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) > bool has_idle_core = false; > struct sched_domain *sd; > unsigned long task_util, util_min, util_max; > - int i, recent_used_cpu; > + int i, recent_used_cpu, prev_aff = -1; > > /* > * On asymmetric system, update task utilization because we will check > @@ -7379,6 +7379,8 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) > > if (cpus_share_resources(prev, target)) > return prev; > + > + prev_aff = prev; > } > > /* > @@ -7411,6 +7413,8 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) > > if (cpus_share_resources(recent_used_cpu, target)) > return recent_used_cpu; > + } else { > + recent_used_cpu = -1; > } > > /* > @@ -7451,6 +7455,17 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) > if ((unsigned)i < nr_cpumask_bits) > return i; > > + /* > + * For cluster machines which have lower sharing cache like L2 or > + * LLC Tag, we tend to find an idle CPU in the target's cluster > + * first. But prev_cpu or recent_used_cpu may also be a good candidate, > + * use them if possible when no idle CPU found in select_idle_cpu(). > + */ > + if ((unsigned int)prev_aff < nr_cpumask_bits) > + return prev_aff; > + if ((unsigned int)recent_used_cpu < nr_cpumask_bits) > + return recent_used_cpu; > + > return target; > } > > -- > 2.24.0 >