Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2805195rwb; Fri, 20 Jan 2023 07:34:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXt1nrZaQ3i/ow0pTBVVJEYsuAS8ZnCPKCZy5qElV+6Q2QbPHQQyYjuw5mHp8+gD8B0IPSP0 X-Received: by 2002:a17:90a:dc82:b0:229:f0c7:487d with SMTP id j2-20020a17090adc8200b00229f0c7487dmr6079279pjv.2.1674228888799; Fri, 20 Jan 2023 07:34:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674228888; cv=none; d=google.com; s=arc-20160816; b=MKQdZzIFD/Xt6q/KG1Ob/L4n0yA1vgZDJ6ykEZQ3KJi7W2VFfRgQl08GAOXvjXULEY jBhvuc9Y0M4H6sOz7reK2iCDdh67U3Ox/72nzYKcuMStsl/L98fraMyBC66Wclt4tut1 BGIHuY/X0urrusIKVwk/Hl+shCwTipDyqTo8UuvofrKbRKw8C912Y89UccgpdwMYtZcb 9nPQWsJl8zQ6Yy9xRNDQA5+qfRrobGGSjDTFwiq0EwOiILT8KrF8gNznbGbWun9xyRKj zWigEK8773mMQ7W3+N2XufHERdwsVeWvGphZhov5gXMzTVJ2z6+Kqlx+XsCVDBfZqe3A Kwig== 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=7JiJaP6su5KvwMYnGt0BiCA+1/YWb4xPYsZDqW+uplQ=; b=Tr1L3P54sLAZ6Hg2+Cu3SpuOshxL+JyOlMVl0jdmSADPrhgQpot/CM+lqzqw5GN3hy XkeBCUEn8WSOWpQssU1omBjtw28tDzF/d2VsuLDyxtaFG488XK76w1P3J6JUYs0bkcVe 6ajsmVw7fxyXp7QkzglDq6QvQgS9D1q+H2uH+kZ5Bcob1cotKDXoriCwYEPeimhMRiT/ zuITUz/AEpKgq/Sz/O8RG8dEJ/7a4IuXteyE7RPdGqbzUDZbcO7ytzWyR4jmQCU9liR2 /eRg7CW4xJaNCnHsZWK5RtRp4qzH8MicTmCCHACpPwNwTz1e2Y6qhnCykkbctAg+PZnm yNnQ== 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 t2-20020a17090aba8200b00219d31681b8si2845856pjr.42.2023.01.20.07.34.42; Fri, 20 Jan 2023 07:34:48 -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 S230047AbjATOkH (ORCPT + 49 others); Fri, 20 Jan 2023 09:40:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230042AbjATOkE (ORCPT ); Fri, 20 Jan 2023 09:40:04 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C6BB96191; Fri, 20 Jan 2023 06:39:25 -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 D4A671576; Fri, 20 Jan 2023 06:38:51 -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 3F5FB3F67D; Fri, 20 Jan 2023 06:38:07 -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 v5 4/8] perf pmu: Add function to check if a pmu file exists Date: Fri, 20 Jan 2023 14:36:57 +0000 Message-Id: <20230120143702.4035046-5-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230120143702.4035046-1-james.clark@arm.com> References: <20230120143702.4035046-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 23e1d70fa343..8abf5b8439a7 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1742,6 +1742,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 742d4db319a0..2bdc560f19c7 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