Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754364AbbGWTEe (ORCPT ); Thu, 23 Jul 2015 15:04:34 -0400 Received: from mga02.intel.com ([134.134.136.20]:40612 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754031AbbGWTEa (ORCPT ); Thu, 23 Jul 2015 15:04:30 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,532,1432623600"; d="scan'208";a="768439038" From: kan.liang@intel.com To: a.p.zijlstra@chello.nl, acme@kernel.org Cc: luto@kernel.org, mingo@redhat.com, eranian@google.com, ak@linux.intel.com, mark.rutland@arm.com, adrian.hunter@intel.com, jolsa@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, Kan Liang Subject: [PATCH 1/5] perf,tools: introduce get_cpu_max_freq Date: Thu, 23 Jul 2015 07:49:39 -0400 Message-Id: <1437652183-62080-2-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1437652183-62080-1-git-send-email-kan.liang@intel.com> References: <1437652183-62080-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2326 Lines: 88 From: Kan Liang Get cpu max frequency from the first online cpu, and save the MHz value in get_cpu_max_freq. Signed-off-by: Kan Liang --- tools/perf/builtin-report.c | 2 ++ tools/perf/util/cpumap.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/cpumap.h | 2 ++ 3 files changed, 36 insertions(+) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 95a4771..62cce98 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -818,6 +818,8 @@ repeat: symbol_conf.cumulate_callchain = false; } + cpu_max_freq = get_cpu_max_freq() / 1000; + if (setup_sorting() < 0) { if (sort_order) parse_options_usage(report_usage, options, "s", 1); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 3667e21..548ef13 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -499,3 +499,35 @@ int cpu__setup_cpunode_map(void) closedir(dir1); return 0; } + +unsigned int get_cpu_max_freq(void) +{ + const char *mnt; + char path[PATH_MAX], tmp; + FILE *fp; + unsigned int freq; + int cpu = 0; + int ret; + + mnt = sysfs__mountpoint(); + if (!mnt) + return 0; + + snprintf(path, PATH_MAX, "%s/devices/system/cpu/online", mnt); + fp = fopen(path, "r"); + if (fp) { + ret = fscanf(fp, "%u%c", &cpu, &tmp); + fclose(fp); + if (ret < 1) + return 0; + } + + snprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", mnt, cpu); + fp = fopen(path, "r"); + if (!fp) + return 0; + ret = fscanf(fp, "%u", &freq); + fclose(fp); + + return (ret == 1) ? freq : 0; +} diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 0af9cec..70ac686 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -56,8 +56,10 @@ static inline bool cpu_map__empty(const struct cpu_map *map) int max_cpu_num; int max_node_num; int *cpunode_map; +unsigned int cpu_max_freq; int cpu__setup_cpunode_map(void); +unsigned int get_cpu_max_freq(void); static inline int cpu__max_node(void) { -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/