Skip to content

Refactor reentrant flag to be set during channel creation. #1738

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

Dimi1010
Copy link
Collaborator

Split of #1668

This PR aims to standardize m_ReentrantMode to be set during the channel opening phase instead of the capture initialization phase as it is determined by the opening flags. The currently used implementation essentially assumes the what the reentrant mode is based on the function being called to start the capture, instead of recording the correct value.

…nnelImpl` to remove ambiguity between public and private calls.
… of when starting capture as it is determined by the PF_RING_REENTRANT flag.

- Added ability to choose if `openSingleChannelImpl` will open w/reenterant flag.
int res = openSingleRxChannel(ringName.c_str(), &m_PfRingDescriptors[i]);
// todo: Shouldn't we use the reentrant mode here? We are opening multiple channels?
// todo: Potentially only open in reenterant mode if creating N > 1 channels?
int res = openSingleRxChannelImpl(ringName.c_str(), &m_PfRingDescriptors[i]);
Copy link
Collaborator Author

@Dimi1010 Dimi1010 Mar 23, 2025

Choose a reason for hiding this comment

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

@seladb Can you please check this code?

Why is the implementation opening multiple Rx channels in non-reentrant mode here, when the other multiple channel function opens them in reentrant mode?

Copy link

codecov bot commented Mar 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.21%. Comparing base (9aefc1f) to head (60b353e).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1738      +/-   ##
==========================================
- Coverage   83.21%   83.21%   -0.01%     
==========================================
  Files         282      282              
  Lines       48741    48741              
  Branches    10314    10334      +20     
==========================================
- Hits        40560    40558       -2     
+ Misses       7051     7050       -1     
- Partials     1130     1133       +3     
Flag Coverage Δ
alpine320 75.20% <ø> (ø)
fedora40 75.24% <ø> (-0.02%) ⬇️
macos-13 80.71% <ø> (ø)
macos-14 80.71% <ø> (ø)
macos-15 80.68% <ø> (ø)
mingw32 70.86% <ø> (-0.02%) ⬇️
mingw64 70.80% <ø> (-0.04%) ⬇️
npcap 85.30% <ø> (-0.02%) ⬇️
rhel94 75.07% <ø> (-0.03%) ⬇️
ubuntu2004 58.62% <ø> (ø)
ubuntu2004-zstd 58.74% <ø> (-0.02%) ⬇️
ubuntu2204 74.99% <ø> (-0.03%) ⬇️
ubuntu2204-icpx 61.37% <ø> (ø)
ubuntu2404 75.23% <ø> (-0.03%) ⬇️
unittest 83.21% <ø> (-0.01%) ⬇️
windows-2019 85.33% <ø> (-0.01%) ⬇️
windows-2022 85.36% <ø> (-0.01%) ⬇️
winpcap 85.33% <ø> (ø)
xdp 50.68% <ø> (ø)

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dimi1010 Dimi1010 marked this pull request as ready for review April 4, 2025 08:39
@Dimi1010 Dimi1010 requested a review from seladb as a code owner April 4, 2025 08:39
@seladb
Copy link
Owner

seladb commented Apr 11, 2025

@Dimi1010 this code was written many years ago so I don't remember all the details, but I think the PF_RING_REENTRANT flag should be set if multiple threads are going to read from the same PF_RING device. However, if we know that a single thread is going to read from a a PF_RING device then this flag is redundant because it has a performance cost.

The problem with the current implementation is that when opening the channels we don't know how many threads will read from them:

  • We could open multiple channels, but only a single thread will read from them - the flag is redundant
  • We could open multiple channels, and multiple threads will read from each of them - the flag is needed
  • We could open a single channel, and multiple threads will read from it - the flag is needed
  • We could open a single channel, and a single thread will read from it- the flag is redundant

In addition - if opening in reentrant mode then zero copy can't be used, hence the m_ReentrantMode private member.

We may need a bigger refactor to allow the user to choose when opening the device whether multiple threads will read from each channel (and set the flag accordingly), and when start capturing verify that we don't allow multiple threads to read from the same channel.

But this is something that needs further testing with a PF_RING environment to test in - do you have such an environment?

@Dimi1010
Copy link
Collaborator Author

We may need a bigger refactor to allow the user to choose when opening the device whether multiple threads will read from each channel (and set the flag accordingly), and when start capturing verify that we don't allow multiple threads to read from the same channel.

This would work. I think a bool in the openChannel functions would be enough. Something like multithreadedCaptureSupport that controls if the flag is used.

But this is something that needs further testing with a PF_RING environment to test in - do you have such an environment?

Not fully. I have a WSL to confirm compilation, but not sure if that will work for actual capture testing.

@seladb
Copy link
Owner

seladb commented Apr 13, 2025

This would work. I think a bool in the openChannel functions would be enough. Something like multithreadedCaptureSupport that controls if the flag is used.

Yes, something like that could work

Not fully. I have a WSL to confirm compilation, but not sure if that will work for actual capture testing.

I'm not sure it'll work well with WSL, you may need to set up an Ubuntu VM. I use VirtualBox on Windows...

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.

2 participants