Skip to contentSkip to conversation

tcp: extend access to CC information

PATCH Applied Eric Dumazet 6 participants 17 messages Apr 28, 2015 – Apr 30, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover tcp: extend access to CC information

Instead of being forced to use netlink, we want to get (optional) CC information using a getsockopt() on the socket file handle.

Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

Eric Dumazet (2):
tcp: prepare CC get_info() access from getsockopt()
tcp: add TCP_CC_INFO socket option

 include/net/tcp.h              |  5 ++++-
 include/uapi/linux/inet_diag.h |  4 ++++
 include/uapi/linux/tcp.h       |  1 +
 net/ipv4/inet_diag.c           |  8 +++++---
 net/ipv4/tcp.c                 | 21 +++++++++++++++++++++
 net/ipv4/tcp_dctcp.c           | 20 ++++++++++----------
 net/ipv4/tcp_illinois.c        | 21 +++++++++++----------
 net/ipv4/tcp_vegas.c           | 19 ++++++++++---------
 net/ipv4/tcp_vegas.h           |  3 ++-
 9 files changed, 68 insertions(+), 34 deletions(-)
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw

PATCH 1/2 tcp: prepare CC get_info() access from getsockopt()

We would like that optional info provided by Congestion Control modules using netlink can also be read using getsockopt()

This patch changes get_info() to put this information in a buffer, instead of skb, like tcp_get_info(), so that following patch can reuse this common infrastructure.

Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>
---
 include/net/tcp.h              |  5 ++++-
 include/uapi/linux/inet_diag.h |  4 ++++
 net/ipv4/inet_diag.c           |  8 +++++---
 net/ipv4/tcp_dctcp.c           | 20 ++++++++++----------
 net/ipv4/tcp_illinois.c        | 21 +++++++++++----------
 net/ipv4/tcp_vegas.c           | 19 ++++++++++---------
 net/ipv4/tcp_vegas.h           |  3 ++-
 7 files changed, 46 insertions(+), 34 deletions(-)
include/net/tcp.h +4 -1
index 051dc5c2802d..d5b3089317fb 100644
@@ -804,6 +804,8 @@ enum tcp_ca_ack_event_flags {
 /* Requires ECN/ECT set on all packets */
 #define TCP_CONG_NEEDS_ECN	0x2
 
+union tcp_cc_info;
+
 struct tcp_congestion_ops {
 	struct list_head	list;
 	u32 key;
@@ -829,7 +831,8 @@ struct tcp_congestion_ops {
 	/* hook for packet ack accounting (optional) */
 	void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us);
 	/* get info for inet_diag (optional) */
-	int (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb);
+	size_t (*get_info)(struct sock *sk, u32 ext, int *attr,
+			   union tcp_cc_info *info);
 
 	char 		name[TCP_CA_NAME_MAX];
 	struct module 	*owner;
include/uapi/linux/inet_diag.h +4 -0
index d65c0a09efd3..c7093c75bdd6 100644
@@ -143,4 +143,8 @@ struct tcp_dctcp_info {
 	__u32	dctcp_ab_tot;
 };
 
+union tcp_cc_info {
+	struct tcpvegas_info	vegas;
+	struct tcp_dctcp_info	dctcp;
+};
 #endif /* _UAPI_INET_DIAG_H_ */
net/ipv4/inet_diag.c +5 -3
index bb77ebdae3b3..4d32262c7502 100644
@@ -224,14 +224,16 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 	handler->idiag_get_info(sk, r, info);
 
 	if (sk->sk_state < TCP_TIME_WAIT) {
-		int err = 0;
+		union tcp_cc_info info;
+		size_t sz = 0;
+		int attr;
 
 		rcu_read_lock();
 		ca_ops = READ_ONCE(icsk->icsk_ca_ops);
 		if (ca_ops && ca_ops->get_info)
-			err = ca_ops->get_info(sk, ext, skb);
+			sz = ca_ops->get_info(sk, ext, &attr, &info);
 		rcu_read_unlock();
-		if (err < 0)
+		if (sz && nla_put(skb, attr, sz, &info) < 0)
 			goto errout;
 	}
 
net/ipv4/tcp_dctcp.c +10 -10
index 4376016f7fa5..4c41c1287197 100644
@@ -277,7 +277,8 @@ static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
 	}
 }
 
-static int dctcp_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
+static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
+			     union tcp_cc_info *info)
 {
 	const struct dctcp *ca = inet_csk_ca(sk);
 
@@ -286,18 +287,17 @@ static int dctcp_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
 	 */
 	if (ext & (1 << (INET_DIAG_DCTCPINFO - 1)) ||
 	    ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
-		struct tcp_dctcp_info info;
-
-		memset(&info, 0, sizeof(info));
+		memset(info, 0, sizeof(struct tcp_dctcp_info));
 		if (inet_csk(sk)->icsk_ca_ops != &dctcp_reno) {
-			info.dctcp_enabled = 1;
-			info.dctcp_ce_state = (u16) ca->ce_state;
-			info.dctcp_alpha = ca->dctcp_alpha;
-			info.dctcp_ab_ecn = ca->acked_bytes_ecn;
-			info.dctcp_ab_tot = ca->acked_bytes_total;
+			info->dctcp.dctcp_enabled = 1;
+			info->dctcp.dctcp_ce_state = (u16) ca->ce_state;
+			info->dctcp.dctcp_alpha = ca->dctcp_alpha;
+			info->dctcp.dctcp_ab_ecn = ca->acked_bytes_ecn;
+			info->dctcp.dctcp_ab_tot = ca->acked_bytes_total;
 		}
 
-		return nla_put(skb, INET_DIAG_DCTCPINFO, sizeof(info), &info);
+		*attr = INET_DIAG_DCTCPINFO;
+		return sizeof(*info);
 	}
 	return 0;
 }
net/ipv4/tcp_illinois.c +11 -10
index 67476f085e48..f71002e4db0b 100644
@@ -300,24 +300,25 @@ static u32 tcp_illinois_ssthresh(struct sock *sk)
 }
 
 /* Extract info for Tcp socket info provided via netlink. */
-static int tcp_illinois_info(struct sock *sk, u32 ext, struct sk_buff *skb)
+static size_t tcp_illinois_info(struct sock *sk, u32 ext, int *attr,
+				union tcp_cc_info *info)
 {
 	const struct illinois *ca = inet_csk_ca(sk);
 
 	if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
-		struct tcpvegas_info info = {
-			.tcpv_enabled = 1,
-			.tcpv_rttcnt = ca->cnt_rtt,
-			.tcpv_minrtt = ca->base_rtt,
-		};
+		info->vegas.tcpv_enabled = 1;
+		info->vegas.tcpv_rttcnt = ca->cnt_rtt;
+		info->vegas.tcpv_minrtt = ca->base_rtt;
+		info->vegas.tcpv_rtt = 0;
 
-		if (info.tcpv_rttcnt > 0) {
+		if (info->vegas.tcpv_rttcnt > 0) {
 			u64 t = ca->sum_rtt;
 
-			do_div(t, info.tcpv_rttcnt);
-			info.tcpv_rtt = t;
+			do_div(t, info->vegas.tcpv_rttcnt);
+			info->vegas.tcpv_rtt = t;
 		}
-		return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
+		*attr = INET_DIAG_VEGASINFO;
+		return sizeof(struct tcpvegas_info);
 	}
 	return 0;
 }
net/ipv4/tcp_vegas.c +10 -9
index c71a1b8f7bde..a6cea1d5e20d 100644
@@ -286,18 +286,19 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 acked)
 }
 
 /* Extract info for Tcp socket info provided via netlink. */
-int tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
+size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
+			  union tcp_cc_info *info)
 {
 	const struct vegas *ca = inet_csk_ca(sk);
+
 	if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
-		struct tcpvegas_info info = {
-			.tcpv_enabled = ca->doing_vegas_now,
-			.tcpv_rttcnt = ca->cntRTT,
-			.tcpv_rtt = ca->baseRTT,
-			.tcpv_minrtt = ca->minRTT,
-		};
-
-		return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
+		info->vegas.tcpv_enabled = ca->doing_vegas_now,
+		info->vegas.tcpv_rttcnt = ca->cntRTT,
+		info->vegas.tcpv_rtt = ca->baseRTT,
+		info->vegas.tcpv_minrtt = ca->minRTT,
+
+		*attr = INET_DIAG_VEGASINFO;
+		return sizeof(struct tcpvegas_info);
 	}
 	return 0;
 }
net/ipv4/tcp_vegas.h +2 -1
index e8a6b33cc61d..ef9da5306c68 100644
@@ -19,6 +19,7 @@ void tcp_vegas_init(struct sock *sk);
 void tcp_vegas_state(struct sock *sk, u8 ca_state);
 void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us);
 void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event);
-int tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb);
+size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
+			  union tcp_cc_info *info);
 
 #endif	/* __TCP_VEGAS_H */
Signature · 1 line
2.2.0.rc0.207.ga3a616c
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH net-next 1/2] tcp: prepare CC get_info() access from getsockopt()

Quoted 11 lines · Eric Dumazet

We would like that optional info provided by Congestion Control modules using netlink can also be read using getsockopt()

This patch changes get_info() to put this information in a buffer, instead of skb, like tcp_get_info(), so that following patch can reuse this common infrastructure.

Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

---

Thanks, Eric!

neal

Acked-by on v1 1/2
#3 lore raw

Re: [PATCH net-next 1/2] tcp: prepare CC get_info() access from getsockopt()

In reply to Eric Dumazet
Quoted 10 lines · Eric Dumazet

We would like that optional info provided by Congestion Control modules using netlink can also be read using getsockopt()

This patch changes get_info() to put this information in a buffer, instead of skb, like tcp_get_info(), so that following patch can reuse this common infrastructure.

Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

Looks good to me, thanks!

Acked-by on v1 1/2
#4 lore raw

Re: [PATCH net-next 1/2] tcp: prepare CC get_info() access from getsockopt()

In reply to Eric Dumazet
Quoted 10 lines · Eric Dumazet

We would like that optional info provided by Congestion Control modules using netlink can also be read using getsockopt()

This patch changes get_info() to put this information in a buffer, instead of skb, like tcp_get_info(), so that following patch can reuse this common infrastructure.

Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>
Quoted 200 lines
---
 include/net/tcp.h              |  5 ++++-
 include/uapi/linux/inet_diag.h |  4 ++++
 net/ipv4/inet_diag.c           |  8 +++++---
 net/ipv4/tcp_dctcp.c           | 20 ++++++++++----------
 net/ipv4/tcp_illinois.c        | 21 +++++++++++----------
 net/ipv4/tcp_vegas.c           | 19 ++++++++++---------
 net/ipv4/tcp_vegas.h           |  3 ++-
 7 files changed, 46 insertions(+), 34 deletions(-)
include/net/tcp.h +4 -1
index 051dc5c2802d..d5b3089317fb 100644
@@ -804,6 +804,8 @@ enum tcp_ca_ack_event_flags {
 /* Requires ECN/ECT set on all packets */
 #define TCP_CONG_NEEDS_ECN     0x2
 
+union tcp_cc_info;
+
 struct tcp_congestion_ops {
        struct list_head        list;
        u32 key;
@@ -829,7 +831,8 @@ struct tcp_congestion_ops {
        /* hook for packet ack accounting (optional) */
        void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us);
        /* get info for inet_diag (optional) */
-       int (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb);
+       size_t (*get_info)(struct sock *sk, u32 ext, int *attr,
+                          union tcp_cc_info *info);
 
        char            name[TCP_CA_NAME_MAX];
        struct module   *owner;
include/uapi/linux/inet_diag.h +4 -0
index d65c0a09efd3..c7093c75bdd6 100644
@@ -143,4 +143,8 @@ struct tcp_dctcp_info {
        __u32   dctcp_ab_tot;
 };
 
+union tcp_cc_info {
+       struct tcpvegas_info    vegas;
+       struct tcp_dctcp_info   dctcp;
+};
 #endif /* _UAPI_INET_DIAG_H_ */
net/ipv4/inet_diag.c +5 -3
index bb77ebdae3b3..4d32262c7502 100644
@@ -224,14 +224,16 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
        handler->idiag_get_info(sk, r, info);
 
        if (sk->sk_state < TCP_TIME_WAIT) {
-               int err = 0;
+               union tcp_cc_info info;
+               size_t sz = 0;
+               int attr;
 
                rcu_read_lock();
                ca_ops = READ_ONCE(icsk->icsk_ca_ops);
                if (ca_ops && ca_ops->get_info)
-                       err = ca_ops->get_info(sk, ext, skb);
+                       sz = ca_ops->get_info(sk, ext, &attr, &info);
                rcu_read_unlock();
-               if (err < 0)
+               if (sz && nla_put(skb, attr, sz, &info) < 0)
                        goto errout;
        }
 
net/ipv4/tcp_dctcp.c +10 -10
index 4376016f7fa5..4c41c1287197 100644
@@ -277,7 +277,8 @@ static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
        }
 }
 
-static int dctcp_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
+static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
+                            union tcp_cc_info *info)
 {
        const struct dctcp *ca = inet_csk_ca(sk);
 
@@ -286,18 +287,17 @@ static int dctcp_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
         */
        if (ext & (1 << (INET_DIAG_DCTCPINFO - 1)) ||
            ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
-               struct tcp_dctcp_info info;
-
-               memset(&info, 0, sizeof(info));
+               memset(info, 0, sizeof(struct tcp_dctcp_info));
                if (inet_csk(sk)->icsk_ca_ops != &dctcp_reno) {
-                       info.dctcp_enabled = 1;
-                       info.dctcp_ce_state = (u16) ca->ce_state;
-                       info.dctcp_alpha = ca->dctcp_alpha;
-                       info.dctcp_ab_ecn = ca->acked_bytes_ecn;
-                       info.dctcp_ab_tot = ca->acked_bytes_total;
+                       info->dctcp.dctcp_enabled = 1;
+                       info->dctcp.dctcp_ce_state = (u16) ca->ce_state;
+                       info->dctcp.dctcp_alpha = ca->dctcp_alpha;
+                       info->dctcp.dctcp_ab_ecn = ca->acked_bytes_ecn;
+                       info->dctcp.dctcp_ab_tot = ca->acked_bytes_total;
                }
 
-               return nla_put(skb, INET_DIAG_DCTCPINFO, sizeof(info), &info);
+               *attr = INET_DIAG_DCTCPINFO;
+               return sizeof(*info);
        }
        return 0;
 }
net/ipv4/tcp_illinois.c +11 -10
index 67476f085e48..f71002e4db0b 100644
@@ -300,24 +300,25 @@ static u32 tcp_illinois_ssthresh(struct sock *sk)
 }
 
 /* Extract info for Tcp socket info provided via netlink. */
-static int tcp_illinois_info(struct sock *sk, u32 ext, struct sk_buff *skb)
+static size_t tcp_illinois_info(struct sock *sk, u32 ext, int *attr,
+                               union tcp_cc_info *info)
 {
        const struct illinois *ca = inet_csk_ca(sk);
 
        if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
-               struct tcpvegas_info info = {
-                       .tcpv_enabled = 1,
-                       .tcpv_rttcnt = ca->cnt_rtt,
-                       .tcpv_minrtt = ca->base_rtt,
-               };
+               info->vegas.tcpv_enabled = 1;
+               info->vegas.tcpv_rttcnt = ca->cnt_rtt;
+               info->vegas.tcpv_minrtt = ca->base_rtt;
+               info->vegas.tcpv_rtt = 0;
 
-               if (info.tcpv_rttcnt > 0) {
+               if (info->vegas.tcpv_rttcnt > 0) {
                        u64 t = ca->sum_rtt;
 
-                       do_div(t, info.tcpv_rttcnt);
-                       info.tcpv_rtt = t;
+                       do_div(t, info->vegas.tcpv_rttcnt);
+                       info->vegas.tcpv_rtt = t;
                }
-               return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
+               *attr = INET_DIAG_VEGASINFO;
+               return sizeof(struct tcpvegas_info);
        }
        return 0;
 }
net/ipv4/tcp_vegas.c +10 -9
index c71a1b8f7bde..a6cea1d5e20d 100644
@@ -286,18 +286,19 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 acked)
 }
 
 /* Extract info for Tcp socket info provided via netlink. */
-int tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb)
+size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
+                         union tcp_cc_info *info)
 {
        const struct vegas *ca = inet_csk_ca(sk);
+
        if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
-               struct tcpvegas_info info = {
-                       .tcpv_enabled = ca->doing_vegas_now,
-                       .tcpv_rttcnt = ca->cntRTT,
-                       .tcpv_rtt = ca->baseRTT,
-                       .tcpv_minrtt = ca->minRTT,
-               };
-
-               return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
+               info->vegas.tcpv_enabled = ca->doing_vegas_now,
+               info->vegas.tcpv_rttcnt = ca->cntRTT,
+               info->vegas.tcpv_rtt = ca->baseRTT,
+               info->vegas.tcpv_minrtt = ca->minRTT,
+
+               *attr = INET_DIAG_VEGASINFO;
+               return sizeof(struct tcpvegas_info);
        }
        return 0;
 }
net/ipv4/tcp_vegas.h +2 -2
index e8a6b33cc61d..ef9da5306c68 100644
@@ -19,6 +19,7 @@ void tcp_vegas_init(struct sock *sk);
 void tcp_vegas_state(struct sock *sk, u8 ca_state);
 void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us);
 void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event);
-int tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb);
+size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
+                         union tcp_cc_info *info);
 
 #endif /* __TCP_VEGAS_H */
--

2.2.0.rc0.207.ga3a616c

maintainer Applied
#5 lore raw

Re: [PATCH net-next 1/2] tcp: prepare CC get_info() access from getsockopt()

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Tue, 28 Apr 2015 16:23:48 -0700

Quoted 8 lines

We would like that optional info provided by Congestion Control modules using netlink can also be read using getsockopt()

This patch changes get_info() to put this information in a buffer, instead of skb, like tcp_get_info(), so that following patch can reuse this common infrastructure.

Applied.

#6 lore raw

Re: [PATCH net-next 1/2] tcp: prepare CC get_info() access from getsockopt()

Quoted 6 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Tue, 28 Apr 2015 16:23:48 -0700

Quoted 3 lines

We would like that optional info provided by Congestion Control modules using netlink can also be read using getsockopt()

Quoted 7 lines
Quoted 5 lines

This patch changes get_info() to put this information in a buffer, instead of skb, like tcp_get_info(), so that following patch can reuse this common infrastructure.

Applied.

Thanks David, I'll send an update to tcp_westwood, kbuild test robot gave me a notice.

#7 lore raw

PATCH 1/1 tcp_westwood: fix tcp_westwood_info()

From: Eric Dumazet <[email protected]>

I forgot to update tcp_westwood when changing get_info() behavior, this patch should fix this.

Fixes 64f40ff5bbdb ("tcp: prepare CC get_info() access from getsockopt()")
---
 net/ipv4/tcp_westwood.c |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
net/ipv4/tcp_westwood.c +8 -7
index b3c57cceb9907fe9d79f33f33369a96b647b5f26..c10732e39837872c724b801700f627a7fb1c9390 100644
@@ -256,18 +256,19 @@ static void tcp_westwood_event(struct sock *sk, enum tcp_ca_event event)
 }
 
 /* Extract info for Tcp socket info provided via netlink. */
-static int tcp_westwood_info(struct sock *sk, u32 ext, struct sk_buff *skb)
+static size_t tcp_westwood_info(struct sock *sk, u32 ext, int *attr,
+				union tcp_cc_info *info)
 {
 	const struct westwood *ca = inet_csk_ca(sk);
 
 	if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
-		struct tcpvegas_info info = {
-			.tcpv_enabled = 1,
-			.tcpv_rtt = jiffies_to_usecs(ca->rtt),
-			.tcpv_minrtt = jiffies_to_usecs(ca->rtt_min),
-		};
+		info->vegas.tcpv_enabled = 1;
+		info->vegas.tcpv_rttcnt	= 0;
+		info->vegas.tcpv_rtt	= jiffies_to_usecs(ca->rtt),
+		info->vegas.tcpv_minrtt	= jiffies_to_usecs(ca->rtt_min),
 
-		return nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
+		*attr = INET_DIAG_VEGASINFO;
+		return sizeof(struct tcpvegas_info);
 	}
 	return 0;
 }
maintainer Acked-by on v1 1/1
#8 lore raw

Re: [PATCH net-next] tcp_westwood: fix tcp_westwood_info()

Quoted 8 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

I forgot to update tcp_westwood when changing get_info() behavior, this patch should fix this.

Fixes 64f40ff5bbdb ("tcp: prepare CC get_info() access from getsockopt()")

neal

maintainer Applied
#9 lore raw

Re: [PATCH net-next] tcp_westwood: fix tcp_westwood_info()

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Wed, 29 Apr 2015 16:20:58 -0700

Quoted 8 lines

From: Eric Dumazet <[email protected]>

I forgot to update tcp_westwood when changing get_info() behavior, this patch should fix this.

Fixes 64f40ff5bbdb ("tcp: prepare CC get_info() access from getsockopt()")

Applied, thanks Eric.

#10 lore raw

PATCH 2/2 tcp: add TCP_CC_INFO socket option

In reply to Eric Dumazet

Some Congestion Control modules can provide per flow information, but current way to get this information is to use netlink.

Like TCP_INFO, let's add TCP_CC_INFO so that applications can issue a getsockopt() if they have a socket file descriptor, instead of playing complex netlink games.

Sample usage would be :

  union tcp_cc_info info;
  socklen_t len = sizeof(info);

if (getsockopt(fd, SOL_TCP, TCP_CC_INFO, &info, &len) == -1)

Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>
---
 include/uapi/linux/tcp.h |  1 +
 net/ipv4/tcp.c           | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
include/uapi/linux/tcp.h +1 -0
index 3b9718328d8b..937ec387276f 100644
@@ -112,6 +112,7 @@ enum {
 #define TCP_FASTOPEN		23	/* Enable FastOpen on listeners */
 #define TCP_TIMESTAMP		24
 #define TCP_NOTSENT_LOWAT	25	/* limit number of unsent bytes in write queue */
+#define TCP_CC_INFO		26	/* Get Congestion Control (optional) info */
 
 struct tcp_repair_opt {
 	__u32	opt_code;
net/ipv4/tcp.c +21 -0
index 8c5cd9efebbc..1e06c75a6837 100644
@@ -252,6 +252,7 @@
 #include <linux/types.h>
 #include <linux/fcntl.h>
 #include <linux/poll.h>
+#include <linux/inet_diag.h>
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/skbuff.h>
@@ -2734,6 +2735,26 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
 			return -EFAULT;
 		return 0;
 	}
+	case TCP_CC_INFO: {
+		const struct tcp_congestion_ops *ca_ops;
+		union tcp_cc_info info;
+		size_t sz = 0;
+		int attr;
+
+		if (get_user(len, optlen))
+			return -EFAULT;
+
+		ca_ops = icsk->icsk_ca_ops;
+		if (ca_ops && ca_ops->get_info)
+			sz = ca_ops->get_info(sk, ~0U, &attr, &info);
+
+		len = min_t(unsigned int, len, sz);
+		if (put_user(len, optlen))
+			return -EFAULT;
+		if (copy_to_user(optval, &info, len))
+			return -EFAULT;
+		return 0;
+	}
 	case TCP_QUICKACK:
 		val = !icsk->icsk_ack.pingpong;
 		break;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
maintainer Acked-by on v1 2/2
#11 lore raw

Re: [PATCH net-next 2/2] tcp: add TCP_CC_INFO socket option

Quoted 12 lines · Eric Dumazet

Some Congestion Control modules can provide per flow information, but current way to get this information is to use netlink.

Like TCP_INFO, let's add TCP_CC_INFO so that applications can issue a getsockopt() if they have a socket file descriptor, instead of playing complex netlink games.

Sample usage would be :

  union tcp_cc_info info;
  socklen_t len = sizeof(info);
Quoted 6 lines

if (getsockopt(fd, SOL_TCP, TCP_CC_INFO, &info, &len) == -1)

Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

---

A very useful facility. Thanks for putting this together, Eric!

neal

Acked-by on v1 2/2
#12 lore raw

Re: [PATCH net-next 2/2] tcp: add TCP_CC_INFO socket option

In reply to Eric Dumazet
Quoted 9 lines · Eric Dumazet

Some Congestion Control modules can provide per flow information, but current way to get this information is to use netlink.

Like TCP_INFO, let's add TCP_CC_INFO so that applications can issue a getsockopt() if they have a socket file descriptor, instead of playing complex netlink games.

Sample usage would be :

Quoted 8 lines
   union tcp_cc_info info;
   socklen_t len = sizeof(info);
   if (getsockopt(fd, SOL_TCP, TCP_CC_INFO, &info, &len) == -1)
Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

Presuming other cc algorithms would in future also export internal information through this interface, would it make sense to put tcp_cc_info into a container structure so we don't miss out attr (vegas, dctcp, ...), like:

  struct tcp_cc_exp {
    u32               kind;
    union tcp_cc_info info;
  };

Otherwise looks good:

#13 lore raw

Re: [PATCH net-next 2/2] tcp: add TCP_CC_INFO socket option

Quoted 24 lines · Daniel Borkmann
Quoted 9 lines · Eric Dumazet

Some Congestion Control modules can provide per flow information, but current way to get this information is to use netlink.

Like TCP_INFO, let's add TCP_CC_INFO so that applications can issue a getsockopt() if they have a socket file descriptor, instead of playing complex netlink games.

Sample usage would be :

Quoted 8 lines
   union tcp_cc_info info;
   socklen_t len = sizeof(info);
   if (getsockopt(fd, SOL_TCP, TCP_CC_INFO, &info, &len) == -1)
Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

Presuming other cc algorithms would in future also export internal information through this interface, would it make sense to put tcp_cc_info into a container structure so we don't miss out attr (vegas, dctcp, ...), like:

Quoted 8 lines
   struct tcp_cc_exp {
     u32               kind;
     union tcp_cc_info info;
   };

Otherwise looks good:

I thought of this, but I really believe this is not needed, as the application can already fetch CC name (if really its does not know yet)

And I also wanted to get same layout for info provided by netlink and getsockopt()

Thanks !

#14 lore raw

Re: [PATCH net-next 2/2] tcp: add TCP_CC_INFO socket option

Quoted 32 lines · Eric Dumazet
Quoted 31 lines · Daniel Borkmann
Quoted 9 lines · Eric Dumazet

Some Congestion Control modules can provide per flow information, but current way to get this information is to use netlink.

Like TCP_INFO, let's add TCP_CC_INFO so that applications can issue a getsockopt() if they have a socket file descriptor, instead of playing complex netlink games.

Sample usage would be :

Quoted 8 lines
    union tcp_cc_info info;
    socklen_t len = sizeof(info);

    if (getsockopt(fd, SOL_TCP, TCP_CC_INFO, &info, &len) == -1)
Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

Presuming other cc algorithms would in future also export internal information through this interface, would it make sense to put tcp_cc_info into a container structure so we don't miss out attr (vegas, dctcp, ...), like:

    struct tcp_cc_exp {
      u32               kind;
      union tcp_cc_info info;
    };

Otherwise looks good:

Quoted 7 lines
Quoted 1 line

I thought of this, but I really believe this is not needed, as the application can already fetch CC name (if really its does not know yet)

And I also wanted to get same layout for info provided by netlink and getsockopt()

Ok, I'm fine with that. Presumably, applications making use of this facility would most likely set the cc op themselves from the application, so they know exactly what to expect here. Or, might have fetched it via the cc name albeit a bit inconvenient, but not impossible.

Thanks,
Daniel

Acked-by on v1 2/2
#15 lore raw

Re: [PATCH net-next 2/2] tcp: add TCP_CC_INFO socket option

In reply to Eric Dumazet
Quoted 9 lines · Eric Dumazet

Some Congestion Control modules can provide per flow information, but current way to get this information is to use netlink.

Like TCP_INFO, let's add TCP_CC_INFO so that applications can issue a getsockopt() if they have a socket file descriptor, instead of playing complex netlink games.

Sample usage would be :

Quoted 8 lines
  union tcp_cc_info info;
  socklen_t len = sizeof(info);

if (getsockopt(fd, SOL_TCP, TCP_CC_INFO, &info, &len) == -1)

Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

Nice extension!

Quoted 59 lines
---
 include/uapi/linux/tcp.h |  1 +
 net/ipv4/tcp.c           | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
include/uapi/linux/tcp.h +1 -0
index 3b9718328d8b..937ec387276f 100644
@@ -112,6 +112,7 @@ enum {
 #define TCP_FASTOPEN           23      /* Enable FastOpen on listeners */
 #define TCP_TIMESTAMP          24
 #define TCP_NOTSENT_LOWAT      25      /* limit number of unsent bytes in write queue */
+#define TCP_CC_INFO            26      /* Get Congestion Control (optional) info */
 
 struct tcp_repair_opt {
        __u32   opt_code;
net/ipv4/tcp.c +21 -1
index 8c5cd9efebbc..1e06c75a6837 100644
@@ -252,6 +252,7 @@
 #include <linux/types.h>
 #include <linux/fcntl.h>
 #include <linux/poll.h>
+#include <linux/inet_diag.h>
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/skbuff.h>
@@ -2734,6 +2735,26 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
                        return -EFAULT;
                return 0;
        }
+       case TCP_CC_INFO: {
+               const struct tcp_congestion_ops *ca_ops;
+               union tcp_cc_info info;
+               size_t sz = 0;
+               int attr;
+
+               if (get_user(len, optlen))
+                       return -EFAULT;
+
+               ca_ops = icsk->icsk_ca_ops;
+               if (ca_ops && ca_ops->get_info)
+                       sz = ca_ops->get_info(sk, ~0U, &attr, &info);
+
+               len = min_t(unsigned int, len, sz);
+               if (put_user(len, optlen))
+                       return -EFAULT;
+               if (copy_to_user(optval, &info, len))
+                       return -EFAULT;
+               return 0;
+       }
        case TCP_QUICKACK:
                val = !icsk->icsk_ack.pingpong;
                break;
--

2.2.0.rc0.207.ga3a616c

maintainer Applied
#16 lore raw

Re: [PATCH net-next 2/2] tcp: add TCP_CC_INFO socket option

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Tue, 28 Apr 2015 16:23:49 -0700

Quoted 7 lines

Some Congestion Control modules can provide per flow information, but current way to get this information is to use netlink.

Like TCP_INFO, let's add TCP_CC_INFO so that applications can issue a getsockopt() if they have a socket file descriptor, instead of playing complex netlink games.

Quoted 8 lines

Sample usage would be :

  union tcp_cc_info info;
  socklen_t len = sizeof(info);

if (getsockopt(fd, SOL_TCP, TCP_CC_INFO, &info, &len) == -1)

Applied.