Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4160106rdb; Thu, 28 Dec 2023 12:10:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXc2OJiHdePv5QhM7yJzdIDTkMl6PeJI+ApgviaapwF6qAmHJW4faTMg+QBvxO6uDW3Gkx X-Received: by 2002:a05:6e02:18c7:b0:35f:d99b:2f5d with SMTP id s7-20020a056e0218c700b0035fd99b2f5dmr20012510ilu.8.1703794240552; Thu, 28 Dec 2023 12:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703794240; cv=none; d=google.com; s=arc-20160816; b=dcObniPDAbmulmx2FDmprI+GMPMwbiP7L9GTK9e/KtPwWsoAR8MT+6gwOl0Yl2Kovk c6stOFUaROe4s1qBhL9IH+2MlwDuuYf7PQknW2rfyb/eOrrm6mu55g0G/UCMKUpNbAPR 5pZSeXuRIHcnc+0o/JUso5NiAf5WQFu012qT/VQ0/EB5RccT4qE+dF4PqT4Tp34LxTYV 7LV0lgYS6RnNJin7yNR0G8Ht+sR0RQ2MoVty14tQDgARm9l/++BCM1wsxsvacGURVDux iKWixVW4xwb8tMtUMcOtVmeA8M+5ytE2Mr18E/dEcfDjwpd2QrSbkmyjNSw0CZGNG360 6R+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=l8PF5TYSB+fNMcICiC7EawuixTtkSNVX+hQlbjAGH9E=; fh=kL/RA2Gd9NuQcovU0+7My8qgZ6xDrReyLO6zCGgffAQ=; b=Dg/rtldZR3afaCP/qjNI0JQIoh0VdKSscp1iefEGeY46KBRZm1SWbnObfFgAPnqCZx FsYvuYX6etKe/BDzdQzjT6DkOzR0bKMBOEw3pMxnivnfJiY5WNYw0vOdUwqUyLJ8dZnt Qh5pXPCvoNrf+mpldXypGxf35CcPnju1TRN5MX1fTLVzPTMak0U+7VMLgvrZ4DRF0qge FDWN1N3tTPkLJj7Geo9M8jNokIevdbVoJQ+WbMQLs2uU3K7noRxitHE6QkHfeoB/PWSq 7B4g1sHn4ya2YArsDv4qjM0vC6xoUW4SVOHSXrFFIdMf0YKlfossQ/CIA9rFi1pNLyEn VZIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DtW7GVeC; spf=pass (google.com: domain of linux-kernel+bounces-12845-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12845-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bj19-20020a056a02019300b005b7160263f2si13933813pgb.154.2023.12.28.12.10.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:10:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12845-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DtW7GVeC; spf=pass (google.com: domain of linux-kernel+bounces-12845-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12845-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 36D60286558 for ; Thu, 28 Dec 2023 20:10:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9855111198; Thu, 28 Dec 2023 20:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DtW7GVeC" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 728B410A0F for ; Thu, 28 Dec 2023 20:09:45 +0000 (UTC) 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 Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-5e7bb1e0db8so51508057b3.0 for ; Thu, 28 Dec 2023 12:09:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794184; x=1704398984; 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=l8PF5TYSB+fNMcICiC7EawuixTtkSNVX+hQlbjAGH9E=; b=DtW7GVeCm2M3ou5Sx6eirGs1wkcWtbvocVgfrZNscqn969DS7ANqIp3JHFTtbHgmQ5 NvNuAh+EAu8q4+oKtHYId/0i+IBKjC94Wdkk0fzmll3w4p/O62xAhlUgL7n2e2NhjGAA T73oFX9ei/ApmeQEfPlYC7jQOhVD3i/cUcC9aC+tKOWT05tnQW8q2KaXcZOd88hBJ8QW 3Do1knKCaVp087AGrqVsRzLPV56Q2NBUv+SCy21atoJdotGfjAxksdd5q5TqMpr7hjgF 9amJq4uEue+8XfAbcZ9q6rQWcvO+1RDXWKHnF6j7BwyaX3YgxKOxVznlMRdrXGDEChG5 TLdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794184; x=1704398984; 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=l8PF5TYSB+fNMcICiC7EawuixTtkSNVX+hQlbjAGH9E=; b=iEsjZoQgoa8sou4LYm8XzFq+sHO5UP8jTUtjKN6xxbe6cM9no5TgxiXn62HUO1D6G2 vtjNaZaVF5XlTWJ2HEuO+IJZzo+yY30AXtnpcUDDAFbCj/KLcM3KtpjXD4OwHd2jcqC3 z/9zYO47t/6vx5MZ4JeFMsVM9EhrczF3DuY1b/Kpqq8sz8hQ36Ck2OoEc/bbJIHufC/g iITczADKUhI62bw2pEfkPnO4HeJcJ85DV1xedDWyAM5HzSruBcfcGobSvVV4EZKKwHtc Tpc/WYCI89EHxrMSaLnGBXuOygqekZpH3Pgl4ovvlNDBCM2H0ZWxbvdkRztKpDnc4X3R rEOA== X-Gm-Message-State: AOJu0YwKTKARa9FU+Fx0r3CDb1eeK8CWcbHhltWSKVAc8AdZvboyO2hR Z2e3fCVQTNjndrDacG82TM2/Di4d0d4= X-Received: by 2002:a05:690c:2e92:b0:5eb:eb51:aa5d with SMTP id eu18-20020a05690c2e9200b005ebeb51aa5dmr3908051ywb.28.1703794184189; Thu, 28 Dec 2023 12:09:44 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id d3-20020a0df403000000b0059f766f9750sm7825729ywf.124.2023.12.28.12.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:43 -0800 (PST) From: Yury Norov To: Andrew Morton , Thomas Gleixner , Ming Lei , linux-kernel@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes Subject: [PATCH 4/9] lib/group_cpus: optimize outer loop in grp_spread_init_one() Date: Thu, 28 Dec 2023 12:09:31 -0800 Message-Id: <20231228200936.2475595-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231228200936.2475595-1-yury.norov@gmail.com> References: <20231228200936.2475595-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: 8bit Similarly to the inner loop, in the outer loop we can use for_each_cpu() macro, and skip CPUs that have been copied. With this patch, the function becomes O(1), despite that it's a double-loop. While here, add a comment why we can't merge the inner and outer logic. Signed-off-by: Yury Norov --- lib/group_cpus.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 0a8ac7cb1a5d..952aac9eaa81 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -17,16 +17,17 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk, const struct cpumask *siblmsk; int cpu, sibl; - for ( ; cpus_per_grp > 0; ) { - cpu = cpumask_first(nmsk); - - /* Should not happen, but I'm too lazy to think about it */ - if (cpu >= nr_cpu_ids) + for_each_cpu(cpu, nmsk) { + if (cpus_per_grp-- == 0) return; + /* + * If a caller wants to spread IRQa on offline CPUs, we need to + * take care of it explicitly because those offline CPUS are not + * included in siblings cpumask. + */ __cpumask_clear_cpu(cpu, nmsk); __cpumask_set_cpu(cpu, irqmsk); - cpus_per_grp--; /* If the cpu has siblings, use them first */ siblmsk = topology_sibling_cpumask(cpu); @@ -38,6 +39,7 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk, __cpumask_clear_cpu(sibl, nmsk); __cpumask_set_cpu(sibl, irqmsk); + cpu = sibl + 1; } } } -- 2.40.1