From nobody Sun Dec 28 00:14:47 2025 Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) (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 38D9A101F8 for ; Thu, 28 Dec 2023 20:09:40 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hX87VFm6" Received: by mail-io1-f52.google.com with SMTP id ca18e2360f4ac-7b3b819f8a3so338100439f.1 for ; Thu, 28 Dec 2023 12:09:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794180; x=1704398980; 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=t+ncE/Ke8W/9eSicUFGfjAMk7XfHt6TzmaC+XB67O8c=; b=hX87VFm68TvZCoWI+oNASYDa+8iXTtG2+fel4NQMpBYpefiZvwQ3Kg3aAImVHF+oYU vbhMvx76dOKygUsn/UwBWjwIgkUEvm0Z8y3nL+1KZXngwaxYauy0gTEpKbdD9gLr+tiZ rBEVQcV/bfbwelTKtpU7X2X1SP85D5t/+UtUEs8ELkvQ6+UBDxEYQX4wI2hm4gGsDEPu dVR5VTnAA45WC07+e7fyqD9YaJsTZgrJI5ir6UroQm26ggVD6WcqNIqfEhibqQB9wklw g7gZD/j6/uc0SIZsLzQ/LqZuNbY4Bz5V/Dknc5S7P074yKB0Of3MekqFmni4ELdpDz91 NZkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794180; x=1704398980; 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=t+ncE/Ke8W/9eSicUFGfjAMk7XfHt6TzmaC+XB67O8c=; b=IPcjWVqVWPJaQmLmrxhfFt97RqfhdO39lwruIpiNOjnp5s1HP2hiduBkzvvWxaqwwC KR6bnApTdCnzQhfxtrd1/CZ+RhzklOE0ti/+2THXr8vKgjAEWReSdR1Gaz6otHrBltZZ vuVZKY7QEbl7WW6CDNqbvq8KzFVSoN4rSRPNUKAVtEUX8QeiLio0Y4t0DCYZ6iuVwB0v ikYJrX0M/HYH74AbDVZVG+v98WDFHPp3uvMyej22Vp2OQMnO/fvo+0908FwkodwAvAv9 krzHEflaDYTFqLq18ykGa12NAsZ7ZlNConzkvb/CVvVnIij2lV5AJHSIaVeqEc4Igey3 hh4Q== X-Gm-Message-State: AOJu0YxjAcL1zFasFNYsU+FTpi1W1TPjZfiiFdZEsM3LXbNisoeLrBBE /oUU3jYlbT6/LlEGDWkFr4M= X-Google-Smtp-Source: AGHT+IEuA7vQwpAxd31H9FBHqzWEuKeId5J+ssN4C4kptziIh6MKYskaoMQzEIuv8u3BjcqQL5u6Fw== X-Received: by 2002:a05:6e02:1c4e:b0:35f:d727:1dba with SMTP id d14-20020a056e021c4e00b0035fd7271dbamr9385256ilg.63.1703794179967; Thu, 28 Dec 2023 12:09:39 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id d3-20020a0df403000000b0059f766f9750sm7825671ywf.124.2023.12.28.12.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:39 -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 1/9] cpumask: introduce for_each_cpu_and_from() Date: Thu, 28 Dec 2023 12:09:28 -0800 Message-Id: <20231228200936.2475595-2-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: quoted-printable Content-Type: text/plain; charset="utf-8" Similarly to for_each_cpu_and(), introduce a for_each_cpu_and_from(), which is handy when it's needed to traverse 2 cpumasks or bitmaps, starting from a given position. Signed-off-by: Yury Norov --- include/linux/cpumask.h | 11 +++++++++++ include/linux/find.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index cfb545841a2c..73ff2e0ef090 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -332,6 +332,17 @@ unsigned int __pure cpumask_next_wrap(int n, const str= uct cpumask *mask, int sta #define for_each_cpu_and(cpu, mask1, mask2) \ for_each_and_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), small_cpu= mask_bits) =20 +/** + * for_each_cpu_and_from - iterate over every cpu in both masks starting f= rom a given cpu + * @cpu: the (optionally unsigned) integer iterator + * @mask1: the first cpumask pointer + * @mask2: the second cpumask pointer + * + * After the loop, cpu is >=3D nr_cpu_ids. + */ +#define for_each_cpu_and_from(cpu, mask1, mask2) \ + for_each_and_bit_from(cpu, cpumask_bits(mask1), cpumask_bits(mask2), smal= l_cpumask_bits) + /** * for_each_cpu_andnot - iterate over every cpu present in one mask, exclu= ding * those present in another. diff --git a/include/linux/find.h b/include/linux/find.h index 5e4f39ef2e72..dfd3d51ff590 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -563,6 +563,9 @@ unsigned long find_next_bit_le(const void *addr, unsign= ed (bit) =3D find_next_and_bit((addr1), (addr2), (size), (bit)), (bit) = < (size);\ (bit)++) =20 +#define for_each_and_bit_from(bit, addr1, addr2, size) \ + for (; (bit) =3D find_next_and_bit((addr1), (addr2), (size), (bit)), (bit= ) < (size); (bit)++) + #define for_each_andnot_bit(bit, addr1, addr2, size) \ for ((bit) =3D 0; \ (bit) =3D find_next_andnot_bit((addr1), (addr2), (size), (bit)), (bi= t) < (size);\ --=20 2.40.1 From nobody Sun Dec 28 00:14:47 2025 Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) (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 81DCF107A4 for ; Thu, 28 Dec 2023 20:09:42 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mTS/Is/R" Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-5e54d40cca2so40808897b3.3 for ; Thu, 28 Dec 2023 12:09:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794181; x=1704398981; 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=MTJvjOs9CDMbScRZQ2ed7lVLiXIATMKcHXT0ZLGRjno=; b=mTS/Is/R17lJ6dI4n66t1gdgquPt5KIYB4dkAHxanoYbD1qTSQ/hIUha+3mjJyJ+Kd ZLVfHQ5eZ3j2CkXDYze10iDiyEldjuT9VSX6c+9199g3krpYMb+XBYOGxh9n8DuruI33 Kx6O5rjEeZPrw5arNdat0t8H60zgEtnlSQ1GOgekDG/BH3LsqgL9cq0VBtXt+GDPTRtc KijHiufAbd5EmRqUCjZOtI1j/572cFNi+b6xRemGoiVzBYO81feOPVjY9twmhFdWQQG1 x+CSEcAtcaEuq7EilWZ4kDAenLTKzf0RYDjKS8GH4EUPBf9ZLbz9eVIWMdNoTNe//br/ ++kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794181; x=1704398981; 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=MTJvjOs9CDMbScRZQ2ed7lVLiXIATMKcHXT0ZLGRjno=; b=uh2LXB1SYqvbjpTloV9gFXYXSmid9AvmkJop8pNes9iPAQWV6GD3hbgk+GN1Mc2mdX kMt/LjhZlK62tuhJrR7zC7j35m+F6Pl78KZTQTnWG0X+VGcVJXAe4bqLK3IcA4eB5m7L 14JV1EnnL18cKY0prV59YBbxnOhvjZETL6f0WwLWiHL6HBia//ZOrO9SXd4oLZXKDjpP D+L37gd+omMsIDMp7hiVFrTZE1JZX/zyUarqxxyFL5wAzPDpil4QgYPcobphNj0Ioo4S q74mxDT1fS7YWddxBWi81icWFim2dxxlFffVtbQAarkmiBIdbjaRLTBKLQhEU6fURouV gPIg== X-Gm-Message-State: AOJu0YzEI+WPtaJKQZrC4DnT29GZKsGok+D0pG/GzSOikpEggFD+JknN dQrZz9OBw/jRD//gVAgw71E= X-Google-Smtp-Source: AGHT+IGGhx2yGE46hMQp8zWymRb4aaEZ/el9a7/MCTXYKakHGTFSkhELP8lH16OaCVxTEwpniW74vg== X-Received: by 2002:a81:5483:0:b0:5e5:39aa:2b4e with SMTP id i125-20020a815483000000b005e539aa2b4emr4631014ywb.26.1703794181469; Thu, 28 Dec 2023 12:09:41 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id c67-20020a814e46000000b005e4d89b4520sm7743452ywb.47.2023.12.28.12.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:40 -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 2/9] lib/group_cpus: optimize inner loop in grp_spread_init_one() Date: Thu, 28 Dec 2023 12:09:29 -0800 Message-Id: <20231228200936.2475595-3-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: quoted-printable Content-Type: text/plain; charset="utf-8" The loop starts from the beginning every time we switch to the next sibling mask. This is the Schlemiel the Painter's style of coding because we know for sure that nmsk is clear up to the current CPU, and we can just continue from the next CPU. Also, we can do it nicer if leverage the dedicated for_each() iterator, and simplify the logic of clearing a bit in nmsk. Signed-off-by: Yury Norov --- lib/group_cpus.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index ee272c4cefcc..063ed9ae1b8d 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -30,14 +30,14 @@ static void grp_spread_init_one(struct cpumask *irqmsk,= struct cpumask *nmsk, =20 /* If the cpu has siblings, use them first */ siblmsk =3D topology_sibling_cpumask(cpu); - for (sibl =3D -1; cpus_per_grp > 0; ) { - sibl =3D cpumask_next(sibl, siblmsk); - if (sibl >=3D nr_cpu_ids) - break; - if (!cpumask_test_and_clear_cpu(sibl, nmsk)) - continue; + sibl =3D cpu + 1; + + for_each_cpu_and_from(sibl, siblmsk, nmsk) { + if (cpus_per_grp-- =3D=3D 0) + return; + + cpumask_clear_cpu(sibl, nmsk); cpumask_set_cpu(sibl, irqmsk); - cpus_per_grp--; } } } --=20 2.40.1 From nobody Sun Dec 28 00:14:47 2025 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 E5EBE10950 for ; Thu, 28 Dec 2023 20:09:43 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f6qTVTvP" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-5e7467eb93aso40915817b3.1 for ; Thu, 28 Dec 2023 12:09:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794183; x=1704398983; 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=OZXxoyrdPME2Vm14lDGLzixuTAYKwkD/pDvmny1lU3w=; b=f6qTVTvPQ9p3f2VrmgZNP5CSz1wdgcEriZ51p7lkhAEACQfjIceDNaZt4en6IfQVLy GFcRTPL6qda5sKU/DCBbxaSHrARmMP2I0ug1xjrFCLvjgSLeXdt8A2RRM/BbdDVzpfyl tf5//xiBBYsVoLNp0VVrAdY7Q9bEthvZvpdUHwO+3O9hZYBOR+7wTkoJCHVHz/+mVCWP CyyI87QDVRCNWVAF71GUdz/tj3O+kr2tV8ivkQqrdnceMIs43ekaWpejoFPf2/ZgoK6X mYge7sv7BVaf4/sLuOHP9eVWvJL5lbV9b9tXH+WcTD3L57w664/D+2qoMDP5rgWW6bsQ KXxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794183; x=1704398983; 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=OZXxoyrdPME2Vm14lDGLzixuTAYKwkD/pDvmny1lU3w=; b=c2RXw+uUDM3tf6/gBu4n1PEH/mg7xOiO31P47YGmEji9CcO1G76KZuYZj+3qoRMLrf 9pXchiCrDRcSF4B8jiaakv3XHH1blEqYPJlDm6YDKJ01eQHRlWc6ikif4QEX6uRV7KQp 2DT8bbJHyGWw2rIrd+kGCAl1Omg/JYu9k2RMvrHj0UWXhENPQE2WwxVNztSEByA2z0vx 0a1wOKo22YI2Ya9UQcS5CcqPhy1HpM9Qdh6rBvD8AFBfVXbI975b/sUq4rjpK0pbLfC6 +YzX9w3ZtN75sX6uE+whrd0xv3hoYJsuUZro6Nqfxe8u3gvefo5jp22qJHGDcxp1kOmD OnlA== X-Gm-Message-State: AOJu0YxcgldXAMCsDexmc2FGpJ36zFEXkRKmN9lAqsVurXgRI2P7KdjH wsvN5cEtPxu5hd5XEH8ApJs= X-Google-Smtp-Source: AGHT+IHK+WvFUJwAhNJSbh8vOeu0A2orn641t053fR5bpXBgUUW8PuXjjIX63e66VFNzLoWJUKfmAQ== X-Received: by 2002:a81:de0d:0:b0:5ee:7299:e2cf with SMTP id k13-20020a81de0d000000b005ee7299e2cfmr1564530ywj.52.1703794182867; Thu, 28 Dec 2023 12:09:42 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id l17-20020a814011000000b005ed71d004b5sm2887863ywn.62.2023.12.28.12.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:42 -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 3/9] lib/group_cpus: relax atomicity requirement in grp_spread_init_one() Date: Thu, 28 Dec 2023 12:09:30 -0800 Message-Id: <20231228200936.2475595-4-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: quoted-printable Content-Type: text/plain; charset="utf-8" Because nmsk and irqmsk are stable, extra atomicity is not required. Signed-off-by: Yury Norov NAKed-by: Ming Lei --- lib/group_cpus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 063ed9ae1b8d..0a8ac7cb1a5d 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -24,8 +24,8 @@ static void grp_spread_init_one(struct cpumask *irqmsk, s= truct cpumask *nmsk, if (cpu >=3D nr_cpu_ids) return; =20 - cpumask_clear_cpu(cpu, nmsk); - cpumask_set_cpu(cpu, irqmsk); + __cpumask_clear_cpu(cpu, nmsk); + __cpumask_set_cpu(cpu, irqmsk); cpus_per_grp--; =20 /* If the cpu has siblings, use them first */ @@ -36,8 +36,8 @@ static void grp_spread_init_one(struct cpumask *irqmsk, s= truct cpumask *nmsk, if (cpus_per_grp-- =3D=3D 0) return; =20 - cpumask_clear_cpu(sibl, nmsk); - cpumask_set_cpu(sibl, irqmsk); + __cpumask_clear_cpu(sibl, nmsk); + __cpumask_set_cpu(sibl, irqmsk); } } } --=20 2.40.1 From nobody Sun Dec 28 00:14:47 2025 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DtW7GVeC" 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-Google-Smtp-Source: AGHT+IE//TotKL+aI3R/b6hMZ911AUJ74tGL0ZeBQAPRf1IhjLzEzGgTwGUL3iZVBR/XruZIPAKSOA== 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: quoted-printable Content-Type: text/plain; charset="utf-8" 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; =20 - for ( ; cpus_per_grp > 0; ) { - cpu =3D cpumask_first(nmsk); - - /* Should not happen, but I'm too lazy to think about it */ - if (cpu >=3D nr_cpu_ids) + for_each_cpu(cpu, nmsk) { + if (cpus_per_grp-- =3D=3D 0) return; =20 + /* + * 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--; =20 /* If the cpu has siblings, use them first */ siblmsk =3D topology_sibling_cpumask(cpu); @@ -38,6 +39,7 @@ static void grp_spread_init_one(struct cpumask *irqmsk, s= truct cpumask *nmsk, =20 __cpumask_clear_cpu(sibl, nmsk); __cpumask_set_cpu(sibl, irqmsk); + cpu =3D sibl + 1; } } } --=20 2.40.1 From nobody Sun Dec 28 00:14:47 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 BF76110A31 for ; Thu, 28 Dec 2023 20:09:46 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UCFjgp5X" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-5e266e8d39eso54825027b3.1 for ; Thu, 28 Dec 2023 12:09:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794185; x=1704398985; 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=Fiqg7NMTo1hnms2N+QcuxP30iXk/HvqGHex9PC1KYAY=; b=UCFjgp5XnaVjOjmorJ/Ed1flWnOHA9/D3ztHX2r1SbV/8/TXsW52EW89yrI4Xe7zpy HJJPVfWmCAorjUIhHZ7z+iBYtjCysDuzX4psoAWqdsGrhM/4HLL+UKzOMEmodb+qsO/B 73SjlgXWGU2s+okfTOxWxuB0JgQcTeK93QrxgXVrMEUTDFdBYwtWwwRAB5FzWb5wgubf D5M+6H5tqVyT7RIdh33M4CF19PCpQHBhDzasXqnIUwIBrBC4P2YXD8WWqLGqOo0FIXVa lnbq8fajbwCRBm0TvHXNdMdDAUEjtuieV3JQPk13LYJt3Fnt/SZsk5uKSlaK0UFeZVgU rXAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794185; x=1704398985; 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=Fiqg7NMTo1hnms2N+QcuxP30iXk/HvqGHex9PC1KYAY=; b=NguC6cNOSmZ35iQoFXJ4vKXIOkTSm4N9gPmyhPZhN/xgOZw1Ps8VjrU0GlyDw487SR NhPO7vQg7R1O9sfGcAoXTEc2UCKGzl8ApVMuocUQXokkBw5HddXZCPZ/bnqxffHro5mm Bl9Mvh0D4oAGlkknOIJ3WJdRNMBoSN4bPkyFvE1uJbFAfDKXy4Vd83Mh2zl8WputkB7v hw3tu2fBC2HKNkIBGbw6q9Mto0g5QTNt4CGKsSBi2VXvrVieArTqrRZTqKhoZiyP0Tf+ nCC0utOWHgUv6V8fzX6LATXQOmsmozPE6JoTWz9niiXAc/SjjeSjd+snVHagwai7pQ0/ 1gJg== X-Gm-Message-State: AOJu0Yx8F+/6xHyVgC+SbRDovsJM/OXNwkC/XiSJqcig7jmmDA9hUPsc +dnGg1WR1qma3MaVlWiFaok= X-Google-Smtp-Source: AGHT+IER6tNGef2L3hiXuMT0rLdDBtturZ2Q3+wyCn4IOGclEdDMoL2I66MldAZV8xbecCgLWJeq0A== X-Received: by 2002:a0d:d2c6:0:b0:5e7:cd6d:b6da with SMTP id u189-20020a0dd2c6000000b005e7cd6db6damr7447267ywd.47.1703794185564; Thu, 28 Dec 2023 12:09:45 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id n127-20020a817285000000b005ca99793930sm7691447ywc.20.2023.12.28.12.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:44 -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 5/9] lib/group_cpus: don't zero cpumasks in group_cpus_evenly() on allocation Date: Thu, 28 Dec 2023 12:09:32 -0800 Message-Id: <20231228200936.2475595-6-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: quoted-printable Content-Type: text/plain; charset="utf-8" nmsk and npresmsk are both allocated with zalloc_cpumask_var(), but they are initialized by copying later in the code, and so may be allocated uninitialized. Signed-off-by: Yury Norov --- lib/group_cpus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index 952aac9eaa81..72c308f8c322 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -354,10 +354,10 @@ struct cpumask *group_cpus_evenly(unsigned int numgrp= s) int ret =3D -ENOMEM; struct cpumask *masks =3D NULL; =20 - if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL)) + if (!alloc_cpumask_var(&nmsk, GFP_KERNEL)) return NULL; =20 - if (!zalloc_cpumask_var(&npresmsk, GFP_KERNEL)) + if (!alloc_cpumask_var(&npresmsk, GFP_KERNEL)) goto fail_nmsk; =20 node_to_cpumask =3D alloc_node_to_cpumask(); --=20 2.40.1 From nobody Sun Dec 28 00:14:47 2025 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 D67DE111A0 for ; Thu, 28 Dec 2023 20:09:47 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Eja/+ae/" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-5e54d40cca2so40809207b3.3 for ; Thu, 28 Dec 2023 12:09:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794187; x=1704398987; 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=oeRpHv3Rhilh+EuNYr3bORiW/nxnS2Awjr3v2Rkry9o=; b=Eja/+ae/XJcxuLTLIZmeaQ+OPV2QONh46htJCpY7l0ArQDois0UVMNqr2I/kpidJ0D l97e9PPfR45+RMCGsdBnxwFMxs6rpaPOKm08gy9c+xGzHYn+nMPEKkJd/AuuCQ2VQRk8 cxtLQMhoQD1djjBE7a017GIe7mU9CUC4LVT6g20w2Cl0HyMXWpz8BVi7EoyPxFKPL/bZ 3oO/9L47u6vqw9Ivcc9Cd/RIo8oujj3Ot1WnumMMAq7EvwqaTd561PvXlTvnJXhbNpUk bBaS28FpYo1CjkCadNhWqe0DaKZFZrJNE1skLypOw8wYIlDLW17y5QEZwscMX8fj1mIb OZGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794187; x=1704398987; 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=oeRpHv3Rhilh+EuNYr3bORiW/nxnS2Awjr3v2Rkry9o=; b=CCC2VM7uEqnKL/vP/T+AyXFqVGSMj3ENpn87vDui0WxM8l+T+1y+LoR2TktJs7LI9I EYPJdw+P5GTsDLLO4St529/35PrvCdYXbStfWEP8nwS7fP0asdKYVOo016xEjBfngOrt XJfhgNMpZB6o92Ufa9FzOX+Jtj2cY0IUwdaGuz+5HZYHteJ9PcN1cvXETP2ocpbWUj5s nqhraYlD0meWI/dGfAVA/jL9RrK5XK0q16gMlAvNheWCHBuPPT+Ks+uk1omO1arwmLa8 4L7bDRxWQoaxtY4QHjQjTQUlpAo2a228a+CiHW4F2umlOFleRbV/UMZnTeI2xWw2s0hV 5T9w== X-Gm-Message-State: AOJu0YzdwWIX2p9vknAliY3rFln3P28+2ehUqjxVhO6Du4EatYBJvK3W cO3haqtlGlNReDEXwEB7DSo= X-Google-Smtp-Source: AGHT+IHcbFk05w6SJYqvEuo5VRQtvdXG7sZmGKgqL+yYU9vmUaxJMjyDmh/gtRJllpF5LyxL0d18VA== X-Received: by 2002:a81:c603:0:b0:5ee:f221:326f with SMTP id l3-20020a81c603000000b005eef221326fmr1132194ywi.58.1703794186968; Thu, 28 Dec 2023 12:09:46 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id d13-20020a81ab4d000000b005e71fbbc661sm7657164ywk.143.2023.12.28.12.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:46 -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 6/9] lib/group_cpus: drop unneeded cpumask_empty() call in __group_cpus_evenly() Date: Thu, 28 Dec 2023 12:09:33 -0800 Message-Id: <20231228200936.2475595-7-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: quoted-printable Content-Type: text/plain; charset="utf-8" The function is called twice. First time it's called with cpumask_present as a parameter, which can't be empty. Second time it's called with a mask created with cpumask_andnot(), which returns false if the result is an empty mask. We can safely drop redundant cpumask_empty() call from the __group_cpus_evenly() and save few cycles. Signed-off-by: Yury Norov Reviewed-by: Ming Lei --- 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 72c308f8c322..b8c0c3ae2bbd 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -259,9 +259,6 @@ static int __group_cpus_evenly(unsigned int startgrp, u= nsigned int numgrps, nodemask_t nodemsk =3D NODE_MASK_NONE; struct node_groups *node_groups; =20 - if (cpumask_empty(cpu_mask)) - return 0; - nodes =3D get_nodes_in_cpumask(node_to_cpumask, cpu_mask, &nodemsk); =20 /* @@ -401,9 +398,14 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps) curgrp =3D 0; else curgrp =3D nr_present; - cpumask_andnot(npresmsk, cpu_possible_mask, npresmsk); - ret =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, - npresmsk, nmsk, masks); + + if (cpumask_andnot(npresmsk, cpu_possible_mask, npresmsk)) + /* If npresmsk is not empty */ + ret =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, + npresmsk, nmsk, masks); + else + ret =3D 0; + if (ret >=3D 0) nr_others =3D ret; =20 --=20 2.40.1 From nobody Sun Dec 28 00:14:47 2025 Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) (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 4A7DC11705 for ; Thu, 28 Dec 2023 20:09:49 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UzeQM+vF" Received: by mail-io1-f41.google.com with SMTP id ca18e2360f4ac-7b7d55d7717so293128539f.2 for ; Thu, 28 Dec 2023 12:09:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794188; x=1704398988; 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=HfZWh6S86hfLbf3ALuySh4PKa92mkoOaYgRP6tzCQaQ=; b=UzeQM+vFVJ1Z33zQAvAHTAHjxGTHwLNIeQX066HcWxc6uwdbYCagg+E8AEPY1hGbpJ /kBzDFdin6YQbFBPIU6J7Zi8XwzZJkYaZK2IBG48MKqhJOC6FVwuJwMoJpkTfPhRzmCu dsUh80Fg0dhuYsSZGOjlRBbUqkhgm4GQg2hzPHBVW79L+xXq2N6srNINPwgr2DyHcyrD tBteBTkeQuvMdrWiZPiNIm/k3WHOEzCz3LuXz0bPj+89T/TpuJQOW69IGtemCht+KNxD va/rA+EQtXBE3dq/GVxsCBsAsSflH4jYmZJH94jo4dUFco1WyLgg5Zwze2LYmcxTfpb2 j12w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794188; x=1704398988; 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=HfZWh6S86hfLbf3ALuySh4PKa92mkoOaYgRP6tzCQaQ=; b=ZRYcMNfht/Nbvno9lIxDTh/rWIeZNR929kuUvgJf/OrDJARxoMr4bwViRVe57Io2QN Ctv89QW79lp1e/8thfAWO+xmzNm1AjugBXj2IrbMxMd6Wi832Nn4i9qy4fz96F1Ju0qs nap2M5cK65zy2Qn56tUhGHr/bsluXmbNkhfGkWExJTQy4fxhQ2643qO+gZy0/ZCASUEK co55vlYxyFERy/Bj/nHXvdNASv4d1CKwYm0vRN7dZJbW/7td3DMbGPPdWdCMeVj1Qi+Y rl+2O0rgh/KkVbdojGrGiLtl3Hwv1P9SDDYK+DA7s1hVyfRdbbvodI2rS28b3gWm3s5b lVWg== X-Gm-Message-State: AOJu0YwKJLyjW3Uzevt2O+ywB5300brwQqyYGm4pKvVNW6tjbtnm8VdF ZMvqmgkVtv/N8JTXKnIbtr0= X-Google-Smtp-Source: AGHT+IG9Lqqh2T5AlaAupitak9SDKW67lW/8ZquP3N4mohdxhGbx0NttQfb1TF3K5GkIEQUNGQzi2w== X-Received: by 2002:a05:6e02:1785:b0:35f:e9a7:372a with SMTP id y5-20020a056e02178500b0035fe9a7372amr11090768ilu.47.1703794188311; Thu, 28 Dec 2023 12:09:48 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id gz17-20020a05690c471100b005e93604a567sm7604354ywb.52.2023.12.28.12.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:47 -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 7/9] cpumask: define cleanup function for cpumasks Date: Thu, 28 Dec 2023 12:09:34 -0800 Message-Id: <20231228200936.2475595-8-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: quoted-printable Content-Type: text/plain; charset="utf-8" Now we can simplify a code that allocates cpumasks for local needs. Signed-off-by: Yury Norov --- include/linux/cpumask.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 73ff2e0ef090..f85515ebcf42 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -7,6 +7,7 @@ * set of CPUs in a system, one bit position per CPU number. In general, * only nr_cpu_ids (<=3D NR_CPUS) bits are valid. */ +#include #include #include #include @@ -988,6 +989,8 @@ static inline bool cpumask_available(cpumask_var_t mask) } #endif /* CONFIG_CPUMASK_OFFSTACK */ =20 +DEFINE_FREE(free_cpumask_var, struct cpumask *, if (_T) free_cpumask_var(_= T)); + /* It's common to want to use cpu_all_mask in struct member initializers, * so it has to refer to an address rather than a pointer. */ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS); --=20 2.40.1 From nobody Sun Dec 28 00:14:47 2025 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (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 C0F4611C86 for ; Thu, 28 Dec 2023 20:09:50 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BOtHbzZT" Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-5e7bb1e0db8so51508527b3.0 for ; Thu, 28 Dec 2023 12:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794190; x=1704398990; 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=9TlZbwiWH1Vw1yns1kCBHb/nB4XyLWx4ePYr3lVNDe0=; b=BOtHbzZTOSKvn1C1KCqBDEpwzb1/GE9PqC7WuXzGgkBujhtePTR4z/0t5WSfYeXe7L dRB4nCEaSBgK7wKWDLgNttfAc7gOggJJu9F1DVwwC8Q4MPebygThcNJ86H3LkudI2iwZ kqfMdHbX5O7vuQtRMLL8t0NcaH4zMN8+pICWWPKIKM9JQ7CGIgUnmxH0Dsiu6SAuC3hI ffzrhr2PvZQnRNoKxU3Fal/aW7uFrYpjaQIzeacqHD1pdVv1LshLCvYwvXOo7l890UqM DP4f7nLpoYu1zzZaLQmnREtg1x3sapE9wTzItXrnTJP+SJ6BCI81sBvFkqh0F7PaB4HB e1Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794190; x=1704398990; 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=9TlZbwiWH1Vw1yns1kCBHb/nB4XyLWx4ePYr3lVNDe0=; b=hj+RXtgtt5Hyit1j48wINCHRHWDKHPT3WhHXvs5Vem9/m7Q71oN/36KcMnmfHBWU63 OS/6doNNYTzToyeHQFFWBS1BBVf9+kuTbQnUrNBhIM+kZrCMDm6Lf1IvPk2gSsfLVG1T rXItX3U6kgvBbKAI5qvrdW3W6adAVGKn8ncpmOvArXi2CH9EomQ681Bakk+j+BixPgRy q5K5d7CNIn/P57FNRFS/QzMqVydHjSoCCGIq9BTITRLnxPAA+kHFmQHiJpEXFcZ0rscU bCtNlQG6ywmTlpLz8ad8RLPDV0fwv6NwKaHXRulYYGsxZL9VEjHx2HPVqJgcUL7xMoJy CqfQ== X-Gm-Message-State: AOJu0Yy+DJnED5NBlIgnklYweZT9ZAbK9R0adit1VuI9uNy8nyyFGO9H GZZTgJ0zi1ZZG39ESNcd9Ps= X-Google-Smtp-Source: AGHT+IEWxqyGLbrIXb7NZcPO9H8pmvjZvPfzBkTcaALqI3LX+W+Usl3clXueRADT8bD6BbAx++kEcg== X-Received: by 2002:a81:4522:0:b0:5eb:1edf:ae28 with SMTP id s34-20020a814522000000b005eb1edfae28mr5483139ywa.57.1703794189674; Thu, 28 Dec 2023 12:09:49 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id w126-20020a817b84000000b005e79f80959bsm7812882ywc.112.2023.12.28.12.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:49 -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 8/9] lib/group_cpus: rework group_cpus_evenly() Date: Thu, 28 Dec 2023 12:09:35 -0800 Message-Id: <20231228200936.2475595-9-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: quoted-printable Content-Type: text/plain; charset="utf-8" Leverage cleanup machinery and drop most of housekeeping code. Particularly, drop unneeded and erroneously initialized with -ENOMEM variable ret. Signed-off-by: Yury Norov --- lib/group_cpus.c | 79 +++++++++++++++--------------------------------- 1 file changed, 25 insertions(+), 54 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index b8c0c3ae2bbd..b9ab32e00a79 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -76,6 +76,8 @@ static void free_node_to_cpumask(cpumask_var_t *masks) kfree(masks); } =20 +DEFINE_FREE(free_node_to_cpumask, cpumask_var_t *, if (_T) free_node_to_cp= umask(_T)); + static void build_node_to_cpumask(cpumask_var_t *masks) { int cpu; @@ -345,26 +347,16 @@ static int __group_cpus_evenly(unsigned int startgrp,= unsigned int numgrps, */ struct cpumask *group_cpus_evenly(unsigned int numgrps) { - unsigned int curgrp =3D 0, nr_present =3D 0, nr_others =3D 0; - cpumask_var_t *node_to_cpumask; - cpumask_var_t nmsk, npresmsk; - int ret =3D -ENOMEM; - struct cpumask *masks =3D NULL; - - if (!alloc_cpumask_var(&nmsk, GFP_KERNEL)) + cpumask_var_t *node_to_cpumask __free(free_node_to_cpumask) =3D alloc_nod= e_to_cpumask(); + struct cpumask *masks __free(kfree) =3D kcalloc(numgrps, sizeof(*masks), = GFP_KERNEL); + cpumask_var_t npresmsk __free(free_cpumask_var); + cpumask_var_t nmsk __free(free_cpumask_var); + unsigned int curgrp, nr_present, nr_others; + + if (!masks || !node_to_cpumask || !alloc_cpumask_var(&nmsk, GFP_KERNEL) + || !alloc_cpumask_var(&npresmsk, GFP_KERNEL)) return NULL; =20 - if (!alloc_cpumask_var(&npresmsk, GFP_KERNEL)) - goto fail_nmsk; - - node_to_cpumask =3D alloc_node_to_cpumask(); - if (!node_to_cpumask) - goto fail_npresmsk; - - masks =3D kcalloc(numgrps, sizeof(*masks), GFP_KERNEL); - if (!masks) - goto fail_node_to_cpumask; - build_node_to_cpumask(node_to_cpumask); =20 /* @@ -382,11 +374,15 @@ struct cpumask *group_cpus_evenly(unsigned int numgrp= s) cpumask_copy(npresmsk, data_race(cpu_present_mask)); =20 /* grouping present CPUs first */ - ret =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, - npresmsk, nmsk, masks); - if (ret < 0) - goto fail_build_affinity; - nr_present =3D ret; + nr_present =3D __group_cpus_evenly(0, numgrps, node_to_cpumask, npresmsk,= nmsk, masks); + if (nr_present < 0) + return NULL; + + /* If npresmsk is empty */ + if (!cpumask_andnot(npresmsk, cpu_possible_mask, npresmsk)) + return_ptr(masks); + + curgrp =3D nr_present < numgrps ? nr_present : 0; =20 /* * Allocate non present CPUs starting from the next group to be @@ -394,38 +390,13 @@ struct cpumask *group_cpus_evenly(unsigned int numgrp= s) * group space, assign the non present CPUs to the already * allocated out groups. */ - if (nr_present >=3D numgrps) - curgrp =3D 0; - else - curgrp =3D nr_present; - - if (cpumask_andnot(npresmsk, cpu_possible_mask, npresmsk)) - /* If npresmsk is not empty */ - ret =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, - npresmsk, nmsk, masks); - else - ret =3D 0; - - if (ret >=3D 0) - nr_others =3D ret; - - fail_build_affinity: - if (ret >=3D 0) - WARN_ON(nr_present + nr_others < numgrps); - - fail_node_to_cpumask: - free_node_to_cpumask(node_to_cpumask); - - fail_npresmsk: - free_cpumask_var(npresmsk); - - fail_nmsk: - free_cpumask_var(nmsk); - if (ret < 0) { - kfree(masks); + nr_others =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, + npresmsk, nmsk, masks); + if (nr_others < 0) return NULL; - } - return masks; + + WARN_ON(nr_present + nr_others < numgrps); + return_ptr(masks); } #else /* CONFIG_SMP */ struct cpumask *group_cpus_evenly(unsigned int numgrps) --=20 2.40.1 From nobody Sun Dec 28 00:14:47 2025 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 330AB11CB7 for ; Thu, 28 Dec 2023 20:09:52 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KNXQMtKG" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-5ebca94cf74so26631017b3.0 for ; Thu, 28 Dec 2023 12:09:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703794191; x=1704398991; 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=zuwjfzn9Rfwwgagf8FmGExz6QUv+UeUHULe7+jnQcq0=; b=KNXQMtKGf3U+zjtBUmWGOpdnRNrLimoC8Z5HyKHcnq7BeOWvqqEfeUxNuu5YzCBgac Jdg3WFoMq6zYllgrJa3FBNSQaYy/P2fUBDbkGWWKn1712kCLzoI1LRwRMAVFHlq5X3xW tiieTqfO0BjCYpFi56HCbNd2r3WBQeDWja+0CLCoZYwXaJGz4EfmRvwP69CFY72FBskR /q7GZwUFWN8RBNeDnykP12vHw7oqzhaYGdJEQ9va7KLj/G6Q8A1Xv1Rcn/dZD1G+y34R 4/JFnqcjfaSkAXresDG/LnvudJFMupe5fODmdyJl0y/7GsCp+k/MAn/qsZntfzQkNmiP fZ7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703794191; x=1704398991; 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=zuwjfzn9Rfwwgagf8FmGExz6QUv+UeUHULe7+jnQcq0=; b=Qq9A7DInuA/bH95e9DjkPIg26vysGtYBcIOBFK/K2n1ojpcfZwP+8CtxheWHdA1erY UNaeRbI6riJSMluMziir74NZZKWemJEM7aTHROaBNnWPuagp1bbfjuUJPO6jlmojGAxj qXaQDqV5mnPckMh6nY6jf9fwjWGJ1G4815jlkLZKX9z76xofGp2EnhFhVIfV62gPLzvs +9Va8Pw6rhlK0kWdNtLAyfQbgCrOsZyM29PdFz/E1BqxqIYFe7IZ0qzk5vFzg0IuOg+z 5arJN4tftHO6EmsvQaibKy5JRh/aTZ+8/n7wvDtaQj1YF3kD7lMl3+19wWsgCY6lguWa /j0w== X-Gm-Message-State: AOJu0YxSsi0Q41cjgcP6h4fOsBnCv7a3G65OQBu7e3glqHwSf0xx8nYk 8Cx0PM9Wab49orADscSNRcE= X-Google-Smtp-Source: AGHT+IFbF1+LVktMVD7en5D6HNE0SGHAz/HAc5YF47LDJpVcDL8ft1yLx9TCEJehoNm6TpwGlxsapQ== X-Received: by 2002:a0d:d74c:0:b0:5e7:5577:2af2 with SMTP id z73-20020a0dd74c000000b005e755772af2mr5990440ywd.62.1703794191147; Thu, 28 Dec 2023 12:09:51 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:967c:a333:ae09:3f60]) by smtp.gmail.com with ESMTPSA id q126-20020a815c84000000b005e8af6a6e19sm7749528ywb.144.2023.12.28.12.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 12:09:50 -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 9/9] lib/group_cpus: simplify group_cpus_evenly() for more Date: Thu, 28 Dec 2023 12:09:36 -0800 Message-Id: <20231228200936.2475595-10-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: quoted-printable Content-Type: text/plain; charset="utf-8" The nmsk parameter is used only in helper function, so move it there. Suggested-by: Ming Lei Signed-off-by: Yury Norov --- lib/group_cpus.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/group_cpus.c b/lib/group_cpus.c index b9ab32e00a79..3a0db0f51f09 100644 --- a/lib/group_cpus.c +++ b/lib/group_cpus.c @@ -253,13 +253,17 @@ static void alloc_nodes_groups(unsigned int numgrps, static int __group_cpus_evenly(unsigned int startgrp, unsigned int numgrps, cpumask_var_t *node_to_cpumask, const struct cpumask *cpu_mask, - struct cpumask *nmsk, struct cpumask *masks) + struct cpumask *masks) { unsigned int i, n, nodes, cpus_per_grp, extra_grps, done =3D 0; unsigned int last_grp =3D numgrps; unsigned int curgrp =3D startgrp; nodemask_t nodemsk =3D NODE_MASK_NONE; struct node_groups *node_groups; + cpumask_var_t nmsk __free(free_cpumask_var); + + if (!alloc_cpumask_var(&nmsk, GFP_KERNEL)) + return -ENOMEM; =20 nodes =3D get_nodes_in_cpumask(node_to_cpumask, cpu_mask, &nodemsk); =20 @@ -350,11 +354,9 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps) cpumask_var_t *node_to_cpumask __free(free_node_to_cpumask) =3D alloc_nod= e_to_cpumask(); struct cpumask *masks __free(kfree) =3D kcalloc(numgrps, sizeof(*masks), = GFP_KERNEL); cpumask_var_t npresmsk __free(free_cpumask_var); - cpumask_var_t nmsk __free(free_cpumask_var); unsigned int curgrp, nr_present, nr_others; =20 - if (!masks || !node_to_cpumask || !alloc_cpumask_var(&nmsk, GFP_KERNEL) - || !alloc_cpumask_var(&npresmsk, GFP_KERNEL)) + if (!masks || !node_to_cpumask || !alloc_cpumask_var(&npresmsk, GFP_KERNE= L)) return NULL; =20 build_node_to_cpumask(node_to_cpumask); @@ -374,7 +376,7 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps) cpumask_copy(npresmsk, data_race(cpu_present_mask)); =20 /* grouping present CPUs first */ - nr_present =3D __group_cpus_evenly(0, numgrps, node_to_cpumask, npresmsk,= nmsk, masks); + nr_present =3D __group_cpus_evenly(0, numgrps, node_to_cpumask, npresmsk,= masks); if (nr_present < 0) return NULL; =20 @@ -390,8 +392,7 @@ struct cpumask *group_cpus_evenly(unsigned int numgrps) * group space, assign the non present CPUs to the already * allocated out groups. */ - nr_others =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, - npresmsk, nmsk, masks); + nr_others =3D __group_cpus_evenly(curgrp, numgrps, node_to_cpumask, npres= msk, masks); if (nr_others < 0) return NULL; =20 --=20 2.40.1