Skip to contentSkip to conversation

qdisc: new rate limiter

PATCH In review Stephen Hemminger 4 participants 7 messages Dec 8, 2007 – Dec 10, 2007

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

PATCH 1/1 qdisc: new rate limiter

This is a time based rate limiter for use in network testing. When doing network tests it is often useful to test at reduced bandwidths. The existing Token Bucket Filter provides rate control, but causes bursty traffic that can cause different performance than real world. Another alternative is the PSPacer, but it depends on pause frames which may also cause issues.

The qdisc depends on high resolution timers and clocks, so it will probably use more CPU than others making it a poor choice for use when doing traffic shaping for QOS.

include/linux/pkt_sched.h +6 -0
@@ -475,4 +475,10 @@ struct tc_netem_corrupt
 
 #define NETEM_DIST_SCALE	8192
 
+struct tc_rlim_qopt
+{
+	__u32   limit;		/* fifo limit (packets) */
+	__u32	rate;		/* bits per sec */
+};
+
 #endif
net/sched/Kconfig +13 -0
@@ -196,6 +196,19 @@ config NET_SCH_NETEM
 
 	  If unsure, say N.
 
+config NET_SCH_RLIM
+       tristate "Network Rate Limiter"
+	---help---
+	  Say Y here if you want to use timer based network rate limiter
+	  algorithm.
+
+	  See the top of <file:net/sched/sch_rlim.c> for more details.
+
+	  To compile this code as a module, choose M here: the
+	  module will be called sch_rlim.
+
+	  If unsure, say N.
+
 config NET_SCH_INGRESS
 	tristate "Ingress Qdisc"
 	---help---
net/sched/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_NET_SCH_TEQL)	+= sch_teql.o
 obj-$(CONFIG_NET_SCH_PRIO)	+= sch_prio.o
 obj-$(CONFIG_NET_SCH_ATM)	+= sch_atm.o
 obj-$(CONFIG_NET_SCH_NETEM)	+= sch_netem.o
+obj-$(CONFIG_NET_SCH_RLIM)	+= sch_rlim.o
 obj-$(CONFIG_NET_CLS_U32)	+= cls_u32.o
 obj-$(CONFIG_NET_CLS_ROUTE4)	+= cls_route.o
 obj-$(CONFIG_NET_CLS_FW)	+= cls_fw.o
net/sched/sch_rlim.c new file +350 -0

350 lines not on this page · raw message

#1 lore raw

PATCH 1/1 rlim qdisc support.

Setup code for new rlim qdisc. For use by anyone who wants to test rlim before kernel inclusion.

---
 include/linux/pkt_sched.h |    6 ++
 tc/Makefile               |    1 +
 tc/q_rlim.c               |  115 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+), 0 deletions(-)
 create mode 100644 tc/q_rlim.c
include/linux/pkt_sched.h +6 -0
index 919af93..7973dc4 100644
@@ -475,4 +475,10 @@ struct tc_netem_corrupt
 
 #define NETEM_DIST_SCALE	8192
 
+struct tc_rlim_qopt
+{
+	__u32   limit;		/* fifo limit (packets) */
+	__u32	rate;		/* bits per sec */
+};
+
 #endif
tc/Makefile +1 -0
index a715566..e46954d 100644
@@ -13,6 +13,7 @@ TCMODULES += q_tbf.o
 TCMODULES += q_cbq.o
 TCMODULES += q_rr.o
 TCMODULES += q_netem.o
+TCMODULES += q_rlim.o
 TCMODULES += f_rsvp.o
 TCMODULES += f_u32.o
 TCMODULES += f_route.o
tc/q_rlim.c new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
1.5.3.4
#2 lore raw
In reply to Stephen Hemminger
Quoted 15 lines · Stephen Hemminger

This is a time based rate limiter for use in network testing. When doing network tests it is often useful to test at reduced bandwidths. The existing Token Bucket Filter provides rate control, but causes bursty traffic that can cause different performance than real world. Another alternative is the PSPacer, but it depends on pause frames which may also cause issues.

The qdisc depends on high resolution timers and clocks, so it will probably use more CPU than others making it a poor choice for use when doing traffic shaping for QOS.

include/linux/pkt_sched.h struct tc_netem_corrupt · line 482

Quoted 8 lines
include/linux/pkt_sched.h +4 -0
@@ -475,4 +475,10 @@ struct tc_netem_corrupt
 
 #define NETEM_DIST_SCALE	8192
 
+struct tc_rlim_qopt
+{
+	__u32   limit;		/* fifo limit (packets) */
+	__u32	rate;		/* bits per sec */
 

This seems a bit small, 512mbit is the maximum rate.

Quoted 12 lines
net/sched/sch_rlim.c new file +8 -0
@@ -0,0 +1,350 @@
+static struct sk_buff *rlim_dequeue(struct Qdisc *sch)
+{
+	struct rlim_sched_data *q = qdisc_priv(sch);
+	struct sk_buff *skb;
+	ktime_t now = ktime_get();
+
+	/* if haven't reached the correct time slot, start timer */
+	if (now.tv64 < q->next_send.tv64) {

net/sched/sch_rlim.c line 18

Quoted 10 lines
net/sched/sch_rlim.c new file +10 -0
+		sch->flags |= TCQ_F_THROTTLED;
+		hrtimer_start(&q->watchdog.timer, q->next_send,
+			      HRTIMER_MODE_ABS);
+		return NULL;
+	}
+
+	skb = q->qdisc->dequeue(q->qdisc);
+	if (skb) {
+		q->next_send = ktime_add_ns(now, pkt_time(q, skb));
+		sch->flags &= ~TCQ_F_THROTTLED;

qlen is not decremented here.

Quoted 14 lines
net/sched/sch_rlim.c new file +14 -0
+	}
+	return skb;
+}
+
+static int rlim_requeue(struct sk_buff *skb, struct Qdisc *sch)
+{
+	struct rlim_sched_data *q = qdisc_priv(sch);
+	int ret;
+
+	ret = q->qdisc->ops->requeue(skb, q->qdisc);
+	if (!ret) {
+		q->next_send = ktime_sub_ns(q->next_send, pkt_time(q, skb));
+		sch->q.qlen++;
+		sch->qstats.requeues++;

net/sched/sch_rlim.c line 126

Quoted 10 lines
net/sched/sch_rlim.c new file +10 -0
+	}
+
+	return ret;
+}
+
+static void rlim_reset(struct Qdisc *sch)
+{
+	struct rlim_sched_data *q = qdisc_priv(sch);
+
+	qdisc_reset_queue(sch);

This should reset the child.

Quoted 6 lines
net/sched/sch_rlim.c new file +5 -0
+
+	q->next_send = ktime_get();
+	qdisc_watchdog_cancel(&q->watchdog);
+}
+

net/sched/sch_rlim.c line 164

Quoted 10 lines
net/sched/sch_rlim.c new file +10 -0
+static int rlim_change(struct Qdisc *sch, struct rtattr *opt)
+{
+	struct rlim_sched_data *q = qdisc_priv(sch);
+	const struct tc_rlim_qopt *qopt;
+	int err;
+
+	if (opt == NULL || RTA_PAYLOAD(opt) < sizeof(struct tc_rlim_qopt))
+		return -EINVAL;
+
+	qopt = RTA_DATA(opt);

Using nested attributes would make sure we don't run into problems with extensibility.

Quoted 10 lines
net/sched/sch_rlim.c new file +9 -0
+	err = set_fifo_limit(q->qdisc, qopt->limit);
+	if (err)
+		return err;
+
+	q->limit = qopt->limit;
+	if (qopt->rate == 0)
+		q->cost = 0;	/* unlimited */
+	else {
+		q->cost = (u64)NSEC_PER_SEC << NSEC_SCALE;

net/sched/sch_rlim.c

Quoted 10 lines
net/sched/sch_rlim.c new file +10 -0
+		do_div(q->cost, qopt->rate);
+	}
+
+	pr_debug("rlim_change: rate=%u cost=%llu\n",
+		 qopt->rate, q->cost);
+
+	return 0;
+}
+
+static struct Qdisc_class_ops rlim_class_ops = {

This can be const.

Quoted 13 lines
net/sched/sch_rlim.c new file +10 -0
+	.graft	   = rlim_graft,
+	.leaf	   = rlim_leaf,
+	.get	   = rlim_get,
+	.put	   = rlim_put,
+	.change	   = rlim_change_class,
+	.delete	   = rlim_delete,
+	.walk	   = rlim_walk,
+	.tcf_chain = rlim_find_tcf,
+	.dump	   = rlim_dump_class,
+};
#3 lore raw
Quoted 9 lines · Patrick McHardy

include/linux/pkt_sched.h struct tc_netem_corrupt · line 481

Quoted 6 lines · Stephen Hemminger
include/linux/pkt_sched.h +4 -0
+struct tc_rlim_qopt
+{
+    __u32   limit;        /* fifo limit (packets) */
+    __u32    rate;        /* bits per sec */

This seems a bit small, 512mbit is the maximum rate.

Its 4gbit of course, so I guess its enough :)

#4 lore raw
Quoted 11 lines · Patrick McHardy
Quoted 9 lines · Patrick McHardy

include/linux/pkt_sched.h struct tc_netem_corrupt · line 481

Quoted 6 lines · Stephen Hemminger
include/linux/pkt_sched.h +4 -0
+struct tc_rlim_qopt
+{
+    __u32   limit;        /* fifo limit (packets) */
+    __u32    rate;        /* bits per sec */

This seems a bit small, 512mbit is the maximum rate.

Quoted 1 line

Its 4gbit of course, so I guess its enough :)

Actually, since we already have 10-Gbps nets, with 40-Gbps and 100-Gbps nets upcoming, it maybe should be __u64.

-Bill

#5 lore raw
In reply to Patrick McHardy
Quoted 11 lines · Patrick McHardy
Quoted 9 lines · Patrick McHardy

include/linux/pkt_sched.h struct tc_netem_corrupt · line 481

Quoted 6 lines · Stephen Hemminger
include/linux/pkt_sched.h +4 -0
+struct tc_rlim_qopt
+{
+    __u32   limit;        /* fifo limit (packets) */
+    __u32    rate;        /* bits per sec */

This seems a bit small, 512mbit is the maximum rate.

Quoted 1 line

Its 4gbit of course, so I guess its enough :)

Even 4Gbps is well within the means of today's commodity hardware...seems easier to bump to 64 bits now rather than have to make some backwards-compat hack a year from now...

Ben

Signature · 1 line
Ben Greear <[email protected]> Candela Technologies Inc  http://www.candelatech.com
#6 lore raw

PATCH 1/1 qdisc: new rate limiter (v2)

In reply to Patrick McHardy

This is a time based rate limiter for use in network testing. When doing network tests it is often useful to test at reduced bandwidths. The existing Token Bucket Filter provides rate control, but causes bursty traffic that can cause different performance than real world. Another alternative is the PSPacer, but it depends on pause frames which may also cause issues.

The qdisc depends on high resolution timers and clocks, so it will probably use more CPU than others making it a poor choice for use when doing traffic shaping for QOS.

---
 include/linux/pkt_sched.h |   15 +
 net/sched/Kconfig         |   13 +
 net/sched/Makefile        |    1 
 net/sched/sch_rlim.c      |  354 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 383 insertions(+)
include/linux/pkt_sched.h +15 -0
@@ -475,4 +475,19 @@ struct tc_netem_corrupt
 
 #define NETEM_DIST_SCALE	8192
 
+enum
+{
+	TCA_RLIM_UNSPEC,
+	TCA_RLIM_PARMS,
+	__TCA_RLIM_MAX,
+};
+#define TCA_RLIM_MAX (__TCA_RLIM_MAX - 1)
+
+struct tc_rlim_qopt
+{
+	__u64	rate;		/* bits per sec */
+	__u32	overhead;	/* crc overhad */
+	__u32   limit;		/* fifo limit (packets) */
+};
+
 #endif
net/sched/Kconfig +13 -0
@@ -196,6 +196,19 @@ config NET_SCH_NETEM
 
 	  If unsure, say N.
 
+config NET_SCH_RLIM
+       tristate "Network Rate Limiter"
+	---help---
+	  Say Y here if you want to use timer based network rate limiter
+	  algorithm.
+
+	  See the top of <file:net/sched/sch_rlim.c> for more details.
+
+	  To compile this code as a module, choose M here: the
+	  module will be called sch_rlim.
+
+	  If unsure, say N.
+
 config NET_SCH_INGRESS
 	tristate "Ingress Qdisc"
 	---help---
net/sched/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_NET_SCH_TEQL)	+= sch_teql.o
 obj-$(CONFIG_NET_SCH_PRIO)	+= sch_prio.o
 obj-$(CONFIG_NET_SCH_ATM)	+= sch_atm.o
 obj-$(CONFIG_NET_SCH_NETEM)	+= sch_netem.o
+obj-$(CONFIG_NET_SCH_RLIM)	+= sch_rlim.o
 obj-$(CONFIG_NET_CLS_U32)	+= cls_u32.o
 obj-$(CONFIG_NET_CLS_ROUTE4)	+= cls_route.o
 obj-$(CONFIG_NET_CLS_FW)	+= cls_fw.o
net/sched/sch_rlim.c new file +353 -0

353 lines not on this page · raw message