Message ID | 20221222160328.3639989-5-james.clark@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp35758wrn; Thu, 22 Dec 2022 08:10:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRXhp0ZRnPHGuqRovdwpOKs1Ry8KUULwYV0T6FiH5rZNqdp+i4gkBc4C82VGLr9GDVEc7A X-Received: by 2002:a05:6a00:1248:b0:576:9455:4c5e with SMTP id u8-20020a056a00124800b0057694554c5emr8488051pfi.24.1671725446371; Thu, 22 Dec 2022 08:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671725446; cv=none; d=google.com; s=arc-20160816; b=095uf9LW9Xd4pTXKubG4z08Ry/JKmuaEe40gLh1rUkEvzsrhHblf0eVQMfLbRqR99j SUK/cG8pAYUCG/XHW3IK6LhZT9lVLq3YU827kTZqUhuHNEuW2jPvaC1COdUBD/i4CfRU v3cfeKA+rJ2bvNvyx3CEaWFiBAqFNZJmjkxzQ7iMzifXZF3qINFlAQsccy8MWuFWeCSL 3SLd4RMYhGAl/JM0+LayWeVHUiRJPpxZ7ij6IPJcu++VvutkSVibyIC6MtkTdzLb8PTl wj4iJ1hdl8zc2bN1We3wOlTJWHTRKF/pO2FoS0EJrIufO2eaMNgTdwgD4cpuEasMQsUH FXWw== 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=bSrZs/Q7yLSaatgeCCvhhuC6h+crI2UJr4EDiBQ3rOg=; b=AyehmwRoK2R8EJkVt40NZNJdFsft6eftCvN+xNiYYLHSMUIOQgqZ1vrG9LX6dlDPpK dBZ9r9m9QDE/s0fv4aJ+smwtW0CGQItH1lvHBm8b4bTdf/Z/k2kMJDkP2zhZgc68ZUvE gl5RNBvsxt9iKu4Sw4CuI06xLTeLgQo7Yd2D9UC1HxdPKG8BZWgfpqbTNM+bxUc47y/h I+0vEPpgaoXXRQTvcG1Yy9EmJa5QRU/7HGCUA03KB+HNFAtFL25GPYaj8r0voLP8Kaxy vBJWRd8HNQp2fG4sYCcI0n4VzvzFby6L9iU5+DolcOit6YZpGT9WDPA2anILqMyQGFS3 C8Cw== 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 q15-20020aa7960f000000b0056e48944895si915449pfg.317.2022.12.22.08.10.33; Thu, 22 Dec 2022 08:10: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 S235309AbiLVQIH (ORCPT <rfc822;pacteraone@gmail.com> + 99 others); Thu, 22 Dec 2022 11:08:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231129AbiLVQHi (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 22 Dec 2022 11:07:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 25A2E1AF20; Thu, 22 Dec 2022 08:07:34 -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 C268A152B; Thu, 22 Dec 2022 08:08:14 -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 AA8C43FAFB; Thu, 22 Dec 2022 08:07:30 -0800 (PST) From: James Clark <james.clark@arm.com> To: linux-perf-users@vger.kernel.org, tanmay@marvell.com Cc: sgoutham@marvell.com, gcherian@marvell.com, lcherian@marvell.com, bbhushan2@marvell.com, German Gomez <german.gomez@arm.com>, James Clark <james.clark@arm.com>, Mathieu Poirier <mathieu.poirier@linaro.org>, Suzuki K Poulose <suzuki.poulose@arm.com>, Mike Leach <mike.leach@linaro.org>, Leo Yan <leo.yan@linaro.org>, John Garry <john.g.garry@oracle.com>, Will Deacon <will@kernel.org>, 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>, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] perf pmu: Add function to check if a pmu file exists Date: Thu, 22 Dec 2022 16:03:24 +0000 Message-Id: <20221222160328.3639989-5-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221222160328.3639989-1-james.clark@arm.com> References: <20221222160328.3639989-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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752931181684579539?= X-GMAIL-MSGID: =?utf-8?q?1752931181684579539?= |
Series |
perf cs_etm: Basic support for virtual/kernel timestamps
|
|
Commit Message
James Clark
Dec. 22, 2022, 4:03 p.m. UTC
From: German Gomez <german.gomez@arm.com> 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 <german.gomez@arm.com> Signed-off-by: James Clark <james.clark@arm.com> --- tools/perf/util/pmu.c | 14 ++++++++++++++ tools/perf/util/pmu.h | 2 ++ 2 files changed, 16 insertions(+)
Comments
On Thu, Dec 22, 2022 at 04:03:24PM +0000, James Clark wrote: > From: German Gomez <german.gomez@arm.com> > > 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 <german.gomez@arm.com> > Signed-off-by: James Clark <james.clark@arm.com> > --- > tools/perf/util/pmu.c | 14 ++++++++++++++ > tools/perf/util/pmu.h | 2 ++ > 2 files changed, 16 insertions(+) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index 15b852b3c401..b72b2d892949 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -1739,6 +1739,20 @@ 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]; > + struct stat statbuf; > + > + if (!perf_pmu__pathname_scnprintf(path, PATH_MAX, pmu->name, name)) > + return false; > + > + if (!file_available(path)) > + return false; > + > + return stat(path, &statbuf) == 0; Can we simply return the returned value from file_available() and skip calling stat()? Because file_available() invokes access() to detect if a file is existed or not, so here calling stat() is redundant. Thanks, Leo > +} > + > 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); > -- > 2.25.1 >
On 23/12/2022 06:26, Leo Yan wrote: > On Thu, Dec 22, 2022 at 04:03:24PM +0000, James Clark wrote: >> From: German Gomez <german.gomez@arm.com> >> >> 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 <german.gomez@arm.com> >> Signed-off-by: James Clark <james.clark@arm.com> >> --- >> tools/perf/util/pmu.c | 14 ++++++++++++++ >> tools/perf/util/pmu.h | 2 ++ >> 2 files changed, 16 insertions(+) >> >> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c >> index 15b852b3c401..b72b2d892949 100644 >> --- a/tools/perf/util/pmu.c >> +++ b/tools/perf/util/pmu.c >> @@ -1739,6 +1739,20 @@ 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]; >> + struct stat statbuf; >> + >> + if (!perf_pmu__pathname_scnprintf(path, PATH_MAX, pmu->name, name)) >> + return false; >> + >> + if (!file_available(path)) >> + return false; >> + >> + return stat(path, &statbuf) == 0; > > Can we simply return the returned value from file_available() and skip > calling stat()? Because file_available() invokes access() to detect if > a file is existed or not, so here calling stat() is redundant. > Yep that works. Fixed in V3.
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 15b852b3c401..b72b2d892949 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1739,6 +1739,20 @@ 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]; + struct stat statbuf; + + if (!perf_pmu__pathname_scnprintf(path, PATH_MAX, pmu->name, name)) + return false; + + if (!file_available(path)) + return false; + + return stat(path, &statbuf) == 0; +} + 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);