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

fix(libpman): try to get a new event on the same CPU after increasing the producer #2009

Merged
merged 3 commits into from
Aug 26, 2024

Conversation

Andreagit97
Copy link
Member

@Andreagit97 Andreagit97 commented Aug 19, 2024

What type of PR is this?

/kind bug

/kind cleanup

Any specific area of the project related to this PR?

/area libpman

Does this PR require a change in the driver versions?

No

What this PR does / why we need it:

This PR reduces the possibility of facing out-of-order events with the modern ebpf probe. When we reach the producer the right thing to do is to insist on the same CPU to check if the producer has pushed some new events instead of skipping the current buffer returning a NULL event. Otherwise, there is the risk that we skip some events with a lower timestamp with respect to the others in the other buffers.

Added also some handy debug print. Example

-----------------------------
Iterate over all the buffers
[NULL Event] buf: 0
[NULL Event] buf: 1
[NULL Event] buf: 2
[NULL Event] buf: 3
[NULL Event] buf: 4
[NULL Event] buf: 5
[Event] ts: 1724060673955668930, buf: 6
Found new min with ts '1724060673955668930'  on buffer 6
[NULL Event] buf: 7
Send event -> [Event] ts: 1724060673955668930, buf: 6

-----------------------------
Iterate over all the buffers
[NULL Event] buf: 0
[NULL Event] buf: 1
[NULL Event] buf: 2
[NULL Event] buf: 3
[NULL Event] buf: 4
[NULL Event] buf: 5
[Event] ts: 1724060673955681382, buf: 6
Found new min with ts '1724060673955681382'  on buffer 6
[NULL Event] buf: 7
Send event -> [Event] ts: 1724060673955681382, buf: 6

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fix(libpman): try to get a new event on the same CPU after increasing the producer

@Andreagit97 Andreagit97 changed the title Improve ringbuf algorithm fix(libpman): try to get a new event on the same CPU after increasing the producer Aug 19, 2024
Copy link

github-actions bot commented Aug 19, 2024

Perf diff from master - unit tests

    12.04%     -1.34%  [.] sinsp_parser::reset
     4.98%     +1.22%  [.] sinsp_evt::get_type
     8.17%     -1.09%  [.] sinsp::next
     3.45%     +0.72%  [.] gzfile_read
     5.14%     -0.58%  [.] next
     1.37%     -0.48%  [.] std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>
     2.22%     -0.47%  [.] scap_event_decode_params
     0.95%     -0.42%  [.] std::_Hashtable<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__detail::_Identity, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, true> >::find
     1.17%     +0.41%  [.] sinsp_evt::get_ts
     0.58%     -0.39%  [.] thread_group_info::get_first_thread

Heap diff from master - unit tests

peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: -765.17K

Heap diff from master - scap file

peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

@Andreagit97 Andreagit97 added this to the 0.18.0 milestone Aug 19, 2024
@FedeDP
Copy link
Contributor

FedeDP commented Aug 21, 2024

This needs to be rebased on latest master to fix CI, right?

Andreagit97 and others added 3 commits August 22, 2024 17:04
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
Co-authored-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
@Andreagit97
Copy link
Member Author

This needs to be rebased on latest master to fix CI, right?

done :)

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Aug 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana
Copy link
Contributor

poiana commented Aug 22, 2024

LGTM label has been added.

Git tree hash: 53a37e06692505a971307bfc53f2cfcbdf253f9b

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.14%. Comparing base (839efec) to head (a384441).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2009   +/-   ##
=======================================
  Coverage   74.14%   74.14%           
=======================================
  Files         253      253           
  Lines       30834    30834           
  Branches     5404     5410    +6     
=======================================
  Hits        22863    22863           
- Misses       7946     7970   +24     
+ Partials       25        1   -24     
Flag Coverage Δ
libsinsp 74.14% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@poiana poiana merged commit 2b0fa60 into falcosecurity:master Aug 26, 2024
42 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants