mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [tip:perf/core] perf cpu_map: Use sysfs__read_int in get_{core, socket}_id()
@ 2015-09-15  7:04 tip-bot for Arnaldo Carvalho de Melo
  0 siblings, 0 replies; only message in thread
From: tip-bot for Arnaldo Carvalho de Melo @ 2015-09-15  7:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, namhyung, acme, hpa, fweisbec, bp, dsahern, tglx, eranian,
	linux-kernel, adrian.hunter, wangnan0, jolsa, kan.liang

Commit-ID:  5d8cf721cb13be92e96f22846e5bcd31040d4d0b
Gitweb:     http://git.kernel.org/tip/5d8cf721cb13be92e96f22846e5bcd31040d4d0b
Author:     Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Fri, 11 Sep 2015 10:49:45 -0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Sep 2015 12:50:27 -0300

perf cpu_map: Use sysfs__read_int in get_{core,socket}_id()

We have the tools/lib/ sysfs__read_int() for that, avoid code
duplication.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-fqg6vt5ku72pbf54ljg6tmoy@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cpumap.c | 46 ++++++++++------------------------------------
 1 file changed, 10 insertions(+), 36 deletions(-)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index a05d76a..c51c29f 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -225,28 +225,20 @@ void cpu_map__put(struct cpu_map *map)
 		cpu_map__delete(map);
 }
 
-int cpu_map__get_socket_id(int cpu)
+static int cpu__get_topology_int(int cpu, const char *name, int *value)
 {
-	FILE *fp;
-	const char *mnt;
 	char path[PATH_MAX];
-	int socket_id, ret;
-
-	mnt = sysfs__mountpoint();
-	if (!mnt)
-		return -1;
 
 	snprintf(path, PATH_MAX,
-		"%s/devices/system/cpu/cpu%d/topology/physical_package_id",
-		mnt, cpu);
+		"devices/system/cpu/cpu%d/topology/%s", cpu, name);
 
-	fp = fopen(path, "r");
-	if (!fp)
-		return -1;
-	ret = fscanf(fp, "%d", &socket_id);
-	fclose(fp);
+	return sysfs__read_int(path, value);
+}
 
-	return ret == 1 ? socket_id : -1;
+int cpu_map__get_socket_id(int cpu)
+{
+	int value, ret = cpu__get_topology_int(cpu, "physical_package_id", &value);
+	return ret ?: value;
 }
 
 int cpu_map__get_socket(struct cpu_map *map, int idx)
@@ -299,26 +291,8 @@ static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
 
 int cpu_map__get_core_id(int cpu)
 {
-	FILE *fp;
-	const char *mnt;
-	char path[PATH_MAX];
-	int core_id, ret;
-
-	mnt = sysfs__mountpoint();
-	if (!mnt)
-		return -1;
-
-	snprintf(path, PATH_MAX,
-		"%s/devices/system/cpu/cpu%d/topology/core_id",
-		mnt, cpu);
-
-	fp = fopen(path, "r");
-	if (!fp)
-		return -1;
-	ret = fscanf(fp, "%d", &core_id);
-	fclose(fp);
-
-	return ret == 1 ? core_id : -1;
+	int value, ret = cpu__get_topology_int(cpu, "core_id", &value);
+	return ret ?: value;
 }
 
 int cpu_map__get_core(struct cpu_map *map, int idx)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-09-15  7:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-15  7:04 [tip:perf/core] perf cpu_map: Use sysfs__read_int in get_{core, socket}_id() tip-bot for Arnaldo Carvalho de Melo

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®