Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4367102rdh; Tue, 28 Nov 2023 22:03:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJkATKosjMXa5iphdw1+dc1Iu/emFOc/1esNco5stW/YCxCvyHWzKXP0MEItSwYyR3BoHr X-Received: by 2002:a05:6a20:4425:b0:18b:cb93:ebd9 with SMTP id ce37-20020a056a20442500b0018bcb93ebd9mr19049343pzb.54.1701237795330; Tue, 28 Nov 2023 22:03:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701237795; cv=none; d=google.com; s=arc-20160816; b=H4uwdajSB0vEkTqWZejRu6RDHgU7hg+kr1WExyDySYGGdP4DCJXm3ckM7ZXr4LJ2c4 fDlUF0cKyC42YvMHoc0Vky0LP6QxEiBjKzWBC3b/5YIw7CJZzEhRueOQ5qn5124Uz32U GZhKjhMx1k/JZAnnpJRlxMcyUCMbYh+Hp4kYFEGhd0NUKs9uEy+93Oow8hbmI0H1TLy1 4Cl85yDOnVL1IircYR2MFx3E3TKyds9AvQF2vN7GOLa6TV1gbrtwIQOJDvl4s7/VLV0E aDtHK8L5O97yY2DebG4RqtM9euDcvXoWitFW6ubE4ugtJn+kZLcijG/J0Nr0i65yW0qg 5rUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=u4ZVQm6BXfm09/tS57asaxt2XeV8jv3rjSJhFgaw+iA=; fh=uYKNI4aCUAMYZ/8oQVBIse94GgoxWIIZr1zaTbrWG7c=; b=JCdoNR27Aw6z5oibvsDfeQ10l93MXaj3XhMxZmC7J7F716w88SGg2K19Fe5avcOAbL Yn7fSUY+qPo2vzaVA8UKkNyORimF7a0U/dj53KIymb6iOsRq6elVw9mOBVFfAtNEjMQ+ +1qVkypoYGATkv+2hO17bYaWf9yqxPALshgdVhk9XHnadCg4JlaGtI6HM4NHn3SmVIQ3 XiLT+t+l0L/vWce1j15s2fwlOj1n0p/AtPPCzHsXr/VS9MYaMKMH6OXGi/Pupk+6tSYw MdMicIFnw4HKzKoPIof/JY5TuB7W3GS1sJH2krsUWStm0cMxKompIC1CKbzhue70zokA kzuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ybnh1lIH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h5-20020a056a00170500b006cd908c05acsi5896190pfc.278.2023.11.28.22.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 22:03:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ybnh1lIH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4259180A64E9; Tue, 28 Nov 2023 22:03:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377028AbjK2GCm (ORCPT + 99 others); Wed, 29 Nov 2023 01:02:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234938AbjK2GCc (ORCPT ); Wed, 29 Nov 2023 01:02:32 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F40AF1BC3 for ; Tue, 28 Nov 2023 22:02:27 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cb79eb417so6649263276.2 for ; Tue, 28 Nov 2023 22:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701237747; x=1701842547; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=u4ZVQm6BXfm09/tS57asaxt2XeV8jv3rjSJhFgaw+iA=; b=ybnh1lIHrqCD75MWPzDGjjlZEGSE6JvL1bGsP63SmVP5TDDczIG0mK42B2wyYyKJAe GhcmUFT2PqIqEqK3kr+XjXEhpcv+O8K28eAikeVJ73WIPedf8e0+uUveJ233kGX3JH8g dP85102lX13NMXZenBa2nDjZ6b4QhCi/Jlo9QPKv3Xf7cOeP/toykEweiA1zY1MPrtdq CW9hwAk4MaBwoYaLIDmsEUrNDky2rJvMNtFNjHNhtHFh5VoN4UrZwol6AgZ1sym/pjMK OVpuBRsaiz4pudo/ld/F+Tc2tvFl/TUNukOV7/y90p1vHrNs4VYAbgEPGFxNkX/7840g iZAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701237747; x=1701842547; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u4ZVQm6BXfm09/tS57asaxt2XeV8jv3rjSJhFgaw+iA=; b=HhVCTldSxZyc1AFJ7unyYNDxvxQpu1bOO6T/NpaXcr0fqBbBIJSxejr5+GWwRw02p1 BYc5ZSiKBvLKKp6a3tSIhK1p6QIM27DMA79oGci4lcSfEPjOb+UNdD60z8WLYxZDv+IO 4lcdiLkuA65SSRf5DWyPA7m5YO7TMgvKS2selWsX4WB/SpGpq8GMRii6qn6nAqFRskoP z8cxxlhCDpaqBDLAJfrqcvOJ8viUt5vdXl7v/F8kEzkAWliF9xebK5YCLfkcUKF6S8kL KhKQdPmP+iEw3j2dUd+HGwFqJZQYCcjWVnKRCRBmqilPMAGeQUMuuDVHQndkfYOALGlU vgSA== X-Gm-Message-State: AOJu0Yz8V0Z9jvHQFNfEcr32u0xEQs9RJkhOq37B4ckK/1Sigz6ukI6s HHNdVT1mB6NJTFJiqQ/lIpGCSp5ziWQF X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:763b:80fa:23ca:96f8]) (user=irogers job=sendgmr) by 2002:a25:7141:0:b0:da0:c9a5:b529 with SMTP id m62-20020a257141000000b00da0c9a5b529mr472146ybc.12.1701237746973; Tue, 28 Nov 2023 22:02:26 -0800 (PST) Date: Tue, 28 Nov 2023 22:02:02 -0800 In-Reply-To: <20231129060211.1890454-1-irogers@google.com> Message-Id: <20231129060211.1890454-6-irogers@google.com> Mime-Version: 1.0 References: <20231129060211.1890454-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v1 05/14] libperf cpumap: Add for_each_cpu that skips the "any CPU" case From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 28 Nov 2023 22:03:09 -0800 (PST) When iterating CPUs in a CPU map it is often desirable to skip the "any CPU" (aka dummy) case. Add a helper for this and use in builtin-record. Signed-off-by: Ian Rogers --- tools/lib/perf/include/perf/cpumap.h | 6 ++++++ tools/perf/builtin-record.c | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h index 9cf361fc5edc..dbe0a7352b64 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -64,6 +64,12 @@ LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map); (idx) < perf_cpu_map__nr(cpus); \ (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx)) +#define perf_cpu_map__for_each_cpu_skip_any(_cpu, idx, cpus) \ + for ((idx) = 0, (_cpu) = perf_cpu_map__cpu(cpus, idx); \ + (idx) < perf_cpu_map__nr(cpus); \ + (idx)++, (_cpu) = perf_cpu_map__cpu(cpus, idx)) \ + if ((_cpu).cpu != -1) + #define perf_cpu_map__for_each_idx(idx, cpus) \ for ((idx) = 0; (idx) < perf_cpu_map__nr(cpus); (idx)++) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 8ec818568662..066f9232e947 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3580,9 +3580,7 @@ static int record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cp if (cpu_map__is_dummy(cpus)) return 0; - perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - if (cpu.cpu == -1) - continue; + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, cpus) { /* Return ENODEV is input cpu is greater than max cpu */ if ((unsigned long)cpu.cpu > mask->nbits) return -ENODEV; -- 2.43.0.rc1.413.gea7ed67945-goog