From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, shuah@kernel.org,
willemb@google.com, petrm@nvidia.com, donald.hunter@gmail.com,
michael.chan@broadcom.com, pavan.chebbi@broadcom.com,
linux-kselftest@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 6/9] selftests: drv-net: gro: use SO_TXTIME to schedule packets together
Date: Thu, 5 Feb 2026 14:05:38 -0800 [thread overview]
Message-ID: <20260205220541.2992807-7-kuba@kernel.org> (raw)
In-Reply-To: <20260205220541.2992807-1-kuba@kernel.org>
Longer packet sequence tests are quite flaky when the test is run
over a real network. Try to avoid at least the jitter on the sender
side by scheduling all the packets to be sent at once using SO_TXTIME.
Use hardcoded tx time of 5msec in the future. In my test increasing
this time past 2msec makes no difference so 5msec is plenty of margin.
Since we now expect more output buffering make sure to raise SNDBUF.
Experimenting with long sequences I see frequent failures when sending
200 packets, only 50-100 packets get coalesced. With this change
up to 1000 packets get coalesced relatively reliably.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/testing/selftests/net/lib/gro.c | 49 +++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/lib/gro.c b/tools/testing/selftests/net/lib/gro.c
index 3c0745b68bfa..832edf3e1290 100644
--- a/tools/testing/selftests/net/lib/gro.c
+++ b/tools/testing/selftests/net/lib/gro.c
@@ -63,6 +63,7 @@
#include <linux/filter.h>
#include <linux/if_packet.h>
#include <linux/ipv6.h>
+#include <linux/net_tstamp.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <netinet/in.h>
@@ -74,6 +75,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include "kselftest.h"
@@ -123,6 +125,9 @@ static int tcp_offset = -1;
static int total_hdr_len = -1;
static int ethhdr_proto = -1;
static bool ipip;
+static uint64_t txtime_ns;
+
+#define TXTIME_DELAY_MS 5
static void vlog(const char *fmt, ...)
{
@@ -330,13 +335,35 @@ static void fill_transportlayer(void *buf, int seq_offset, int ack_offset,
static void write_packet(int fd, char *buf, int len, struct sockaddr_ll *daddr)
{
+ char control[CMSG_SPACE(sizeof(uint64_t))];
+ struct msghdr msg = {};
+ struct iovec iov = {};
+ struct cmsghdr *cm;
int ret = -1;
- ret = sendto(fd, buf, len, 0, (struct sockaddr *)daddr, sizeof(*daddr));
+ iov.iov_base = buf;
+ iov.iov_len = len;
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = daddr;
+ msg.msg_namelen = sizeof(*daddr);
+
+ memset(control, 0, sizeof(control));
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control);
+
+ cm = CMSG_FIRSTHDR(&msg);
+ cm->cmsg_level = SOL_SOCKET;
+ cm->cmsg_type = SCM_TXTIME;
+ cm->cmsg_len = CMSG_LEN(sizeof(uint64_t));
+ memcpy(CMSG_DATA(cm), &txtime_ns, sizeof(txtime_ns));
+
+ ret = sendmsg(fd, &msg, 0);
if (ret == -1)
- error(1, errno, "sendto failure");
+ error(1, errno, "sendmsg failure");
if (ret != len)
- error(1, errno, "sendto wrong length");
+ error(1, 0, "sendmsg wrong length: %d vs %d", ret, len);
}
static void create_packet(void *buf, int seq_offset, int ack_offset,
@@ -1058,15 +1085,31 @@ static void check_recv_pkts(int fd, int *correct_payload,
static void gro_sender(void)
{
+ struct sock_txtime so_txtime = { .clockid = CLOCK_MONOTONIC, };
+ int bufsize = 4 * 1024 * 1024; /* 4 MB */
const int fin_delay_us = 100 * 1000;
static char fin_pkt[MAX_HDR_LEN];
struct sockaddr_ll daddr = {};
+ struct timespec ts;
int txfd = -1;
txfd = socket(PF_PACKET, SOCK_RAW, IPPROTO_RAW);
if (txfd < 0)
error(1, errno, "socket creation");
+ if (setsockopt(txfd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize)))
+ error(1, errno, "cannot set sndbuf size, setsockopt failed");
+
+ if (setsockopt(txfd, SOL_SOCKET, SO_TXTIME,
+ &so_txtime, sizeof(so_txtime)))
+ error(1, errno, "setsockopt SO_TXTIME");
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts))
+ error(1, errno, "clock_gettime");
+
+ txtime_ns = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+ txtime_ns += TXTIME_DELAY_MS * 1000000ULL;
+
memset(&daddr, 0, sizeof(daddr));
daddr.sll_ifindex = if_nametoindex(ifname);
if (daddr.sll_ifindex == 0)
--
2.53.0
next prev parent reply other threads:[~2026-02-05 22:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-05 22:05 [PATCH net-next 0/9] net: stats, tools, driver tests for HW GRO Jakub Kicinski
2026-02-05 22:05 ` [PATCH net-next 1/9] eth: bnxt: gather and report HW-GRO stats Jakub Kicinski
2026-02-05 22:44 ` Michael Chan
2026-02-06 0:24 ` Jakub Kicinski
2026-02-05 22:05 ` [PATCH net-next 2/9] tools: ynltool: factor out qstat dumping Jakub Kicinski
2026-02-06 14:58 ` Petr Machata
2026-02-05 22:05 ` [PATCH net-next 3/9] tools: ynltool: add qstats analysis for HW-GRO efficiency / savings Jakub Kicinski
2026-02-06 13:44 ` Petr Machata
2026-02-05 22:05 ` [PATCH net-next 4/9] selftests: net: move gro to lib for HW vs SW reuse Jakub Kicinski
2026-02-06 15:01 ` Petr Machata
2026-02-05 22:05 ` [PATCH net-next 5/9] selftests: drv-net: give HW stats sync time extra 25% of margin Jakub Kicinski
2026-02-06 14:40 ` Petr Machata
2026-02-05 22:05 ` Jakub Kicinski [this message]
2026-02-06 15:19 ` [PATCH net-next 6/9] selftests: drv-net: gro: use SO_TXTIME to schedule packets together Petr Machata
2026-02-05 22:05 ` [PATCH net-next 7/9] selftests: drv-net: gro: test GRO stats Jakub Kicinski
2026-02-05 22:05 ` [PATCH net-next 8/9] selftests: drv-net: gro: add test for packet ordering Jakub Kicinski
2026-02-05 22:05 ` [PATCH net-next 9/9] selftests: drv-net: gro: add a test for HW-GRO depth Jakub Kicinski
2026-02-06 15:36 ` [PATCH net-next 0/9] net: stats, tools, driver tests for HW GRO Petr Machata
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260205220541.2992807-7-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=petrm@nvidia.com \
--cc=shuah@kernel.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox