Skip to content

Commit a73ed26

Browse files
Eric Dumazetdavem330
authored andcommitted
sch_red: generalize accurate MAX_P support to RED/GRED/CHOKE
Now RED uses a Q0.32 number to store max_p (max probability), allow RED/GRED/CHOKE to use/report full resolution at config/dump time. Old tc binaries are non aware of new attributes, and still set/get Plog. New tc binary set/get both Plog and max_p for backward compatibility, they display "probability value" if they get max_p from new kernels. # tc -d qdisc show dev ... ... qdisc red 10: parent 1:1 limit 360Kb min 30Kb max 90Kb ecn ewma 5 probability 0.09 Scell_log 15 Make sure we avoid potential divides by 0 in reciprocal_value(), if (max_th - min_th) is big. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0221cd5 commit a73ed26

5 files changed

Lines changed: 45 additions & 12 deletions

File tree

‎include/linux/pkt_sched.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ enum {
216216
TCA_GRED_PARMS,
217217
TCA_GRED_STAB,
218218
TCA_GRED_DPS,
219+
TCA_GRED_MAX_P,
219220
__TCA_GRED_MAX,
220221
};
221222

@@ -255,6 +256,7 @@ enum {
255256
TCA_CHOKE_UNSPEC,
256257
TCA_CHOKE_PARMS,
257258
TCA_CHOKE_STAB,
259+
TCA_CHOKE_MAX_P,
258260
__TCA_CHOKE_MAX,
259261
};
260262

‎include/net/red.h‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ static inline u32 red_maxp(u8 Plog)
155155

156156
static inline void red_set_parms(struct red_parms *p,
157157
u32 qth_min, u32 qth_max, u8 Wlog, u8 Plog,
158-
u8 Scell_log, u8 *stab)
158+
u8 Scell_log, u8 *stab, u32 max_P)
159159
{
160160
int delta = qth_max - qth_min;
161+
u32 max_p_delta;
161162

162163
/* Reset average queue length, the value is strictly bound
163164
* to the parameters below, reseting hurts a bit but leaving
@@ -173,10 +174,14 @@ static inline void red_set_parms(struct red_parms *p,
173174
if (delta < 0)
174175
delta = 1;
175176
p->qth_delta = delta;
176-
p->max_P = red_maxp(Plog);
177-
p->max_P *= delta; /* max_P = (qth_max-qth_min)/2^Plog */
178-
179-
p->max_P_reciprocal = reciprocal_value(p->max_P / delta);
177+
if (!max_P) {
178+
max_P = red_maxp(Plog);
179+
max_P *= delta; /* max_P = (qth_max - qth_min)/2^Plog */
180+
}
181+
p->max_P = max_P;
182+
max_p_delta = max_P / delta;
183+
max_p_delta = max(max_p_delta, 1U);
184+
p->max_P_reciprocal = reciprocal_value(max_p_delta);
180185

181186
/* RED Adaptative target :
182187
* [min_th + 0.4*(min_th - max_th),
@@ -380,6 +385,7 @@ static inline void red_adaptative_algo(struct red_parms *p)
380385
p->max_P = (p->max_P/10)*9; /* maxp = maxp * Beta */
381386

382387
max_p_delta = DIV_ROUND_CLOSEST(p->max_P, p->qth_delta);
388+
max_p_delta = max(max_p_delta, 1U);
383389
p->max_P_reciprocal = reciprocal_value(max_p_delta);
384390
}
385391
#endif

‎net/sched/sch_choke.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ static void choke_reset(struct Qdisc *sch)
394394
static const struct nla_policy choke_policy[TCA_CHOKE_MAX + 1] = {
395395
[TCA_CHOKE_PARMS] = { .len = sizeof(struct tc_red_qopt) },
396396
[TCA_CHOKE_STAB] = { .len = RED_STAB_SIZE },
397+
[TCA_CHOKE_MAX_P] = { .type = NLA_U32 },
397398
};
398399

399400

@@ -415,6 +416,7 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt)
415416
int err;
416417
struct sk_buff **old = NULL;
417418
unsigned int mask;
419+
u32 max_P;
418420

419421
if (opt == NULL)
420422
return -EINVAL;
@@ -427,6 +429,8 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt)
427429
tb[TCA_CHOKE_STAB] == NULL)
428430
return -EINVAL;
429431

432+
max_P = tb[TCA_CHOKE_MAX_P] ? nla_get_u32(tb[TCA_CHOKE_MAX_P]) : 0;
433+
430434
ctl = nla_data(tb[TCA_CHOKE_PARMS]);
431435

432436
if (ctl->limit > CHOKE_MAX_QUEUE)
@@ -476,7 +480,8 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt)
476480

477481
red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog,
478482
ctl->Plog, ctl->Scell_log,
479-
nla_data(tb[TCA_CHOKE_STAB]));
483+
nla_data(tb[TCA_CHOKE_STAB]),
484+
max_P);
480485

481486
if (q->head == q->tail)
482487
red_end_of_idle_period(&q->parms);
@@ -510,6 +515,7 @@ static int choke_dump(struct Qdisc *sch, struct sk_buff *skb)
510515
goto nla_put_failure;
511516

512517
NLA_PUT(skb, TCA_CHOKE_PARMS, sizeof(opt), &opt);
518+
NLA_PUT_U32(skb, TCA_CHOKE_MAX_P, q->parms.max_P);
513519
return nla_nest_end(skb, opts);
514520

515521
nla_put_failure:

‎net/sched/sch_gred.c‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct gred_sched;
3434

3535
struct gred_sched_data {
3636
u32 limit; /* HARD maximal queue length */
37-
u32 DP; /* the drop pramaters */
37+
u32 DP; /* the drop parameters */
3838
u32 bytesin; /* bytes seen on virtualQ so far*/
3939
u32 packetsin; /* packets seen on virtualQ so far*/
4040
u32 backlog; /* bytes on the virtualQ */
@@ -379,7 +379,8 @@ static inline int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps)
379379
}
380380

381381
static inline int gred_change_vq(struct Qdisc *sch, int dp,
382-
struct tc_gred_qopt *ctl, int prio, u8 *stab)
382+
struct tc_gred_qopt *ctl, int prio,
383+
u8 *stab, u32 max_P)
383384
{
384385
struct gred_sched *table = qdisc_priv(sch);
385386
struct gred_sched_data *q;
@@ -400,7 +401,7 @@ static inline int gred_change_vq(struct Qdisc *sch, int dp,
400401

401402
red_set_parms(&q->parms,
402403
ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Plog,
403-
ctl->Scell_log, stab);
404+
ctl->Scell_log, stab, max_P);
404405

405406
return 0;
406407
}
@@ -409,6 +410,7 @@ static const struct nla_policy gred_policy[TCA_GRED_MAX + 1] = {
409410
[TCA_GRED_PARMS] = { .len = sizeof(struct tc_gred_qopt) },
410411
[TCA_GRED_STAB] = { .len = 256 },
411412
[TCA_GRED_DPS] = { .len = sizeof(struct tc_gred_sopt) },
413+
[TCA_GRED_MAX_P] = { .type = NLA_U32 },
412414
};
413415

414416
static int gred_change(struct Qdisc *sch, struct nlattr *opt)
@@ -418,6 +420,7 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt)
418420
struct nlattr *tb[TCA_GRED_MAX + 1];
419421
int err, prio = GRED_DEF_PRIO;
420422
u8 *stab;
423+
u32 max_P;
421424

422425
if (opt == NULL)
423426
return -EINVAL;
@@ -433,6 +436,8 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt)
433436
tb[TCA_GRED_STAB] == NULL)
434437
return -EINVAL;
435438

439+
max_P = tb[TCA_GRED_MAX_P] ? nla_get_u32(tb[TCA_GRED_MAX_P]) : 0;
440+
436441
err = -EINVAL;
437442
ctl = nla_data(tb[TCA_GRED_PARMS]);
438443
stab = nla_data(tb[TCA_GRED_STAB]);
@@ -457,7 +462,7 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt)
457462

458463
sch_tree_lock(sch);
459464

460-
err = gred_change_vq(sch, ctl->DP, ctl, prio, stab);
465+
err = gred_change_vq(sch, ctl->DP, ctl, prio, stab, max_P);
461466
if (err < 0)
462467
goto errout_locked;
463468

@@ -498,6 +503,7 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
498503
struct gred_sched *table = qdisc_priv(sch);
499504
struct nlattr *parms, *opts = NULL;
500505
int i;
506+
u32 max_p[MAX_DPs];
501507
struct tc_gred_sopt sopt = {
502508
.DPs = table->DPs,
503509
.def_DP = table->def,
@@ -509,6 +515,14 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
509515
if (opts == NULL)
510516
goto nla_put_failure;
511517
NLA_PUT(skb, TCA_GRED_DPS, sizeof(sopt), &sopt);
518+
519+
for (i = 0; i < MAX_DPs; i++) {
520+
struct gred_sched_data *q = table->tab[i];
521+
522+
max_p[i] = q ? q->parms.max_P : 0;
523+
}
524+
NLA_PUT(skb, TCA_GRED_MAX_P, sizeof(max_p), max_p);
525+
512526
parms = nla_nest_start(skb, TCA_GRED_PARMS);
513527
if (parms == NULL)
514528
goto nla_put_failure;

‎net/sched/sch_red.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ static void red_destroy(struct Qdisc *sch)
170170
static const struct nla_policy red_policy[TCA_RED_MAX + 1] = {
171171
[TCA_RED_PARMS] = { .len = sizeof(struct tc_red_qopt) },
172172
[TCA_RED_STAB] = { .len = RED_STAB_SIZE },
173+
[TCA_RED_MAX_P] = { .type = NLA_U32 },
173174
};
174175

175176
static int red_change(struct Qdisc *sch, struct nlattr *opt)
@@ -179,6 +180,7 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt)
179180
struct tc_red_qopt *ctl;
180181
struct Qdisc *child = NULL;
181182
int err;
183+
u32 max_P;
182184

183185
if (opt == NULL)
184186
return -EINVAL;
@@ -191,6 +193,8 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt)
191193
tb[TCA_RED_STAB] == NULL)
192194
return -EINVAL;
193195

196+
max_P = tb[TCA_RED_MAX_P] ? nla_get_u32(tb[TCA_RED_MAX_P]) : 0;
197+
194198
ctl = nla_data(tb[TCA_RED_PARMS]);
195199

196200
if (ctl->limit > 0) {
@@ -209,8 +213,9 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt)
209213
}
210214

211215
red_set_parms(&q->parms, ctl->qth_min, ctl->qth_max, ctl->Wlog,
212-
ctl->Plog, ctl->Scell_log,
213-
nla_data(tb[TCA_RED_STAB]));
216+
ctl->Plog, ctl->Scell_log,
217+
nla_data(tb[TCA_RED_STAB]),
218+
max_P);
214219

215220
del_timer(&q->adapt_timer);
216221
if (ctl->flags & TC_RED_ADAPTATIVE)

0 commit comments

Comments
 (0)