Skip to content

Commit eeca668

Browse files
Eric Dumazetdavem330
authored andcommitted
net_sched: red: split red_parms into parms and vars
This patch splits the red_parms structure into two components. One holding the RED 'constant' parameters, and one containing the variables. This permits a size reduction of GRED qdisc, and is a preliminary step to add an optional RED unit to SFQ. SFQRED will have a single red_parms structure shared by all flows, and a private red_vars per flow. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> CC: Dave Taht <dave.taht@gmail.com> CC: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 18cb809 commit eeca668

4 files changed

Lines changed: 117 additions & 95 deletions

File tree

‎include/net/red.h‎

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ struct red_parms {
137137
u8 Wlog; /* log(W) */
138138
u8 Plog; /* random number bits */
139139
u8 Stab[RED_STAB_SIZE];
140+
};
140141

142+
struct red_vars {
141143
/* Variables */
142144
int qcount; /* Number of packets since last random
143145
number generation */
@@ -152,6 +154,16 @@ static inline u32 red_maxp(u8 Plog)
152154
return Plog < 32 ? (~0U >> Plog) : ~0U;
153155
}
154156

157+
static inline void red_set_vars(struct red_vars *v)
158+
{
159+
/* Reset average queue length, the value is strictly bound
160+
* to the parameters below, reseting hurts a bit but leaving
161+
* it might result in an unreasonable qavg for a while. --TGR
162+
*/
163+
v->qavg = 0;
164+
165+
v->qcount = -1;
166+
}
155167

156168
static inline void red_set_parms(struct red_parms *p,
157169
u32 qth_min, u32 qth_max, u8 Wlog, u8 Plog,
@@ -160,13 +172,6 @@ static inline void red_set_parms(struct red_parms *p,
160172
int delta = qth_max - qth_min;
161173
u32 max_p_delta;
162174

163-
/* Reset average queue length, the value is strictly bound
164-
* to the parameters below, reseting hurts a bit but leaving
165-
* it might result in an unreasonable qavg for a while. --TGR
166-
*/
167-
p->qavg = 0;
168-
169-
p->qcount = -1;
170175
p->qth_min = qth_min << Wlog;
171176
p->qth_max = qth_max << Wlog;
172177
p->Wlog = Wlog;
@@ -197,31 +202,32 @@ static inline void red_set_parms(struct red_parms *p,
197202
memcpy(p->Stab, stab, sizeof(p->Stab));
198203
}
199204

200-
static inline int red_is_idling(const struct red_parms *p)
205+
static inline int red_is_idling(const struct red_vars *v)
201206
{
202-
return p->qidlestart.tv64 != 0;
207+
return v->qidlestart.tv64 != 0;
203208
}
204209

205-
static inline void red_start_of_idle_period(struct red_parms *p)
210+
static inline void red_start_of_idle_period(struct red_vars *v)
206211
{
207-
p->qidlestart = ktime_get();
212+
v->qidlestart = ktime_get();
208213
}
209214

210-
static inline void red_end_of_idle_period(struct red_parms *p)
215+
static inline void red_end_of_idle_period(struct red_vars *v)
211216
{
212-
p->qidlestart.tv64 = 0;
217+
v->qidlestart.tv64 = 0;
213218
}
214219

215-
static inline void red_restart(struct red_parms *p)
220+
static inline void red_restart(struct red_vars *v)
216221
{
217-
red_end_of_idle_period(p);
218-
p->qavg = 0;
219-
p->qcount = -1;
222+
red_end_of_idle_period(v);
223+
v->qavg = 0;
224+
v->qcount = -1;
220225
}
221226

222-
static inline unsigned long red_calc_qavg_from_idle_time(const struct red_parms *p)
227+
static inline unsigned long red_calc_qavg_from_idle_time(const struct red_parms *p,
228+
const struct red_vars *v)
223229
{
224-
s64 delta = ktime_us_delta(ktime_get(), p->qidlestart);
230+
s64 delta = ktime_us_delta(ktime_get(), v->qidlestart);
225231
long us_idle = min_t(s64, delta, p->Scell_max);
226232
int shift;
227233

@@ -248,7 +254,7 @@ static inline unsigned long red_calc_qavg_from_idle_time(const struct red_parms
248254
shift = p->Stab[(us_idle >> p->Scell_log) & RED_STAB_MASK];
249255

250256
if (shift)
251-
return p->qavg >> shift;
257+
return v->qavg >> shift;
252258
else {
253259
/* Approximate initial part of exponent with linear function:
254260
*
@@ -257,16 +263,17 @@ static inline unsigned long red_calc_qavg_from_idle_time(const struct red_parms
257263
* Seems, it is the best solution to
258264
* problem of too coarse exponent tabulation.
259265
*/
260-
us_idle = (p->qavg * (u64)us_idle) >> p->Scell_log;
266+
us_idle = (v->qavg * (u64)us_idle) >> p->Scell_log;
261267

262-
if (us_idle < (p->qavg >> 1))
263-
return p->qavg - us_idle;
268+
if (us_idle < (v->qavg >> 1))
269+
return v->qavg - us_idle;
264270
else
265-
return p->qavg >> 1;
271+
return v->qavg >> 1;
266272
}
267273
}
268274

269275
static inline unsigned long red_calc_qavg_no_idle_time(const struct red_parms *p,
276+
const struct red_vars *v,
270277
unsigned int backlog)
271278
{
272279
/*
@@ -278,16 +285,17 @@ static inline unsigned long red_calc_qavg_no_idle_time(const struct red_parms *p
278285
*
279286
* --ANK (980924)
280287
*/
281-
return p->qavg + (backlog - (p->qavg >> p->Wlog));
288+
return v->qavg + (backlog - (v->qavg >> p->Wlog));
282289
}
283290

284291
static inline unsigned long red_calc_qavg(const struct red_parms *p,
292+
const struct red_vars *v,
285293
unsigned int backlog)
286294
{
287-
if (!red_is_idling(p))
288-
return red_calc_qavg_no_idle_time(p, backlog);
295+
if (!red_is_idling(v))
296+
return red_calc_qavg_no_idle_time(p, v, backlog);
289297
else
290-
return red_calc_qavg_from_idle_time(p);
298+
return red_calc_qavg_from_idle_time(p, v);
291299
}
292300

293301

@@ -296,7 +304,9 @@ static inline u32 red_random(const struct red_parms *p)
296304
return reciprocal_divide(net_random(), p->max_P_reciprocal);
297305
}
298306

299-
static inline int red_mark_probability(const struct red_parms *p, unsigned long qavg)
307+
static inline int red_mark_probability(const struct red_parms *p,
308+
const struct red_vars *v,
309+
unsigned long qavg)
300310
{
301311
/* The formula used below causes questions.
302312
@@ -314,7 +324,7 @@ static inline int red_mark_probability(const struct red_parms *p, unsigned long
314324
315325
Any questions? --ANK (980924)
316326
*/
317-
return !(((qavg - p->qth_min) >> p->Wlog) * p->qcount < p->qR);
327+
return !(((qavg - p->qth_min) >> p->Wlog) * v->qcount < v->qR);
318328
}
319329

320330
enum {
@@ -323,7 +333,7 @@ enum {
323333
RED_ABOVE_MAX_TRESH,
324334
};
325335

326-
static inline int red_cmp_thresh(struct red_parms *p, unsigned long qavg)
336+
static inline int red_cmp_thresh(const struct red_parms *p, unsigned long qavg)
327337
{
328338
if (qavg < p->qth_min)
329339
return RED_BELOW_MIN_THRESH;
@@ -339,42 +349,44 @@ enum {
339349
RED_HARD_MARK,
340350
};
341351

342-
static inline int red_action(struct red_parms *p, unsigned long qavg)
352+
static inline int red_action(const struct red_parms *p,
353+
struct red_vars *v,
354+
unsigned long qavg)
343355
{
344356
switch (red_cmp_thresh(p, qavg)) {
345357
case RED_BELOW_MIN_THRESH:
346-
p->qcount = -1;
358+
v->qcount = -1;
347359
return RED_DONT_MARK;
348360

349361
case RED_BETWEEN_TRESH:
350-
if (++p->qcount) {
351-
if (red_mark_probability(p, qavg)) {
352-
p->qcount = 0;
353-
p->qR = red_random(p);
362+
if (++v->qcount) {
363+
if (red_mark_probability(p, v, qavg)) {
364+
v->qcount = 0;
365+
v->qR = red_random(p);
354366
return RED_PROB_MARK;
355367
}
356368
} else
357-
p->qR = red_random(p);
369+
v->qR = red_random(p);
358370

359371
return RED_DONT_MARK;
360372

361373
case RED_ABOVE_MAX_TRESH:
362-
p->qcount = -1;
374+
v->qcount = -1;
363375
return RED_HARD_MARK;
364376
}
365377

366378
BUG();
367379
return RED_DONT_MARK;
368380
}
369381

370-
static inline void red_adaptative_algo(struct red_parms *p)
382+
static inline void red_adaptative_algo(struct red_parms *p, struct red_vars *v)
371383
{
372384
unsigned long qavg;
373385
u32 max_p_delta;
374386

375-
qavg = p->qavg;
376-
if (red_is_idling(p))
377-
qavg = red_calc_qavg_from_idle_time(p);
387+
qavg = v->qavg;
388+
if (red_is_idling(v))
389+
qavg = red_calc_qavg_from_idle_time(p, v);
378390

379391
/* p->qavg is fixed point number with point at Wlog */
380392
qavg >>= p->Wlog;

‎net/sched/sch_choke.c‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct choke_sched_data {
5757
struct red_parms parms;
5858

5959
/* Variables */
60+
struct red_vars vars;
6061
struct tcf_proto *filter_list;
6162
struct {
6263
u32 prob_drop; /* Early probability drops */
@@ -265,7 +266,7 @@ static bool choke_match_random(const struct choke_sched_data *q,
265266
static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
266267
{
267268
struct choke_sched_data *q = qdisc_priv(sch);
268-
struct red_parms *p = &q->parms;
269+
const struct red_parms *p = &q->parms;
269270
int ret = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
270271

271272
if (q->filter_list) {
@@ -276,13 +277,13 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
276277

277278
choke_skb_cb(skb)->keys_valid = 0;
278279
/* Compute average queue usage (see RED) */
279-
p->qavg = red_calc_qavg(p, sch->q.qlen);
280-
if (red_is_idling(p))
281-
red_end_of_idle_period(p);
280+
q->vars.qavg = red_calc_qavg(p, &q->vars, sch->q.qlen);
281+
if (red_is_idling(&q->vars))
282+
red_end_of_idle_period(&q->vars);
282283

283284
/* Is queue small? */
284-
if (p->qavg <= p->qth_min)
285-
p->qcount = -1;
285+
if (q->vars.qavg <= p->qth_min)
286+
q->vars.qcount = -1;
286287
else {
287288
unsigned int idx;
288289

@@ -294,8 +295,8 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
294295
}
295296

296297
/* Queue is large, always mark/drop */
297-
if (p->qavg > p->qth_max) {
298-
p->qcount = -1;
298+
if (q->vars.qavg > p->qth_max) {
299+
q->vars.qcount = -1;
299300

300301
sch->qstats.overlimits++;
301302
if (use_harddrop(q) || !use_ecn(q) ||
@@ -305,10 +306,10 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
305306
}
306307

307308
q->stats.forced_mark++;
308-
} else if (++p->qcount) {
309-
if (red_mark_probability(p, p->qavg)) {
310-
p->qcount = 0;
311-
p->qR = red_random(p);
309+
} else if (++q->vars.qcount) {
310+
if (red_mark_probability(p, &q->vars, q->vars.qavg)) {
311+
q->vars.qcount = 0;
312+
q->vars.qR = red_random(p);
312313

313314
sch->qstats.overlimits++;
314315
if (!use_ecn(q) || !INET_ECN_set_ce(skb)) {
@@ -319,7 +320,7 @@ static int choke_enqueue(struct sk_buff *skb, struct Qdisc *sch)
319320
q->stats.prob_mark++;
320321
}
321322
} else
322-
p->qR = red_random(p);
323+
q->vars.qR = red_random(p);
323324
}
324325

325326
/* Admit new packet */
@@ -353,8 +354,8 @@ static struct sk_buff *choke_dequeue(struct Qdisc *sch)
353354
struct sk_buff *skb;
354355

355356
if (q->head == q->tail) {
356-
if (!red_is_idling(&q->parms))
357-
red_start_of_idle_period(&q->parms);
357+
if (!red_is_idling(&q->vars))
358+
red_start_of_idle_period(&q->vars);
358359
return NULL;
359360
}
360361

@@ -377,8 +378,8 @@ static unsigned int choke_drop(struct Qdisc *sch)
377378
if (len > 0)
378379
q->stats.other++;
379380
else {
380-
if (!red_is_idling(&q->parms))
381-
red_start_of_idle_period(&q->parms);
381+
if (!red_is_idling(&q->vars))
382+
red_start_of_idle_period(&q->vars);
382383
}
383384

384385
return len;
@@ -388,7 +389,7 @@ static void choke_reset(struct Qdisc *sch)
388389
{
389390
struct choke_sched_data *q = qdisc_priv(sch);
390391

391-
red_restart(&q->parms);
392+
red_restart(&q->vars);
392393
}
393394

394395
static const struct nla_policy choke_policy[TCA_CHOKE_MAX + 1] = {
@@ -482,9 +483,10 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt)
482483
ctl->Plog, ctl->Scell_log,
483484
nla_data(tb[TCA_CHOKE_STAB]),
484485
max_P);
486+
red_set_vars(&q->vars);
485487

486488
if (q->head == q->tail)
487-
red_end_of_idle_period(&q->parms);
489+
red_end_of_idle_period(&q->vars);
488490

489491
sch_tree_unlock(sch);
490492
choke_free(old);

0 commit comments

Comments
 (0)