Commit 3ba18008 authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1660 from anakryiko/perf_buffer_poll_return_type

Return number of CPUs with data for BPFPerfBufferTable::poll()
parents 5c550b5d 50295999
...@@ -495,11 +495,11 @@ BPFPerfBuffer* BPF::get_perf_buffer(const std::string& name) { ...@@ -495,11 +495,11 @@ BPFPerfBuffer* BPF::get_perf_buffer(const std::string& name) {
return (it == perf_buffers_.end()) ? nullptr : it->second; return (it == perf_buffers_.end()) ? nullptr : it->second;
} }
void BPF::poll_perf_buffer(const std::string& name, int timeout_ms) { int BPF::poll_perf_buffer(const std::string& name, int timeout_ms) {
auto it = perf_buffers_.find(name); auto it = perf_buffers_.find(name);
if (it == perf_buffers_.end()) if (it == perf_buffers_.end())
return; return -1;
it->second->poll(timeout_ms); return it->second->poll(timeout_ms);
} }
StatusTuple BPF::load_func(const std::string& func_name, bpf_prog_type type, StatusTuple BPF::load_func(const std::string& func_name, bpf_prog_type type,
......
...@@ -155,7 +155,11 @@ class BPF { ...@@ -155,7 +155,11 @@ class BPF {
BPFPerfBuffer* get_perf_buffer(const std::string& name); BPFPerfBuffer* get_perf_buffer(const std::string& name);
// Poll an opened Perf Buffer of given name with given timeout, using callback // Poll an opened Perf Buffer of given name with given timeout, using callback
// provided when opening. Do nothing if such open Perf Buffer doesn't exist. // provided when opening. Do nothing if such open Perf Buffer doesn't exist.
void poll_perf_buffer(const std::string& name, int timeout_ms = -1); // Returns:
// -1 on error or if perf buffer with such name doesn't exist;
// 0, if no data was available before timeout;
// number of CPUs that have new data, otherwise.
int poll_perf_buffer(const std::string& name, int timeout_ms = -1);
StatusTuple load_func(const std::string& func_name, enum bpf_prog_type type, StatusTuple load_func(const std::string& func_name, enum bpf_prog_type type,
int& fd); int& fd);
......
...@@ -306,14 +306,13 @@ StatusTuple BPFPerfBuffer::close_all_cpu() { ...@@ -306,14 +306,13 @@ StatusTuple BPFPerfBuffer::close_all_cpu() {
return StatusTuple(0); return StatusTuple(0);
} }
void BPFPerfBuffer::poll(int timeout_ms) { int BPFPerfBuffer::poll(int timeout_ms) {
if (epfd_ < 0) if (epfd_ < 0)
return; return -1;
int cnt = epoll_wait(epfd_, ep_events_.get(), cpu_readers_.size(), timeout_ms); int cnt = epoll_wait(epfd_, ep_events_.get(), cpu_readers_.size(), timeout_ms);
if (cnt <= 0)
return;
for (int i = 0; i < cnt; i++) for (int i = 0; i < cnt; i++)
perf_reader_event_read(static_cast<perf_reader*>(ep_events_[i].data.ptr)); perf_reader_event_read(static_cast<perf_reader*>(ep_events_[i].data.ptr));
return cnt;
} }
BPFPerfBuffer::~BPFPerfBuffer() { BPFPerfBuffer::~BPFPerfBuffer() {
......
...@@ -310,7 +310,7 @@ class BPFPerfBuffer : public BPFTableBase<int, int> { ...@@ -310,7 +310,7 @@ class BPFPerfBuffer : public BPFTableBase<int, int> {
StatusTuple open_all_cpu(perf_reader_raw_cb cb, perf_reader_lost_cb lost_cb, StatusTuple open_all_cpu(perf_reader_raw_cb cb, perf_reader_lost_cb lost_cb,
void* cb_cookie, int page_cnt); void* cb_cookie, int page_cnt);
StatusTuple close_all_cpu(); StatusTuple close_all_cpu();
void poll(int timeout_ms); int poll(int timeout_ms);
private: private:
StatusTuple open_on_cpu(perf_reader_raw_cb cb, perf_reader_lost_cb lost_cb, StatusTuple open_on_cpu(perf_reader_raw_cb cb, perf_reader_lost_cb lost_cb,
......
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