]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
RDMA: hfi1: simplify init_real_cpu_mask()
authorYury Norov [NVIDIA] <yury.norov@gmail.com>
Wed, 4 Jun 2025 19:39:40 +0000 (15:39 -0400)
committerLeon Romanovsky <leon@kernel.org>
Thu, 26 Jun 2025 09:19:39 +0000 (05:19 -0400)
The function opencodes cpumask_nth() and cpumask_clear_cpus(). The
dedicated helpers are easier to use and  usually much faster than
opencoded for-loops.

While there, drop useless clear of real_cpu_mask.

Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com>
Link: https://patch.msgid.link/20250604193947.11834-5-yury.norov@gmail.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/hfi1/affinity.c

index 9ea80b777061e6b185091523b5e80348ec66b8aa..b2884226827a6f83abe602602529e1e0e190fdfa 100644 (file)
@@ -92,9 +92,7 @@ static void cpu_mask_set_put(struct cpu_mask_set *set, int cpu)
 /* Initialize non-HT cpu cores mask */
 void init_real_cpu_mask(void)
 {
-       int possible, curr_cpu, i, ht;
-
-       cpumask_clear(&node_affinity.real_cpu_mask);
+       int possible, curr_cpu, ht;
 
        /* Start with cpu online mask as the real cpu mask */
        cpumask_copy(&node_affinity.real_cpu_mask, cpu_online_mask);
@@ -110,17 +108,10 @@ void init_real_cpu_mask(void)
         * "real" cores.  Assumes that HT cores are not enumerated in
         * succession (except in the single core case).
         */
-       curr_cpu = cpumask_first(&node_affinity.real_cpu_mask);
-       for (i = 0; i < possible / ht; i++)
-               curr_cpu = cpumask_next(curr_cpu, &node_affinity.real_cpu_mask);
-       /*
-        * Step 2.  Remove the remaining HT siblings.  Use cpumask_next() to
-        * skip any gaps.
-        */
-       for (; i < possible; i++) {
-               cpumask_clear_cpu(curr_cpu, &node_affinity.real_cpu_mask);
-               curr_cpu = cpumask_next(curr_cpu, &node_affinity.real_cpu_mask);
-       }
+       curr_cpu = cpumask_nth(possible / ht, &node_affinity.real_cpu_mask) + 1;
+
+       /* Step 2.  Remove the remaining HT siblings. */
+       cpumask_clear_cpus(&node_affinity.real_cpu_mask, curr_cpu, nr_cpu_ids - curr_cpu);
 }
 
 int node_affinity_init(void)