From patchwork Wed Nov 29 06:02:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13472241 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C0D4DC07CB1 for ; Wed, 29 Nov 2023 06:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tYs05AiIe8/Rs0an6z/1j2C/Db72Mp/VVfEa25ogbDU=; b=NEjS+vBLbTC1o3 83YNjb4rX43yBVSiYX0QUa/U8a6UK0zKS/KqSs+MRTXL/oYn16v1aFLk3n0gxGzlhIfV19N7A2Nk0 TQcXuImQuAar8OQJxhY7WsBw6i/WkRHKaT9QzUn02iX7BH77Wr6IkiyvrzrKpCN4pjHeREZCgg4Wd yYGb91BC+XSlLWc+5UtQ6m0CgR9UApZkfExxIaIa2t675oSPB2v0BjE2NIR5jfo3pa/h4ih6IjV10 +9ny97Ad6hSC+ivl8GJ8ffkMtmWZs1H73Blp7Oq/q/1mZK3rC59a4GrSVoNou8MjUbdAQ3QaALSW9 FDPBSS/x4KpvB5z2p6Zg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8Dev-0079UW-1i; Wed, 29 Nov 2023 06:02:53 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8DeW-00794V-1y for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2023 06:02:30 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da04776a869so6662670276.0 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=lists.infradead.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=B9/e1rL3YmMNsSTzihB5XtnpxaVHVv93V32bGY8ZhTo9oCiRnQ8sChTT2Bh71Y/Z0W WEqQsplLIc0CueKdP0ygrJYKhtVgodgDxvEwJMfihv6hnyMVdY6n/qZ4MY0isO/7fJPy dXvrF8utjbbM9nhgiTAvhMjsfL8kK9OQdObxRGyXa0njHqxCapVJuf9TCV2zjFbVyy+i w3boA2o/YvJ3gdnnexE2R0evGiN6CcufUyGDV9UwspBCHcxyFs7Pbcc96P1qz219mHdx AY48djVdwpxUSTBLcqzPQOYPFZPKqkhBlftPdMqp3O3zV0IG6vFXbqKevY7g+b0YSpPu lcIw== 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=aL/BxAhP1fCumlUd7pJ7hAD6hwSOWrSzlxk4MDsPmDckmqB3UYt3ilM/j3iqzfdvDH 69Lw9cegSrIHf/YONAgG6VRdPrCbNLvgpCO4XE/XQZSBQOG+RINUuFYJo/wlqGdBXIkm b1bbYLmgi3pwSOZ8msveU0fxQUGbWbd/XYXYhrl2YvhSvuKem3dPOPthfpPGO07nI5OQ Iq5/KrU33yUPSB+vPfL8NEWKV6Nxf1pANorU+a9/lKFQC4Yxn7qwLynAekAW0Cb1YVnp VsQ9gLgYjLNJB/gjLoPqgSd6HLGWqaCbrDgL4wzccvDVguLqiDWYD2gjmAQRGHoRwJkZ 6llw== X-Gm-Message-State: AOJu0YxJzSMnnhIoa5xkvD2UsHb+E5PwilSnK8dWFRlbc9MZjkeMTjqZ isVqWGDRY8U3+D4AAiD0qSPGV9e1vOGV X-Google-Smtp-Source: AGHT+IGrbmAcgGFKWGO4CN4DZuwGzNNirWTnRPFt7368NYxc+4IVjA+ETsxRxMz4iHCrslIZ6bnFdP+hkjGF 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_Almeida?= " , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231128_220228_669495_3919AAC3 X-CRM114-Status: GOOD ( 15.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: James Clark --- 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;