Skip to content

Specify queue id as a configuration parameter#2009

Open
JasMetzger wants to merge 11 commits into
seladb:devfrom
JasMetzger:dev
Open

Specify queue id as a configuration parameter#2009
JasMetzger wants to merge 11 commits into
seladb:devfrom
JasMetzger:dev

Conversation

@JasMetzger

Copy link
Copy Markdown
Contributor

The queue id can be specified as an additional configuration parameter. It is checked against the maximum queues available by the device using a utility provided as a static function. In the open() function, the configured queue id is used in place of the hardwired zero value that was used before. Added a convenience function to obtain the queue id from device.

Community may consider renaming the XdpDevice to XdpSocketDevice as each instance of the XdpDevice class pertains to a single queue id / socket.

@JasMetzger
JasMetzger requested a review from seladb as a code owner October 27, 2025 20:03
@codecov

codecov Bot commented Oct 27, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.75758% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.46%. Comparing base (a789e12) to head (ca25dcc).
⚠️ Report is 112 commits behind head on dev.

Files with missing lines Patch % Lines
Pcap++/src/XdpDevice.cpp 74.19% 5 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##              dev    #2009    +/-   ##
========================================
  Coverage   83.46%   83.46%            
========================================
  Files         311      312     +1     
  Lines       54556    54606    +50     
  Branches    11491    11821   +330     
========================================
+ Hits        45534    45576    +42     
- Misses       7795     7798     +3     
- Partials     1227     1232     +5     
Flag Coverage Δ
alpine320 75.90% <ø> (-0.01%) ⬇️
fedora42 75.46% <ø> (+<0.01%) ⬆️
macos-14 81.58% <ø> (+<0.01%) ⬆️
macos-15 81.57% <ø> (-0.01%) ⬇️
mingw32 70.00% <ø> (-0.03%) ⬇️
mingw64 69.96% <ø> (+0.07%) ⬆️
npcap ?
rhel94 75.47% <ø> (-0.01%) ⬇️
ubuntu2004 59.48% <ø> (-0.01%) ⬇️
ubuntu2004-zstd 59.57% <ø> (-0.02%) ⬇️
ubuntu2204 75.40% <ø> (-0.03%) ⬇️
ubuntu2204-icpx 57.85% <ø> (+0.01%) ⬆️
ubuntu2404 75.51% <ø> (-0.01%) ⬇️
ubuntu2404-arm64 75.57% <ø> (+<0.01%) ⬆️
unittest 83.46% <75.75%> (+<0.01%) ⬆️
windows-2022 85.43% <ø> (+0.17%) ⬆️
windows-2025 85.46% <ø> (+0.13%) ⬆️
winpcap 85.46% <ø> (-0.07%) ⬇️
xdp 52.99% <75.75%> (-0.02%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good overall. Some minor notes.

XDP CI is failing tho. If you could look into that. 🤔

Comment thread Pcap++/header/XdpDevice.h Outdated
XdpDeviceStats getStatistics();

/// @return Return queue identifier for underlying socket
uint32_t getQueueId()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: I think this method can be marked as const?

Comment thread Pcap++/src/XdpDevice.cpp Outdated
uint32_t XdpDevice::getNumQueues(const std::string& iface, bool tx)
{
// returns number of hardware queues associated with the device
uint32_t rxtxqueues = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: can we rename this to numQueues?

Comment thread Pcap++/src/XdpDevice.cpp
{
std::regex rxtx_regex("^" + prefix + "[0-9]+$");

struct dirent* entry;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Curious why the struct dirent*? Can't we just do dirent*?

@seladb

seladb commented Nov 6, 2025

Copy link
Copy Markdown
Owner

@JasMetzger, please notice that clang-format fails in CI

@JasMetzger

Copy link
Copy Markdown
Contributor Author

Sorry for the delay--- I was out of town. Where is this test failing?

@seladb

seladb commented Nov 9, 2025

Copy link
Copy Markdown
Owner

Sorry for the delay--- I was out of town. Where is this test failing?

@JasMetzger you can see the pre-commit build that failed: https://github.com/seladb/PcapPlusPlus/actions/runs/19214326473/job/54921310413?pr=2009

There are trailing white-spaces and formatting issues. To fix formatting, you should run clang-format as mentioned in https://github.com/seladb/PcapPlusPlus/blob/master/CONTRIBUTING.md

@JasMetzger

Copy link
Copy Markdown
Contributor Author

When I run the pre-commit, there are errors in files that I did not modify. Shall I address those?

@seladb

seladb commented Nov 13, 2025

Copy link
Copy Markdown
Owner

When I run the pre-commit, there are errors in files that I did not modify. Shall I address those?

@JasMetzger there shouldn't be errors in files you did not modify, please avoid updating them in this PR

@seladb seladb linked an issue Nov 30, 2025 that may be closed by this pull request
@seladb

seladb commented Dec 7, 2025

Copy link
Copy Markdown
Owner

@JasMetzger should we move this PR to DRAFT until it's ready for review?
The CI is currently failing...

@JasMetzger

Copy link
Copy Markdown
Contributor Author

When I do a clean make, there are warnings in files I haven't touched, so not sure what to do about that code. The first warning is freebsd running bash but I don't understand how it is failing BSD or what it is doing. Do I need to create a FreeBSD environment? Is it compiling it? I think I need some help with the CI. I got it to pass clang.

@seladb

seladb commented Dec 8, 2025

Copy link
Copy Markdown
Owner

There might be issues with the FreeBSD tests, I need to look into it... 😕

Comment thread Pcap++/header/XdpDevice.h Outdated
/// @
namespace pcpp
{
#define XDP_MAX_RXTX_QUEUES 16

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This const isn't used anywhere, should we remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will remove. I think at first I was simply setting a hard limit before I created a function that can detect it. If the function cannot detect it, it returns 0 which may not be desirable. Maybe it should return 1 if nothing else. That will be the identical behavior in the release version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made the default number 1. So a qid of zero, the default, and as things worked before, will pass the test.

Comment thread Pcap++/src/XdpDevice.cpp
Comment on lines +409 to +410
xskConfig.rx_size = m_Config->rxSize;
xskConfig.tx_size = m_Config->txSize;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This was already fixed in #2030

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will that be a problem if I leave it like this? A merge issue?

Comment thread Pcap++/header/XdpDevice.h Outdated
/// @param[in] interfaceName The interface name to use to detect hardware queues
/// @param[in] tx If true, return TX queues, otherwise RX. Default is false
/// @return The number of hardware queues associated with the device.
static uint32_t numQueues(const std::string& interfaceName, bool tx = false);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why is this a public method? Shouldn't it be private?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It may be useful for configuring the user space, such as limiting the number of threads and resources.

Comment thread Pcap++/src/XdpDevice.cpp Outdated
return false;
}

unsigned int nhwqueues = numQueues(m_InterfaceName);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

nit: let's rename to numOfHardwareQueues?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do.

@JasMetzger

Copy link
Copy Markdown
Contributor Author

Redirecting a packet to a particular rxqueue and associated socket requires a "map" between kernel and userspace. Entries in the map are created on the user space side using the socket's file descriptor. Unless there is a different way, I am considering a function in XdpDevice that passes in a pointer to int for the file descriptor to be written. The function returns a bool, true if the fd was set ok, false otherwise.

@seladb

seladb commented Dec 12, 2025

Copy link
Copy Markdown
Owner

Redirecting a packet to a particular rxqueue and associated socket requires a "map" between kernel and userspace. Entries in the map are created on the user space side using the socket's file descriptor. Unless there is a different way, I am considering a function in XdpDevice that passes in a pointer to int for the file descriptor to be written. The function returns a bool, true if the fd was set ok, false otherwise.

@JasMetzger do you have a code example somewhere that shows how it should be done in AF_XDP?
How should this map be created? How do you pass it to the kernel?
I'm not familiar with this area, so providing more context would definitely help.

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.

Xdp Rx Queue

3 participants