Skip to content

Commit

Permalink
net_sched: restore "overhead xxx" handling
Browse files Browse the repository at this point in the history
commit 56b765b ("htb: improved accuracy at high rates")
broke the "overhead xxx" handling, as well as the "linklayer atm"
attribute.

tc class add ... htb rate X ceil Y linklayer atm overhead 10

This patch restores the "overhead xxx" handling, for htb, tbf
and act_police

The "linklayer atm" thing needs a separate fix.

Reported-by: Jesper Dangaard Brouer <[email protected]>
Signed-off-by: Eric Dumazet <[email protected]>
Cc: Vimalkumar <[email protected]>
Cc: Jiri Pirko <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Jun 3, 2013
1 parent c87a124 commit 01cb71d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
18 changes: 11 additions & 7 deletions include/net/sch_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,22 +679,26 @@ static inline struct sk_buff *skb_act_clone(struct sk_buff *skb, gfp_t gfp_mask,
#endif

struct psched_ratecfg {
u64 rate_bps;
u32 mult;
u32 shift;
u64 rate_bps;
u32 mult;
u16 overhead;
u8 shift;
};

static inline u64 psched_l2t_ns(const struct psched_ratecfg *r,
unsigned int len)
{
return ((u64)len * r->mult) >> r->shift;
return ((u64)(len + r->overhead) * r->mult) >> r->shift;
}

extern void psched_ratecfg_precompute(struct psched_ratecfg *r, u32 rate);
extern void psched_ratecfg_precompute(struct psched_ratecfg *r, const struct tc_ratespec *conf);

static inline u32 psched_ratecfg_getrate(const struct psched_ratecfg *r)
static inline void psched_ratecfg_getrate(struct tc_ratespec *res,
const struct psched_ratecfg *r)
{
return r->rate_bps >> 3;
memset(res, 0, sizeof(*res));
res->rate = r->rate_bps >> 3;
res->overhead = r->overhead;
}

#endif
8 changes: 4 additions & 4 deletions net/sched/act_police.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ static int tcf_act_police_locate(struct net *net, struct nlattr *nla,
}
if (R_tab) {
police->rate_present = true;
psched_ratecfg_precompute(&police->rate, R_tab->rate.rate);
psched_ratecfg_precompute(&police->rate, &R_tab->rate);
qdisc_put_rtab(R_tab);
} else {
police->rate_present = false;
}
if (P_tab) {
police->peak_present = true;
psched_ratecfg_precompute(&police->peak, P_tab->rate.rate);
psched_ratecfg_precompute(&police->peak, &P_tab->rate);
qdisc_put_rtab(P_tab);
} else {
police->peak_present = false;
Expand Down Expand Up @@ -376,9 +376,9 @@ tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ref)
};

if (police->rate_present)
opt.rate.rate = psched_ratecfg_getrate(&police->rate);
psched_ratecfg_getrate(&opt.rate, &police->rate);
if (police->peak_present)
opt.peakrate.rate = psched_ratecfg_getrate(&police->peak);
psched_ratecfg_getrate(&opt.peakrate, &police->peak);
if (nla_put(skb, TCA_POLICE_TBF, sizeof(opt), &opt))
goto nla_put_failure;
if (police->tcfp_result &&
Expand Down
8 changes: 5 additions & 3 deletions net/sched/sch_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,14 +898,16 @@ void dev_shutdown(struct net_device *dev)
WARN_ON(timer_pending(&dev->watchdog_timer));
}

void psched_ratecfg_precompute(struct psched_ratecfg *r, u32 rate)
void psched_ratecfg_precompute(struct psched_ratecfg *r,
const struct tc_ratespec *conf)
{
u64 factor;
u64 mult;
int shift;

r->rate_bps = (u64)rate << 3;
r->shift = 0;
memset(r, 0, sizeof(*r));
r->overhead = conf->overhead;
r->rate_bps = (u64)conf->rate << 3;
r->mult = 1;
/*
* Calibrate mult, shift so that token counting is accurate
Expand Down
8 changes: 4 additions & 4 deletions net/sched/sch_htb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,9 +1090,9 @@ static int htb_dump_class(struct Qdisc *sch, unsigned long arg,

memset(&opt, 0, sizeof(opt));

opt.rate.rate = psched_ratecfg_getrate(&cl->rate);
psched_ratecfg_getrate(&opt.rate, &cl->rate);
opt.buffer = PSCHED_NS2TICKS(cl->buffer);
opt.ceil.rate = psched_ratecfg_getrate(&cl->ceil);
psched_ratecfg_getrate(&opt.ceil, &cl->ceil);
opt.cbuffer = PSCHED_NS2TICKS(cl->cbuffer);
opt.quantum = cl->quantum;
opt.prio = cl->prio;
Expand Down Expand Up @@ -1459,8 +1459,8 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
cl->prio = TC_HTB_NUMPRIO - 1;
}

psched_ratecfg_precompute(&cl->rate, hopt->rate.rate);
psched_ratecfg_precompute(&cl->ceil, hopt->ceil.rate);
psched_ratecfg_precompute(&cl->rate, &hopt->rate);
psched_ratecfg_precompute(&cl->ceil, &hopt->ceil);

cl->buffer = PSCHED_TICKS2NS(hopt->buffer);
cl->cbuffer = PSCHED_TICKS2NS(hopt->buffer);
Expand Down
8 changes: 4 additions & 4 deletions net/sched/sch_tbf.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
q->tokens = q->buffer;
q->ptokens = q->mtu;

psched_ratecfg_precompute(&q->rate, rtab->rate.rate);
psched_ratecfg_precompute(&q->rate, &rtab->rate);
if (ptab) {
psched_ratecfg_precompute(&q->peak, ptab->rate.rate);
psched_ratecfg_precompute(&q->peak, &ptab->rate);
q->peak_present = true;
} else {
q->peak_present = false;
Expand Down Expand Up @@ -350,9 +350,9 @@ static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)
goto nla_put_failure;

opt.limit = q->limit;
opt.rate.rate = psched_ratecfg_getrate(&q->rate);
psched_ratecfg_getrate(&opt.rate, &q->rate);
if (q->peak_present)
opt.peakrate.rate = psched_ratecfg_getrate(&q->peak);
psched_ratecfg_getrate(&opt.peakrate, &q->peak);
else
memset(&opt.peakrate, 0, sizeof(opt.peakrate));
opt.mtu = PSCHED_NS2TICKS(q->mtu);
Expand Down

0 comments on commit 01cb71d

Please sign in to comment.