Message ID | 20231129060211.1890454-6-irogers@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp143986vqn; Tue, 28 Nov 2023 22:03:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLrYwX2ycrORrFBClZp01ie9RWKF9uGNRowODiQZ7TLsMwoJ/llCcHMtmjZZ9jFkWsqg4e X-Received: by 2002:a05:6808:17a6:b0:3b8:33e2:1745 with SMTP id bg38-20020a05680817a600b003b833e21745mr17155583oib.7.1701237783758; Tue, 28 Nov 2023 22:03:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701237783; cv=none; d=google.com; s=arc-20160816; b=dR6YlTLGxNsp5TdfrBnhe+F1Vqwaos7J3/WeBnBr8YU6anzVAxBDJV/CW2+Bn1lYRu USWAqLUrOx/GVwr0ohGevvvMd3QhmUX0UOouocrWU+w5mhbPr9HlTe2HzdFCstXfAvQs vXWMOV4R1NrLG+iqFfwOUZel0pWEZQafUbCK407JlldOUiBN2wtkZwMrvyT0aWgkIeDN x4msHao4A1QcprB5dpyW68rJkTqi1vUKc32J6ulfSjVtiXpgftHXFDsDMrkFbVYHznAQ KgEPg9VYVMRivtqDF9ywZktpri0DTJa426wRMNQ4uw+xuAln2QH5fOXxhEq4svTnPWB2 4MCw== 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 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id g14-20020a63200e000000b0056569ee3ae6si13762253pgg.798.2023.11.28.22.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 22:03:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; 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 2620:137:e000::3:8 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 07C1D80A64EE; Tue, 28 Nov 2023 22:02:58 -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 <rfc822;kernel.ruili@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; Tue, 28 Nov 2023 22:02:27 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cb79eb417so6649263276.2 for <linux-kernel@vger.kernel.org>; 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 <irogers@google.com> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Suzuki K Poulose <suzuki.poulose@arm.com>, Mike Leach <mike.leach@linaro.org>, James Clark <james.clark@arm.com>, Leo Yan <leo.yan@linaro.org>, John Garry <john.g.garry@oracle.com>, Will Deacon <will@kernel.org>, Thomas Gleixner <tglx@linutronix.de>, Darren Hart <dvhart@infradead.org>, Davidlohr Bueso <dave@stgolabs.net>, " =?utf-8?q?Andr=C3=A9_Almeida?= " <andrealmeid@igalia.com>, Kan Liang <kan.liang@linux.intel.com>, K Prateek Nayak <kprateek.nayak@amd.com>, Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com>, Kajol Jain <kjain@linux.ibm.com>, Athira Rajeev <atrajeev@linux.vnet.ibm.com>, Andrew Jones <ajones@ventanamicro.com>, Alexandre Ghiti <alexghiti@rivosinc.com>, Atish Patra <atishp@rivosinc.com>, "Steinar H. Gunderson" <sesse@google.com>, Yang Jihong <yangjihong1@huawei.com>, Yang Li <yang.lee@linux.alibaba.com>, Changbin Du <changbin.du@huawei.com>, Sandipan Das <sandipan.das@amd.com>, Ravi Bangoria <ravi.bangoria@amd.com>, Paran Lee <p4ranlee@gmail.com>, Nick Desaulniers <ndesaulniers@google.com>, Huacai Chen <chenhuacai@kernel.org>, Yanteng Si <siyanteng@loongson.cn>, 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: <linux-kernel.vger.kernel.org> 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:02:58 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783877110168327586 X-GMAIL-MSGID: 1783877110168327586 |
Series |
Clean up libperf cpumap's empty function
|
|
Commit Message
Ian Rogers
Nov. 29, 2023, 6:02 a.m. UTC
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 <irogers@google.com>
---
tools/lib/perf/include/perf/cpumap.h | 6 ++++++
tools/perf/builtin-record.c | 4 +---
2 files changed, 7 insertions(+), 3 deletions(-)
Comments
On 29/11/2023 06:02, Ian Rogers wrote: > 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 <irogers@google.com> Reviewed-by: James Clark <james.clark@arm.com> > --- > 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;
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;