lkml.org 
[lkml]   [2015]   [Jul]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/5] perf,tools: introduce get_cpu_max_freq
Date
Get cpu max frequency from the first online cpu, and save the MHz value
in get_cpu_max_freq.

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
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


\
 
 \ /
  Last update: 2015-07-23 21:21    [W:0.078 / U:0.332 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site