aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJan Stancek <jstancek@redhat.com>2017-02-17 06:10:24 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-02-17 10:33:05 -0500
commit92a7e1278005b6bb3459affc50b2b6e2464e7e7c (patch)
tree54f07cee8f0a9eb221f3a58324d5fe9417d885fa /tools
parent8074bf51fe5af68dcbc12bd7fa72dc4be8f41dde (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.c22
-rw-r--r--tools/perf/util/cpumap.h1
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
11static int max_cpu_num; 11static int max_cpu_num;
12static int max_present_cpu_num;
12static int max_node_num; 13static int max_node_num;
13static int *cpunode_map; 14static 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
459out: 472out:
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
521int 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
508int cpu__get_node(int cpu) 530int 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
63int cpu__max_node(void); 63int cpu__max_node(void);
64int cpu__max_cpu(void); 64int cpu__max_cpu(void);
65int cpu__max_present_cpu(void);
65int cpu__get_node(int cpu); 66int cpu__get_node(int cpu);
66 67
67int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, 68int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,