diff mbox series

[bpf-next,05/10] bpf: selftests, improve test_sockmap total bytes counter

Message ID 158871187408.7537.17124775242608386871.stgit@john-Precision-5820-Tower
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series bpf: selftests, test_sockmap improvements | expand

Commit Message

John Fastabend May 5, 2020, 8:51 p.m. UTC
The recv thread in test_sockmap waits to receive all bytes from sender but
in the case we use pop data it may wait for more bytes then actually being
sent. This stalls the test harness for multiple seconds. Because this
happens in multiple tests it slows time to run the selftest.

Fix by doing a better job of accounting for total bytes when pop helpers
are used.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 tools/testing/selftests/bpf/test_sockmap.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Jakub Sitnicki May 7, 2020, 8:55 a.m. UTC | #1
On Tue, 05 May 2020 13:51:14 -0700
John Fastabend <john.fastabend@gmail.com> wrote:

> The recv thread in test_sockmap waits to receive all bytes from sender but
> in the case we use pop data it may wait for more bytes then actually being
> sent. This stalls the test harness for multiple seconds. Because this
> happens in multiple tests it slows time to run the selftest.
> 
> Fix by doing a better job of accounting for total bytes when pop helpers
> are used.
> 
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> ---
>  tools/testing/selftests/bpf/test_sockmap.c |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
> index a81ed5d..36aca86 100644
> --- a/tools/testing/selftests/bpf/test_sockmap.c
> +++ b/tools/testing/selftests/bpf/test_sockmap.c
> @@ -502,9 +502,10 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
>  		 * paths.
>  		 */
>  		total_bytes = (float)iov_count * (float)iov_length * (float)cnt;
> -		txmsg_pop_total = txmsg_pop;
>  		if (txmsg_apply)
> -			txmsg_pop_total *= (total_bytes / txmsg_apply);
> +			txmsg_pop_total = txmsg_pop * (total_bytes / txmsg_apply);
> +		else
> +			txmsg_pop_total = txmsg_pop * cnt;
>  		total_bytes -= txmsg_pop_total;
>  		err = clock_gettime(CLOCK_MONOTONIC, &s->start);
>  		if (err < 0)
> @@ -638,9 +639,13 @@ static int sendmsg_test(struct sockmap_options *opt)
>  
>  	rxpid = fork();
>  	if (rxpid == 0) {
> +		iov_buf -= (txmsg_pop - txmsg_start_pop + 1);
>  		if (opt->drop_expected)
>  			exit(0);
>  
> +		if (!iov_buf) /* zero bytes sent case */
> +			exit(0);

You probably want to call _exit() from the child to prevent flushing
stdio buffers twice.

> +
>  		if (opt->sendpage)
>  			iov_count = 1;
>  		err = msg_loop(rx_fd, iov_count, iov_buf,
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index a81ed5d..36aca86 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -502,9 +502,10 @@  static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
 		 * paths.
 		 */
 		total_bytes = (float)iov_count * (float)iov_length * (float)cnt;
-		txmsg_pop_total = txmsg_pop;
 		if (txmsg_apply)
-			txmsg_pop_total *= (total_bytes / txmsg_apply);
+			txmsg_pop_total = txmsg_pop * (total_bytes / txmsg_apply);
+		else
+			txmsg_pop_total = txmsg_pop * cnt;
 		total_bytes -= txmsg_pop_total;
 		err = clock_gettime(CLOCK_MONOTONIC, &s->start);
 		if (err < 0)
@@ -638,9 +639,13 @@  static int sendmsg_test(struct sockmap_options *opt)
 
 	rxpid = fork();
 	if (rxpid == 0) {
+		iov_buf -= (txmsg_pop - txmsg_start_pop + 1);
 		if (opt->drop_expected)
 			exit(0);
 
+		if (!iov_buf) /* zero bytes sent case */
+			exit(0);
+
 		if (opt->sendpage)
 			iov_count = 1;
 		err = msg_loop(rx_fd, iov_count, iov_buf,