Skip to content

xdp-trafficgen: add total runtime option to specify number of seconds to run - #590

Merged
tohojo merged 3 commits into
xdp-project:mainfrom
eraycep:add-total-runtime-option
Oct 14, 2026
Merged

tohojo merged 3 commits into
xdp-project:mainfrom
eraycep:add-total-runtime-option

Conversation

@eraycep

@eraycep eraycep commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Add a --duration option to the UDP and TCP traffic-generator modes. Traffic generation stops when either the duration or packet limit is reached.

Batching was implemented because when num_pkts was given a high number like 4 billion and duration was given as 2 seconds, program wouldn't exit after 2 seconds. Doing it with batches allows both options to be checked constantly. BPF program runs are processed in smaller batches to keep duration checks responsive.

Fixes #355.

@eraycep
eraycep force-pushed the add-total-runtime-option branch from f7ebb41 to 8a39779 Compare September 14, 2026 13:10
@eraycep eraycep changed the title Add total runtime option to specify number of seconds to run xdp-trafficgen: add total runtime option to specify number of seconds to run Sep 14, 2026
Comment thread xdp-trafficgen/xdp-trafficgen.c Outdated
.ctx_in = &ctx_in,
.ctx_size_in = sizeof(ctx_in),
.repeat = cfg->num_pkts ?: 1 << 20,
.repeat = cfg->num_pkts && cfg->num_pkts < TEST_RUN_BATCH_SIZE ? cfg->num_pkts : TEST_RUN_BATCH_SIZE,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is too long - split it out to a separate expression before the DECLARE

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.

Got it, separated into expression.

Comment thread xdp-trafficgen/xdp-trafficgen.c Outdated
int err;
bool duration_expired = false;
struct timespec deadline = {};
struct timespec now;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep the declarations sorted by line length; also those two timespecs can be on one line.

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.

Moved them into one line and sorted declarations by line length.

if (remaining < (__u64)opts.repeat)
opts.repeat = (int)remaining;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a separate fix, let's split it out to its own commit. And there's something wrong with the indentation (spaces instead of tabs)

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.

Separated into another commit.

Comment thread xdp-trafficgen/xdp-trafficgen.c Outdated
duration_expired =
now.tv_sec > deadline.tv_sec ||
(now.tv_sec == deadline.tv_sec &&
now.tv_nsec >= deadline.tv_nsec);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might as well just break; here instead of carrying this into the while() check.

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.

Added break;

Add a duration option to the UDP and TCP traffic generators. Use a monotonic clock deadline to stop transmission once the requested number of seconds has elapsed, while preserving the existing packet-count stopping condition.

Signed-off-by: Eray Cepni <cepnieray.tr@gmail.com>
Limit each BPF test run invocation to a fixed-size batch and reduce the final batch to the exact number of packets remaining. This avoids overflowing the signed repeat field for large packet counts while ensuring that only the requested number of packets is sent.

Signed-off-by: Eray Cepni <cepnieray.tr@gmail.com>
@eraycep
eraycep force-pushed the add-total-runtime-option branch from 8a39779 to 048f281 Compare October 6, 2026 06:43
@eraycep
eraycep requested a review from tohojo October 6, 2026 06:45

@tohojo tohojo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code looks good, but please add the new options to the README file and man page as well.

Document the duration option for the UDP and TCP traffic generators in both the README and generated man page, including its interaction with the packet-count limit.

Signed-off-by: Eray Cepni <cepnieray.tr@gmail.com>
@eraycep
eraycep requested a review from tohojo October 9, 2026 15:52
@tohojo
tohojo merged commit 2a3507b into xdp-project:main Oct 14, 2026
140 of 141 checks passed
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-trafficgen: Add option to specify total runtime

2 participants