Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Geliang Tang <geliang@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Mykola Lysenko <mykolal@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Geliang Tang <tanggeliang@kylinos.cn>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 1/4] selftests/bpf: Use post_socket_cb in connect_to_fd_opts
Date: Tue, 21 May 2024 09:56:29 -0700	[thread overview]
Message-ID: <a4db3afb-4dc6-4aea-8424-a1c9cc9563bf@linux.dev> (raw)
In-Reply-To: <0de05f2ffdfa4adb832fb87d08e6d1c56bef62b2.1715745588.git.tanggeliang@kylinos.cn>

On 5/14/24 9:20 PM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Since the post_socket_cb() callback is added in struct network_helper_opts,
> it's make sense to use it not only in __start_server(), but also in
> connect_to_fd_opts(). Then it can be used to set TCP_CONGESTION sockopt.
> 
> Add a post_socket_opts type member cb_opts into struct network_helper_opts,
> then cc can be moved into struct post_socket_opts from network_helper_opts.
> Define a new callback cc_cb() to set TCP_CONGESTION sockopt, and set it to
> post_socket_cb pointer.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>   tools/testing/selftests/bpf/network_helpers.c       | 5 ++---
>   tools/testing/selftests/bpf/network_helpers.h       | 6 ++++--
>   tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 9 ++++++++-
>   3 files changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
> index 35250e6cde7f..d97f8a669b38 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c
> @@ -338,9 +338,8 @@ int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts)
>   	if (settimeo(fd, opts->timeout_ms))
>   		goto error_close;
>   
> -	if (opts->cc && opts->cc[0] &&
> -	    setsockopt(fd, SOL_TCP, TCP_CONGESTION, opts->cc,
> -		       strlen(opts->cc) + 1))
> +	if (opts->post_socket_cb &&
> +	    opts->post_socket_cb(fd, &opts->cb_opts))
>   		goto error_close;
>   
>   	if (!opts->noconnect)
> diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
> index 883c7ea9d8d5..e44a6e5d8344 100644
> --- a/tools/testing/selftests/bpf/network_helpers.h
> +++ b/tools/testing/selftests/bpf/network_helpers.h
> @@ -21,16 +21,18 @@ typedef __u16 __sum16;
>   #define VIP_NUM 5
>   #define MAGIC_BYTES 123
>   
> -struct post_socket_opts {};
> +struct post_socket_opts {
> +	const char *cc;
> +};

 From looking its usage in this set, it has cc name and map fd in it. It becomes 
clear that it is not possible to have one generic/common "struct 
post_socket_opts" for all tests.

>   
>   struct network_helper_opts {
> -	const char *cc;
>   	int timeout_ms;
>   	bool must_fail;
>   	bool noconnect;
>   	int type;
>   	int proto;
>   	int (*post_socket_cb)(int fd, const struct post_socket_opts *opts);
> +	struct post_socket_opts cb_opts;

It is better to have the individual test define its own callback opts struct. 
Something like this:

/* network_helpers.h */
struct network_helper_opts {
	/* ... */
	int (*post_socket_cb)(int fd, void *opts);
	void *post_socket_opts;
};

/* bpf_tcp_ca.c */
struct cb_opts {
	const char *cc;
	int map_fd;
};

struct cb_opts cb_opts = {
	.cc = "bpf_dctcp",
	.map_fd = fd,
};

struct network_helper_opts opts = {
	.post_socket_cb = stg_post_socket_cb,
	.post_sock_opts = &cb_opts,
};

pw-bot: cr

>   };
>   
>   /* ipv4 test vector */
> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> index 0aca02532794..9bc909fa0833 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
> @@ -81,6 +81,12 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
>   	close(fd);
>   }
>   
> +static int cc_cb(int fd, const struct post_socket_opts *opts)
> +{
> +	return setsockopt(fd, SOL_TCP, TCP_CONGESTION, opts->cc,
> +			  strlen(opts->cc) + 1);
> +}
> +
>   static void test_cubic(void)
>   {
>   	struct bpf_cubic *cubic_skel;
> @@ -172,7 +178,8 @@ static void test_dctcp_fallback(void)
>   {
>   	int err, lfd = -1, cli_fd = -1, srv_fd = -1;
>   	struct network_helper_opts opts = {
> -		.cc = "cubic",
> +		.cb_opts.cc = "cubic",
> +		.post_socket_cb = cc_cb,
>   	};
>   	struct bpf_dctcp *dctcp_skel;
>   	struct bpf_link *link = NULL;


  reply	other threads:[~2024-05-21 16:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15  4:20 [PATCH bpf-next v2 0/4] use network helpers, part 5 Geliang Tang
2024-05-15  4:20 ` [PATCH bpf-next v2 1/4] selftests/bpf: Use post_socket_cb in connect_to_fd_opts Geliang Tang
2024-05-21 16:56   ` Martin KaFai Lau [this message]
2024-05-15  4:20 ` [PATCH bpf-next v2 2/4] selftests/bpf: Use start_server_addr in bpf_tcp_ca Geliang Tang
2024-05-21 17:02   ` Martin KaFai Lau
2024-05-15  4:20 ` [PATCH bpf-next v2 3/4] selftests/bpf: Use connect_to_fd_opts in do_test " Geliang Tang
2024-05-15  4:20 ` [PATCH bpf-next v2 4/4] selftests/bpf: Add post_connect_cb callback Geliang Tang

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=a4db3afb-4dc6-4aea-8424-a1c9cc9563bf@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=geliang@kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mykolal@fb.com \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tanggeliang@kylinos.cn \
    --cc=yonghong.song@linux.dev \
    /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