linux/tools/perf/util
Jan Stancek da8a58b56c perf tools: Replace _SC_NPROCESSORS_CONF with max_present_cpu in cpu_topology_map
There are 2 problems wrt. cpu_topology_map on systems with sparse CPUs:

1. offline/absent CPUs will have their socket_id and core_id set to -1
   which triggers:
   "socket_id number is too big.You may need to upgrade the perf tool."

2. size of cpu_topology_map (perf_env.cpu[]) is allocated based on
   _SC_NPROCESSORS_CONF, but can be indexed with CPU ids going above.
   Users of perf_env.cpu[] are using CPU id as index. This can lead
   to read beyond what was allocated:
   ==19991== Invalid read of size 4
   ==19991==    at 0x490CEB: check_cpu_topology (topology.c:69)
   ==19991==    by 0x490CEB: test_session_topology (topology.c:106)
   ...

For example:
  _SC_NPROCESSORS_CONF == 16
  available: 2 nodes (0-1)
  node 0 cpus: 0 6 8 10 16 22 24 26
  node 0 size: 12004 MB
  node 0 free: 9470 MB
  node 1 cpus: 1 7 9 11 23 25 27
  node 1 size: 12093 MB
  node 1 free: 9406 MB
  node distances:
  node   0   1
    0:  10  20
    1:  20  10

This patch changes HEADER_NRCPUS.nr_cpus_available from _SC_NPROCESSORS_CONF
to max_present_cpu and updates any user of cpu_topology_map to iterate
with nr_cpus_avail.

As a consequence HEADER_CPU_TOPOLOGY core_id and socket_id lists get longer,
but maintain compatibility with pre-patch state - index to cpu_topology_map is
CPU id.

  perf test 36 -v
  36: Session topology                           :
  --- start ---
  test child forked, pid 22211
  templ file: /tmp/perf-test-gmdX5i
  CPU 0, core 0, socket 0
  CPU 1, core 0, socket 1
  CPU 6, core 10, socket 0
  CPU 7, core 10, socket 1
  CPU 8, core 1, socket 0
  CPU 9, core 1, socket 1
  CPU 10, core 9, socket 0
  CPU 11, core 9, socket 1
  CPU 16, core 0, socket 0
  CPU 22, core 10, socket 0
  CPU 23, core 10, socket 1
  CPU 24, core 1, socket 0
  CPU 25, core 1, socket 1
  CPU 26, core 9, socket 0
  CPU 27, core 9, socket 1
  test child finished with 0
  ---- end ----
  Session topology: Ok

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/d7c05c6445fca74a8442c2c73cfffd349c52c44f.1487146877.git.jstancek@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-02-17 12:56:35 -03:00
..
c++ perf clang: Compile BPF script using builtin clang support 2016-12-05 15:51:45 -03:00
include perf probe: Support probing on offline cross-arch binary 2016-09-01 12:41:09 -03:00
intel-pt-decoder perf intel pt decoder: clang has no -Wno-override-init 2017-02-14 16:18:02 -03:00
libunwind perf unwind: Fix wrongly used regs for aarch64 unwind 2016-06-23 10:30:31 -03:00
scripting-engines tools perf scripting python: clang doesn't have -spec, remove it 2017-02-17 10:31:13 -03:00
alias.c perf tools: Remove needless includes from cache.h 2016-07-12 15:19:58 -03:00
annotate.c perf annotate: Don't throw error for zero length symbols 2016-12-20 12:00:32 -03:00
annotate.h perf annotate: Fix jump target outside of function address range 2016-12-15 16:25:46 -03:00
auxtrace.c perf record: Add support for using symbols in address filters 2016-09-29 11:17:02 -03:00
auxtrace.h perf record: Add support for using symbols in address filters 2016-09-29 11:17:02 -03:00
block-range.c perf annotate: Add branch stack / basic block 2016-09-08 13:44:03 -03:00
block-range.h perf annotate: Add branch stack / basic block 2016-09-08 13:44:03 -03:00
bpf-loader.c perf bpf: Add missing newline in debug messages 2017-02-08 08:55:02 -03:00
bpf-loader.h perf bpf: Rename bpf__foreach_tev() to bpf__foreach_event() 2016-07-13 23:09:03 -03:00
bpf-prologue.c
bpf-prologue.h
Build perf tools: Move two variables usied in libperf from perf.c 2017-01-17 11:36:45 -03:00
build-id.c perf probe: Increase debug level of SDT debug messages 2016-09-29 11:17:02 -03:00
build-id.h perf probe: Support @BUILDID or @FILE suffix for SDT events 2016-07-13 23:09:08 -03:00
cache.h perf tools: Remove needless includes from cache.h 2016-07-12 15:19:58 -03:00
call-path.c perf tools: Refactor code to move call path handling out of thread-stack 2016-05-06 13:00:43 -03:00
call-path.h perf tools: Refactor code to move call path handling out of thread-stack 2016-05-06 13:00:43 -03:00
callchain.c perf callchain: Reference count maps 2017-02-02 11:39:09 -03:00
callchain.h perf callchain: Reference count maps 2017-02-02 11:39:09 -03:00
cgroup.c perf evlist: Rename for_each() macros to for_each_entry() 2016-06-23 11:26:15 -03:00
cgroup.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
cloexec.c perf tools: Introduce weak alternative to sched_getcpu() 2016-07-12 15:20:34 -03:00
cloexec.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
color.c perf tools: Uninline scnprintf() and vscnprint() 2016-07-12 15:20:24 -03:00
color.h
comm.c
comm.h
config.c perf tools: Propagate perf_config() errors 2017-01-27 12:23:33 -03:00
config.h perf config: Mark where are config items from (user or system) 2016-11-14 13:10:37 -03:00
counts.c
counts.h
cpumap.c perf cpumap: Add cpu__max_present_cpu() 2017-02-17 12:33:05 -03:00
cpumap.h perf cpumap: Add cpu__max_present_cpu() 2017-02-17 12:33:05 -03:00
cs-etm.h perf tools: Add coresight etm PMU record capabilities 2016-09-22 12:19:40 -03:00
ctype.c perf ui/stdio: Align column header for hierarchy output 2016-02-24 20:21:12 -03:00
data-convert-bt.c perf tools: Propagate perf_config() errors 2017-01-27 12:23:33 -03:00
data-convert-bt.h perf data ctf: Pass convert options through opts structure 2016-06-28 10:54:55 -03:00
data-convert.h perf data ctf: Add 'all' option 2016-06-28 10:54:56 -03:00
data.c tools: Introduce str_error_r() 2016-07-12 15:19:47 -03:00
data.h perf data: Add perf_data_file__switch() helper 2016-04-14 08:57:54 -03:00
db-export.c perf thread: Adopt get_main_thread from db-export.c 2016-05-30 12:41:43 -03:00
db-export.h perf script: Add call path id to exported sample in db export 2016-05-06 13:00:53 -03:00
debug.c tools: Introduce tools/include/linux/time64.h for *SEC_PER_*SEC macros 2016-08-23 15:37:33 -03:00
debug.h tools: Introduce str_error_r() 2016-07-12 15:19:47 -03:00
demangle-java.c perf symbols: add Java demangling support 2016-02-05 09:46:45 -03:00
demangle-java.h perf symbols: add Java demangling support 2016-02-05 09:46:45 -03:00
demangle-rust.c perf symbols: Add Rust demangling 2016-07-12 16:12:38 -03:00
demangle-rust.h perf symbols: Add Rust demangling 2016-07-12 16:12:38 -03:00
drv_configs.c perf pmu: Push configuration down to PMU driver 2016-09-22 12:19:41 -03:00
drv_configs.h perf pmu: Push configuration down to PMU driver 2016-09-22 12:19:41 -03:00
dso.c perf unwind: Fix looking up dwarf unwind stack info 2017-01-18 12:29:52 -03:00
dso.h perf tools: Uninline scnprintf() and vscnprint() 2016-07-12 15:20:24 -03:00
dwarf-aux.c perf probe: Match linkage name with mangled name 2016-09-29 11:17:08 -03:00
dwarf-aux.h perf probe: Match linkage name with mangled name 2016-09-29 11:17:08 -03:00
dwarf-regs.c perf probe: Support probing on offline cross-arch binary 2016-09-01 12:41:09 -03:00
env.c perf tools: Replace _SC_NPROCESSORS_CONF with max_present_cpu in cpu_topology_map 2017-02-17 12:56:35 -03:00
env.h perf header: Transform nodes string info to struct 2016-07-04 19:39:01 -03:00
event.c perf tools: Fix include of linux/mman.h 2017-02-08 16:06:21 -03:00
event.h perf intel-pt/bts: Report instruction bytes and length in sample 2016-10-24 10:31:32 -03:00
evlist.c perf record: Add switch-output size warning 2017-01-11 16:48:02 -03:00
evlist.h perf record: Add switch-output size warning 2017-01-11 16:48:02 -03:00
evsel_fprintf.c perf symbols: No need to check if sym->name is NULL 2017-02-13 17:22:34 -03:00
evsel.c perf evsel: Do not put a variable sized type not at the end of a struct 2017-02-14 15:56:54 -03:00
evsel.h perf evsel: Allow to ignore missing pid 2016-12-15 16:25:46 -03:00
find-vdso-map.c
genelf_debug.c perf jit: add source line info support 2016-02-05 12:33:09 -03:00
genelf.c perf jit: Generate .eh_frame/.eh_frame_hdr in DSO 2016-10-24 11:07:40 -03:00
genelf.h perf jit: Generate .eh_frame/.eh_frame_hdr in DSO 2016-10-24 11:07:40 -03:00
generate-cmdlist.sh
group.h perf stat: Basic support for TopDown in perf stat 2016-06-06 17:04:15 -03:00
header.c perf tools: Replace _SC_NPROCESSORS_CONF with max_present_cpu in cpu_topology_map 2017-02-17 12:56:35 -03:00
header.h perf pmu: Use pmu_events table to create aliases 2016-10-03 19:58:00 -03:00
help-unknown-cmd.c perf tools: Uninline scnprintf() and vscnprint() 2016-07-12 15:20:24 -03:00
help-unknown-cmd.h
hist.c perf callchain: Reference count maps 2017-02-02 11:39:09 -03:00
hist.h perf diff: Fix -o/--order option behavior (again) 2017-02-02 11:39:09 -03:00
intel-bts.c perf intel-pt/bts: Report instruction bytes and length in sample 2016-10-24 10:31:32 -03:00
intel-bts.h
intel-pt.c perf tools: Propagate perf_config() errors 2017-01-27 12:23:33 -03:00
intel-pt.h perf intel-pt: Record address filter in AUXTRACE_INFO event 2016-09-29 11:17:05 -03:00
intlist.c
intlist.h perf intlist: Rename for_each() macros to for_each_entry() 2016-06-23 11:39:19 -03:00
jit.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
jitdump.c perf jit: Check JITHEADER_VERSION 2016-10-24 11:07:40 -03:00
jitdump.h perf jit: Add unwinding support 2016-10-24 11:07:39 -03:00
kvm-stat.h perf kvm/powerpc: Port perf kvm stat to powerpc 2016-01-29 17:49:54 -03:00
levenshtein.c perf tools: Remove needless includes from cache.h 2016-07-12 15:19:58 -03:00
levenshtein.h
llvm-utils.c perf tools: Propagate perf_config() errors 2017-01-27 12:23:33 -03:00
llvm-utils.h perf llvm: Extract helpers in llvm-utils.c 2016-12-05 15:51:42 -03:00
lzma.c perf tools: Fix error handling of lzma decompression 2016-08-24 11:20:58 -03:00
machine.c perf tools: Be consistent on the type of map->symbols[] interator 2017-02-14 16:19:56 -03:00
machine.h perf machine: Add a kallsyms loading constructor 2017-01-11 16:48:00 -03:00
map.c perf symbols: dso->name is an array, no need to check it against NULL 2017-02-13 17:22:35 -03:00
map.h perf symbols: Remove symbol_filter_t machinery 2016-09-05 11:14:50 -03:00
mem-events.c perf c2c report: Add struct c2c_stats::tot_hitm field 2016-11-23 10:44:05 -03:00
mem-events.h perf c2c report: Add struct c2c_stats::tot_hitm field 2016-11-23 10:44:05 -03:00
ordered-events.c perf ordered_events: Introduce reinit() 2016-04-14 08:57:54 -03:00
ordered-events.h perf ordered_events: Introduce reinit() 2016-04-14 08:57:54 -03:00
parse-branch-options.c perf tools: Add missing object file to the python binding linkage list 2016-10-28 11:29:45 -02:00
parse-branch-options.h perf tools: Implement branch_type event parameter 2016-10-24 11:07:35 -03:00
parse-events.c perf tools: Do not put a variable sized type not at the end of a struct 2017-02-14 15:19:19 -03:00
parse-events.h perf list: Support long jevents descriptions 2016-10-03 21:35:47 -03:00
parse-events.l perf jevents: Handle events including .c and .o 2016-10-17 11:24:18 -03:00
parse-events.y perf tools: Add missing parse_events_error() prototype 2017-02-15 11:20:49 -03:00
parse-regs-options.c
parse-regs-options.h
path.c perf tools: Remove needless includes from cache.h 2016-07-12 15:19:58 -03:00
perf_regs.c perf tools: Fix perf regs mask generation 2016-05-11 21:54:06 +10:00
perf_regs.h
perf-hooks-list.h perf tools: Introduce perf hooks 2016-11-29 12:13:27 -03:00
perf-hooks.c perf tools: Pass context to perf hook functions 2016-12-05 15:51:42 -03:00
perf-hooks.h perf tools: Pass context to perf hook functions 2016-12-05 15:51:42 -03:00
PERF-VERSION-GEN
pmu.c perf pmu: Fix check for unset alias->unit array 2017-02-15 10:06:20 -03:00
pmu.h perf list: Add debug support for outputing alias string 2017-02-08 08:55:04 -03:00
pmu.l
pmu.y
probe-event.c perf probe: Avoid accessing uninitialized 'map' variable 2017-02-14 15:28:41 -03:00
probe-event.h perf tools: Add missing struct definition in probe_event.h 2016-11-25 11:25:46 -03:00
probe-file.c perf probe: Increase debug level of SDT debug messages 2016-09-29 11:17:02 -03:00
probe-file.h perf probe: Add supported for type casting by the running kernel 2016-08-23 17:03:31 -03:00
probe-finder.c perf probe: Fix to probe on gcc generated functions in modules 2017-01-16 15:43:04 -03:00
probe-finder.h perf probe: Fix to probe on gcc generated functions in modules 2017-01-16 15:43:04 -03:00
pstack.c
pstack.h
python-ext-sources perf tools: Add missing object file to the python binding linkage list 2016-10-28 11:29:45 -02:00
python.c perf tools: Make is_printable_array global 2016-07-18 19:49:47 -03:00
quote.c perf tools: Normalize sq_quote_argv() error reporting 2016-10-24 11:07:44 -03:00
quote.h perf quote: Disentangle headers 2016-07-12 15:19:55 -03:00
rb_resort.h perf rb_resort: Rename for_each() macros to for_each_entry() 2016-06-23 11:35:07 -03:00
rblist.c
rblist.h
record.c perf evlist: Rename for_each() macros to for_each_entry() 2016-06-23 11:26:15 -03:00
session.c perf session: Fix DEBUG=1 build with clang 2017-02-17 12:27:26 -03:00
session.h perf evsel: Move some methods from session.[ch] to evsel.[ch] 2016-04-13 10:11:52 -03:00
setup.py perf python: Filter out -specs=/a/b/c from the python binding cc options 2017-02-17 10:31:13 -03:00
sort.c perf c2c report: Add src line sort key 2016-10-19 13:18:31 -03:00
sort.h perf c2c report: Add src line sort key 2016-10-19 13:18:31 -03:00
srcline.c
stat-shadow.c perf stat: Add computation of TopDown formulas 2016-06-06 17:04:16 -03:00
stat.c perf evlist: Rename for_each() macros to for_each_entry() 2016-06-23 11:26:15 -03:00
stat.h perf stat: Add computation of TopDown formulas 2016-06-06 17:04:16 -03:00
strbuf.c perf strbuf: Add missing headers 2016-07-12 15:19:55 -03:00
strbuf.h perf tools: Experiment with cppcheck 2016-10-03 11:24:13 -03:00
strfilter.c tools strfilter: Use __fallthrough 2017-02-08 17:31:10 -03:00
strfilter.h
string.c tools string: Use __fallthrough in perf_atoll() 2017-02-08 17:31:01 -03:00
strlist.c
strlist.h perf tools: Rename strlist_for_each() macros to for_each_entry() 2016-06-23 11:35:01 -03:00
svghelper.c perf timechart: Use NSEC_PER_U?SEC 2016-08-23 15:37:33 -03:00
svghelper.h perf tools: Remove needless 'extern' from function prototypes 2016-03-23 15:06:35 -03:00
symbol_fprintf.c perf symbols: No need to check if sym->name is NULL 2017-02-13 17:22:34 -03:00
symbol-elf.c perf symbols: Robustify reading of build-id from sysfs 2017-01-03 16:11:13 -03:00
symbol-minimal.c perf symbols: Remove symbol_filter_t machinery 2016-09-05 11:14:50 -03:00
symbol.c perf symbols: Take into account symfs setting when reading file build ID 2017-02-08 09:28:55 -03:00
symbol.h perf script: Add option to stop printing callchain 2016-11-29 13:06:19 -03:00
syscalltbl.c perf tools: Build syscall table .c header from kernel's syscall_64.tbl 2016-04-08 09:58:14 -03:00
syscalltbl.h perf tools: Allow generating per-arch syscall table arrays 2016-04-08 09:58:14 -03:00
target.c perf target: str_error_r() always returns the buffer it receives 2016-07-29 11:54:35 -03:00
target.h
term.c
term.h
thread_map.c perf thread_map: Correctly size buffer used with dirent->dt_name 2017-02-08 17:31:28 -03:00
thread_map.h perf thread_map: Add thread_map__remove function 2016-12-15 16:25:45 -03:00
thread-stack.c perf script: Add callindent option 2016-06-23 17:04:26 -03:00
thread-stack.h perf script: Add callindent option 2016-06-23 17:04:26 -03:00
thread.c perf tools: Experiment with cppcheck 2016-10-03 11:24:13 -03:00
thread.h perf unwind: Move unwind__prepare_access from thread_new into thread__insert_map 2016-06-07 12:08:52 -03:00
time-utils.c perf tools: Move parse_nsec_time to time-utils.c 2016-12-01 13:02:39 -03:00
time-utils.h perf tools: Move parse_nsec_time to time-utils.c 2016-12-01 13:02:39 -03:00
tool.h perf tools: Add time conversion event 2016-03-31 10:52:24 -03:00
top.c
top.h perf top: Use machine->kptr_restrict_warned 2016-05-20 11:43:55 -03:00
trace-event-info.c perf tools: Create for_each_event macro for tracepoints iteration 2017-01-31 16:20:08 -03:00
trace-event-parse.c perf util: Save pid-cmdline mapping into tracing header 2017-01-26 11:42:59 -03:00
trace-event-read.c perf util: Add more debug message on failure path 2017-01-26 11:43:00 -03:00
trace-event-scripting.c perf scripting: Don't die if scripting can't be setup, disable it 2016-10-28 11:29:44 -02:00
trace-event.c perf tools: Introduce trace_event__tp_format_id() 2016-07-12 16:14:52 -03:00
trace-event.h perf util: Save pid-cmdline mapping into tracing header 2017-01-26 11:42:59 -03:00
trigger.h perf tools: Introduce trigger class 2016-04-28 09:58:58 -03:00
tsc.c perf tools: Use 64-bit shifts with (TSC) time conversion 2016-03-08 10:11:18 +01:00
tsc.h perf jit: Add support for using TSC as a timestamp 2016-04-01 18:42:55 -03:00
unwind-libdw.c perf unwind: Use addr_location::addr instead of ip for entries 2016-08-16 15:23:29 -03:00
unwind-libdw.h
unwind-libunwind-local.c perf unwind: Fix looking up dwarf unwind stack info 2017-01-18 12:29:52 -03:00
unwind-libunwind.c perf unwind: Add initialized arg into unwind__prepare_access 2016-07-04 20:27:12 -03:00
unwind.h perf unwind: Add initialized arg into unwind__prepare_access 2016-07-04 20:27:12 -03:00
usage.c perf tools: Simplify die() mechanism 2016-03-23 12:32:31 -03:00
util-cxx.h perf clang: Update test case to use real BPF script 2016-12-05 15:51:44 -03:00
util.c tools perf util: Make rm_rf(path) argument const 2017-01-31 16:20:07 -03:00
util.h tools perf util: Make rm_rf(path) argument const 2017-01-31 16:20:07 -03:00
values.c perf tools: Use normal error reporting when processing PERF_RECORD_READ events 2016-10-24 11:07:44 -03:00
values.h perf tools: Use normal error reporting when processing PERF_RECORD_READ events 2016-10-24 11:07:44 -03:00
vdso.c perf tools: Find right DSO taking into account if binary is 32 or 64-bit 2016-06-23 10:25:58 -03:00
vdso.h
xyarray.c
xyarray.h
zlib.c