Skip to content

Commit ccb3272

Browse files
Dimitri DaskalakisPaolo Abeni
authored andcommitted
selftests: drivers: net: hw: Modify toeplitz.c to poll for packets
Prior to this the receiver would sleep for the configured timeout, then attempt to receive as many packets as possible. This would result in a large burst of packets, and we don't necessarily need that many samples. The tests now run faster. Before ok 12 toeplitz.test.rps_udp_ipv6 # Totals: pass:12 fail:0 xfail:0 xpass:0 skip:0 error:0 real 0m54.792s user 0m12.486s sys 0m10.887s After ok 12 toeplitz.test.rps_udp_ipv6 # Totals: pass:12 fail:0 xfail:0 xpass:0 skip:0 error:0 real 0m36.892s user 0m4.203s sys 0m8.314s Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Dimitri Daskalakis <dimitri.daskalakis1@gmail.com> Link: https://patch.msgid.link/20260207013018.551347-1-dimitri.daskalakis1@gmail.com [pabeni@redhat.com: whitespaces fixes] Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 70f1fbe commit ccb3272

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

tools/testing/selftests/drivers/net/hw/toeplitz.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272

7373
#define RPS_MAX_CPUS 16UL /* must be a power of 2 */
7474

75+
#define MIN_PKT_SAMPLES 40 /* minimum number of packets to receive */
76+
7577
/* configuration options (cmdline arguments) */
7678
static uint16_t cfg_dport = 8000;
7779
static int cfg_family = AF_INET6;
@@ -251,15 +253,31 @@ static bool recv_block(struct ring_state *ring)
251253
return true;
252254
}
253255

254-
/* simple test: sleep once unconditionally and then process all rings */
256+
/* simple test: process all rings until MIN_PKT_SAMPLES packets are received,
257+
* or the test times out.
258+
*/
255259
static void process_rings(void)
256260
{
261+
struct timeval start, now;
262+
bool pkts_found = true;
263+
long elapsed_usec;
257264
int i;
258265

259-
usleep(1000 * cfg_timeout_msec);
266+
gettimeofday(&start, NULL);
260267

261-
for (i = 0; i < num_cpus; i++)
262-
do {} while (recv_block(&rings[i]));
268+
do {
269+
if (!pkts_found)
270+
usleep(100);
271+
272+
pkts_found = false;
273+
for (i = 0; i < num_cpus; i++)
274+
pkts_found |= recv_block(&rings[i]);
275+
276+
gettimeofday(&now, NULL);
277+
elapsed_usec = (now.tv_sec - start.tv_sec) * 1000000 +
278+
(now.tv_usec - start.tv_usec);
279+
} while (frames_received - frames_nohash < MIN_PKT_SAMPLES &&
280+
elapsed_usec < cfg_timeout_msec * 1000);
263281

264282
fprintf(stderr, "count: pass=%u nohash=%u fail=%u\n",
265283
frames_received - frames_nohash - frames_error,

0 commit comments

Comments
 (0)