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

perf: flush Record when deadline is exceeded #1429

Merged
merged 4 commits into from
May 10, 2024
Merged

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Apr 10, 2024

epoll: simplify timeout calculation

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

epoll: fix eventFd.add

eventFd.add hardcoded the value to add to 1 instead of using the argument.
This hasn't caused a bug since we never call add with a different value.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

perf: opportunistically check all rings for data

Waking up user space from the kernel is expensive and so the perf reader 
allows adjusting the rate at which wakeups happen. This saves CPU at the 
cost of latency: some data will remain in the buffer for longer.

The reader is an abstraction over multiple ring buffers. It only reads from
a ring buffer if it has received a wakeup from the kernel. This is wasteful
because wakeups are expensive (due to context switching and so on) but
checking a ring for contents is cheap (just an atomic load).

Change the behaviour so that we read data from any ready ring buffer 
regardless of why we were woken up.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

perf: flush Record when deadline is exceeded

Watermark and WakeupEvents allow reducing the rate at which user space is
woken up. This creates an edge case where Read() returns 
os.ErrDeadlineExceeded even though there is data in one of the rings.

This is also a problem in the ringbuf package, where we've solved this by
checking whether there is any data when encountering an ErrDeadlineExceeded.
Adopt the same approach for the perf reader.

TestPerfReaderWakeupEvents has to change since it relies on the old 
behaviour of not checking for pending data. Rework the test so that it
doesn't test the ErrDeadlineExceeded error: it's not so important that we
don't wake up early.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

perf/reader.go Outdated Show resolved Hide resolved
@lmb lmb marked this pull request as ready for review April 26, 2024 10:05
@lmb lmb requested a review from a team as a code owner April 26, 2024 10:05
@lmb
Copy link
Collaborator Author

lmb commented Apr 26, 2024

Reworked a little bit and fixed test failures. PTAL.

lmb added 4 commits May 10, 2024 15:53
Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
eventFd.add hardcoded the value to add to 1 instead of using the
argument. This hasn't caused a bug since we never call add with
a different value.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
Waking up user space from the kernel is expensive and so the perf reader
allows adjusting the rate at which wakeups happen. This saves CPU at the
cost of latency: some data will remain in the buffer for longer.

The reader is an abstraction over multiple ring buffers. It only reads
from a ring buffer if it has received a wakeup from the kernel. This is
wasteful because wakeups are expensive (due to context switching
and so on) but checking a ring for contents is cheap (just an atomic load).

Change the behaviour so that we read data from any ready ring buffer
regardless of why we were woken up.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
Watermark and WakeupEvents allow reducing the rate at which user
space is woken up. This creates an edge case where Read() returns
os.ErrDeadlineExceeded even though there is data in one of the rings.

This is also a problem in the ringbuf package, where we've solved this
by checking whether there is any data when encountering
an ErrDeadlineExceeded. Adopt the same approach for the perf reader.

TestPerfReaderWakeupEvents has to change since it relies on the old
behaviour of not checking for pending data. Rework the test so that
it doesn't test the ErrDeadlineExceeded error: it's not so important
that we don't wake up early.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
@lmb lmb merged commit 5650724 into cilium:main May 10, 2024
17 checks passed
@lmb lmb deleted the perf-flush-behaviour branch May 10, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants