From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753464AbcE1PPf (ORCPT ); Sat, 28 May 2016 11:15:35 -0400 Received: from mail.kernel.org ([198.145.29.136]:47084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753224AbcE1PPd (ORCPT ); Sat, 28 May 2016 11:15:33 -0400 From: Masami Hiramatsu To: Arnaldo Carvalho de Melo Cc: Masami Hiramatsu , linux-kernel@vger.kernel.org, Namhyung Kim , Peter Zijlstra , Ingo Molnar , Hemant Kumar , Ananth N Mavinakayanahalli , Brendan Gregg Subject: [PATCH perf/core v9 02/16] perf symbol: Cleanup the code flow of dso__find_kallsyms Date: Sun, 29 May 2016 00:15:28 +0900 Message-Id: <20160528151522.16098.43446.stgit@devbox> X-Mailer: git-send-email 2.1.0 In-Reply-To: <20160528151456.16098.90001.stgit@devbox> References: <20160528151456.16098.90001.stgit@devbox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cleanup the code flow of dso__find_kallsyms() to remove redundant checking code and add some comment for readability. Signed-off-by: Masami Hiramatsu --- Changes in v9: - Split into filename__readable() and others. Changes in v8: - Add comments why we can't use access(R_OK) for /proc/kcore access. --- tools/perf/util/symbol.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index a469346..1df6092 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1674,21 +1674,8 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map) sizeof(host_build_id)) == 0) is_host = dso__build_id_equal(dso, host_build_id); - build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id); - - scnprintf(path, sizeof(path), "%s/%s/%s", buildid_dir, - DSO__NAME_KCORE, sbuild_id); - - /* Use /proc/kallsyms if possible */ + /* Try a fast path for /proc/kallsyms if possible */ if (is_host) { - DIR *d; - - /* If no cached kcore go with /proc/kallsyms */ - d = opendir(path); - if (!d) - goto proc_kallsyms; - closedir(d); - /* * Do not check the build-id cache, unless we know we cannot use * /proc/kcore or module maps don't match to /proc/kallsyms. @@ -1699,18 +1686,24 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map) if (filename__readable("/proc/kcore") && !validate_kcore_addresses("/proc/kallsyms", map)) goto proc_kallsyms; - - /* Find kallsyms in build-id cache with kcore */ - if (!find_matching_kcore(map, path, sizeof(path))) - return strdup(path); - - goto proc_kallsyms; } + build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id); + /* Find kallsyms in build-id cache with kcore */ + scnprintf(path, sizeof(path), "%s/%s/%s", + buildid_dir, DSO__NAME_KCORE, sbuild_id); + if (!find_matching_kcore(map, path, sizeof(path))) return strdup(path); + /* Use current /proc/kallsyms if possible */ + if (is_host) { +proc_kallsyms: + return strdup("/proc/kallsyms"); + } + + /* Finally, find a cache of kallsyms */ scnprintf(path, sizeof(path), "%s/%s/%s", buildid_dir, DSO__NAME_KALLSYMS, sbuild_id); @@ -1721,9 +1714,6 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map) } return strdup(path); - -proc_kallsyms: - return strdup("/proc/kallsyms"); } static int dso__load_kernel_sym(struct dso *dso, struct map *map,