Commit 92a7e127 authored by Jan Stancek's avatar Jan Stancek Committed by Arnaldo Carvalho de Melo

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: default avatarJan Stancek <jstancek@redhat.com>
Acked-by: default avatarJiri 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 8074bf51
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "asm/bug.h" #include "asm/bug.h"
static int max_cpu_num; static int max_cpu_num;
static int max_present_cpu_num;
static int max_node_num; static int max_node_num;
static int *cpunode_map; static int *cpunode_map;
...@@ -442,6 +443,7 @@ static void set_max_cpu_num(void) ...@@ -442,6 +443,7 @@ static void set_max_cpu_num(void)
/* set up default */ /* set up default */
max_cpu_num = 4096; max_cpu_num = 4096;
max_present_cpu_num = 4096;
mnt = sysfs__mountpoint(); mnt = sysfs__mountpoint();
if (!mnt) if (!mnt)
...@@ -455,6 +457,17 @@ static void set_max_cpu_num(void) ...@@ -455,6 +457,17 @@ static void set_max_cpu_num(void)
} }
ret = get_max_num(path, &max_cpu_num); ret = get_max_num(path, &max_cpu_num);
if (ret)
goto out;
/* get the highest present cpu number for a sparse allocation */
ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt);
if (ret == PATH_MAX) {
pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX);
goto out;
}
ret = get_max_num(path, &max_present_cpu_num);
out: out:
if (ret) if (ret)
...@@ -505,6 +518,15 @@ int cpu__max_cpu(void) ...@@ -505,6 +518,15 @@ int cpu__max_cpu(void)
return max_cpu_num; return max_cpu_num;
} }
int cpu__max_present_cpu(void)
{
if (unlikely(!max_present_cpu_num))
set_max_cpu_num();
return max_present_cpu_num;
}
int cpu__get_node(int cpu) int cpu__get_node(int cpu)
{ {
if (unlikely(cpunode_map == NULL)) { if (unlikely(cpunode_map == NULL)) {
......
...@@ -62,6 +62,7 @@ int cpu__setup_cpunode_map(void); ...@@ -62,6 +62,7 @@ int cpu__setup_cpunode_map(void);
int cpu__max_node(void); int cpu__max_node(void);
int cpu__max_cpu(void); int cpu__max_cpu(void);
int cpu__max_present_cpu(void);
int cpu__get_node(int cpu); int cpu__get_node(int cpu);
int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment