Skip to content

Commit

Permalink
Fix perf event API implementations
Browse files Browse the repository at this point in the history
- Set `inherit = 1` only for per-task perf event. Inspired from change
  torvalds/linux@81b9cf8
- Kernel now support more events (see #1448). Also it's checked in
  `bpf_attach_perf_event` already. Remove the check from C++ API
  • Loading branch information
palmtenor committed Dec 15, 2017
1 parent bebb9c8 commit 99978d2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/cc/api/BPF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include <linux/bpf.h>
#include <linux/perf_event.h>
#include <unistd.h>
#include <cstdio>
#include <cstring>
Expand Down Expand Up @@ -417,8 +416,6 @@ StatusTuple BPF::open_perf_event(const std::string& name,
name.c_str());
perf_event_arrays_[name] = new BPFPerfEventArray(it->second);
}
if (type != PERF_TYPE_RAW && type != PERF_TYPE_HARDWARE)
return StatusTuple(-1, "open_perf_event unsupported type");
auto table = perf_event_arrays_[name];
TRY2(table->open_all_cpu(type, config));
return StatusTuple(0);
Expand Down
2 changes: 1 addition & 1 deletion src/cc/api/BPFTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ BPFStackTable::~BPFStackTable() {
}

void BPFStackTable::clear_table_non_atomic() {
for (int i = 0; i < capacity(); i++) {
for (int i = 0; size_t(i) < capacity(); i++) {
remove(&i);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/cc/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,8 @@ int bpf_attach_perf_event(int progfd, uint32_t ev_type, uint32_t ev_config,
struct perf_event_attr attr = {};
attr.type = ev_type;
attr.config = ev_config;
attr.inherit = 1;
if (pid > 0)
attr.inherit = 1;
if (sample_freq > 0) {
attr.freq = 1;
attr.sample_freq = sample_freq;
Expand Down

0 comments on commit 99978d2

Please sign in to comment.