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 V2 1/6] perf,tools: save cpu max freq in perf header
Date: Fri, 24 Jul 2015 09:48:27 -0400	[thread overview]
Message-ID: <1437745712-16649-2-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1437745712-16649-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 perf.data header.

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 tools/perf/util/cpumap.c | 32 ++++++++++++++++++++++++++++++++
 tools/perf/util/cpumap.h |  1 +
 tools/perf/util/header.c | 35 +++++++++++++++++++++++++++++++++++
 tools/perf/util/header.h |  2 ++
 4 files changed, 70 insertions(+)

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..6784677 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -58,6 +58,7 @@ int max_node_num;
 int *cpunode_map;
 
 int cpu__setup_cpunode_map(void);
+unsigned int get_cpu_max_freq(void);
 
 static inline int cpu__max_node(void)
 {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 03ace57..287a488 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -862,6 +862,16 @@ write_it:
 	return do_write_string(fd, buffer);
 }
 
+static int write_cpu_max_freq(int fd, struct perf_header *h __maybe_unused,
+			      struct perf_evlist *evlist __maybe_unused)
+{
+	u32 freq;
+
+	freq = get_cpu_max_freq() / 1000;
+
+	return do_write(fd, &freq, sizeof(freq));
+}
+
 static int write_branch_stack(int fd __maybe_unused,
 			      struct perf_header *h __maybe_unused,
 		       struct perf_evlist *evlist __maybe_unused)
@@ -1158,6 +1168,11 @@ static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
 	fprintf(fp, "# cpuid : %s\n", ph->env.cpuid);
 }
 
+static void print_cpu_max_freq(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
+{
+	fprintf(fp, "# CPU max frequency : %u MHz\n", ph->env.cpu_max_freq);
+}
+
 static void print_branch_stack(struct perf_header *ph __maybe_unused,
 			       int fd __maybe_unused, FILE *fp)
 {
@@ -1471,6 +1486,25 @@ static int process_cpuid(struct perf_file_section *section __maybe_unused,
 	return ph->env.cpuid ? 0 : -ENOMEM;
 }
 
+static int process_cpu_max_freq(struct perf_file_section *section __maybe_unused,
+				struct perf_header *ph, int fd,
+				void *data __maybe_unused)
+{
+	ssize_t ret;
+	u32 nr;
+
+	ret = readn(fd, &nr, sizeof(nr));
+	if (ret != sizeof(nr))
+		return -1;
+
+	if (ph->needs_swap)
+		nr = bswap_32(nr);
+
+	ph->env.cpu_max_freq = nr;
+
+	return 0;
+}
+
 static int process_total_mem(struct perf_file_section *section __maybe_unused,
 			     struct perf_header *ph, int fd,
 			     void *data __maybe_unused)
@@ -1885,6 +1919,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
 	FEAT_OPP(HEADER_NRCPUS,		nrcpus),
 	FEAT_OPP(HEADER_CPUDESC,	cpudesc),
 	FEAT_OPP(HEADER_CPUID,		cpuid),
+	FEAT_OPP(HEADER_CPU_MAX_FREQ,	cpu_max_freq),
 	FEAT_OPP(HEADER_TOTAL_MEM,	total_mem),
 	FEAT_OPP(HEADER_EVENT_DESC,	event_desc),
 	FEAT_OPP(HEADER_CMDLINE,	cmdline),
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index d4d5796..a646025 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -22,6 +22,7 @@ enum {
 	HEADER_NRCPUS,
 	HEADER_CPUDESC,
 	HEADER_CPUID,
+	HEADER_CPU_MAX_FREQ,
 	HEADER_TOTAL_MEM,
 	HEADER_CMDLINE,
 	HEADER_EVENT_DESC,
@@ -75,6 +76,7 @@ struct perf_session_env {
 	int			nr_cpus_avail;
 	char			*cpu_desc;
 	char			*cpuid;
+	int			cpu_max_freq;
 	unsigned long long	total_mem;
 
 	int			nr_cmdline;
-- 
1.8.3.1


  reply	other threads:[~2015-07-24 21:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-24 13:48 [PATCH V2 0/6] Freq/CPU%/CORE_BUSY% support kan.liang
2015-07-24 13:48 ` kan.liang [this message]
2015-07-26 16:31   ` [PATCH V2 1/6] perf,tools: save cpu max freq in perf header Jiri Olsa
2015-07-26 16:32   ` Jiri Olsa
2015-07-24 13:48 ` [PATCH V2 2/6] perf,tools: read cpu max freq and msr type from header kan.liang
2015-07-24 13:48 ` [PATCH V2 3/6] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D kan.liang
2015-07-26 16:31   ` Jiri Olsa
2015-07-24 13:48 ` [PATCH V2 4/6] perf,tools: save misc sample read value in struct perf_sample kan.liang
2015-07-26 16:31   ` Jiri Olsa
2015-07-27 22:24     ` Liang, Kan
2015-07-28 13:55       ` Jiri Olsa
2015-07-24 13:48 ` [PATCH V2 5/6] perf,tools: caculate and save freq/CPU%/CORE_BUSY% in he_stat kan.liang
2015-07-26 16:31   ` Jiri Olsa
2015-07-27 17:19     ` Liang, Kan
2015-07-27 17:27       ` Jiri Olsa
2015-07-27 22:34     ` Liang, Kan
2015-07-28 13:50       ` Jiri Olsa
2015-07-26 16:31   ` Jiri Olsa
2015-07-27 17:11     ` Liang, Kan
2015-07-27 17:16       ` Jiri Olsa
2015-07-24 13:48 ` [PATCH V2 6/6] perf,tools: Show freq/CPU%/CORE_BUSY% in perf report --stdio kan.liang
2015-07-26 16:32   ` Jiri Olsa

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=1437745712-16649-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

all inboxes | Powered by JetHome®