Skip to contentSkip to conversation

Interface for TCP Metrics

PATCH Superseded Julian Anastasov 3 participants 7 messages Sep 2, 2012 – Sep 4, 2012

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Interface for TCP Metrics

This patchset contains 2 patches, one for kernel
and one for iproute2. We add DUMP/GET/DEL support for genl "tcp_metrics" and minimal support for filtering by address prefix and family in user space.

I tested show/del/flush, filtering by family, IPv4 prefix,
output for metrics such as rtt, rttvar, cwnd, ssthresh (after modifying route). I didn't tested output for fast open.

May be some corrections in output can be desired.

The kernel patch has some parts to check:

- in tcp_metrics_nl_cmd_del I'm trying to flush all addresses with single request, eg. when no family, address or other selectors are provided. I use some arbitrary counter sync_count to force memory to be freed in parts by using synchronize_rcu, note that we are under genl_mutex, so may be this is bad idea to delay other genl users? My idea was to avoid many commands on "flush all", may be we should trigger flush by using some other mechanism that is pernet? And I don't know how to test it properly without large cache.

- I enabled lockdep in config and don't see any warnings. make C=2 net/ipv4/tcp_metrics.o is silent too.

v2:
- patch 1: remove rcu_assign_pointer, add tcp_metrics_flush_all
- patch 2: properly flush by specifying address, improve man page

#1 lore raw

PATCH v2 1/2 tcp: add generic netlink support for tcp_metrics

Add support for genl "tcp_metrics". No locking
is changed, only that now we can unlink and delete entries after grace period. We implement get/del for single entry and dump to support show/flush filtering in user space. Del without address attribute causes flush for all addresses, sadly under genl_mutex.

v2:
- remove rcu_assign_pointer as suggested by Eric Dumazet, it is not needed because there are no other writes under lock
- move the flushing code in tcp_metrics_flush_all

---
 include/linux/Kbuild        |    1 +
 include/linux/tcp_metrics.h |   54 +++++++
 net/ipv4/tcp_metrics.c      |  357 +++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 399 insertions(+), 13 deletions(-)
 create mode 100644 include/linux/tcp_metrics.h
include/linux/Kbuild +1 -0
index 1f2c1c7..90da0af 100644
@@ -363,6 +363,7 @@ header-y += sysctl.h
 header-y += sysinfo.h
 header-y += taskstats.h
 header-y += tcp.h
+header-y += tcp_metrics.h
 header-y += telephony.h
 header-y += termios.h
 header-y += time.h
include/linux/tcp_metrics.h new file +54 -0

54 lines not on this page · raw message

net/ipv4/tcp_metrics.c +344 -13

389 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#2 lore raw

Re: [PATCH v2 1/2] tcp: add generic netlink support for tcp_metrics

Quoted 17 lines · Julian Anastasov
net/ipv4/tcp_metrics.c +17 -0
+
+static int tcp_metrics_flush_all(struct net *net)
+{
+	unsigned int max_rows = 1U << net->ipv4.tcp_metrics_hash_log;
+	struct tcpm_hash_bucket *hb = net->ipv4.tcp_metrics_hash;
+	struct tcp_metrics_block *tm;
+	unsigned int sync_count = 0;
+	unsigned int row;
+
+	for (row = 0; row < max_rows; row++, hb++) {
+		spin_lock_bh(&tcp_metrics_lock);
+		tm = deref_locked_genl(hb->chain);
+		if (tm)
+			hb->chain = NULL;
+		spin_unlock_bh(&tcp_metrics_lock);
+		while (tm) {
+			struct tcp_metrics_block *next;

net/ipv4/tcp_metrics.c void tcp_fastopen_cache_set(struct sock *sk, u16 mss, · line 956

Quoted 10 lines
net/ipv4/tcp_metrics.c +10 -0
+
+			next = deref_genl(tm->tcpm_next);
+			kfree_rcu(tm, rcu_head);
+			if (!((++sync_count) & 2047))
+				synchronize_rcu();
+			tm = next;
+		}
+	}
+	return 0;
+}

It looks like the synchronize_rcu() call is not exactly what you wanted, but then net/ipv4/fib_trie.c has the same mistake.

What we want here is to force pending call_rcu() calls to complete, so that we dont consume too much memory. So it would probably better to call rcu_barrier() instead.

If other cpus are idle or outside of rcu read lock sections, synchronize_rcu() should basically do nothing at all.

But I am not sure its worth the trouble ?

Commit c3059477fce2d956a0bb3e04357324780c5d8eeb (ipv4: Use synchronize_rcu() during trie_rebalance()) was needed because FIB TRIE can really use huge amounts of memory, thats hardly the case with tcp_metrics.

#3 lore raw

Re: [PATCH v2 1/2] tcp: add generic netlink support for tcp_metrics

Hello,

Quoted 23 lines · Eric Dumazet
Quoted 22 lines · Julian Anastasov
net/ipv4/tcp_metrics.c +22 -0
+
+static int tcp_metrics_flush_all(struct net *net)
+{
+	unsigned int max_rows = 1U << net->ipv4.tcp_metrics_hash_log;
+	struct tcpm_hash_bucket *hb = net->ipv4.tcp_metrics_hash;
+	struct tcp_metrics_block *tm;
+	unsigned int sync_count = 0;
+	unsigned int row;
+
+	for (row = 0; row < max_rows; row++, hb++) {
+		spin_lock_bh(&tcp_metrics_lock);
+		tm = deref_locked_genl(hb->chain);
+		if (tm)
+			hb->chain = NULL;
+		spin_unlock_bh(&tcp_metrics_lock);
+		while (tm) {
+			struct tcp_metrics_block *next;
+
+			next = deref_genl(tm->tcpm_next);
+			kfree_rcu(tm, rcu_head);
+			if (!((++sync_count) & 2047))
+				synchronize_rcu();
Quoted 8 lines

net/ipv4/tcp_metrics.c void tcp_fastopen_cache_set(struct sock *sk, u16 mss, · line 956

Quoted 5 lines
net/ipv4/tcp_metrics.c +5 -0
+			tm = next;
+		}
+	}
+	return 0;
+}

It looks like the synchronize_rcu() call is not exactly what you wanted, but then net/ipv4/fib_trie.c has the same mistake.

I used fib_trie as reference...

Quoted 3 lines

What we want here is to force pending call_rcu() calls to complete, so that we dont consume too much memory. So it would probably better to call rcu_barrier() instead.

I see

Quoted 9 lines

If other cpus are idle or outside of rcu read lock sections, synchronize_rcu() should basically do nothing at all.

But I am not sure its worth the trouble ?

Commit c3059477fce2d956a0bb3e04357324780c5d8eeb (ipv4: Use synchronize_rcu() during trie_rebalance()) was needed because FIB TRIE can really use huge amounts of memory, thats hardly the case with tcp_metrics.

I was worrying for the case
(TCP_METRICS_RECLAIM_DEPTH + 1) * tcpmhash_entries to be large, eg. if some non-default value is configured. May be the chance table to be filled immediately is small. I'll remove it.

BTW, is it appropriate to use kmem_cache for
metrics and as result call_rcu for freeing?

Regards

--
Julian Anastasov <[email protected]>

maintainer
#4 lore raw

Re: [PATCH v2 1/2] tcp: add generic netlink support for tcp_metrics

From: Julian Anastasov <[email protected]>
Date: Mon, 3 Sep 2012 11:22:15 +0300 (EEST)

Quoted 2 lines

BTW, is it appropriate to use kmem_cache for
metrics and as result call_rcu for freeing?

I think it would work as things are implemented currently in slab/slub/slob, however I would not rely upon it.

If you do move to a SLAB cache for the tcp metrics objects, you might consider SLAB_DESTROY_BY_RCU. It's a very delicate facility (read the huge comment in linux/slab.h) but I think it provides the semantics we need for TCP metrics blobs.

Looking forward to v3 :-)

#5 lore raw

Re: [PATCH v2 1/2] tcp: add generic netlink support for tcp_metrics

Hello,

Quoted 6 lines · David Miller

From: Julian Anastasov <[email protected]>
Date: Mon, 3 Sep 2012 11:22:15 +0300 (EEST)

Quoted 2 lines

BTW, is it appropriate to use kmem_cache for
metrics and as result call_rcu for freeing?

Quoted 7 lines

I think it would work as things are implemented currently in slab/slub/slob, however I would not rely upon it.

If you do move to a SLAB cache for the tcp metrics objects, you might consider SLAB_DESTROY_BY_RCU. It's a very delicate facility (read the huge comment in linux/slab.h) but I think it provides the semantics we need for TCP metrics blobs.

ok, I'll not mix it with the genl support
because I'm not prepared to do it soon...

Quoted 1 line

Looking forward to v3 :-)

	Sending...

Regards

--
Julian Anastasov <[email protected]>

#6 lore raw

PATCH v2 2/2 iproute2: add support for tcp_metrics

In reply to Julian Anastasov

ip tcp_metrics/tcpmetrics

v2:
- On flush we should provide the address in req2
- "flush all" should use single del, just like when "all" is not provided
- Explain printed information in man page

---

include/linux/tcp_metrics.h +54 -0
diff -urpN iproute2-3.5.1/include/linux/tcp_metrics.h iproute2-3.5.1-tcp_metrics/include/linux/tcp_metrics.h
@@ -0,0 +1,54 @@
+/* tcp_metrics.h - TCP Metrics Interface */
+
+#ifndef _LINUX_TCP_METRICS_H
+#define _LINUX_TCP_METRICS_H
+
+#include <linux/types.h>
+
+/* NETLINK_GENERIC related info
+ */
+#define TCP_METRICS_GENL_NAME		"tcp_metrics"
+#define TCP_METRICS_GENL_VERSION	0x1
+
+enum tcp_metric_index {
+	TCP_METRIC_RTT,
+	TCP_METRIC_RTTVAR,
+	TCP_METRIC_SSTHRESH,
+	TCP_METRIC_CWND,
+	TCP_METRIC_REORDERING,
+
+	/* Always last.  */
+	__TCP_METRIC_MAX,
+};
+
+#define TCP_METRIC_MAX	(__TCP_METRIC_MAX - 1)
+
+enum {
+	TCP_METRICS_ATTR_UNSPEC,
+	TCP_METRICS_ATTR_ADDR_IPV4,		/* u32 */
+	TCP_METRICS_ATTR_ADDR_IPV6,		/* binary */
+	TCP_METRICS_ATTR_AGE,			/* msecs */
+	TCP_METRICS_ATTR_TW_TSVAL,		/* u32, raw, rcv tsval */
+	TCP_METRICS_ATTR_TW_TS_STAMP,		/* s32, sec age */
+	TCP_METRICS_ATTR_VALS,			/* nested +1, u32 */
+	TCP_METRICS_ATTR_FOPEN_MSS,		/* u16 */
+	TCP_METRICS_ATTR_FOPEN_SYN_DROPS,	/* u16, count of drops */
+	TCP_METRICS_ATTR_FOPEN_SYN_DROP_TS,	/* msecs age */
+	TCP_METRICS_ATTR_FOPEN_COOKIE,		/* binary */
+
+	__TCP_METRICS_ATTR_MAX,
+};
+
+#define TCP_METRICS_ATTR_MAX	(__TCP_METRICS_ATTR_MAX - 1)
+
+enum {
+	TCP_METRICS_CMD_UNSPEC,
+	TCP_METRICS_CMD_GET,
+	TCP_METRICS_CMD_DEL,
+
+	__TCP_METRICS_CMD_MAX,
+};
+
+#define TCP_METRICS_CMD_MAX	(__TCP_METRICS_CMD_MAX - 1)
+
+#endif /* _LINUX_TCP_METRICS_H */
ip/Makefile +1 -1
diff -urpN iproute2-3.5.1/ip/Makefile iproute2-3.5.1-tcp_metrics/ip/Makefile
@@ -3,7 +3,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o ipr
     ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o iptuntap.o \
     ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o \
     iplink_vlan.o link_veth.o link_gre.o iplink_can.o \
-    iplink_macvlan.o iplink_macvtap.o ipl2tp.o
+    iplink_macvlan.o iplink_macvtap.o ipl2tp.o tcp_metrics.o
 
 RTMONOBJ=rtmon.o
 
ip/ip.c +3 -1
diff -urpN iproute2-3.5.1/ip/ip.c iproute2-3.5.1-tcp_metrics/ip/ip.c
@@ -45,7 +45,7 @@ static void usage(void)
 "       ip [ -force ] -batch filename\n"
 "where  OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |\n"
 "                   tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |\n"
-"                   netns | l2tp }\n"
+"                   netns | l2tp | tcp_metrics }\n"
 "       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n"
 "                    -f[amily] { inet | inet6 | ipx | dnet | link } |\n"
 "                    -l[oops] { maximum-addr-flush-attempts } |\n"
@@ -78,6 +78,8 @@ static const struct cmd {
 	{ "tunl",	do_iptunnel },
 	{ "tuntap",	do_iptuntap },
 	{ "tap",	do_iptuntap },
+	{ "tcpmetrics",	do_tcp_metrics },
+	{ "tcp_metrics",do_tcp_metrics },
 	{ "monitor",	do_ipmonitor },
 	{ "xfrm",	do_xfrm },
 	{ "mroute",	do_multiroute },
ip/ip_common.h +1 -0
diff -urpN iproute2-3.5.1/ip/ip_common.h iproute2-3.5.1-tcp_metrics/ip/ip_common.h
@@ -42,6 +42,7 @@ extern int do_multirule(int argc, char *
 extern int do_netns(int argc, char **argv);
 extern int do_xfrm(int argc, char **argv);
 extern int do_ipl2tp(int argc, char **argv);
+extern int do_tcp_metrics(int argc, char **argv);
 
 static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
 {
ip/tcp_metrics.c +504 -0

504 lines not on this page · raw message

man/man8/Makefile +2 -1
diff -urpN iproute2-3.5.1/man/man8/Makefile iproute2-3.5.1-tcp_metrics/man/man8/Makefile
@@ -7,7 +7,8 @@ MAN8PAGES = $(TARGETS) ip.8 arpd.8 lnsta
 	bridge.8 rtstat.8 ctstat.8 nstat.8 routef.8 \
 	ip-tunnel.8 ip-rule.8 ip-ntable.8 \
 	ip-monitor.8 tc-stab.8 tc-hfsc.8 ip-xfrm.8 ip-netns.8 \
-	ip-neighbour.8 ip-mroute.8 ip-maddress.8 ip-addrlabel.8 
+	ip-neighbour.8 ip-mroute.8 ip-maddress.8 ip-addrlabel.8 \
+	ip-tcp_metrics.8
 
 
 all: $(TARGETS)
man/man8/ip-tcp_metrics.8 +143 -0

143 lines not on this page · raw message

man/man8/ip.8 +6 -1
diff -urpN iproute2-3.5.1/man/man8/ip.8 iproute2-3.5.1-tcp_metrics/man/man8/ip.8
@@ -15,7 +15,7 @@ ip \- show / manipulate routing, devices
 .IR OBJECT " := { "
 .BR link " | " addr " | " addrlabel " | " route " | " rule " | " neigh " | "\
  ntable " | " tunnel " | " tuntap " | " maddr " | "  mroute " | " mrule " | "\
- monitor " | " xfrm " | " netns " | "  l2tp " }"
+ monitor " | " xfrm " | " netns " | "  l2tp " | "  tcp_metrics " }"
 .sp
 
 .ti -8
@@ -156,6 +156,10 @@ host addresses.
 - rule in routing policy database.
 
 .TP
+.B tcp_metrics/tcpmetrics
+- manage TCP Metrics
+
+.TP
 .B tunnel
 - tunnel over IP.
 
@@ -215,6 +219,7 @@ was written by Alexey N. Kuznetsov and a
 .BR ip-ntable (8),
 .BR ip-route (8),
 .BR ip-rule (8),
+.BR ip-tcp_metrics (8),
 .BR ip-tunnel (8),
 .BR ip-xfrm (8)
 .br