diff options
author | Stephane Eranian <eranian@google.com> | 2013-02-06 09:46:01 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-02-06 16:09:26 -0500 |
commit | 5ac59a8a77e3faa1eaf9bfe82a61e9396b082c3d (patch) | |
tree | 31bac73e17a1caf1dd34dbfb0a4fada571abb9e4 /tools/perf/util/cpumap.c | |
parent | 0479b8b9cf4377df5d2c81506ce93326c31eff40 (diff) |
perf tools: Add cpu_map processor socket level functions
This patch adds:
- cpu_map__get_socket: get socked id from cpu
- cpu_map__build_socket_map: build socket map
- cpu_map__socket: gets acutal socket from logical socket
Those functions are used by uncore and processor socket-level
aggregation modes.
Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1360161962-9675-2-git-send-email-eranian@google.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.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 2b32ffa9ebdb..f817046e22b1 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "util.h" | 1 | #include "util.h" |
2 | #include "sysfs.h" | ||
2 | #include "../perf.h" | 3 | #include "../perf.h" |
3 | #include "cpumap.h" | 4 | #include "cpumap.h" |
4 | #include <assert.h> | 5 | #include <assert.h> |
@@ -201,3 +202,56 @@ void cpu_map__delete(struct cpu_map *map) | |||
201 | { | 202 | { |
202 | free(map); | 203 | free(map); |
203 | } | 204 | } |
205 | |||
206 | int cpu_map__get_socket(struct cpu_map *map, int idx) | ||
207 | { | ||
208 | FILE *fp; | ||
209 | const char *mnt; | ||
210 | char path[PATH_MAX]; | ||
211 | int cpu, ret; | ||
212 | |||
213 | if (idx > map->nr) | ||
214 | return -1; | ||
215 | |||
216 | cpu = map->map[idx]; | ||
217 | |||
218 | mnt = sysfs_find_mountpoint(); | ||
219 | if (!mnt) | ||
220 | return -1; | ||
221 | |||
222 | sprintf(path, | ||
223 | "%s/devices/system/cpu/cpu%d/topology/physical_package_id", | ||
224 | mnt, cpu); | ||
225 | |||
226 | fp = fopen(path, "r"); | ||
227 | if (!fp) | ||
228 | return -1; | ||
229 | ret = fscanf(fp, "%d", &cpu); | ||
230 | fclose(fp); | ||
231 | return ret == 1 ? cpu : -1; | ||
232 | } | ||
233 | |||
234 | int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp) | ||
235 | { | ||
236 | struct cpu_map *sock; | ||
237 | int nr = cpus->nr; | ||
238 | int cpu, s1, s2; | ||
239 | |||
240 | sock = calloc(1, sizeof(*sock) + nr * sizeof(int)); | ||
241 | if (!sock) | ||
242 | return -1; | ||
243 | |||
244 | for (cpu = 0; cpu < nr; cpu++) { | ||
245 | s1 = cpu_map__get_socket(cpus, cpu); | ||
246 | for (s2 = 0; s2 < sock->nr; s2++) { | ||
247 | if (s1 == sock->map[s2]) | ||
248 | break; | ||
249 | } | ||
250 | if (s2 == sock->nr) { | ||
251 | sock->map[sock->nr] = s1; | ||
252 | sock->nr++; | ||
253 | } | ||
254 | } | ||
255 | *sockp = sock; | ||
256 | return 0; | ||
257 | } | ||