Commit ccb32726 authored by Dimitri Daskalakis's avatar Dimitri Daskalakis Committed by Paolo Abeni
Browse files

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: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDimitri 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: default avatarPaolo Abeni <pabeni@redhat.com>
parent 70f1fbee
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -72,6 +72,8 @@

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

#define MIN_PKT_SAMPLES 40	/* minimum number of packets to receive */

/* configuration options (cmdline arguments) */
static uint16_t cfg_dport =	8000;
static int cfg_family =		AF_INET6;
@@ -251,15 +253,31 @@ static bool recv_block(struct ring_state *ring)
	return true;
}

/* simple test: sleep once unconditionally and then process all rings */
/* simple test: process all rings until MIN_PKT_SAMPLES packets are received,
 * or the test times out.
 */
static void process_rings(void)
{
	struct timeval start, now;
	bool pkts_found = true;
	long elapsed_usec;
	int i;

	usleep(1000 * cfg_timeout_msec);
	gettimeofday(&start, NULL);

	do {
		if (!pkts_found)
			usleep(100);

		pkts_found = false;
		for (i = 0; i < num_cpus; i++)
		do {} while (recv_block(&rings[i]));
			pkts_found |= recv_block(&rings[i]);

		gettimeofday(&now, NULL);
		elapsed_usec = (now.tv_sec - start.tv_sec) * 1000000 +
			       (now.tv_usec - start.tv_usec);
	} while (frames_received - frames_nohash < MIN_PKT_SAMPLES &&
		 elapsed_usec < cfg_timeout_msec * 1000);

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