Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7150281rwr; Tue, 2 May 2023 10:07:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rMo+zf3eoSaqBySdK4Y2a+J50y21ForvJaGJCBLFgckJyDHE5PvgtrEeYZgx0lhTH4Jk7 X-Received: by 2002:aca:1903:0:b0:389:14bd:8246 with SMTP id l3-20020aca1903000000b0038914bd8246mr9138587oii.13.1683047220774; Tue, 02 May 2023 10:07:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683047220; cv=none; d=google.com; s=arc-20160816; b=MoX16KKYLki9OZkUkRwbruEwIycbksJ11r/gc4Ib4zR7eMw+KZnW3axUcxOn58ZFhk Xg8tNWqpw8c5cx3zCGZsuqKzknrRocJ4neNaohIduAlPgqDG63UcKnLqcFx5v7kozbbK a8h8Cj61fukDNPmCBTX42tpd87roQJh5HZ24WppCXnRUfn8+V7p/geOlkFpbWSzg/VVj UlgdYQOrskpx2so25g8QtlfQ4vz404DM4Hv4CjrLtFLOmGrivWI1zvh5NWVNCOSfKnCu utda6W9m3y6qOhpvU2g/dU2/SjEywMVbtTBEcm0xH9PX+WNY2oEZNodDedypf6R0s7aS nmwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=soAlhU+u59r6N3bBwieU8qJXFtY5WnxjTNdmvTWn4Lo=; b=ZvCeuF4nW1PCAxAJYnjWz+zhenq08jVxbRYiGhaydSerHK+e/J/beZuo+6YTFK9D1J +fGPJmSKGqD9P2XLyBB1zGt5idz2jO/aSiTB1XRuk3YK2pta4XU8Hp08YT1A+EpMfOeW Mqx2tcxcn9qovt+xdrKkUvNJ8ogfrq4TY8IAwEQJRnqR6mU7IeEMtEKWZA9catnmP4qt 4S+OvZ8Is4bKI6beD+Xr1CUZB+1YEWZu6+5YcBdOCWDEVzAmYypIl5H97ciEpLc7LOmq ICMt71aMPyBeOHw5+IqwAz3/mBkFLqzbhSRMCrUQJ5nwci2g354gwoaMU8Zzr/f0Eb1Y ADAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HJgRLgPr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e205-20020acab5d6000000b003891553af83si21911155oif.200.2023.05.02.10.06.47; Tue, 02 May 2023 10:07:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HJgRLgPr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233697AbjEBRAz (ORCPT + 99 others); Tue, 2 May 2023 13:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233737AbjEBRAu (ORCPT ); Tue, 2 May 2023 13:00:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2277B136 for ; Tue, 2 May 2023 10:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683046803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=soAlhU+u59r6N3bBwieU8qJXFtY5WnxjTNdmvTWn4Lo=; b=HJgRLgPrhLEP2UK3TrQ/meDMmOAxSSlvU5EiBxVn0Ttgc9+w2aPAuIun7Z8mbYI5Rr0s6h Y7vcOmCG3yJlxXIWcvvcPeKU5LUu6L+WsZexze+iGUuwV0Fcbw1ioC34qqz6kXF27mssMq NNKOZk5BvkDDO12qs0gZtu+upQeqkRk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-19bpN06dO4qOEEK-Y3JUGw-1; Tue, 02 May 2023 12:59:59 -0400 X-MC-Unique: 19bpN06dO4qOEEK-Y3JUGw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f1757ebb1eso12348345e9.2 for ; Tue, 02 May 2023 09:59:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683046798; x=1685638798; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=soAlhU+u59r6N3bBwieU8qJXFtY5WnxjTNdmvTWn4Lo=; b=Jti+ba9QCMT6xbR0JqCFY9NCVEJLIE9NHxMBR/CIsYiGJaDds2DwuE8h5julwIjFSy l1fn/8JNFNHTL3Mcj0mINvcA2xFvVNMe79HaYQkYimuNwyMWz33eFX4s2evDf0Gwkp8j J6PTSnLRHDNHt7RpyUUW7x+3Y5vp9b4P2oPHe68Ln/kqt3HpIc/JRihMUZL+u84TwVE9 wPLdscRtKXJKrqXgu8Qmnk+cEjSt91j0bnm9OBy6MKH0l950eFn1G8wCbyNao4ebyIKI C2zqIMb/bBE9qzG/0WVaUI/tybikmewmkZe7EIDo1VDgn8smj115ufJV9UvgYQoYe1r6 hpBA== X-Gm-Message-State: AC+VfDz2ANXQSw/lF5HOxn8JWFb8ZvpawOJqVCComOF04Ctt0Lr94GZl N/kgB56yce+aM89zos52r0OviVab3HQAfB0vwnqnPJdGVozOMlmUaIe/wn5e4VFB+Vc3NLRgOs+ MoNjKfYLH2pSsbNowKR1ah4/h X-Received: by 2002:a7b:cb45:0:b0:3f3:3063:f904 with SMTP id v5-20020a7bcb45000000b003f33063f904mr7647321wmj.31.1683046798741; Tue, 02 May 2023 09:59:58 -0700 (PDT) X-Received: by 2002:a7b:cb45:0:b0:3f3:3063:f904 with SMTP id v5-20020a7bcb45000000b003f33063f904mr7647289wmj.31.1683046798409; Tue, 02 May 2023 09:59:58 -0700 (PDT) Received: from vschneid.remote.csb ([154.57.232.159]) by smtp.gmail.com with ESMTPSA id h15-20020a05600c314f00b003f1978bbcd6sm41882983wmo.3.2023.05.02.09.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 09:59:57 -0700 (PDT) From: Valentin Schneider To: Yury Norov , 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 , Tariq Toukan , Gal Pressman , Greg Kroah-Hartman , Heiko Carstens , Barry Song Subject: Re: [PATCH v2 0/8] sched/topology: add for_each_numa_cpu() macro In-Reply-To: <20230430171809.124686-1-yury.norov@gmail.com> References: <20230430171809.124686-1-yury.norov@gmail.com> Date: Tue, 02 May 2023 17:59:55 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/04/23 10:18, Yury Norov wrote: > for_each_cpu() is widely used in 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. > > This series adds for_each_numa_cpu(), which 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 has a more standard 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. > LGTM, I ran the tests on a few NUMA topologies and that all seems to behave as expected. Thanks for working on this! Reviewed-by: Valentin Schneider