From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C71CC46467 for ; Tue, 3 Jan 2023 16:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238124AbjACQX6 (ORCPT ); Tue, 3 Jan 2023 11:23:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238107AbjACQWq (ORCPT ); Tue, 3 Jan 2023 11:22:46 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7F7BF10B4A; Tue, 3 Jan 2023 08:22:17 -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 E5D5C152B; Tue, 3 Jan 2023 08:22:58 -0800 (PST) Received: from [10.32.36.24] (e121896.Emea.Arm.com [10.32.36.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 02EE43F71A; Tue, 3 Jan 2023 08:22:12 -0800 (PST) Message-ID: <150442e1-4717-2b18-8f7d-febbd95ae570@arm.com> Date: Tue, 3 Jan 2023 16:22:11 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2 4/7] perf pmu: Add function to check if a pmu file exists Content-Language: en-US To: Leo Yan Cc: linux-perf-users@vger.kernel.org, tanmay@marvell.com, sgoutham@marvell.com, gcherian@marvell.com, lcherian@marvell.com, bbhushan2@marvell.com, German Gomez , Mathieu Poirier , Suzuki K Poulose , Mike Leach , 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 References: <20221222160328.3639989-1-james.clark@arm.com> <20221222160328.3639989-5-james.clark@arm.com> From: James Clark In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> >> 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 | 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.