Skip to contentSkip to conversation

display "last time" actions info

PATCH Superseded Geliang Tang 3 participants 8 messages Mar 18, 2024 – Mar 27, 2024

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

cover display "last time" actions info

From: Geliang Tang <[email protected]>

Geliang Tang (3):
mptcp: add last time fields in mptcp_sock
mptcp: add last time fields in mptcp_info
selftests: mptcp: add last time actions tests

 include/uapi/linux/mptcp.h                    |  3 +++
 net/mptcp/options.c                           |  1 +
 net/mptcp/protocol.c                          |  5 +++++
 net/mptcp/protocol.h                          |  3 +++
 net/mptcp/sockopt.c                           |  5 +++++
 .../testing/selftests/net/mptcp/mptcp_join.sh | 21 +++++++++++++++++++
 6 files changed, 38 insertions(+)
Signature · 1 line
2.40.1
author reviewer
#1 lore raw

PATCH 1/3 mptcp: add last time fields in mptcp_sock

From: Geliang Tang <[email protected]>

This patch adds "last time" fields last_data_sent, last_data_recv and last_ack_recv in struct mptcp_sock to record the last time data_sent, data_recv and ack_recv happened. They all are initialized as tcp_jiffies32 in __mptcp_init_sock(), but updated as tcp_jiffies32 too when data is sent in __subflow_push_pending(), data is received in mptcp_recvmsg(), and ack is received in ack_update_msk().

---
 net/mptcp/options.c  | 1 +
 net/mptcp/protocol.c | 5 +++++
 net/mptcp/protocol.h | 3 +++
 3 files changed, 9 insertions(+)
net/mptcp/options.c +1 -0
index 5926955625cf..c0832df3b0a3 100644
@@ -1069,6 +1069,7 @@ static void ack_update_msk(struct mptcp_sock *msk,
 		__mptcp_snd_una_update(msk, new_snd_una);
 		__mptcp_data_acked(sk);
 	}
+	msk->last_ack_recv = tcp_jiffies32;
 	mptcp_data_unlock(sk);
 
 	trace_ack_update_msk(mp_opt->data_ack,
net/mptcp/protocol.c +5 -0
index cdf9ec67795e..a6b5c6492e9b 100644
@@ -1556,6 +1556,7 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,
 	err = copied;
 
 out:
+	msk->last_data_sent = tcp_jiffies32;
 	return err;
 }
 
@@ -2262,6 +2263,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 		 skb_queue_empty(&msk->receive_queue), copied);
 	if (!(flags & MSG_PEEK))
 		mptcp_rcv_space_adjust(msk, copied);
+	msk->last_data_recv = tcp_jiffies32;
 
 	release_sock(sk);
 	return copied;
@@ -2793,6 +2795,9 @@ static void __mptcp_init_sock(struct sock *sk)
 	WRITE_ONCE(msk->allow_infinite_fallback, true);
 	msk->recovery = false;
 	msk->subflow_id = 1;
+	msk->last_data_sent = tcp_jiffies32;
+	msk->last_data_recv = tcp_jiffies32;
+	msk->last_ack_recv = tcp_jiffies32;
 
 	mptcp_pm_data_init(msk);
 
net/mptcp/protocol.h +3 -0
index 5a4538205fd6..3a3fed3642dd 100644
@@ -282,6 +282,9 @@ struct mptcp_sock {
 	u64		bytes_acked;
 	u64		snd_una;
 	u64		wnd_end;
+	u32		last_data_sent;
+	u32		last_data_recv;
+	u32		last_ack_recv;
 	unsigned long	timer_ival;
 	u32		token;
 	int		rmem_released;
Signature · 1 line
2.40.1
maintainer
#2 lore raw

Re: [PATCH mptcp-next 1/3] mptcp: add last time fields in mptcp_sock

Quoted 36 lines · Geliang Tang

From: Geliang Tang <[email protected]>

This patch adds "last time" fields last_data_sent, last_data_recv and last_ack_recv in struct mptcp_sock to record the last time data_sent, data_recv and ack_recv happened. They all are initialized as tcp_jiffies32 in __mptcp_init_sock(), but updated as tcp_jiffies32 too when data is sent in __subflow_push_pending(), data is received in mptcp_recvmsg(), and ack is received in ack_update_msk().

---

net/mptcp/options.c  | 1 +
net/mptcp/protocol.c | 5 +++++
net/mptcp/protocol.h | 3 +++
3 files changed, 9 insertions(+)
net/mptcp/options.c +1 -0
index 5926955625cf..c0832df3b0a3 100644
@@ -1069,6 +1069,7 @@ static void ack_update_msk(struct mptcp_sock *msk,
 		__mptcp_snd_una_update(msk, new_snd_una);
 		__mptcp_data_acked(sk);
 	}
+	msk->last_ack_recv = tcp_jiffies32;
 	mptcp_data_unlock(sk);
 
 	trace_ack_update_msk(mp_opt->data_ack,
net/mptcp/protocol.c +0 -0
index cdf9ec67795e..a6b5c6492e9b 100644
@@ -1556,6 +1556,7 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,
 	err = copied;
 

out:

net/mptcp/protocol.c

Quoted 1 line
net/mptcp/protocol.c +1 -0
+	msk->last_data_sent = tcp_jiffies32;

Hi Geliang -

I think msk->last_data_sent should only be updated if err > 0.

net/mptcp/protocol.c static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, · line 2266

Quoted 8 lines
	return err;
}
net/mptcp/protocol.c +1 -0
@@ -2262,6 +2263,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 		 skb_queue_empty(&msk->receive_queue), copied);
 	if (!(flags & MSG_PEEK))
 		mptcp_rcv_space_adjust(msk, copied);
+	msk->last_data_recv = tcp_jiffies32;

This is too late in the receive process, to be comparable to TCP I think this timestamp should be set in __mptcp_move_skbs_from_subflow().

- Mat

Quoted 32 lines
net/mptcp/protocol.c +3 -0
 	release_sock(sk);
 	return copied;
@@ -2793,6 +2795,9 @@ static void __mptcp_init_sock(struct sock *sk)
 	WRITE_ONCE(msk->allow_infinite_fallback, true);
 	msk->recovery = false;
 	msk->subflow_id = 1;
+	msk->last_data_sent = tcp_jiffies32;
+	msk->last_data_recv = tcp_jiffies32;
+	msk->last_ack_recv = tcp_jiffies32;
 
 	mptcp_pm_data_init(msk);
 
net/mptcp/protocol.h +3 -0
index 5a4538205fd6..3a3fed3642dd 100644
@@ -282,6 +282,9 @@ struct mptcp_sock {
 	u64		bytes_acked;
 	u64		snd_una;
 	u64		wnd_end;
+	u32		last_data_sent;
+	u32		last_data_recv;
+	u32		last_ack_recv;
 	unsigned long	timer_ival;
 	u32		token;
 	int		rmem_released;
Signature · 1 line
2.40.1
author reviewer
#3 lore raw

PATCH 2/3 mptcp: add last time fields in mptcp_info

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Similar to tcpi_last_data_sent, tcpi_last_data_recv and tcpi_last_ack_recv exposed with TCP, this patch exposes the last time "an action happened" for MPTCP in mptcp_info, named mptcpi_last_data_sent, mptcpi_last_data_recv and mptcpi_last_ack_recv, calculated In mptcp_diag_fill_info() as the time deltas between now and the newly added last time fields in mptcp_sock.

---
 include/uapi/linux/mptcp.h | 3 +++
 net/mptcp/sockopt.c        | 5 +++++
 2 files changed, 8 insertions(+)
include/uapi/linux/mptcp.h +3 -0
index 74cfe496891e..7126563542b3 100644
@@ -58,6 +58,9 @@ struct mptcp_info {
 	__u64	mptcpi_bytes_received;
 	__u64	mptcpi_bytes_acked;
 	__u8	mptcpi_subflows_total;
+	__u32	mptcpi_last_data_sent;
+	__u32	mptcpi_last_data_recv;
+	__u32	mptcpi_last_ack_recv;
 };
 
 /* MPTCP Reset reason codes, rfc8684 */
net/mptcp/sockopt.c +5 -0
index dcd1c76d2a3b..1e74851614e8 100644
@@ -898,6 +898,7 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
 	struct sock *sk = (struct sock *)msk;
 	u32 flags = 0;
 	bool slow;
+	u32 now;
 
 	memset(info, 0, sizeof(*info));
 
@@ -942,6 +943,10 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
 	info->mptcpi_bytes_retrans = msk->bytes_retrans;
 	info->mptcpi_subflows_total = info->mptcpi_subflows +
 		__mptcp_has_initial_subflow(msk);
+	now = tcp_jiffies32;
+	info->mptcpi_last_data_sent = jiffies_to_msecs(now - msk->last_data_sent);
+	info->mptcpi_last_data_recv = jiffies_to_msecs(now - msk->last_data_recv);
+	info->mptcpi_last_ack_recv = jiffies_to_msecs(now - msk->last_ack_recv);
 	unlock_sock_fast(sk, slow);
 }
 EXPORT_SYMBOL_GPL(mptcp_diag_fill_info);
Signature · 1 line
2.40.1
maintainer
#4 lore raw

Re: [PATCH mptcp-next 2/3] mptcp: add last time fields in mptcp_info

Quoted 20 lines · Geliang Tang

From: Geliang Tang <[email protected]>

Similar to tcpi_last_data_sent, tcpi_last_data_recv and tcpi_last_ack_recv exposed with TCP, this patch exposes the last time "an action happened" for MPTCP in mptcp_info, named mptcpi_last_data_sent, mptcpi_last_data_recv and mptcpi_last_ack_recv, calculated In mptcp_diag_fill_info() as the time deltas between now and the newly added last time fields in mptcp_sock.

---
include/uapi/linux/mptcp.h | 3 +++
net/mptcp/sockopt.c | 5 +++++

2 files changed, 8 insertions(+)
include/uapi/linux/mptcp.h +0 -0
index 74cfe496891e..7126563542b3 100644

include/uapi/linux/mptcp.h struct mptcp_info { · line 60

Quoted 3 lines
include/uapi/linux/mptcp.h +0 -0
@@ -58,6 +58,9 @@ struct mptcp_info {
 	__u64	mptcpi_bytes_received;
 	__u64	mptcpi_bytes_acked;
 	__u8	mptcpi_subflows_total;

Hi Geliang -

Should add three reserved bytes after mptcpi_subflows_total, otherwise we lose them to alignment. See other uapi header files with "reserved", "reserved2", etc.

- Mat

Quoted 34 lines
include/uapi/linux/mptcp.h +3 -0
+	__u32	mptcpi_last_data_sent;
+	__u32	mptcpi_last_data_recv;
+	__u32	mptcpi_last_ack_recv;
 };
 
 /* MPTCP Reset reason codes, rfc8684 */
net/mptcp/sockopt.c +5 -0
index dcd1c76d2a3b..1e74851614e8 100644
@@ -898,6 +898,7 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
 	struct sock *sk = (struct sock *)msk;
 	u32 flags = 0;
 	bool slow;
+	u32 now;
 
 	memset(info, 0, sizeof(*info));
 
@@ -942,6 +943,10 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
 	info->mptcpi_bytes_retrans = msk->bytes_retrans;
 	info->mptcpi_subflows_total = info->mptcpi_subflows +
 		__mptcp_has_initial_subflow(msk);
+	now = tcp_jiffies32;
+	info->mptcpi_last_data_sent = jiffies_to_msecs(now - msk->last_data_sent);
+	info->mptcpi_last_data_recv = jiffies_to_msecs(now - msk->last_data_recv);
+	info->mptcpi_last_ack_recv = jiffies_to_msecs(now - msk->last_ack_recv);
 	unlock_sock_fast(sk, slow);
 }
 EXPORT_SYMBOL_GPL(mptcp_diag_fill_info);
Signature · 1 line
2.40.1
author reviewer
#5 lore raw

PATCH 3/3 selftests: mptcp: add last time actions tests

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch adds a new helper show_mptcp_info() to show the counters in mptcp_info of the given infos. Use it to show newly added last_data_sent, last_data_recv and last_ack_recv in mptcp_info in endpoint_tests().

---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +21 -0
index 70621cbbab09..6a6caf472d68 100755
@@ -1855,6 +1855,25 @@ chk_subflows_total()
 	fi
 }
 
+show_mptcp_info()
+{
+	local info
+
+	for info in "${@}"; do
+		local cnt1
+		local cnt2
+
+		cnt1=$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value "$info" "$info")
+		cnt2=$(ss -N $ns2 -inmHM | mptcp_lib_get_info_value "$info" "$info")
+		print_check "mptcp_info ${info:0:15}=$cnt1:$cnt2"
+		if [ -z "$cnt1" ] || [ -z "$cnt2" ]; then
+			print_skip
+		else
+			print_ok
+		fi
+	done
+}
+
 chk_link_usage()
 {
 	local ns=$1
@@ -3589,6 +3608,7 @@ endpoint_tests()
 			$ns2 10.0.2.2 id 1 flags implicit
 		chk_mptcp_info subflows 1 subflows 1
 		chk_mptcp_info add_addr_signal 1 add_addr_accepted 1
+		show_mptcp_info last_data_sent last_data_recv last_ack_recv
 
 		pm_nl_add_endpoint $ns2 10.0.2.2 id 33 2>/dev/null
 		pm_nl_check_endpoint "ID change is prevented" \
@@ -3612,6 +3632,7 @@ endpoint_tests()
 		wait_mpj $ns2
 		chk_subflow_nr "before delete" 2
 		chk_mptcp_info subflows 1 subflows 1
+		show_mptcp_info last_data_sent last_data_recv last_ack_recv
 
 		pm_nl_del_endpoint $ns2 2 10.0.2.2
 		sleep 0.5
Signature · 1 line
2.40.1
maintainer
#6 lore raw

Re: [PATCH mptcp-next 3/3] selftests: mptcp: add last time actions tests

tools/testing/selftests/net/mptcp/mptcp_join.sh

Quoted 15 lines · Geliang Tang

From: Geliang Tang <[email protected]>

This patch adds a new helper show_mptcp_info() to show the counters in mptcp_info of the given infos. Use it to show newly added last_data_sent, last_data_recv and last_ack_recv in mptcp_info in endpoint_tests().

---
.../testing/selftests/net/mptcp/mptcp_join.sh | 21 +++++++++++++++++++

1 file changed, 21 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +0 -0
index 70621cbbab09..6a6caf472d68 100755

Hi Geliang -

diag.sh would be a better location for new mptcp_info tests. Could check that the timestamps move forward when data is sent or received, that would verify functionality more than the informational messages below.

Thanks,

Mat

Quoted 47 lines
tools/testing/selftests/net/mptcp/mptcp_join.sh +21 -0
@@ -1855,6 +1855,25 @@ chk_subflows_total()
 	fi
 }
 
+show_mptcp_info()
+{
+	local info
+
+	for info in "${@}"; do
+		local cnt1
+		local cnt2
+
+		cnt1=$(ss -N $ns1 -inmHM | mptcp_lib_get_info_value "$info" "$info")
+		cnt2=$(ss -N $ns2 -inmHM | mptcp_lib_get_info_value "$info" "$info")
+		print_check "mptcp_info ${info:0:15}=$cnt1:$cnt2"
+		if [ -z "$cnt1" ] || [ -z "$cnt2" ]; then
+			print_skip
+		else
+			print_ok
+		fi
+	done
+}
+
 chk_link_usage()
 {
 	local ns=$1
@@ -3589,6 +3608,7 @@ endpoint_tests()
 			$ns2 10.0.2.2 id 1 flags implicit
 		chk_mptcp_info subflows 1 subflows 1
 		chk_mptcp_info add_addr_signal 1 add_addr_accepted 1
+		show_mptcp_info last_data_sent last_data_recv last_ack_recv
 
 		pm_nl_add_endpoint $ns2 10.0.2.2 id 33 2>/dev/null
 		pm_nl_check_endpoint "ID change is prevented" \
@@ -3612,6 +3632,7 @@ endpoint_tests()
 		wait_mpj $ns2
 		chk_subflow_nr "before delete" 2
 		chk_mptcp_info subflows 1 subflows 1
+		show_mptcp_info last_data_sent last_data_recv last_ack_recv
 
 		pm_nl_del_endpoint $ns2 2 10.0.2.2
 		sleep 0.5
Signature · 1 line
2.40.1
#7 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Unstable: 2 failed test(s): packetdrill_sockopts selftest_mptcp_join 🔴
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/8323279037

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/75ec3d556008
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=836000

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)