fix iteration over CPUs
authorAndreas Gerstmayr <andreas.gerstmayr@catalysts.cc>
Mon, 16 Jan 2017 15:35:58 +0000 (16:35 +0100)
committerAndreas Gerstmayr <andreas.gerstmayr@catalysts.cc>
Mon, 16 Jan 2017 15:39:19 +0000 (16:39 +0100)
commit7e0784d37aa66fff936aeebcc042ff5602cae890
tree0c4931d4628a03d67ae96d37334152a82b5a1fef
parentec9d42c8aa35b59eced7aafb21fb4842265daf4d
fix iteration over CPUs

Since kernel version 4.9.0 BPF stopped working in a KVM guest.
The problem are calls to perf_event_open with CPU identifiers which do
not exist (ENODEV). The root cause for this is that the current code
assumes ascending numbered CPUs. However, this is not always the case
(e.g. CPU hotplugging).

This patch introduces the get_online_cpus() and get_possible_cpus()
helper functions and uses the appropriate function for iterations over
CPUs. The BPF_MAP_TYPE_PERF_EVENT_ARRAY map contains now an entry for
each possible CPU instead of for each online CPU.

Fixes: #893
Signed-off-by: Andreas Gerstmayr <andreas.gerstmayr@catalysts.cc>
15 files changed:
src/cc/BPF.cc
src/cc/BPFTable.cc
src/cc/CMakeLists.txt
src/cc/common.cc [new file with mode: 0644]
src/cc/common.h
src/cc/frontends/clang/CMakeLists.txt
src/cc/frontends/clang/b_frontend_action.cc
src/python/bcc/__init__.py
src/python/bcc/perf.py
src/python/bcc/table.py
src/python/bcc/utils.py [new file with mode: 0644]
tests/cc/test_c_api.cc
tests/python/CMakeLists.txt
tests/python/test_array.py
tests/python/test_utils.py [new file with mode: 0755]