Received: by 2002:ac8:1418:0:b0:3ab:920c:4c8b with SMTP id k24csp439844qtj; Thu, 19 Jan 2023 08:13:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXsf27o3VWUqeh0DxGY7swHOYfCP5WUy/k7zYBkFXvEXw7KC1Dq5OCKIFnw4BU1LSCSmBDCj X-Received: by 2002:a17:902:d203:b0:194:d603:5be9 with SMTP id t3-20020a170902d20300b00194d6035be9mr1322496ply.13.1674144826337; Thu, 19 Jan 2023 08:13:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674144826; cv=none; d=google.com; s=arc-20160816; b=pCQ/DFP69p+xPKltZ20vEpp2Cw4NcEhpUTAFWIp+IS1bZqtZy8MW/s5BXEMJ66+gHE EtU570uABlsb8wH0AS/H6vEXZQjrafhZaAOyQPS0etQ7SVJ82A/K5Ee27+YeMLMtcErs Ybuk8bJj90iMHjckxIc5248NWUzRwcOwOGGDXIsGq1IJ/RXEdJXVFHyJRbrXH9a5lOd7 1Wa+mF9yfmNSNgA17+t7jR30yCDilUrlZjjshlKq9tvWrv3etyhomM0oqrX6BGtCx39c cMbw5Vf+UbV+jwaMkZKNGbozZmHqbB50t0wfG7ibEQq+DEzVKGlmZnkhFQHISw/SS0Rm zWqw== 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=c42W50saEyrh0FiL5/P87nvaZw6HlGP2MtP8neTXrjw=; b=IznB1VAQvCj8IKzZmJKMxY5413XEu0niE6+dKKELZT1DgsgibCwqeU6f3V0f0NbY1E QoEU9ke+O+/gpwszdssYtx3yLnG8QurMVDY/cL/F3FJU1BxCtFD2Ptw5z+FLAefg1lBB Joofvx1Cn2Tp/WDiDE5PXg1FN0s261eNNgoanEZM8Q+djLYyGYCex5xMLoE94UR/joMz BKxNHSnIBrmN6Shevyv8mJFaHeFWkJ4n+AltHy15XhCZQ/qw6o4o/zK6XIzQe0baULoc Obi9/p9Kgx8zk4piwNI/Rh1vCLWgLhlyIB19zCKT5ZVVJq30bpqV5IG5kbcQgTcQO8Zn SIHw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a170903110d00b001930d8dc59csi41496899plh.305.2023.01.19.08.13.40; Thu, 19 Jan 2023 08:13:46 -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 S230190AbjASPqg (ORCPT + 45 others); Thu, 19 Jan 2023 10:46:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbjASPqT (ORCPT ); Thu, 19 Jan 2023 10:46:19 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7036A875A9; Thu, 19 Jan 2023 07:46:08 -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 9F7361FB; Thu, 19 Jan 2023 07:46:49 -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 027EF3F445; Thu, 19 Jan 2023 07:46:04 -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 v4 4/8] perf pmu: Add function to check if a pmu file exists Date: Thu, 19 Jan 2023 15:43:03 +0000 Message-Id: <20230119154308.3815108-5-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230119154308.3815108-1-james.clark@arm.com> References: <20230119154308.3815108-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 3ef99f096852..db51fa82a9a7 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); -- 2.25.1