mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kan Liang <kan.liang@intel.com>
To: acme@kernel.org
Cc: a.p.zijlstra@chello.nl, 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 V4 1/7] perf,tools: introduce generic FEAT for CPU attributes
Date: Tue, 18 Aug 2015 10:16:35 -0400	[thread overview]
Message-ID: <1439907401-37226-2-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1439907401-37226-1-git-send-email-kan.liang@intel.com>

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

This patch introduces generic FEAT for CPU attributes. For the patch
set, we only need cpu max frequency. But it can be easily extented to
support more other CPU attributes.
The cpu max frequency is from the first online cpu.

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 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/header.h |  7 +++++++
 4 files changed, 90 insertions(+)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 3667e21..ef7e57e 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;
 }
+
+u64 get_cpu_max_freq(void)
+{
+	const char *mnt;
+	char path[PATH_MAX], tmp;
+	FILE *fp;
+	u64 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, "%lu", &freq);
+	fclose(fp);
+
+	return (ret == 1) ? freq : 0;
+}
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 0af9cec..8fd2bd6 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);
+u64 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 179b2bd..0a06fb8 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -862,6 +862,23 @@ write_it:
 	return do_write_string(fd, buffer);
 }
 
+#define MAX_FREQ_TAG_STR	"max_freq"
+
+static int write_cpu_attributes(int fd, struct perf_header *h __maybe_unused,
+				struct perf_evlist *evlist __maybe_unused)
+{
+	u64 freq;
+	int ret;
+
+	freq = get_cpu_max_freq();
+
+	ret = do_write_string(fd, MAX_FREQ_TAG_STR);
+	if (ret)
+		return ret;
+
+	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)
@@ -1154,6 +1171,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_attributes(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
+{
+	fprintf(fp, "# CPU attributes: max frequency = %lu KHz\n", ph->env.cpu_attr[PERF_HEADER_CPU_MAX_FREQ]);
+}
+
 static void print_branch_stack(struct perf_header *ph __maybe_unused,
 			       int fd __maybe_unused, FILE *fp)
 {
@@ -1467,6 +1489,33 @@ static int process_cpuid(struct perf_file_section *section __maybe_unused,
 	return ph->env.cpuid ? 0 : -ENOMEM;
 }
 
+static int process_cpu_attributes(struct perf_file_section *section __maybe_unused,
+				  struct perf_header *ph, int fd,
+				  void *data __maybe_unused)
+{
+	ssize_t ret;
+	char *tag;
+	u64 nr;
+
+	tag = do_read_string(fd, ph);
+	if (!tag)
+		return -1;
+
+	if (strcmp(tag, MAX_FREQ_TAG_STR))
+		return -1;
+
+	ret = readn(fd, &nr, sizeof(nr));
+	if (ret != sizeof(nr))
+		return -1;
+
+	if (ph->needs_swap)
+		nr = bswap_64(nr);
+
+	ph->env.cpu_attr[PERF_HEADER_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)
@@ -1899,6 +1948,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
 	FEAT_OPP(HEADER_PMU_MAPPINGS,	pmu_mappings),
 	FEAT_OPP(HEADER_GROUP_DESC,	group_desc),
 	FEAT_OPP(HEADER_AUXTRACE,	auxtrace),
+	FEAT_OPP(HEADER_CPU_ATTR,	cpu_attributes),
 };
 
 struct header_print_data {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 9b53b65..233c24d 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -31,6 +31,7 @@ enum {
 	HEADER_PMU_MAPPINGS,
 	HEADER_GROUP_DESC,
 	HEADER_AUXTRACE,
+	HEADER_CPU_ATTR,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
@@ -66,6 +67,11 @@ struct perf_header;
 int perf_file_header__read(struct perf_file_header *header,
 			   struct perf_header *ph, int fd);
 
+enum perf_header_cpu_attr {
+	PERF_HEADER_CPU_MAX_FREQ	= 0,
+	PERF_HEADER_CPU_ATTR_MAX,
+};
+
 struct perf_session_env {
 	char			*hostname;
 	char			*os_release;
@@ -75,6 +81,7 @@ struct perf_session_env {
 	int			nr_cpus_avail;
 	char			*cpu_desc;
 	char			*cpuid;
+	u64			cpu_attr[PERF_HEADER_CPU_ATTR_MAX];
 	unsigned long long	total_mem;
 
 	int			nr_cmdline;
-- 
1.8.3.1


  reply	other threads:[~2015-08-18 21:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18 14:16 [PATCH V4 0/7] Freq/CPU%/CORE_BUSY% support Kan Liang
2015-08-18 14:16 ` Kan Liang [this message]
2015-08-21  8:55   ` [PATCH V4 1/7] perf,tools: introduce generic FEAT for CPU attributes Jiri Olsa
2015-08-21  8:57   ` Jiri Olsa
2015-08-21 14:22     ` Liang, Kan
2015-08-18 14:16 ` [PATCH V4 2/7] perf,tools: read msr pmu type from header Kan Liang
2015-08-18 14:16 ` [PATCH V4 3/7] perf,tools: rename perf_session_env and add backpointer to evlist Kan Liang
2015-08-18 14:16 ` [PATCH V4 4/7] perf evsel: Add a backpointer to the evlist a evsel is in Kan Liang
2015-08-18 14:16 ` [PATCH V4 5/7] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D Kan Liang
2015-08-18 14:16 ` [PATCH V4 6/7] perf,tools: caculate and save freq/CPU%/CORE_BUSY% in he_stat Kan Liang
2015-08-18 14:16 ` [PATCH V4 7/7] perf,tools: Show freq/CPU%/CORE_BUSY% in perf report --stdio 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=1439907401-37226-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