Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1326983rwb; Tue, 27 Sep 2022 11:23:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6W2Jjs+SS6M53evC2we5XL/j36bIgXrO7MnUu54AYIpOr68w0zr/JUB+YJ4lwIqGPOYFFh X-Received: by 2002:a17:90b:394d:b0:203:d5a:d9c9 with SMTP id oe13-20020a17090b394d00b002030d5ad9c9mr5980371pjb.49.1664302989246; Tue, 27 Sep 2022 11:23:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664302989; cv=none; d=google.com; s=arc-20160816; b=jBhtXW+vqVT1tp/xGJCemQgjCZsYQ2fIhrtCH/TvLEaH0ZwHciF9hzonp64cNHWMGH 3JsbyCHogoN5+gEVRvHeaeLru6JqPLQPcNmUSzK+rUSoH2gqbIRE2qAHxH9IZMoEPzKb CH70PsrYa6M4GLPrEpDDDakdxQcMJBjfdORtOl+4a4YlcRlP4CQBVRaZA86E3XVWoIQN g0kJjoh3sE+o65PMKcQaUDX9VKJ11vMVU9+Wb5HeD6iqpFyoY3ZJ74JxLBsBWqzKz0wf HbcWH5aOG5aLENAfhL/7WrUbwctDBKJLH2KiTDXlmZ2DA74dKHaASi9gUdCXEAQrOMEI IlJw== 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=3aYh91Y5WzQL9iD8Qk6Vf/HhWFbftIWDiE0GIw3ZzEc=; b=MF1XHEPAI2joEY8B8Su495ZzuCJAgTjFtBXt5kC97VRRWBbj1yUUANB+eoYfz9VYQb swMzwVdvT/KwEWktrvTd4+u1J2ChB0ugt8hLnjwSGvA8X0HXEZydIkyoWemlkNoEohOL 2g+IkFSIpkJ2v1245eHHr2mgY99x4mnINRIbHn2IFvjFNALGAfqHYvgV7vVx25a9ju7f ceVEA8E944TYwHxsu7O4sk3g9HfXUKWC1W95T/idOX0H55pOdOhPqnZQHM9NQ+P+D09L 8K8emxs6Zfi+7clXv9QKPMtgMc5sdA9A9WW0+ZUTlmY4Z+xAoCst5ibt3TJr8FXLSpqO DQ+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DuvPYxMa; 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 t9-20020a6549c9000000b00439494dfd20si2616577pgs.202.2022.09.27.11.22.58; Tue, 27 Sep 2022 11:23:09 -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=DuvPYxMa; 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 S233148AbiI0QqP (ORCPT + 99 others); Tue, 27 Sep 2022 12:46:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233143AbiI0Qpa (ORCPT ); Tue, 27 Sep 2022 12:45:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72F9117E21 for ; Tue, 27 Sep 2022 09:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664297126; 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=3aYh91Y5WzQL9iD8Qk6Vf/HhWFbftIWDiE0GIw3ZzEc=; b=DuvPYxMaPZz6de2Pu/n5Ju+6Uqk5E0TouIj7nMzlxMMJ4M6eNiiiq6+hGcPPGZf8dRoBpk qGaKXE8HdmyOeTlQL+DcapxPWOoH8VLJdGHFbW4vlnvtoIkMIuA/Syt9VDcicMICdPOAyf We8x1AGKbueiL/n8kyslIPUSz79KHMU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-672-CzI-CpiMOGucsFIxBmEyDg-1; Tue, 27 Sep 2022 12:45:25 -0400 X-MC-Unique: CzI-CpiMOGucsFIxBmEyDg-1 Received: by mail-wm1-f70.google.com with SMTP id d5-20020a05600c34c500b003b4fb42ccdeso8844891wmq.8 for ; Tue, 27 Sep 2022 09:45:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date; bh=3aYh91Y5WzQL9iD8Qk6Vf/HhWFbftIWDiE0GIw3ZzEc=; b=RLV5H7cDM3OKlqN19V00zID+JmTP4DQ2e7D4eU6VAjz1yXbX2xk3VKMiWrwsgkrBVJ JTMpc50bTloyvvHpTrJtjlDUwp3y8gKODZIJCvE5bs2evlKDSGdOQkAe7XPOfT0RTjGw 4BnQivb5vbkOAHQUF/VoqVknhVtKbcvdavc7S9jt5/BdtqEQ2uOwkehaU68gdgdIKtSG pji4fxLJlVoKo+fFSAl/oZ0JpxrOi2zIYvnGiCSSX6xXa5jW2cAuGOr0s5J+11N+KaYD MG87V0+qXSmml0xENGBtLiemMShzG4hLs4e1Jgx6y1RVtpePbAqx5uYivMDKHrUIXAlI 8r8Q== X-Gm-Message-State: ACrzQf1RUfawiuV/iIPIGmBPhXk93wS4eD6U7WmZ2ZAAZgEx0QdbZcU5 8aDyi5GqU2s2ikZPFQY03302boX6003M5JNtqi2M2WECupsm12clEobbH/F1tF5HkgEEdbIeV7Y AJAdJ/ZpVPLl8CsPLpdcrMVpa X-Received: by 2002:a05:6000:1081:b0:22a:2ecf:9cf8 with SMTP id y1-20020a056000108100b0022a2ecf9cf8mr16895806wrw.205.1664297123828; Tue, 27 Sep 2022 09:45:23 -0700 (PDT) X-Received: by 2002:a05:6000:1081:b0:22a:2ecf:9cf8 with SMTP id y1-20020a056000108100b0022a2ecf9cf8mr16895793wrw.205.1664297123592; Tue, 27 Sep 2022 09:45:23 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id t18-20020adfe452000000b00228cd9f6349sm2287334wrm.106.2022.09.27.09.45.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 09:45:22 -0700 (PDT) From: Valentin Schneider To: Yury Norov Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andy Shevchenko , Rasmus Villemoes , Ingo Molnar , Peter Zijlstra , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Mel Gorman , Greg Kroah-Hartman , Heiko Carstens , Tony Luck , Jonathan Cameron , Gal Pressman , Tariq Toukan , Jesse Brandeburg Subject: Re: [PATCH v4 6/7] sched/topology: Introduce for_each_numa_hop_cpu() In-Reply-To: References: <20220923132527.1001870-1-vschneid@redhat.com> <20220923155542.1212814-5-vschneid@redhat.com> Date: Tue, 27 Sep 2022 17:45:21 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 25/09/22 07:58, Yury Norov wrote: > On Fri, Sep 23, 2022 at 04:55:41PM +0100, Valentin Schneider wrote: >> +/** >> + * for_each_numa_hop_cpu - iterate over CPUs by increasing NUMA distance, >> + * starting from a given node. >> + * @cpu: the iteration variable. >> + * @node: the NUMA node to start the search from. >> + * >> + * Requires rcu_lock to be held. >> + * Careful: this is a double loop, 'break' won't work as expected. > > This warning concerns me not only because new iteration loop hides > complexity and breaks 'break' (sic!), but also because it looks too > specific. Why don't you split it, so instead: > > for_each_numa_hop_cpu(cpu, dev->priv.numa_node) { > cpus[i] = cpu; > if (++i == ncomp_eqs) > goto spread_done; > } > > in the following patch you would have something like this: > > for_each_node_hop(hop, node) { > struct cpumask hop_cpus = sched_numa_hop_mask(node, hop); > > for_each_cpu_andnot(cpu, hop_cpus, ...) { > cpus[i] = cpu; > if (++i == ncomp_eqs) > goto spread_done; > } > } > > It looks more bulky, but I believe there will be more users for > for_each_node_hop() alone. > > On top of that, if you really like it, you can implement > for_each_numa_hop_cpu() if you want. > IIUC you're suggesting to introduce an iterator for the cpumasks first, and then maybe add one on top for the individual cpus. I'm happy to do that, though I have to say I'm keen to keep the CPU iterator - IMO the complexity is justified if it is centralized in one location and saves us from boring old boilerplate code. >> + * Implementation notes: >> + * >> + * Providing it is valid, the mask returned by >> + * sched_numa_hop_mask(node, hops+1) >> + * is a superset of the one returned by >> + * sched_numa_hop_mask(node, hops) >> + * which may not be that useful for drivers that try to spread things out and >> + * want to visit a CPU not more than once. >> + * >> + * To accommodate for that, we use for_each_cpu_andnot() to iterate over the cpus >> + * of sched_numa_hop_mask(node, hops+1) with the CPUs of >> + * sched_numa_hop_mask(node, hops) removed, IOW we only iterate over CPUs >> + * a given distance away (rather than *up to* a given distance). >> + * >> + * hops=0 forces us to play silly games: we pass cpu_none_mask to >> + * for_each_cpu_andnot(), which turns it into for_each_cpu(). >> + */ >> +#define for_each_numa_hop_cpu(cpu, node) \ >> + for (struct { const struct cpumask *curr, *prev; int hops; } __v = \ >> + { sched_numa_hop_mask(node, 0), NULL, 0 }; \ > > This anonymous structure is never used as structure. What for you > define it? Why not just declare hops, prev and curr without packing > them? > I haven't found a way to do this that doesn't involve a struct - apparently you can't mix types in a for loop declaration clause. > Thanks, > Yury >