summaryrefslogtreecommitdiff
path: root/tools/perf/util/cpumap.c
diff options
context:
space:
mode:
authorKan Liang <kan.liang@intel.com>2015-09-01 16:58:11 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-09-02 22:30:47 +0300
commit193b6bd339ccb30c861a307a915d4532f443e0fb (patch)
tree4eb3ed51a61f229f8c09ceaf150df99b0fdf7d37 /tools/perf/util/cpumap.c
parent76055940c1afc8d445992fb0278b80cf205bbf97 (diff)
downloadlinux-193b6bd339ccb30c861a307a915d4532f443e0fb.tar.xz
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>
Diffstat (limited to 'tools/perf/util/cpumap.c')
-rw-r--r--tools/perf/util/cpumap.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 3667e2123e5b..a05d76ab18d8 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;