diff options
author | Jan Stancek <jstancek@redhat.com> | 2017-02-17 06:10:24 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-17 10:33:05 -0500 |
commit | 92a7e1278005b6bb3459affc50b2b6e2464e7e7c (patch) | |
tree | 54f07cee8f0a9eb221f3a58324d5fe9417d885fa /tools | |
parent | 8074bf51fe5af68dcbc12bd7fa72dc4be8f41dde (diff) |
perf cpumap: Add cpu__max_present_cpu()
Similar to cpu__max_cpu() (which returns the max possible CPU), returns
the max present CPU.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/8ea4601b5cacc49927235b4ebac424bd6eeccb06.1487146877.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/cpumap.c | 22 | ||||
-rw-r--r-- | tools/perf/util/cpumap.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 2c0b52264a46..8c7504939113 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include "asm/bug.h" | 9 | #include "asm/bug.h" |
10 | 10 | ||
11 | static int max_cpu_num; | 11 | static int max_cpu_num; |
12 | static int max_present_cpu_num; | ||
12 | static int max_node_num; | 13 | static int max_node_num; |
13 | static int *cpunode_map; | 14 | static int *cpunode_map; |
14 | 15 | ||
@@ -442,6 +443,7 @@ static void set_max_cpu_num(void) | |||
442 | 443 | ||
443 | /* set up default */ | 444 | /* set up default */ |
444 | max_cpu_num = 4096; | 445 | max_cpu_num = 4096; |
446 | max_present_cpu_num = 4096; | ||
445 | 447 | ||
446 | mnt = sysfs__mountpoint(); | 448 | mnt = sysfs__mountpoint(); |
447 | if (!mnt) | 449 | if (!mnt) |
@@ -455,6 +457,17 @@ static void set_max_cpu_num(void) | |||
455 | } | 457 | } |
456 | 458 | ||
457 | ret = get_max_num(path, &max_cpu_num); | 459 | ret = get_max_num(path, &max_cpu_num); |
460 | if (ret) | ||
461 | goto out; | ||
462 | |||
463 | /* get the highest present cpu number for a sparse allocation */ | ||
464 | ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt); | ||
465 | if (ret == PATH_MAX) { | ||
466 | pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); | ||
467 | goto out; | ||
468 | } | ||
469 | |||
470 | ret = get_max_num(path, &max_present_cpu_num); | ||
458 | 471 | ||
459 | out: | 472 | out: |
460 | if (ret) | 473 | if (ret) |
@@ -505,6 +518,15 @@ int cpu__max_cpu(void) | |||
505 | return max_cpu_num; | 518 | return max_cpu_num; |
506 | } | 519 | } |
507 | 520 | ||
521 | int cpu__max_present_cpu(void) | ||
522 | { | ||
523 | if (unlikely(!max_present_cpu_num)) | ||
524 | set_max_cpu_num(); | ||
525 | |||
526 | return max_present_cpu_num; | ||
527 | } | ||
528 | |||
529 | |||
508 | int cpu__get_node(int cpu) | 530 | int cpu__get_node(int cpu) |
509 | { | 531 | { |
510 | if (unlikely(cpunode_map == NULL)) { | 532 | if (unlikely(cpunode_map == NULL)) { |
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 06bd689f5989..1a0549af8f5c 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h | |||
@@ -62,6 +62,7 @@ int cpu__setup_cpunode_map(void); | |||
62 | 62 | ||
63 | int cpu__max_node(void); | 63 | int cpu__max_node(void); |
64 | int cpu__max_cpu(void); | 64 | int cpu__max_cpu(void); |
65 | int cpu__max_present_cpu(void); | ||
65 | int cpu__get_node(int cpu); | 66 | int cpu__get_node(int cpu); |
66 | 67 | ||
67 | int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, | 68 | int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, |