All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Stephen Hemminger <shemminger@linux-foundation.org>
Cc: "David S. Miller" <davem@davemloft.net>, netdev@vger.kernel.org
Subject: Re: [PATCH net-2.6.25] qdisc: new rate limiter
Date: Sat, 08 Dec 2007 03:57:08 +0100	[thread overview]
Message-ID: <475A0804.1060006@trash.net> (raw)
In-Reply-To: <20071207162618.35715892@freepuppy.rosehill>

Stephen Hemminger wrote:
> 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. 
>
> Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
>
> --- a/include/linux/pkt_sched.h	2007-10-30 09:18:29.000000000 -0700
> +++ b/include/linux/pkt_sched.h	2007-12-07 13:37:50.000000000 -0800
> @@ -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.

> --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> +++ b/net/sched/sch_rlim.c	2007-12-07 16:22:10.000000000 -0800
> @@ -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) {
> +		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.
> +	}
> +	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++;
> +	}
> +
> +	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.

> +
> +	q->next_send = ktime_get();
> +	qdisc_watchdog_cancel(&q->watchdog);
> +}
> +
> +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.

> +	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;
> +		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.

> +	.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,
> +};
>
>
>   


  parent reply	other threads:[~2007-12-08  2:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-08  0:26 [PATCH net-2.6.25] qdisc: new rate limiter Stephen Hemminger
2007-12-08  0:29 ` [PATCH iproute2] rlim qdisc support Stephen Hemminger
2007-12-08  2:57 ` Patrick McHardy [this message]
2007-12-08  3:02   ` [PATCH net-2.6.25] qdisc: new rate limiter Patrick McHardy
2007-12-08  8:11     ` Bill Fink
2007-12-08 21:59     ` Ben Greear
2007-12-10 21:28   ` [PATCH net-2.6.25] qdisc: new rate limiter (v2) Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=475A0804.1060006@trash.net \
    --to=kaber@trash.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.