Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(bpf_engine): add some docs and rename some variables #1984

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions userspace/libscap/engine/bpf/scap_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@

static inline void scap_bpf_get_buf_pointers(scap_device *dev, uint64_t *phead, uint64_t *ptail, uint64_t *pread_size)
{
struct perf_event_mmap_page *header;
uint64_t begin;
uint64_t end;

header = (struct perf_event_mmap_page *) dev->m_buffer;
struct perf_event_mmap_page * header = (struct perf_event_mmap_page *) dev->m_buffer;

Check warning on line 46 in userspace/libscap/engine/bpf/scap_bpf.h

View check run for this annotation

Codecov / codecov/patch

userspace/libscap/engine/bpf/scap_bpf.h#L46

Added line #L46 was not covered by tests

*phead = header->data_head;
*ptail = header->data_tail;
Expand All @@ -56,16 +52,42 @@
asm volatile("" ::: "memory");
// clang-format on

begin = *ptail % header->data_size;
end = *phead % header->data_size;

if(begin > end)
uint64_t cons = *ptail % header->data_size; // consumer position
uint64_t prod = *phead % header->data_size; // producer position

Check warning on line 56 in userspace/libscap/engine/bpf/scap_bpf.h

View check run for this annotation

Codecov / codecov/patch

userspace/libscap/engine/bpf/scap_bpf.h#L55-L56

Added lines #L55 - L56 were not covered by tests

/* `pread_size` is the number of bytes our consumer has to read to reach the producer.
* We want to obtain this information so we know how many bytes we can read.
*
* We have 2 possible cases:
* Where
* '*' = empty space
* '-' = data space
* 's' = total buffer size
* 'c' = consumer position
* 'p' = producer position
*
* 1. consumer > producer
*
* p c s
* |----|*********|--|
*
*
* We want to obtain the data space so we do `s - c + p`.
*
* 2. consumer <= producer
*
* c p s
* |****|---------|**|
*
* We want to obtain the data space so we do `p - c`.
*/
if(cons > prod)
{
*pread_size = header->data_size - begin + end;
*pread_size = header->data_size - cons + prod;

Check warning on line 86 in userspace/libscap/engine/bpf/scap_bpf.h

View check run for this annotation

Codecov / codecov/patch

userspace/libscap/engine/bpf/scap_bpf.h#L86

Added line #L86 was not covered by tests
}
else
{
*pread_size = end - begin;
*pread_size = prod - cons;

Check warning on line 90 in userspace/libscap/engine/bpf/scap_bpf.h

View check run for this annotation

Codecov / codecov/patch

userspace/libscap/engine/bpf/scap_bpf.h#L90

Added line #L90 was not covered by tests
}
}

Expand Down
Loading