All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Kan Liang <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, jolsa@kernel.org, kan.liang@intel.com,
	tglx@linutronix.de, ak@linux.intel.com,
	linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com
Subject: [tip:perf/core] perf cpumap: Factor out functions to get core_id and socket_id
Date: Tue, 8 Sep 2015 07:31:45 -0700	[thread overview]
Message-ID: <tip-193b6bd339ccb30c861a307a915d4532f443e0fb@git.kernel.org> (raw)
In-Reply-To: <1441115893-22006-1-git-send-email-kan.liang@intel.com>

Commit-ID:  193b6bd339ccb30c861a307a915d4532f443e0fb
Gitweb:     http://git.kernel.org/tip/193b6bd339ccb30c861a307a915d4532f443e0fb
Author:     Kan Liang <kan.liang@intel.com>
AuthorDate: Tue, 1 Sep 2015 09:58:11 -0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 2 Sep 2015 16:30:47 -0300

perf cpumap: Factor out functions to get core_id and socket_id

This patch moves the code which reads core_id and socket_id into
separate functions.

Signed-off-by: Kan Liang <kan.liang@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/1441115893-22006-1-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cpumap.c | 51 +++++++++++++++++++++++++++++++-----------------
 tools/perf/util/cpumap.h |  2 ++
 2 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 3667e21..a05d76a 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -225,17 +225,12 @@ void cpu_map__put(struct cpu_map *map)
 		cpu_map__delete(map);
 }
 
-int cpu_map__get_socket(struct cpu_map *map, int idx)
+int cpu_map__get_socket_id(int cpu)
 {
 	FILE *fp;
 	const char *mnt;
 	char path[PATH_MAX];
-	int cpu, ret;
-
-	if (idx > map->nr)
-		return -1;
-
-	cpu = map->map[idx];
+	int socket_id, ret;
 
 	mnt = sysfs__mountpoint();
 	if (!mnt)
@@ -248,9 +243,22 @@ int cpu_map__get_socket(struct cpu_map *map, int idx)
 	fp = fopen(path, "r");
 	if (!fp)
 		return -1;
-	ret = fscanf(fp, "%d", &cpu);
+	ret = fscanf(fp, "%d", &socket_id);
 	fclose(fp);
-	return ret == 1 ? cpu : -1;
+
+	return ret == 1 ? socket_id : -1;
+}
+
+int cpu_map__get_socket(struct cpu_map *map, int idx)
+{
+	int cpu;
+
+	if (idx > map->nr)
+		return -1;
+
+	cpu = map->map[idx];
+
+	return cpu_map__get_socket_id(cpu);
 }
 
 static int cmp_ids(const void *a, const void *b)
@@ -289,17 +297,12 @@ static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
 	return 0;
 }
 
-int cpu_map__get_core(struct cpu_map *map, int idx)
+int cpu_map__get_core_id(int cpu)
 {
 	FILE *fp;
 	const char *mnt;
 	char path[PATH_MAX];
-	int cpu, ret, s;
-
-	if (idx > map->nr)
-		return -1;
-
-	cpu = map->map[idx];
+	int core_id, ret;
 
 	mnt = sysfs__mountpoint();
 	if (!mnt)
@@ -312,11 +315,23 @@ int cpu_map__get_core(struct cpu_map *map, int idx)
 	fp = fopen(path, "r");
 	if (!fp)
 		return -1;
-	ret = fscanf(fp, "%d", &cpu);
+	ret = fscanf(fp, "%d", &core_id);
 	fclose(fp);
-	if (ret != 1)
+
+	return ret == 1 ? core_id : -1;
+}
+
+int cpu_map__get_core(struct cpu_map *map, int idx)
+{
+	int cpu, s;
+
+	if (idx > map->nr)
 		return -1;
 
+	cpu = map->map[idx];
+
+	cpu = cpu_map__get_core_id(cpu);
+
 	s = cpu_map__get_socket(map, idx);
 	if (s == -1)
 		return -1;
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 0af9cec..8982d53 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -18,7 +18,9 @@ struct cpu_map *cpu_map__new(const char *cpu_list);
 struct cpu_map *cpu_map__dummy_new(void);
 struct cpu_map *cpu_map__read(FILE *file);
 size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
+int cpu_map__get_socket_id(int cpu);
 int cpu_map__get_socket(struct cpu_map *map, int idx);
+int cpu_map__get_core_id(int cpu);
 int cpu_map__get_core(struct cpu_map *map, int idx);
 int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
 int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);

      parent reply	other threads:[~2015-09-08 14:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-01 13:58 [PATCH V4 1/3] perf,tools: Separated functions to get core_id and socket_id Kan Liang
2015-09-01 13:58 ` [PATCH V4 2/3] perf,tools: store cpu socket_id and core_id in perf.date Kan Liang
2015-09-01 22:24   ` Arnaldo Carvalho de Melo
2015-09-08 14:32   ` [tip:perf/core] perf tools: Store the cpu socket and core ids in the perf.data header tip-bot for Kan Liang
2015-09-01 13:58 ` [PATCH V4 3/3] perf,test: test cpu topology Kan Liang
2015-09-01 22:29   ` Arnaldo Carvalho de Melo
2015-09-01 23:25     ` Liang, Kan
2015-09-02  6:03       ` Jiri Olsa
2015-09-08 14:31 ` tip-bot for Kan Liang [this message]

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=tip-193b6bd339ccb30c861a307a915d4532f443e0fb@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.