From patchwork Tue Jan 3 16:20:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 38502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4703941wrt; Tue, 3 Jan 2023 08:23:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXtQCi1Z7sHh+cTav8zYCs9kXC8e8PMdhD9fhQmzDZ41QcIvEU+j0vdyw7bvf8L0WYDqawrE X-Received: by 2002:a17:90a:df8e:b0:221:6899:4485 with SMTP id p14-20020a17090adf8e00b0022168994485mr50124091pjv.15.1672763012004; Tue, 03 Jan 2023 08:23:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672763011; cv=none; d=google.com; s=arc-20160816; b=gutpTbsqTpXatZ3jjSRdUmpVI3gzH7qVpm1NP0EsOMyBwylgO322ugZoxRTFkaKxOH OU3Mi4lnR2dTW/6jXnJJtoDpG/3fDE1dXJ7XZT6/sCek1hNi+Sat7V7B+ukjG/aNKr7t R4Q/nBPPQIQNWgrANEpuqtuJIOxdhupViv4gNvPQ1dU+6DzYx1d3QkMsGN9efH5i70Vl GKlW4dOrCNpTx87IGyutJeYNEdIvAp8IU0LSVu/12mOmEmRdJfMyKkUO4Rl5MNifdwFY 0zESeS3P7dm9+KxSo6wGboWjBuCzfg6ttPQKLeisUP12R01UjXVlvziGSzg0XynTuaLL qLgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ke71/8QjUK+HsJHzoZqMJ5J2i8V1CftZLBncazlte1A=; b=SbUgHzTTLMH8a7OXNsCV0K5Ybd4aq/7xex9biMEm7W97k22uF7BiM1riXoGQCThUaS eF0YdjgBoIduzGgz9+SG+YTCcpc+1t0Pwa3BJCUlLpKLdUjP+io+2uRe8IRZBBoEiAVR Omw3XMfg+0jOU+DnKkcwPoO+en7dy+K6esxCAqkJDi7z5zo6nUwql+PrLBpAh3v4R6hE 0tuBesoeq136NKcYYz38MPFFU3gxPSYBIMC4H6PDGZkMiEBN9P9/SxdKsX73rAThYZ++ Yop4jrKq4qWa7pz3Vr3DRl2bHlt5jHXF+scHotsAtnYOCrQNVGRK34XnmBFWcDGzFB7f xRRg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo7-20020a17090b1c8700b00200e221e9a0si39321126pjb.149.2023.01.03.08.23.20; Tue, 03 Jan 2023 08:23:31 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233073AbjACQWs (ORCPT + 99 others); Tue, 3 Jan 2023 11:22:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238263AbjACQWI (ORCPT ); Tue, 3 Jan 2023 11:22:08 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 246EA13D36; Tue, 3 Jan 2023 08:21:37 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 89C221516; Tue, 3 Jan 2023 08:22:18 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CFA183F71A; Tue, 3 Jan 2023 08:21:33 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org, tanmay@marvell.com, leo.yan@linaro.org, mike.leach@linaro.org Cc: sgoutham@marvell.com, gcherian@marvell.com, lcherian@marvell.com, bbhushan2@marvell.com, German Gomez , James Clark , Mathieu Poirier , Suzuki K Poulose , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/7] perf pmu: Add function to check if a pmu file exists Date: Tue, 3 Jan 2023 16:20:38 +0000 Message-Id: <20230103162042.423694-5-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230103162042.423694-1-james.clark@arm.com> References: <20230103162042.423694-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754019147870466756?= X-GMAIL-MSGID: =?utf-8?q?1754019147870466756?= From: German Gomez Add a utility function perf_pmu__file_exists() to check if a given pmu file exists in the sysfs filesystem. Signed-off-by: German Gomez Signed-off-by: James Clark --- tools/perf/util/pmu.c | 10 ++++++++++ tools/perf/util/pmu.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 7a4e243a370d..3529556d57dc 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1741,6 +1741,16 @@ int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, return ret; } +bool perf_pmu__file_exists(struct perf_pmu *pmu, const char *name) +{ + char path[PATH_MAX]; + + if (!perf_pmu__pathname_scnprintf(path, sizeof(path), pmu->name, name)) + return false; + + return file_available(path); +} + static int perf_pmu__new_caps(struct list_head *list, char *name, char *value) { struct perf_pmu_caps *caps = zalloc(sizeof(*caps)); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 8f39e2d17fb1..c1d138fe9602 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -230,6 +230,8 @@ bool pmu_have_event(const char *pname, const char *name); int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4); +bool perf_pmu__file_exists(struct perf_pmu *pmu, const char *name); + int perf_pmu__test(void); struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);