From nobody Fri Dec 19 10:47:38 2025 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B7973B1AC for ; Mon, 2 Sep 2024 18:36:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302175; cv=none; b=AvPgvLw0LrHRNFFThWlJ52ny4pXAXhNsDjYJnhMogm70LeZfZnXfREAtyJqth1YVtsBhYkgBAvzt7ASCNNNZHmozN3jszsmnei1uoO6lXotyFAeiBcIWSTK3glVZQ7I9iK6+c7LtpiDobvKp0xRj71K0MvqxI1/ia1PHK+hl9SA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302175; c=relaxed/simple; bh=fhf8WmY08QVVGMblvZuMnpvOp2GjY5jXRtZrrIc5Tj0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ji/Z3nc8hRWvyqfbvL2vHdluwYmFQHp9XrnmsMUTkATKwpqkrlBFJIjZoe0o2V/SvYNp+bDSuvAd+Qo//t84LCwTpf+UmMpQW/jsrmGJldZ8MdHD0RwzBjS0VR7WGNRbh58nKNI7Q8BrOSaOQFnGHiz7c9Z40pT80ZY1Q0CeXxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aq0/jgC0; arc=none smtp.client-ip=209.85.128.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aq0/jgC0" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-6b4412fac76so35630607b3.1 for ; Mon, 02 Sep 2024 11:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302173; x=1725906973; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MFb8yYHlbtqc71k+q1vVXsGuwhqBH0JTZbKgqgv4lxs=; b=aq0/jgC0vEL8DvQ/lVR9q4uvWzWtz4/BDAV8C96QKpohsQ7thbn+rOfQGVL8pSPqkW KBCW0BlCWL2Do8a6t5pqpZS/StbJ0EnmrTGbV4acuccQe+oGev/ytSsuSMgJPtlSuyzh MUIIC7WlZsXD2k7NrlbbuW6DW42pczrhEvXogJAQWjEDskKC5lDC1aE/uOBPx/nIFCeg UYMeXU3+5D5f8xui8L4nYmmKdpNlLdVA9ub1y3vVXM09RCLqmLj/Qr0x/5J4/RauHQjT DoJsusZWGefaEVbOUXxP6JBsBVWytsfSAFUG9XE3JvzsU+PZb9tCjLRuP8dgWtszH2lj LS1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302173; x=1725906973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MFb8yYHlbtqc71k+q1vVXsGuwhqBH0JTZbKgqgv4lxs=; b=AYzI/xNwA496VmxvCJ1qvWmcnbinvug3bdxaXRdTEZxKhJCgxw3UFAARYfZaRVVoCG EHdjbuObQNWgxrLwOM7ZfN3tB6bpO8L4ryQzykgZONalL1/7mxjBbr1Wue566BAK2cWF GRXzrqNkuF9LsKLbpq4oPHlUJhpIaHVdIQI3YA9DpOVrGOR1PEnP24RaGGSOOUalzL8m qhA91SrmFmSHa/9dJzfz25pUGUCUD269XAq4R+RW02jeVVxlNCzcekHuWxWBEsZ7q85x hUBNnJzGKi/vKAxLdTFBQl/DZY5UunsM1fmFTHr40WOnPbkNWuBq/D9cn3l3KSBWMsCq JvIQ== X-Gm-Message-State: AOJu0Yxml1GONNaQxHX77IpuR8vggpTb/l/uslwESOHLqK5b1S3E4s5q rWWVMPJktlxQROBcEn7A6kdDmkASL4iKKfcnEQT225K1RN3jPzxOoK9wBmFS X-Google-Smtp-Source: AGHT+IFwrxSb0Xf8RylF/z03m3gS87dIiEIP9go27R9TEk+3nL0JfGeHbqolY/mEO+hNsJWM/svI0g== X-Received: by 2002:a05:690c:6587:b0:6ab:e840:7f4d with SMTP id 00721157ae682-6d4104e5158mr97819507b3.46.1725302173253; Mon, 02 Sep 2024 11:36:13 -0700 (PDT) Received: from localhost (c-71-203-131-184.hsd1.fl.comcast.net. [71.203.131.184]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6d58b38ce9asm8667847b3.17.2024.09.02.11.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:36:12 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Christophe JAILLET Cc: Yury Norov , Chen Yu , Leonardo Bras , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH v3 1/3] sched/topology: pre-compute topology_span_sane() loop params Date: Mon, 2 Sep 2024 11:36:05 -0700 Message-ID: <20240902183609.1683756-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240902183609.1683756-1-yury.norov@gmail.com> References: <20240902183609.1683756-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" tl->mask() is called inside the loop with the same parameters more than once. We can pre-calculate it. After that, 'cpu' doesn't have to keep its value while running the loop iterations. We can drop the 'i' iterator, and re-use 'cpu' in the for_each_cpu_from() loop. Reviewed-by: Chen Yu Signed-off-by: Yury Norov --- kernel/sched/topology.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 76504b776d03..ffbe3a28d2d4 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2353,27 +2353,30 @@ static struct sched_domain *build_sched_domain(stru= ct sched_domain_topology_leve static bool topology_span_sane(struct sched_domain_topology_level *tl, const struct cpumask *cpu_map, int cpu) { - int i =3D cpu + 1; + const struct cpumask *mi, *mc; =20 /* NUMA levels are allowed to overlap */ if (tl->flags & SDTL_OVERLAP) return true; =20 + mc =3D tl->mask(cpu++); + /* * Non-NUMA levels cannot partially overlap - they must be either * completely equal or completely disjoint. Otherwise we can end up * breaking the sched_group lists - i.e. a later get_group() pass * breaks the linking done for an earlier span. */ - for_each_cpu_from(i, cpu_map) { + for_each_cpu_from(cpu, cpu_map) { + mi =3D tl->mask(cpu); + /* * We should 'and' all those masks with 'cpu_map' to exactly * match the topology we're about to build, but that can only * remove CPUs, which only lessens our ability to detect * overlaps */ - if (!cpumask_equal(tl->mask(cpu), tl->mask(i)) && - cpumask_intersects(tl->mask(cpu), tl->mask(i))) + if (!cpumask_equal(mc, mi) && cpumask_intersects(mc, mi)) return false; } =20 --=20 2.43.0 From nobody Fri Dec 19 10:47:38 2025 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFD381AB6F0 for ; Mon, 2 Sep 2024 18:36:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302177; cv=none; b=GFWwwvaESeUUH2OvwzPA41jO8LYuWploJkskqStqc3qkg4QQZtlmAffsgOpurAFSNcOS3fhlbWLOQMHemYfiqya1K1Rxt5IXtySXKIhqgMcfsvHqD3XrV0rSf/rPldOrT9y5NCL5iFm0tdlOFx0CFDk9A1useLfQk+/r6LWrjRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302177; c=relaxed/simple; bh=cXI0aLpbkNFzG2I2XJ4KaFkC1Vk7m5so2zzeOp2ZpTA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BfP65PZm58zizq50IGL7jxDpVC3NFSo2XSsdwVqR9Rx5awBM5IzznLDMHm6JRH5ztMuwO+TBnalu5ZX9NKGa8vho5l/7ai1XYHKbnAeZ7ZpXCX9KyfYAA+NsuEMhogS/zVZBI6KEQDu07+BNnkbkoW3U5Q6mrmV8DbA1Qt2XI2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nJ25Ez/o; arc=none smtp.client-ip=209.85.219.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nJ25Ez/o" Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e04196b7603so4890468276.0 for ; Mon, 02 Sep 2024 11:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302175; x=1725906975; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7LiUbyQ8pr+2ihhv3bomzpX3ODdNk5TniI0rAo29ma8=; b=nJ25Ez/ofa2V9yTCNAh8Ms7Q33voyItNJLR4rskK2oAx0OECrMHCGD9zR0VTe8xcSr 0yHcMy5rOC731q8PhajvK3zvX9SCWoQKktLD5VkjDSfGmlirM/E4ZaQ/US1IlbadNYpY iIZvQWktlaDY0D/ZCy3z0abOEdFzga5YibyZ7NPy8oejtk5Yg4TfJP2GwEnpMadgjlvK rI/9m++vO5EYRNUsHIUgcOYfUQcmP36QVndTREUP15+fx/aCNUlUc9ebwIKr6FGzwuxH vc1S3ZQ8/m+aOMwqEnxEybNhIan7pglUA2wAJdZf4LrGr0KK1iuUGSBu6YNgTrFgm4f5 k5oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302175; x=1725906975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7LiUbyQ8pr+2ihhv3bomzpX3ODdNk5TniI0rAo29ma8=; b=Kpv9xGFnjT3ZEKzngA48zHnBgU7gB834H2VopdtHuuttX/em57QCubdg4fbG/rbnuw cGIYUG6TUV8k8Lcz/L80QawL4yweCupsEg/Ewfo2OaFGk7Gev+E3NZMfaq+0CDhLZRz5 Nmk1STXpFiuq+G532lVj4OwNG52xN+JmJSvlhXXt1M5f79lXf+fCsWcAfMd1f4YQgLnX ZBAhw9TY2t2qFqJ1Q+v1pmzolDkIM2OMnV4E4+CcV/fCc6L87PBMlGlf0zFShRsgcR4E 9ZYNv8RTUi9o7C3kiKF0ifQEa4vPYyRk3yFS7D9dXkASzQFSuWskFQGzYFPWpKPmjOS9 Ersg== X-Gm-Message-State: AOJu0Yw8NC1g8rd5xk2S1hUQNWEQ/yJ9oXqgV3GOMcG8crBWHo35rwhI IHUrYrqT/NC5YVDZSgFSh26hsO5PWqy332Fo24v0O3qPliZ9ai8h3OQ18p+O X-Google-Smtp-Source: AGHT+IE4bvB21w/EI92y9RBVrxNLU4TDs0iCR7/PEs+mcyoTCEUNG5+qtuOpOZe7COXL33tqhFJTQg== X-Received: by 2002:a05:6902:2708:b0:e13:d8e9:4a35 with SMTP id 3f1490d57ef6-e1a7a02611emr8964922276.25.1725302174633; Mon, 02 Sep 2024 11:36:14 -0700 (PDT) Received: from localhost (c-71-203-131-184.hsd1.fl.comcast.net. [71.203.131.184]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e1a62681583sm1776143276.33.2024.09.02.11.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:36:14 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Christophe JAILLET Cc: Yury Norov , Chen Yu , Leonardo Bras , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH v3 2/3] sched/topology: optimize topology_span_sane() Date: Mon, 2 Sep 2024 11:36:06 -0700 Message-ID: <20240902183609.1683756-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240902183609.1683756-1-yury.norov@gmail.com> References: <20240902183609.1683756-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function may call cpumask_equal with mi =3D=3D mc, even though the CPUs= are different. In such case, cpumask_equal() would always return true, and we can proceed to the next iteration immediately. This happens when topologies re-use the same mask for many CPUs. The detailed comment is provided by Valentin Schneider. Reviewed-by: Valentin Schneider Signed-off-by: Yury Norov --- kernel/sched/topology.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index ffbe3a28d2d4..04a3b3d7b6f4 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2370,6 +2370,19 @@ static bool topology_span_sane(struct sched_domain_t= opology_level *tl, for_each_cpu_from(cpu, cpu_map) { mi =3D tl->mask(cpu); =20 + /* + * Some topology levels (e.g. PKG in default_topology[]) + * have a sched_domain_mask_f implementation that reuses + * the same mask for several CPUs (in PKG's case, one mask + * for all CPUs in the same NUMA node). + * + * For such topology levels, repeating cpumask_equal() + * checks is wasteful. Instead, we first check that the + * tl->mask(i) pointers aren't the same. + */ + if (mi =3D=3D mc) + continue; + /* * We should 'and' all those masks with 'cpu_map' to exactly * match the topology we're about to build, but that can only --=20 2.43.0 From nobody Fri Dec 19 10:47:38 2025 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 250741C62C6 for ; Mon, 2 Sep 2024 18:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302178; cv=none; b=IOsNFDdhrvcBfaeUYQHfHtG44j18WeaYHFXLJhU3sLN7nJXETiu3y4S9ReqxiQXqpcMamRbWJqLNgr0KiWbOLcIy7k9t3kyi0HS5jaWHStnGmywNyprQXY1KNblGsU1SvG18FwFz1Ibo/Aih+WlULIYbMo343FRkKnqiKOzYKuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725302178; c=relaxed/simple; bh=n4DY9fWvNNP+vPnev4QnAxb6kTHbVIPvGqngyfcYTZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NmFq355xVJTOo9q0xiFKSBH5btUoCefqVTi1syB8SGVJgFELrhozeTB92FPLR67FwOX6EPoeZ06nyLxo21QL5MBSa0Zk7E3ucvuz7pqtlWCuc2wbc5I+wkwSAM/BeozvFpTpMDozYQudGwZhohYJVcL2R/uVEZEogI1IoGHr9sg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S/+Yswah; arc=none smtp.client-ip=209.85.219.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S/+Yswah" Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-e1a7d43a226so2958127276.3 for ; Mon, 02 Sep 2024 11:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725302176; x=1725906976; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=81Pwg90lkrxuPa74EcD9qWBo9vF1Zvhp5af4I0TH1fk=; b=S/+Yswah46fJmnK9YpIHFww3mCh8zFTXlf8Q7VXF7v+kk+rMnqoItQcjh0scSuB7Bg u0LUXZSdq3ICthfl3NOSOEhF434XLH4N4td0iBL45KQ/RUWInbGg5g9xQDTHHmJkAjJ/ 839F1lzctXNKuXVNSkX0rN4T5XAR53m26J7IA4abiKkTmr21/0I45+agBjIzabR1RZ0T 5TScYMNED2cm0uty5mwouiasKgNii/DMvdN2gYa+yahIBBmmqtDBHtUFzFOBc38XDOs1 hf/as0Re4kGq5zHpVSH80PjY2P9bKB1v+IZ7qoPJ8lwIL8oKXhzlgvYHjO07jC6//Fj7 axiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725302176; x=1725906976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=81Pwg90lkrxuPa74EcD9qWBo9vF1Zvhp5af4I0TH1fk=; b=Gvxn0v/KIsIl34HYTuiFJbf+bOyN69DhuyegZ0N9qjZe79r9hnrZg6PdeqC8GnGRmE SHcD28Ml3Ez6Bopk5Lcb9u6mJrb97RcoaDXk2CEV0lQGPibzcIrEkopu6pZLsARLFhIN vAInN4vfo7snMakM+RfI9NKUPUSrBQ1+zfa4cAcP0276/EDX+eVpMUA7RU2ncZZp+RfI jrAea7TI2ariktzbIa9hACWeKRWCmUS392ogCZ7kD+lo9L3gkgmBQEABnU86dI4Un/CF 8FBkXLXlxjfqGJVOiXSAt5hZUlmJifZdHAGnGqrLMNk090C3KsE9LerZEbGqmlnfcnfm BOug== X-Gm-Message-State: AOJu0YwYFL8MScdfn9xd7PRetkR3uf/gJ5mlUmBKLxm8yQZJQA4dmbE+ 9Fa1/RhM1qaCay+3JqN6saAofVt30AEFjETyYTqLjVHqM94Nk5Yai1pC/DjP X-Google-Smtp-Source: AGHT+IGo+Ur1m2xegyqr/Z8b1jMaHVXT+p5bk0e9C4xNp6mTRFu67zOVctFekJE8dEMvZb0KnHxclg== X-Received: by 2002:a05:690c:c89:b0:646:7b75:5c2c with SMTP id 00721157ae682-6d40f34125amr127977357b3.16.1725302175953; Mon, 02 Sep 2024 11:36:15 -0700 (PDT) Received: from localhost (c-71-203-131-184.hsd1.fl.comcast.net. [71.203.131.184]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6d2d57de3fbsm16890097b3.78.2024.09.02.11.36.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 11:36:15 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Christophe JAILLET Cc: Yury Norov , Chen Yu , Leonardo Bras , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH v3 3/3] sched/topology: reorganize topology_span_sane() checking order Date: Mon, 2 Sep 2024 11:36:07 -0700 Message-ID: <20240902183609.1683756-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240902183609.1683756-1-yury.norov@gmail.com> References: <20240902183609.1683756-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function currently makes 3 checks: 1. mc =3D=3D mi; 2. cpumask_equal(mc, mi); 3. cpumask_intersects(mc, mi). Historically, 2 last checks build a single condition for if() statement. Logically, #1 and #2 should be tested together, because for the topology sanity checking purposes, they do the same thing. In contrast, #3 tests for intersection, which is a different logical unit. This patch creates a helper for #1 and #2 and puts the corresponding comment on top of the helper; unloading the main topology_span_sane(). Signed-off-by: Yury Norov --- kernel/sched/topology.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 04a3b3d7b6f4..bbbe7955d37c 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2346,6 +2346,22 @@ static struct sched_domain *build_sched_domain(struc= t sched_domain_topology_leve return sd; } =20 +/* + * Some topology levels (e.g. PKG in default_topology[]) have a + * sched_domain_mask_f implementation that reuses the same mask for + * several CPUs (in PKG's case, one mask * for all CPUs in the same + * NUMA node). + * + * For such topology levels, repeating cpumask_equal() checks is + * wasteful. Instead, we first check that the tl->mask(i) pointers + * aren't the same. + */ +static inline bool topology_cpumask_equal(const struct cpumask *m1, + const struct cpumask *m2) +{ + return m1 =3D=3D m2 || cpumask_equal(m1, m2); +} + /* * Ensure topology masks are sane, i.e. there are no conflicts (overlaps) = for * any two given CPUs at this (non-NUMA) topology level. @@ -2369,18 +2385,7 @@ static bool topology_span_sane(struct sched_domain_t= opology_level *tl, */ for_each_cpu_from(cpu, cpu_map) { mi =3D tl->mask(cpu); - - /* - * Some topology levels (e.g. PKG in default_topology[]) - * have a sched_domain_mask_f implementation that reuses - * the same mask for several CPUs (in PKG's case, one mask - * for all CPUs in the same NUMA node). - * - * For such topology levels, repeating cpumask_equal() - * checks is wasteful. Instead, we first check that the - * tl->mask(i) pointers aren't the same. - */ - if (mi =3D=3D mc) + if (topology_cpumask_equal(mc, mi)) continue; =20 /* @@ -2389,7 +2394,7 @@ static bool topology_span_sane(struct sched_domain_to= pology_level *tl, * remove CPUs, which only lessens our ability to detect * overlaps */ - if (!cpumask_equal(mc, mi) && cpumask_intersects(mc, mi)) + if (cpumask_intersects(mc, mi)) return false; } =20 --=20 2.43.0