From patchwork Sat Mar 25 18:55:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13187862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEF63C6FD20 for ; Sat, 25 Mar 2023 18:55:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229446AbjCYSz1 (ORCPT ); Sat, 25 Mar 2023 14:55:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230223AbjCYSz0 (ORCPT ); Sat, 25 Mar 2023 14:55:26 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17CDD8A6B; Sat, 25 Mar 2023 11:55:25 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id s8so3615975ois.2; Sat, 25 Mar 2023 11:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679770524; 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=P8DARwyXB1+f8bu+p73b5c/Fp4Rp72nImACGHBPnqI8=; b=IdkxR+kxYgzj76LG+tvXbGzVQrTmA+weS+xDTfhfxO1G9+bJ7pznH6RtR9snmX9jwi g112eus5kfFOueYG3J811mzC9ykU6d5wloVvAaaDqfPQeAQpib+JsOT83HmdBV+dTNhK Sqv/Z5s68bM1OQ+iOK3QKAxn9LH0Qa5G7/yPPeClPsV3YyQioTtubyrTilr+qWi+JLw0 q9AydQ/RERe54yNKnLRNiL0R07d7lgDMcUCNNnevaDvTvShTzMsiBPSQNs8MpNNcpnCd cQ9uXJbE9CK1cBeOiKjxea/FwJyRECQ0fstzFwglYaIVtwuUuBuL6a+E4u3U/M5pRxKt VvjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679770524; 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=P8DARwyXB1+f8bu+p73b5c/Fp4Rp72nImACGHBPnqI8=; b=H3wOFmBEtRfA/1jOlHcHXWQyIPxs2INlngGcyRKLvmyk9gc0ayrSsVciGe2ac//BpJ 6o9WQwO9t3JzShaFfPUHBf8fB+3raV9Dbsa57+Za+zERER59Rg1BqK8WqDokcuFY++62 E6/YmdO0OD79uMEQX1grNKzudPYZ6ot7M6dRNNG+t38B8pcCcgCoexpKA517ets9lc20 hXtfM7Jjr0oDkEoSR+TDLBX7F0qZYdlMfDauAx2tShBQN7LKFL1J/eS19tAE0nqVHjLO JQmeVIY0AONp5ic6CEsPR01ntKBzU5zxrd8Y90//ATEtl7MYh0rdPg3ZF0MufkmXORtk yVgw== X-Gm-Message-State: AO0yUKW4c6TXbQWqK5VWi+vxPk0Q3cCuMuKYaSVJ7YGrGOeZlLKX1c85 3dhXWVLuWPVXtjdh6Y8G/2E= X-Google-Smtp-Source: AK7set+UxP7Iq9OQ1/Cyls3NrcFxB4JDS701EemJFeg1cf2g7q33ne9kN5OpaqhZuvwMpJ73veQPfQ== X-Received: by 2002:a05:6808:1584:b0:386:d1bd:8766 with SMTP id t4-20020a056808158400b00386d1bd8766mr4843928oiw.13.1679770524348; Sat, 25 Mar 2023 11:55:24 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id o187-20020acaf0c4000000b0038476262f65sm9559710oih.33.2023.03.25.11.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 11:55:24 -0700 (PDT) From: Yury Norov To: Jakub Kicinski , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Pawel Chmielewski , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: [PATCH 1/8] lib/find: add find_next_and_andnot_bit() Date: Sat, 25 Mar 2023 11:55:07 -0700 Message-Id: <20230325185514.425745-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325185514.425745-1-yury.norov@gmail.com> References: <20230325185514.425745-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Similarly to find_nth_and_andnot_bit(), find_next_and_andnot_bit() is a convenient helper that allows traversing bitmaps without storing intermediate results in a temporary bitmap. In the following patches the function is used to implement NUMA-aware CPUs enumeration. Signed-off-by: Yury Norov --- include/linux/find.h | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/find_bit.c | 12 ++++++++++++ 2 files changed, 55 insertions(+) diff --git a/include/linux/find.h b/include/linux/find.h index 4647864a5ffd..bde0ba9fa59b 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -14,6 +14,9 @@ unsigned long _find_next_and_bit(const unsigned long *addr1, const unsigned long unsigned long nbits, unsigned long start); unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, unsigned long start); +unsigned long _find_next_and_andnot_bit(const unsigned long *addr1, const unsigned long *addr2, + const unsigned long *addr3, unsigned long nbits, + unsigned long start); unsigned long _find_next_zero_bit(const unsigned long *addr, unsigned long nbits, unsigned long start); extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size); @@ -127,6 +130,40 @@ unsigned long find_next_andnot_bit(const unsigned long *addr1, } #endif +#ifndef find_next_and_andnot_bit +/** + * find_next_and_andnot_bit - find the next bit set in *addr1 and *addr2, + * excluding all the bits in *addr3 + * @addr1: The first address to base the search on + * @addr2: The second address to base the search on + * @addr3: The third address to base the search on + * @size: The bitmap size in bits + * @offset: The bitnumber to start searching at + * + * Returns the bit number for the next set bit + * If no bits are set, returns @size. + */ +static __always_inline +unsigned long find_next_and_andnot_bit(const unsigned long *addr1, + const unsigned long *addr2, + const unsigned long *addr3, + unsigned long size, + unsigned long offset) +{ + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >= size)) + return size; + + val = *addr1 & *addr2 & ~*addr3 & GENMASK(size - 1, offset); + return val ? __ffs(val) : size; + } + + return _find_next_and_andnot_bit(addr1, addr2, addr3, size, offset); +} +#endif + #ifndef find_next_zero_bit /** * find_next_zero_bit - find the next cleared bit in a memory region @@ -536,6 +573,12 @@ unsigned long find_next_bit_le(const void *addr, unsigned (bit) = find_next_andnot_bit((addr1), (addr2), (size), (bit)), (bit) < (size);\ (bit)++) +#define for_each_and_andnot_bit(bit, addr1, addr2, addr3, size) \ + for ((bit) = 0; \ + (bit) = find_next_and_andnot_bit((addr1), (addr2), (addr3), (size), (bit)),\ + (bit) < (size); \ + (bit)++) + /* same as for_each_set_bit() but use bit as value to start with */ #define for_each_set_bit_from(bit, addr, size) \ for (; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++) diff --git a/lib/find_bit.c b/lib/find_bit.c index c10920e66788..8e2a6b87262f 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -182,6 +182,18 @@ unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsigned l EXPORT_SYMBOL(_find_next_andnot_bit); #endif +#ifndef find_next_and_andnot_bit +unsigned long _find_next_and_andnot_bit(const unsigned long *addr1, + const unsigned long *addr2, + const unsigned long *addr3, + unsigned long nbits, + unsigned long start) +{ + return FIND_NEXT_BIT(addr1[idx] & addr2[idx] & ~addr3[idx], /* nop */, nbits, start); +} +EXPORT_SYMBOL(_find_next_and_andnot_bit); +#endif + #ifndef find_next_zero_bit unsigned long _find_next_zero_bit(const unsigned long *addr, unsigned long nbits, unsigned long start) From patchwork Sat Mar 25 18:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13187863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B170C6FD20 for ; Sat, 25 Mar 2023 18:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231308AbjCYSze (ORCPT ); Sat, 25 Mar 2023 14:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230354AbjCYSz2 (ORCPT ); Sat, 25 Mar 2023 14:55:28 -0400 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CABDD8A6B; Sat, 25 Mar 2023 11:55:26 -0700 (PDT) Received: by mail-ot1-x32d.google.com with SMTP id f4-20020a9d0384000000b0069fab3f4cafso2575110otf.9; Sat, 25 Mar 2023 11:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679770526; 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=nIVu6CybmYtP37ZaP9bFcl3BmGzC5B9pq4ZT5PiZYvs=; b=LgdsFgStEK1Bm6u3wXfL/BQmSTANWjKvvVvs7YZSt49M8B0v2Ydci5Br5fW9VY90nx A80b37Ovw9jXD1Um11sveYZskiTuptupJDJy/psutKH7YN/l2KvS3sXotqBzee1gyJKH wHItNA5ay054G38i23zMRQp9Ydy4WqfoeacjS4KmY+oN5Fc0BkhyFifEsV3tAxqaDqKw eJvj0akYNIjnmO8BM663OcnHUKuSZzGsvRrxpCjjhUEluEVv9ls60eeYlOX9zPTeZe4E ZVD54++Ule9GSLDwSzc4otdO/kU5pPyEFErXRINCBx4t5yhDyOJuy7mlarar5Ts2sEQ7 JBig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679770526; 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=nIVu6CybmYtP37ZaP9bFcl3BmGzC5B9pq4ZT5PiZYvs=; b=I46a3h0cksOGXxH+ik6XQ5fCTD0ZUIjzs3yiu++Fs4TE3yEYs19vU2jGyWgQTy4TMa tNfTs+NK7eJCJpF1k3mt9MUS4LNX223wtdNB5RVQeOWC1Ymc2GRR/6BkwjjOZG93MTKU NLHUfkPP+UKq0zXsJkpZiN92qUXbTBSFdXvPp5HdE41aSpgTLOu6zr8Kh2rQt8X+CFxo YO/q3FZslSEd1o0XpqquTam6x+8xFsRxcOJStwI8fIM9PIjzfn9eoC74/SW3Gz6bMvO0 s1ro//PkyyAGG/DUyQpwRZDhU7zJX83Khk+9Q8oBdBQFFr8b3bQea+sY5XQUiprzJOqL oB/Q== X-Gm-Message-State: AO0yUKWwz0RVyOL51BJR2dEOh8KfGUC0hg9OWJxRpkVxw/nRYLepMHj5 LLj5HVDvwQzxImOQkuYWzIY= X-Google-Smtp-Source: AK7set90m81EkLeRmjrdLOgpXsKKJzMnuO7cK6zuKoU0enaVY3qZaqiPbgmPLH239WTc/ED2MZoKnQ== X-Received: by 2002:a05:6830:124e:b0:694:8a0f:644a with SMTP id s14-20020a056830124e00b006948a0f644amr4229340otp.38.1679770526049; Sat, 25 Mar 2023 11:55:26 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id k12-20020a0568301bec00b0069f8ff38bcbsm5226781otb.16.2023.03.25.11.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 11:55:25 -0700 (PDT) From: Yury Norov To: Jakub Kicinski , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Pawel Chmielewski , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: [PATCH 2/8] sched/topology: introduce sched_numa_find_next_cpu() Date: Sat, 25 Mar 2023 11:55:08 -0700 Message-Id: <20230325185514.425745-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325185514.425745-1-yury.norov@gmail.com> References: <20230325185514.425745-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The function searches for the next CPU in a given cpumask according to NUMA topology, so that it traverses cpus per-hop. If the CPU is the last cpu in a given hop, sched_numa_find_next_cpu() switches to the next hop, and picks the first CPU from there, excluding those already traversed. Signed-off-by: Yury Norov --- include/linux/topology.h | 7 +++++++ kernel/sched/topology.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/linux/topology.h b/include/linux/topology.h index fea32377f7c7..4a63154fa036 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -247,6 +247,7 @@ static inline const struct cpumask *cpu_cpu_mask(int cpu) #ifdef CONFIG_NUMA int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node); +int sched_numa_find_next_cpu(const struct cpumask *cpus, int cpu, int node, unsigned int *hop); extern const struct cpumask *sched_numa_hop_mask(unsigned int node, unsigned int hops); #else static __always_inline int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) @@ -254,6 +255,12 @@ static __always_inline int sched_numa_find_nth_cpu(const struct cpumask *cpus, i return cpumask_nth(cpu, cpus); } +static __always_inline +int sched_numa_find_next_cpu(const struct cpumask *cpus, int cpu, int node, unsigned int *hop) +{ + return find_next_bit(cpumask_bits(cpus), small_cpumask_bits, cpu); +} + static inline const struct cpumask * sched_numa_hop_mask(unsigned int node, unsigned int hops) { diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 051aaf65c749..1860d9487fe1 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2130,6 +2130,45 @@ int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) } EXPORT_SYMBOL_GPL(sched_numa_find_nth_cpu); +/* + * sched_numa_find_next_cpu() - given the NUMA topology, find the next cpu + * cpumask: cpumask to find a cpu from + * cpu: current cpu + * node: local node + * hop: (in/out) indicates distance order of current CPU to a local node + * + * The function searches for next cpu at a given NUMA distance, indicated + * by hop, and if nothing found, tries to find CPUs at a greater distance, + * starting from the beginning. + * + * returns: cpu, or >= nr_cpu_ids when nothing found. + */ +int sched_numa_find_next_cpu(const struct cpumask *cpus, int cpu, int node, unsigned int *hop) +{ + unsigned long *cur, *prev; + struct cpumask ***masks; + unsigned int ret; + + if (*hop >= sched_domains_numa_levels) + return nr_cpu_ids; + + masks = rcu_dereference(sched_domains_numa_masks); + cur = cpumask_bits(masks[*hop][node]); + if (*hop == 0) + ret = find_next_and_bit(cpumask_bits(cpus), cur, nr_cpu_ids, cpu); + else { + prev = cpumask_bits(masks[*hop - 1][node]); + ret = find_next_and_andnot_bit(cpumask_bits(cpus), cur, prev, nr_cpu_ids, cpu); + } + + if (ret < nr_cpu_ids) + return ret; + + *hop += 1; + return sched_numa_find_next_cpu(cpus, 0, node, hop); +} +EXPORT_SYMBOL_GPL(sched_numa_find_next_cpu); + /** * sched_numa_hop_mask() - Get the cpumask of CPUs at most @hops hops away from * @node From patchwork Sat Mar 25 18:55:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13187864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 199C5C6FD1C for ; Sat, 25 Mar 2023 18:55:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231443AbjCYSzl (ORCPT ); Sat, 25 Mar 2023 14:55:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbjCYSz3 (ORCPT ); Sat, 25 Mar 2023 14:55:29 -0400 Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81C19A276; Sat, 25 Mar 2023 11:55:28 -0700 (PDT) Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-17aaa51a911so5193774fac.5; Sat, 25 Mar 2023 11:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679770528; 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=1zfxWgKB5aCk68T/R6TGeUwEdD4lRWRfSSIJlLsnGFw=; b=BAienO2/ibUVO0Z4YAFHfx3M2quWfEawbFJ+DXnct1BU2jsgxyypiaF2BfYRgCTSeR W21P5x+4dfJ+IZNC45wf6AzDKwp+PjNmhe/CQLANkfBiSBe51uugMEhr1hyi/N6hrsn0 Ld955euqWFwDW5o35hwcavZ8r2LDCkt+hxjysTLrEF7GqZ8esft14n9eaghfKiZj5CaM 7QQ/bjd4r0sbnWr+4kRG9/CeKTqTDuQteHdd7DdwROpxZH0zwHVxHFFU07kvqgdQ4yq6 fFUUNcNWFQH41meSzVGMMuJ/CMutrpn6v/Ddq5Ivd+kpYXifQ5aT2/AxcUSoAabt1Wvw yg0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679770528; 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=1zfxWgKB5aCk68T/R6TGeUwEdD4lRWRfSSIJlLsnGFw=; b=FVVKLU7sqjO6J9ZF+jCPZcjj01IjBhi3EIuka2cZEBw6xzbhq+PCXTHi/akwyrQotL SxNHfUeR9BDVQwFZqeCSvjpYJbhQBPjGDd8z+4qAZE/Rg1SHVVnd/HXwpagaSmpLp3zl h3oH8FIcVF/8aRThiHZHVF30RB8weJXMdVZb9O4YA0zOxOySl7k5yqa7Espf3VILMRKi PGz2jmZAUan4aoCp1YEgzTvveIxu5+XH91wfZnOo/dpJxynIyYsMiKg92GynBYUu3F0A NNBA9UBjAywaM8naWPsh3PhQRLrKfNyPadGebi3Y9f7bOk5Pu4cgSNIGUXo/hE8k2MUB mryw== X-Gm-Message-State: AAQBX9cafsHFhJA0vl7hguVYJQ3xhWmYWSsPj0DHK2dVtwep33fK0IVy 1nBSEGe1rjLsmwiSjjZZfAU= X-Google-Smtp-Source: AKy350ZUylzgZXJP+/bps9ubG4lTHaj53Ti/SBgH1G/IyOBLrh7qovnwSLf+0BT8AMiwuDG3n3oBMA== X-Received: by 2002:a05:6871:401:b0:17e:a4d6:5e18 with SMTP id d1-20020a056871040100b0017ea4d65e18mr5316693oag.45.1679770527848; Sat, 25 Mar 2023 11:55:27 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id o9-20020a9d7649000000b00697be532609sm9978293otl.73.2023.03.25.11.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 11:55:27 -0700 (PDT) From: Yury Norov To: Jakub Kicinski , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Pawel Chmielewski , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: [PATCH 3/8] sched/topology: add for_each_numa_cpu() macro Date: Sat, 25 Mar 2023 11:55:09 -0700 Message-Id: <20230325185514.425745-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325185514.425745-1-yury.norov@gmail.com> References: <20230325185514.425745-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org for_each_cpu() is widely used in the kernel, and it's beneficial to create a NUMA-aware version of the macro. Recently added for_each_numa_hop_mask() works, but switching existing codebase to it is not an easy process. New for_each_numa_cpu() is designed to be similar to the for_each_cpu(). It allows to convert existing code to NUMA-aware as simple as adding a hop iterator variable and passing it inside new macro. for_each_numa_cpu() takes care of the rest. At the moment, we have 2 users of NUMA-aware enumerators. One is Melanox's in-tree driver, and another is Intel's in-review driver: https://lore.kernel.org/lkml/20230216145455.661709-1-pawel.chmielewski@intel.com/ Both real-life examples follow the same pattern: for_each_numa_hop_mask(cpus, prev, node) { for_each_cpu_andnot(cpu, cpus, prev) { if (cnt++ == max_num) goto out; do_something(cpu); } prev = cpus; } With the new macro, it would look like this: for_each_numa_cpu(cpu, hop, node, cpu_possible_mask) { if (cnt++ == max_num) break; do_something(cpu); } Straight conversion of existing for_each_cpu() codebase to NUMA-aware version with for_each_numa_hop_mask() is difficult because it doesn't take a user-provided cpu mask, and eventually ends up with open-coded double loop. With for_each_numa_cpu() it shouldn't be a brainteaser. Consider the NUMA-ignorant example: cpumask_t cpus = get_mask(); int cnt = 0, cpu; for_each_cpu(cpu, cpus) { if (cnt++ == max_num) break; do_something(cpu); } Converting it to NUMA-aware version would be as simple as: cpumask_t cpus = get_mask(); int node = get_node(); int cnt = 0, hop, cpu; for_each_numa_cpu(cpu, hop, node, cpus) { if (cnt++ == max_num) break; do_something(cpu); } The latter looks more verbose and avoids from open-coding that annoying double loop. Another advantage is that it works with a 'hop' parameter with the clear meaning of NUMA distance, and doesn't make people not familiar to enumerator internals bothering with current and previous masks machinery. Signed-off-by: Yury Norov --- include/linux/topology.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/topology.h b/include/linux/topology.h index 4a63154fa036..62a9dd8edd77 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -286,4 +286,24 @@ sched_numa_hop_mask(unsigned int node, unsigned int hops) !IS_ERR_OR_NULL(mask); \ __hops++) +/** + * for_each_numa_cpu - iterate over cpus in increasing order taking into account + * NUMA distances from a given node. + * @cpu: the (optionally unsigned) integer iterator + * @hop: the iterator variable, must be initialized to a desired minimal hop. + * @node: the NUMA node to start the search from. + * + * Requires rcu_lock to be held. + * + * Because it's implemented as double-loop, using 'break' inside the body of + * iterator may lead to undefined behaviour. Use 'goto' instead. + * + * Yields intersection of @mask and cpu_online_mask if @node == NUMA_NO_NODE. + */ +#define for_each_numa_cpu(cpu, hop, node, mask) \ + for ((cpu) = 0, (hop) = 0; \ + (cpu) = sched_numa_find_next_cpu((mask), (cpu), (node), &(hop)),\ + (cpu) < nr_cpu_ids; \ + (cpu)++) + #endif /* _LINUX_TOPOLOGY_H */ From patchwork Sat Mar 25 18:55:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13187865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55EA5C77B62 for ; Sat, 25 Mar 2023 18:55:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231716AbjCYSzm (ORCPT ); Sat, 25 Mar 2023 14:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231248AbjCYSze (ORCPT ); Sat, 25 Mar 2023 14:55:34 -0400 Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5219CA5E5; Sat, 25 Mar 2023 11:55:30 -0700 (PDT) Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-177b78067ffso5184860fac.7; Sat, 25 Mar 2023 11:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679770529; 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=owQqtMurqm2qI+24ndEGs/qWEaDzKKQeglmv6UMu1sw=; b=CyTkRcKyeCvHukeGZUb4EgoTMd6scDuf5XkWBsZ5Xoj3o1Fis9RgqD2p3HM3ksyjQV 18iVk82ZJHo6+dn14ukQS0wClpxYkDUsffKEuU8zwuWA3mKkFaOa2B+KSWgTD34oCX+n OKwp9AaawRw9VpgolapOtgK2tO1ald8AQqzD9uFo3gP2Z5HjCOWtGdAaltv5/aZh2BaZ UF2W6B7MvTK4j1vP8FvJ4brIFGtsCHHxp6ndHNIFBRq7cgQ8CtFNQmpCbjyMAL5NKPmB nUg1OUP0cJBLGiS4njWpN6yHp2PYQqcxnb2g1SpoaFJhRX0Y8+PQ/VYqE6SEnoDAKMQ2 kMJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679770529; 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=owQqtMurqm2qI+24ndEGs/qWEaDzKKQeglmv6UMu1sw=; b=McqSa8r1Cv40Di09d+N7xWTDNp4EfMqrplldz7v1d+RngHAHarENIsnnhFyy8q7bhN NYogltvp4lxZPSD9a/efJJu0w5nEkRza1qb7hobo9gbqb8rDFpm2qBSKGO85qlFPO4+Q tZ2soSRNsYNKnL+mDPHMmXdDLgB3hli30Gx2ViDEYrjLyiRK/3OqCZcHmVROquSXG/DO zKgAGc4DtKNC2orQdHKntcPm82OfaRKjpLpM7mPNCZe/ed+sGWEG6ApXBp8vNlXWi/47 H9P41zkviiQv+mwG03eujcdZxcfR5t812Lk9ZuLHOYYJk+ztsBtKCrqQ0V/2eDnEjmkC Vofw== X-Gm-Message-State: AAQBX9e00w6SMztbyO7RYCN74KlwtcsG/0AEcUXWnavoN9F2TRBsZ7z4 otwj7HlgjXAfMJgI2SIgvYM= X-Google-Smtp-Source: AKy350YzaBpxv8S1DyMSbE8BfbzwOluEWimBlPVsmxBI48AxRWDEh3uryOJykSUgwOkLM5yiZprepQ== X-Received: by 2002:a05:6871:a5:b0:177:956c:36d5 with SMTP id u37-20020a05687100a500b00177956c36d5mr5680776oaa.29.1679770529568; Sat, 25 Mar 2023 11:55:29 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id q130-20020acaf288000000b00383ef567cfdsm9417909oih.21.2023.03.25.11.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 11:55:29 -0700 (PDT) From: Yury Norov To: Jakub Kicinski , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Pawel Chmielewski , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: [PATCH 4/8] net: mlx5: switch comp_irqs_request() to using for_each_numa_cpu Date: Sat, 25 Mar 2023 11:55:10 -0700 Message-Id: <20230325185514.425745-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325185514.425745-1-yury.norov@gmail.com> References: <20230325185514.425745-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org for_each_numa_cpu() is a more straightforward alternative to for_each_numa_hop_mask() + for_each_cpu_andnot(). Signed-off-by: Yury Norov --- drivers/net/ethernet/mellanox/mlx5/core/eq.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c index 38b32e98f3bd..80368952e9b1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c @@ -817,12 +817,10 @@ static void comp_irqs_release(struct mlx5_core_dev *dev) static int comp_irqs_request(struct mlx5_core_dev *dev) { struct mlx5_eq_table *table = dev->priv.eq_table; - const struct cpumask *prev = cpu_none_mask; - const struct cpumask *mask; int ncomp_eqs = table->num_comp_eqs; u16 *cpus; int ret; - int cpu; + int cpu, hop; int i; ncomp_eqs = table->num_comp_eqs; @@ -844,15 +842,11 @@ static int comp_irqs_request(struct mlx5_core_dev *dev) i = 0; rcu_read_lock(); - for_each_numa_hop_mask(mask, dev->priv.numa_node) { - for_each_cpu_andnot(cpu, mask, prev) { - cpus[i] = cpu; - if (++i == ncomp_eqs) - goto spread_done; - } - prev = mask; + for_each_numa_cpu(cpu, hop, dev->priv.numa_node, cpu_possible_mask) { + cpus[i] = cpu; + if (++i == ncomp_eqs) + break; } -spread_done: rcu_read_unlock(); ret = mlx5_irqs_request_vectors(dev, cpus, ncomp_eqs, table->comp_irqs); kfree(cpus); From patchwork Sat Mar 25 18:55:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13187866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF8CFC6FD1C for ; Sat, 25 Mar 2023 18:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231834AbjCYSz5 (ORCPT ); Sat, 25 Mar 2023 14:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230223AbjCYSzl (ORCPT ); Sat, 25 Mar 2023 14:55:41 -0400 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A38A5C7; Sat, 25 Mar 2023 11:55:32 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id f19-20020a9d5f13000000b00693ce5a2f3eso2575774oti.8; Sat, 25 Mar 2023 11:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679770531; 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=Nw654FlL6BUkwfjkIWsvpLLmEwiZB7gH0V0i7mwVLn0=; b=O1buRl+cXmYERNkRa0ViEqjRktK0lKq/t2aF9T4kvfbdzLOs2G2FMrZfOJpEwOmVm9 ygQ7msCswMXwobgozy+6WU4IIKcbGgsOqgKuW9dV5o5O6dz5cv5fsqbqy736hDqPGrJQ V03JGH4t+X0umsDBujNZQqdbluFXRNGWjFYk1xcn7/ha0fJwdPHx6HTsIhxeO59BKht8 K7VE57ykrSjN2E+dvYFs4HL/+Dy51s2BANZ9ynav/+F6pZh2JiCVvzVnTC1SGF3wZWl4 ucqjqCW/MleYRGKEG6Sv2T3Q4EF9f3OzSVFGcgudsrRYEKAkaSFrKYawYzLSctFU6orh it/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679770531; 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=Nw654FlL6BUkwfjkIWsvpLLmEwiZB7gH0V0i7mwVLn0=; b=3wLyCFmyHwkOVFTnzCD3oiKN1K3ZxXoz+lA/kDe1MKN8b6LZrbjWlLW3HVYtNzHJJ0 4RttYxQfKGUruFa7dnddCHwSjKDS1Iic2Pl0M1w9iRpNcO/znIfU1vwx0WzCHfejrF0c CLlYq6eSEmwb6oMnZr+anQphI/jg3di9bo6zeUChMo3LDsY3qdBhhDduCcpZjKd+2eo1 sO8w4tw6VysYQg1vUhAOFVQEKZHC/eVbJNDdCOBNAWi2NYLIrLC3z4RYjeZwkyx717kN tryLqxDBEiPRSMBlF4TJQzdP4ntys2tT3w5mcu1EBYhj2/grDBYjzvIQMnQtl91VINEp kHlw== X-Gm-Message-State: AO0yUKX0Ex9Z/oUnH2Jn3OrRjWvP6jAR1XLLlG2tiX0Y1WbOqmUEG9+m QeHtpedd60mYmWZlGPdKgqZtSGC3UJg= X-Google-Smtp-Source: AKy350bbVge6O+ZrE66CYpJHZxTFYDlodaHyMXDOk2H7td8SOsTnBloo26Jkw5VuqZ+c1NmzWl5WVw== X-Received: by 2002:a05:6830:1e1a:b0:69f:8d0f:9a1e with SMTP id s26-20020a0568301e1a00b0069f8d0f9a1emr3623870otr.7.1679770531267; Sat, 25 Mar 2023 11:55:31 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id m2-20020a9d6442000000b0069f0a85fa36sm8532359otl.57.2023.03.25.11.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 11:55:30 -0700 (PDT) From: Yury Norov To: Jakub Kicinski , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Pawel Chmielewski , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: [PATCH 5/8] lib/cpumask: update comment to cpumask_local_spread() Date: Sat, 25 Mar 2023 11:55:11 -0700 Message-Id: <20230325185514.425745-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325185514.425745-1-yury.norov@gmail.com> References: <20230325185514.425745-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Now that we have a for_each_numa_cpu(), which is a more straightforward replacement to the cpumask_local_spread() when it comes to enumeration of CPUs with respect to NUMA topology, it's worth to update the comment. Signed-off-by: Yury Norov --- lib/cpumask.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/cpumask.c b/lib/cpumask.c index e7258836b60b..151d1dc5c593 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -127,11 +127,8 @@ void __init free_bootmem_cpumask_var(cpumask_var_t mask) * * There's a better alternative based on for_each()-like iterators: * - * for_each_numa_hop_mask(mask, node) { - * for_each_cpu_andnot(cpu, mask, prev) - * do_something(cpu); - * prev = mask; - * } + * for_each_numa_cpu(cpu, hop, node, cpu_online_mask) + * do_something(cpu); * * It's simpler and more verbose than above. Complexity of iterator-based * enumeration is O(sched_domains_numa_levels * nr_cpu_ids), while From patchwork Sat Mar 25 18:55:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13187868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC258C77B62 for ; Sat, 25 Mar 2023 18:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231378AbjCYS4D (ORCPT ); Sat, 25 Mar 2023 14:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231801AbjCYSzq (ORCPT ); Sat, 25 Mar 2023 14:55:46 -0400 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B07DAF28; Sat, 25 Mar 2023 11:55:34 -0700 (PDT) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-17ec8963db8so5181768fac.8; Sat, 25 Mar 2023 11:55:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679770533; 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=80EoVBEKXGhEC7DVbLvz7+NhEf3OhSH5JGMlSI/ra5A=; b=c8WsDxlz69yIcMrnWmunFeF8il5WqHtJorGM/XyYJMs70iYPpv46nPF3dBqd99BpdJ W0tVNf8ydUgVClyx+RzGKWpnA6plQ0v92jsxCYGYKtfurnBrzy5HIx8GTebIM5UvKc8K cPEj5R/aDqPk8/ipAO563cTqT+9eZa2AkYCykRNQ681RoYk+C+rB35p4Jo+fP5r3/gkk Yu8YNxArGyyOn5B92nmuhn4yeTOIWzghjpMJhbhxZudr9uE/XLR7rBrEWZ5zOdic6DEi OV6kMH1AZMifMfTcdPIObyunInhhcxBJrgGmzTkzlNB/LQ8CSTi+uLeLh89tAle6fdf7 n6rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679770533; 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=80EoVBEKXGhEC7DVbLvz7+NhEf3OhSH5JGMlSI/ra5A=; b=qkzIjblQ7V0ns/lACgQ9p19HeUQG8NDYdtxP1zqu37VRNvr922pzNQ3YOvyOx/t5eO 3ladYl2JVUCA4RQXsdZB0iK29bjg4qwVam9LbxG79kaoAkdDDM3imQaDbJak6HWwEmtw /yo8NNh3mQcmvNG1svQhEv43j5IR2bfOtsqpro8PYWuRgI9q/PQrHdhsyO0zRH/88cFU LMxnRQzvq64Lpm2LqTx+nR0d7vR0mD6Xr3vLfD2XlCEpPcly8tOVecjdPp3Q18SW8JLn /GD04BHMrTp0jv3MdK8wbxpXuwl49sAul2LtnlgRdLgiyylsVfhOIWchTFjyHqjGeota 1hnQ== X-Gm-Message-State: AAQBX9eN7BeMU5p/KpXaPfIxPI3au3GqqfGhFQHaowedlyT7Wyq4fhVk Nsq/LZGbyV3dfqMw3v5VOJ0= X-Google-Smtp-Source: AK7set+O8JFz+domrA0SIlDcc8yGfcVInje+7s5pfnwITfnb0uJTS8w6y359YhsEL4fO176jhWxetw== X-Received: by 2002:a05:6870:9a14:b0:17e:e1ac:2f09 with SMTP id fo20-20020a0568709a1400b0017ee1ac2f09mr3772222oab.47.1679770533215; Sat, 25 Mar 2023 11:55:33 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id q132-20020acac08a000000b0037fa035f4f3sm9542212oif.53.2023.03.25.11.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 11:55:32 -0700 (PDT) From: Yury Norov To: Jakub Kicinski , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Pawel Chmielewski , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: [PATCH 6/8] sched/topology: export sched_domains_numa_levels Date: Sat, 25 Mar 2023 11:55:12 -0700 Message-Id: <20230325185514.425745-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325185514.425745-1-yury.norov@gmail.com> References: <20230325185514.425745-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The following patch adds a test for NUMA-aware CPU enumerators, and it requires an access to sched_domains_numa_levels. Signed-off-by: Yury Norov --- include/linux/topology.h | 7 +++++++ kernel/sched/topology.c | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/linux/topology.h b/include/linux/topology.h index 62a9dd8edd77..3d8d486c817d 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -43,6 +43,13 @@ for_each_online_node(node) \ if (nr_cpus_node(node)) +#ifdef CONFIG_NUMA +extern int __sched_domains_numa_levels; +#define sched_domains_numa_levels ((const int)__sched_domains_numa_levels) +#else +#define sched_domains_numa_levels (1) +#endif + int arch_update_cpu_topology(void); /* Conform to ACPI 2.0 SLIT distance definitions */ diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 1860d9487fe1..5f5f994a56da 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1508,7 +1508,9 @@ static void claim_allocations(int cpu, struct sched_domain *sd) #ifdef CONFIG_NUMA enum numa_topology_type sched_numa_topology_type; -static int sched_domains_numa_levels; +int __sched_domains_numa_levels; +EXPORT_SYMBOL_GPL(__sched_domains_numa_levels); + static int sched_domains_curr_level; int sched_max_numa_distance; @@ -1872,7 +1874,7 @@ void sched_init_numa(int offline_node) * * We reset it to 'nr_levels' at the end of this function. */ - sched_domains_numa_levels = 0; + __sched_domains_numa_levels = 0; masks = kzalloc(sizeof(void *) * nr_levels, GFP_KERNEL); if (!masks) @@ -1948,7 +1950,7 @@ void sched_init_numa(int offline_node) sched_domain_topology_saved = sched_domain_topology; sched_domain_topology = tl; - sched_domains_numa_levels = nr_levels; + __sched_domains_numa_levels = nr_levels; WRITE_ONCE(sched_max_numa_distance, sched_domains_numa_distance[nr_levels - 1]); init_numa_topology_type(offline_node); @@ -1961,7 +1963,7 @@ static void sched_reset_numa(void) struct cpumask ***masks; nr_levels = sched_domains_numa_levels; - sched_domains_numa_levels = 0; + __sched_domains_numa_levels = 0; sched_max_numa_distance = 0; sched_numa_topology_type = NUMA_DIRECT; distances = sched_domains_numa_distance; From patchwork Sat Mar 25 18:55:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13187867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31662C6FD1C for ; Sat, 25 Mar 2023 18:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231659AbjCYS4B (ORCPT ); Sat, 25 Mar 2023 14:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbjCYSz4 (ORCPT ); Sat, 25 Mar 2023 14:55:56 -0400 Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2CE6AD30; Sat, 25 Mar 2023 11:55:35 -0700 (PDT) Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-17683b570b8so5155964fac.13; Sat, 25 Mar 2023 11:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679770535; 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=OSjdqRXXXgYSdBLqK0Rzny0ztxBdvMaFW0s7IjJDzbk=; b=P0feuUUjKXAKyCstuEoHOPmhO4TyK3/vV/+voVXCmvE98E9bJn0tcyJ4lFEM41GqWl liyARWM0j8ao5ZXutP/8tLQKaz69ng+85A+OqBFDQ9ElMUgFxHXQn4jzbadMPnUwoDUX ququAYjw8kmAsrxnSFcJY7XnAjkAAPUf/aG5n8dPY4erG+XY+0421iKjllXct/gcjOjJ iGUoSQECFIAMYnzCgTuaA7e4a9ZmSYDrBQMgd6rNVP55ZZZQpGngFX3DPiTDdJ8u5dWb ibkvbTg95xydqhVH59WKkWSVhiGGVseIW+Qc0RJWm0cAaQlHtbicU8Rs5mHZzDAdfiti aSwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679770535; 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=OSjdqRXXXgYSdBLqK0Rzny0ztxBdvMaFW0s7IjJDzbk=; b=iW2OoeDw8MY7iBOb62SE2T4humg8W0f+nP4hktYesuCRd8/LsvsviJHZEDAvCm4oVK 4pLVkuidqotx1SWZfFxfkdJnrFwl/I4fKDHjKyhFBE/XzwGfOX63ykIenRaTtNkmLhWt DNJe5R4BhBSYgd/UxwzX2PC79Lj6mRFmXQa1q89bh9BA2SpcWsEjuQcWSzHio+r7eNqc e/f7LC1wzLSewjSOMPJ1tM/rcOquCqgdjwUvyI1hBjpInbUJQzJ5kxnATkPJz/Hu1Oaq 1qr9njjcU2tx1wX6XL/ZNpS5A8+sZs5hynF/0j+Z62FClHu4Qjxx8rgRoBjKUU3/7CV9 nxYg== X-Gm-Message-State: AAQBX9evpSwv7RrVUCPhcdV9MsRBQ7tyF0HDqDnhVJnz6hg71Im+A+Ow YO2++LlMzZQ7+oKd7Tk5UE4= X-Google-Smtp-Source: AKy350Z6M853diS04Xe9me7UO7RJvAwcsEeyUiJUMN/0kO5tO5IbkBrRFlPWIEmyOYFhSTLMzz+C4g== X-Received: by 2002:a05:6870:e255:b0:17e:9f4c:713 with SMTP id d21-20020a056870e25500b0017e9f4c0713mr5212461oac.25.1679770534976; Sat, 25 Mar 2023 11:55:34 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id ug21-20020a0568714d1500b0017af6149e61sm8418379oab.21.2023.03.25.11.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 11:55:34 -0700 (PDT) From: Yury Norov To: Jakub Kicinski , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Pawel Chmielewski , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: [PATCH 7/8] lib: add test for for_each_numa_{cpu,hop_mask}() Date: Sat, 25 Mar 2023 11:55:13 -0700 Message-Id: <20230325185514.425745-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325185514.425745-1-yury.norov@gmail.com> References: <20230325185514.425745-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The test ensures that enumerators' output is consistent with cpumask_local_spread(). Signed-off-by: Yury Norov --- lib/test_bitmap.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index a8005ad3bd58..1b5f805f6879 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "../tools/testing/selftests/kselftest_module.h" @@ -751,6 +752,33 @@ static void __init test_for_each_set_bit_wrap(void) } } +static void __init test_for_each_numa(void) +{ + unsigned int cpu, node; + + for (node = 0; node < sched_domains_numa_levels; node++) { + const struct cpumask *m, *p = cpu_none_mask; + unsigned int c = 0; + + rcu_read_lock(); + for_each_numa_hop_mask(m, node) { + for_each_cpu_andnot(cpu, m, p) + expect_eq_uint(cpumask_local_spread(c++, node), cpu); + p = m; + } + rcu_read_unlock(); + } + + for (node = 0; node < sched_domains_numa_levels; node++) { + unsigned int hop, c = 0; + + rcu_read_lock(); + for_each_numa_cpu(cpu, hop, node, cpu_online_mask) + expect_eq_uint(cpumask_local_spread(c++, node), cpu); + rcu_read_unlock(); + } +} + static void __init test_for_each_set_bit(void) { DECLARE_BITMAP(orig, 500); @@ -1237,6 +1265,7 @@ static void __init selftest(void) test_for_each_clear_bitrange_from(); test_for_each_set_clump8(); test_for_each_set_bit_wrap(); + test_for_each_numa(); } KSTM_MODULE_LOADERS(test_bitmap); From patchwork Sat Mar 25 18:55:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13187869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A9F5C6FD1F for ; Sat, 25 Mar 2023 18:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231861AbjCYS4L (ORCPT ); Sat, 25 Mar 2023 14:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231845AbjCYSz6 (ORCPT ); Sat, 25 Mar 2023 14:55:58 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89613AD34; Sat, 25 Mar 2023 11:55:37 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id o25-20020a9d4119000000b006a11eb19f8eso1391296ote.5; Sat, 25 Mar 2023 11:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679770537; 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=kt1nV0izHo+XQQSqYyOe/0WD7P7tYGip9P1865wg+tY=; b=inVz0XSRlLk1W1rbP83ZhW+h6QqSXDsSY6pY0UA+2M654dZyEEwyxBsc+UcnU0AbIW 2gyMwBud5Ce2EgFauWO8OVuukIalRpQtOm+cmSA/vvkS4nYMqWkjQvKcWgBxMYluSKoe 6qfl5dwESfE8GBkl8/Kuv6lehXHjAJyUhVcNnf5Ce0foper8jv91w1NqZDjHLA3bI6QR uM/TXRhHw8PtPHgVhWqZVG4ggLf0UWsxglfMBp5hEmmgqRI0ie9QTCcD7QEctu9PyZFV pfn/OHj4ukowrYLDLE+TkEK4lYqP4Hxxpt+qS9SHOXZW2HAKr1OEng51wzNGIcczxfr7 RfxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679770537; 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=kt1nV0izHo+XQQSqYyOe/0WD7P7tYGip9P1865wg+tY=; b=gtwIwT7ixUDULmDSKQ4tUcPHf+4TQk36yZb9UQ5Xn1u7nyAhEslrhpKZDEBGnigCOw 1msd82/hjf2Dx7QcGDu8zQXPEVETyfKCF1KcvW1SdpEwKX44Mke0GoO8JnyHRT+uYV+B mtOGBTcusY0nf0UnMyoYwEo7k3l0SuxJ+mua2As7tLcrdWLqOV71zfIMASbB3Nq9NrD9 bSQbRTz8SAFErCrQEDwWGNU/B9JC/njoN11YXMdPUMtPKHdjfJB9gxQXkv95uYFWeSSk Nhpfz45RkvjhWPfjHxYP8FfLT0QlVrjnn60eEjYs9T2vw8Pp/Zkf0OwH31TeEDIuH2ej U0tg== X-Gm-Message-State: AO0yUKVlF/igD1w2QCW9iWZJVYLJvDXRcgKRXdFR7P7w53ZlOZcH9n5h YpgetIEYx8icSxtwSkhXI4A= X-Google-Smtp-Source: AK7set8DuAMn4XuyM4v6I2K7igcUyRQD0ffc61fKXKcekRHZN9YR6m9+iwxAdj+HdX5Um/FRDRfm1A== X-Received: by 2002:a05:6830:10cc:b0:697:a381:a8f8 with SMTP id z12-20020a05683010cc00b00697a381a8f8mr3217617oto.3.1679770536742; Sat, 25 Mar 2023 11:55:36 -0700 (PDT) Received: from localhost ([12.97.180.36]) by smtp.gmail.com with ESMTPSA id p16-20020a9d76d0000000b0068bd922a244sm10121959otl.20.2023.03.25.11.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 11:55:36 -0700 (PDT) From: Yury Norov To: Jakub Kicinski , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yury Norov , Saeed Mahameed , Pawel Chmielewski , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: [RFC PATCH 8/8] sched: drop for_each_numa_hop_mask() Date: Sat, 25 Mar 2023 11:55:14 -0700 Message-Id: <20230325185514.425745-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325185514.425745-1-yury.norov@gmail.com> References: <20230325185514.425745-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Now that we have for_each_numa_cpu(), for_each_numa_hop_mask() and all related code is a deadcode. Drop it. Signed-off-by: Yury Norov --- This is RFC because despite that the code below is unused, there may be new users, particularly Intel, and I don't want to cut people on the fly. Those interested in for_each_numa_hop_mask(), please send NAKs. include/linux/topology.h | 25 ------------------------- kernel/sched/topology.c | 32 -------------------------------- lib/test_bitmap.c | 13 ------------- 3 files changed, 70 deletions(-) diff --git a/include/linux/topology.h b/include/linux/topology.h index 3d8d486c817d..d2defd59b2d0 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -255,7 +255,6 @@ static inline const struct cpumask *cpu_cpu_mask(int cpu) #ifdef CONFIG_NUMA int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node); int sched_numa_find_next_cpu(const struct cpumask *cpus, int cpu, int node, unsigned int *hop); -extern const struct cpumask *sched_numa_hop_mask(unsigned int node, unsigned int hops); #else static __always_inline int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) { @@ -267,32 +266,8 @@ int sched_numa_find_next_cpu(const struct cpumask *cpus, int cpu, int node, unsi { return cpumask_next(cpu, cpus); } - -static inline const struct cpumask * -sched_numa_hop_mask(unsigned int node, unsigned int hops) -{ - return ERR_PTR(-EOPNOTSUPP); -} #endif /* CONFIG_NUMA */ -/** - * for_each_numa_hop_mask - iterate over cpumasks of increasing NUMA distance - * from a given node. - * @mask: the iteration variable. - * @node: the NUMA node to start the search from. - * - * Requires rcu_lock to be held. - * - * Yields cpu_online_mask for @node == NUMA_NO_NODE. - */ -#define for_each_numa_hop_mask(mask, node) \ - for (unsigned int __hops = 0; \ - mask = (node != NUMA_NO_NODE || __hops) ? \ - sched_numa_hop_mask(node, __hops) : \ - cpu_online_mask, \ - !IS_ERR_OR_NULL(mask); \ - __hops++) - /** * for_each_numa_cpu - iterate over cpus in increasing order taking into account * NUMA distances from a given node. diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 5f5f994a56da..2842a4d10624 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2171,38 +2171,6 @@ int sched_numa_find_next_cpu(const struct cpumask *cpus, int cpu, int node, unsi } EXPORT_SYMBOL_GPL(sched_numa_find_next_cpu); -/** - * sched_numa_hop_mask() - Get the cpumask of CPUs at most @hops hops away from - * @node - * @node: The node to count hops from. - * @hops: Include CPUs up to that many hops away. 0 means local node. - * - * Return: On success, a pointer to a cpumask of CPUs at most @hops away from - * @node, an error value otherwise. - * - * Requires rcu_lock to be held. Returned cpumask is only valid within that - * read-side section, copy it if required beyond that. - * - * Note that not all hops are equal in distance; see sched_init_numa() for how - * distances and masks are handled. - * Also note that this is a reflection of sched_domains_numa_masks, which may change - * during the lifetime of the system (offline nodes are taken out of the masks). - */ -const struct cpumask *sched_numa_hop_mask(unsigned int node, unsigned int hops) -{ - struct cpumask ***masks; - - if (node >= nr_node_ids || hops >= sched_domains_numa_levels) - return ERR_PTR(-EINVAL); - - masks = rcu_dereference(sched_domains_numa_masks); - if (!masks) - return ERR_PTR(-EBUSY); - - return masks[hops][node]; -} -EXPORT_SYMBOL_GPL(sched_numa_hop_mask); - #endif /* CONFIG_NUMA */ static int __sdt_alloc(const struct cpumask *cpu_map) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 1b5f805f6879..6becb044a66f 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -756,19 +756,6 @@ static void __init test_for_each_numa(void) { unsigned int cpu, node; - for (node = 0; node < sched_domains_numa_levels; node++) { - const struct cpumask *m, *p = cpu_none_mask; - unsigned int c = 0; - - rcu_read_lock(); - for_each_numa_hop_mask(m, node) { - for_each_cpu_andnot(cpu, m, p) - expect_eq_uint(cpumask_local_spread(c++, node), cpu); - p = m; - } - rcu_read_unlock(); - } - for (node = 0; node < sched_domains_numa_levels; node++) { unsigned int hop, c = 0;