mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 <kan.liang@intel.com>
Subject: [PATCH 1/5] perf,tools: introduce get_cpu_max_freq
Date: Thu, 23 Jul 2015 07:49:39 -0400	[thread overview]
Message-ID: <1437652183-62080-2-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1437652183-62080-1-git-send-email-kan.liang@intel.com>

From: Kan Liang <kan.liang@intel.com>

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


  reply	other threads:[~2015-07-23 19:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23 11:49 [PATCH 0/5] Freq/CPU%/CORE_BUSY% support kan.liang
2015-07-23 11:49 ` kan.liang [this message]
2015-07-23 11:49 ` [PATCH 2/5] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D kan.liang
2015-07-23 11:49 ` [PATCH 3/5] perf,tools: save misc sample read value in struct perf_sample kan.liang
2015-07-23 11:49 ` [PATCH 4/5] perf,tools: caculate and save freq/CPU%/CORE_BUSY% in he_stat kan.liang
2015-07-23 11:49 ` [PATCH 5/5] perf,tools: Show freq/CPU%/CORE_BUSY% in perf report --stdio kan.liang
  -- strict thread matches above, loose matches on Subject: below --
2015-07-23 11:46 [PATCH 0/5] Freq/CPU%/CORE_BUSY% support Kan Liang
2015-07-23 11:46 ` [PATCH 1/5] perf,tools: introduce get_cpu_max_freq Kan Liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1437652183-62080-2-git-send-email-kan.liang@intel.com \
    --to=kan.liang@intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome