From nobody Wed Dec 4 08:32:29 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A13521D0F51 for ; Wed, 30 Oct 2024 06:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730268670; cv=none; b=MJQhHmq5PlzD+T+oPn1xRNFOMIXaEAV2waAqD06Z/fW3IcKzS9WlkQEVm5lEpwIqs6MKWZQ+X+vpIa5+wWGo31is004I6KdVE9X5K7uOmBz2yaQ2AzFIh9cci+LSDMzbNOinyVZSvHmrOWiky5EQadazdNO+iyRQE0YWRz7zLcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730268670; c=relaxed/simple; bh=j6ENN/YA7zBot/DvaKGO32Z9qk2Hwh/KtfV0D8zWm6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T7zpA4CqcwdhD10LkAHcqzmLmuUpMND/ox1vQ/u8kV0lutI3SP/qbFkkNHBtyIytclt5T1vRCUVEljSYm4iXJwlxgL93OwUiBWJFA0cdLq3UtJnTxnZHem/OCTaS8W+1X6WYVUunVbidd3RSVOMhhAqZJ4CR3Lcqcn71j5HDPp0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XZX+iuSR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XZX+iuSR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98B3FC4CEE4; Wed, 30 Oct 2024 06:11:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730268670; bh=j6ENN/YA7zBot/DvaKGO32Z9qk2Hwh/KtfV0D8zWm6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZX+iuSR1y2ocEPjaqlMdZgE1YHnU6EJsqQc1MhN+V/Eg9VNeSTCERLB1O9HURSwk +3LJS6WjzyOBRP2l1BTHlQlfZv3nZ9gJOJkNcGHLm/rBYhmpv0z+bpwwE1NEcJcZTh 1CeKONgOU/PpYg6zQNWKATH3n2Chn/zAa+SMc175ZG8RbFd0+ycOk6j+GUiMAM8WB5 /QXbwWct2j4noBtZkwJACHdp/fV8TDxLh7zdl0CHUi4suvXTxtlMK3RbJBygn6HMHX NT4suIiEd5zzo+k20PQGmyJPLrCXZe7YXO//TJ7+F1e4TiGtpBJXHBtFyRKI6HorpV WaL8noqBbPJfA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v9 10/13] Squash to "selftests/bpf: Add bpf_burst scheduler & test" Date: Wed, 30 Oct 2024 14:10:34 +0800 Message-ID: <7af9d9c97ab72caef4facd23c7d78cf1c8aa83fd.1730268415.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Update test_bpf_sched(). Use the newly added bpf_for_each() helper to walk the conn_list. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 2 +- .../selftests/bpf/progs/mptcp_bpf_burst.c | 73 ++++++++----------- 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index e845809cd2a8..dbdff62e430f 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -732,7 +732,7 @@ static void test_burst(void) if (!ASSERT_OK_PTR(skel, "open_and_load: burst")) return; =20 - test_bpf_sched(skel->obj, "burst", WITH_DATA, WITH_DATA); + test_bpf_sched(skel->maps.burst, "burst", WITH_DATA, WITH_DATA); mptcp_bpf_burst__destroy(skel); } =20 diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c b/tools/te= sting/selftests/bpf/progs/mptcp_bpf_burst.c index eb21119aa8f7..f0c9f5984736 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c @@ -9,10 +9,14 @@ char _license[] SEC("license") =3D "GPL"; =20 #define MPTCP_SEND_BURST_SIZE 65428 =20 +#define SSK_MODE_ACTIVE 0 +#define SSK_MODE_BACKUP 1 +#define SSK_MODE_MAX 2 + #define min(a, b) ((a) < (b) ? (a) : (b)) =20 struct bpf_subflow_send_info { - __u8 subflow_id; + struct mptcp_subflow_context *subflow; __u64 linger_time; }; =20 @@ -23,10 +27,6 @@ extern bool tcp_stream_memory_free(const struct sock *sk= , int wake) __ksym; extern bool bpf_mptcp_subflow_queues_empty(struct sock *sk) __ksym; extern void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struc= t sock *ssk) __ksym; =20 -#define SSK_MODE_ACTIVE 0 -#define SSK_MODE_BACKUP 1 -#define SSK_MODE_MAX 2 - static __always_inline __u64 div_u64(__u64 dividend, __u32 divisor) { return dividend / divisor; @@ -67,8 +67,7 @@ void BPF_PROG(mptcp_sched_burst_release, struct mptcp_soc= k *msk) { } =20 -static int bpf_burst_get_send(struct mptcp_sock *msk, - struct mptcp_sched_data *data) +static int bpf_burst_get_send(struct mptcp_sock *msk) { struct bpf_subflow_send_info send_info[SSK_MODE_MAX]; struct mptcp_subflow_context *subflow; @@ -80,18 +79,12 @@ static int bpf_burst_get_send(struct mptcp_sock *msk, =20 /* pick the subflow with the lower wmem/wspace ratio */ for (i =3D 0; i < SSK_MODE_MAX; ++i) { - send_info[i].subflow_id =3D MPTCP_SUBFLOWS_MAX; + send_info[i].subflow =3D NULL; send_info[i].linger_time =3D -1; } =20 - for (i =3D 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { - bool backup; - - subflow =3D bpf_mptcp_subflow_ctx_by_pos(data, i); - if (!subflow) - break; - - backup =3D subflow->backup || subflow->request_bkup; + bpf_for_each(mptcp_subflow, subflow, msk) { + bool backup =3D subflow->backup || subflow->request_bkup; =20 ssk =3D mptcp_subflow_tcp_sock(subflow); if (!mptcp_subflow_active(subflow)) @@ -109,7 +102,9 @@ static int bpf_burst_get_send(struct mptcp_sock *msk, =20 linger_time =3D div_u64((__u64)ssk->sk_wmem_queued << 32, pace); if (linger_time < send_info[backup].linger_time) { - send_info[backup].subflow_id =3D i; + if (!sk_stream_memory_free(ssk)) + continue; + send_info[backup].subflow =3D subflow; send_info[backup].linger_time =3D linger_time; } } @@ -117,13 +112,14 @@ static int bpf_burst_get_send(struct mptcp_sock *msk, =20 /* pick the best backup if no other subflow is active */ if (!nr_active) - send_info[SSK_MODE_ACTIVE].subflow_id =3D send_info[SSK_MODE_BACKUP].sub= flow_id; + send_info[SSK_MODE_ACTIVE].subflow =3D send_info[SSK_MODE_BACKUP].subflo= w; =20 - subflow =3D bpf_mptcp_subflow_ctx_by_pos(data, send_info[SSK_MODE_ACTIVE]= .subflow_id); + subflow =3D bpf_core_cast(send_info[SSK_MODE_ACTIVE].subflow, + struct mptcp_subflow_context); if (!subflow) return -1; ssk =3D mptcp_subflow_tcp_sock(subflow); - if (!ssk || !sk_stream_memory_free(ssk)) + if (!ssk) return -1; =20 burst =3D min(MPTCP_SEND_BURST_SIZE, mptcp_wnd_end(msk) - msk->snd_nxt); @@ -141,23 +137,18 @@ static int bpf_burst_get_send(struct mptcp_sock *msk, return 0; } =20 -static int bpf_burst_get_retrans(struct mptcp_sock *msk, - struct mptcp_sched_data *data) +static int bpf_burst_get_retrans(struct mptcp_sock *msk) { - int backup =3D MPTCP_SUBFLOWS_MAX, pick =3D MPTCP_SUBFLOWS_MAX, subflow_i= d; + struct sock *backup =3D NULL, *pick =3D NULL; struct mptcp_subflow_context *subflow; int min_stale_count =3D INT_MAX; - struct sock *ssk; =20 - for (int i =3D 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { - subflow =3D bpf_mptcp_subflow_ctx_by_pos(data, i); - if (!subflow) - break; + bpf_for_each(mptcp_subflow, subflow, msk) { + struct sock *ssk =3D mptcp_subflow_tcp_sock(subflow); =20 if (!mptcp_subflow_active(subflow)) continue; =20 - ssk =3D mptcp_subflow_tcp_sock(subflow); /* still data outstanding at TCP level? skip this */ if (!tcp_rtx_and_write_queues_empty(ssk)) { mptcp_pm_subflow_chk_stale(msk, ssk); @@ -166,23 +157,23 @@ static int bpf_burst_get_retrans(struct mptcp_sock *m= sk, } =20 if (subflow->backup || subflow->request_bkup) { - if (backup =3D=3D MPTCP_SUBFLOWS_MAX) - backup =3D i; + if (!backup) + backup =3D ssk; continue; } =20 - if (pick =3D=3D MPTCP_SUBFLOWS_MAX) - pick =3D i; + if (!pick) + pick =3D ssk; } =20 - if (pick < MPTCP_SUBFLOWS_MAX) { - subflow_id =3D pick; + if (pick) goto out; - } - subflow_id =3D min_stale_count > 1 ? backup : MPTCP_SUBFLOWS_MAX; + pick =3D min_stale_count > 1 ? backup : NULL; =20 out: - subflow =3D bpf_mptcp_subflow_ctx_by_pos(data, subflow_id); + if (!pick) + return -1; + subflow =3D bpf_mptcp_subflow_ctx(pick); if (!subflow) return -1; mptcp_subflow_set_scheduled(subflow, true); @@ -194,11 +185,11 @@ int BPF_PROG(bpf_burst_get_subflow, struct mptcp_sock= *msk, struct mptcp_sched_data *data) { if (data->reinject) - return bpf_burst_get_retrans(msk, data); - return bpf_burst_get_send(msk, data); + return bpf_burst_get_retrans(msk); + return bpf_burst_get_send(msk); } =20 -SEC(".struct_ops") +SEC(".struct_ops.link") struct mptcp_sched_ops burst =3D { .init =3D (void *)mptcp_sched_burst_init, .release =3D (void *)mptcp_sched_burst_release, --=20 2.45.2