]>
Commit | Line | Data |
---|---|---|
d4b36210 VS |
1 | /* Copyright (C) 2013 Cisco Systems, Inc, 2013. |
2 | * | |
3 | * This program is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the GNU General Public License | |
5 | * as published by the Free Software Foundation; either version 2 | |
6 | * of the License. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * Author: Vijay Subramanian <vijaynsu@cisco.com> | |
14 | * Author: Mythili Prabhu <mysuryan@cisco.com> | |
15 | * | |
16 | * ECN support is added by Naeem Khademi <naeemk@ifi.uio.no> | |
17 | * University of Oslo, Norway. | |
219e288e VS |
18 | * |
19 | * References: | |
24ed4900 | 20 | * RFC 8033: https://tools.ietf.org/html/rfc8033 |
d4b36210 VS |
21 | */ |
22 | ||
23 | #include <linux/module.h> | |
24 | #include <linux/slab.h> | |
25 | #include <linux/types.h> | |
26 | #include <linux/kernel.h> | |
27 | #include <linux/errno.h> | |
28 | #include <linux/skbuff.h> | |
29 | #include <net/pkt_sched.h> | |
30 | #include <net/inet_ecn.h> | |
31 | ||
57509003 | 32 | #define QUEUE_THRESHOLD 16384 |
d4b36210 | 33 | #define DQCOUNT_INVALID -1 |
3f7ae5f3 | 34 | #define MAX_PROB 0xffffffffffffffff |
d4b36210 VS |
35 | #define PIE_SCALE 8 |
36 | ||
37 | /* parameters used */ | |
38 | struct pie_params { | |
39 | psched_time_t target; /* user specified target delay in pschedtime */ | |
40 | u32 tupdate; /* timer frequency (in jiffies) */ | |
41 | u32 limit; /* number of packets that can be enqueued */ | |
219e288e | 42 | u32 alpha; /* alpha and beta are between 0 and 32 */ |
d4b36210 VS |
43 | u32 beta; /* and are used for shift relative to 1 */ |
44 | bool ecn; /* true if ecn is enabled */ | |
45 | bool bytemode; /* to scale drop early prob based on pkt size */ | |
46 | }; | |
47 | ||
48 | /* variables used */ | |
49 | struct pie_vars { | |
3f7ae5f3 | 50 | u64 prob; /* probability but scaled by u64 limit. */ |
d4b36210 VS |
51 | psched_time_t burst_time; |
52 | psched_time_t qdelay; | |
53 | psched_time_t qdelay_old; | |
54 | u64 dq_count; /* measured in bytes */ | |
55 | psched_time_t dq_tstamp; /* drain rate */ | |
95400b97 | 56 | u64 accu_prob; /* accumulated drop probability */ |
d4b36210 VS |
57 | u32 avg_dq_rate; /* bytes per pschedtime tick,scaled */ |
58 | u32 qlen_old; /* in bytes */ | |
95400b97 | 59 | u8 accu_prob_overflows; /* overflows of accu_prob */ |
d4b36210 VS |
60 | }; |
61 | ||
62 | /* statistics gathering */ | |
63 | struct pie_stats { | |
64 | u32 packets_in; /* total number of packets enqueued */ | |
65 | u32 dropped; /* packets dropped due to pie_action */ | |
66 | u32 overlimit; /* dropped due to lack of space in queue */ | |
67 | u32 maxq; /* maximum queue size */ | |
68 | u32 ecn_mark; /* packets marked with ECN */ | |
69 | }; | |
70 | ||
71 | /* private data for the Qdisc */ | |
72 | struct pie_sched_data { | |
73 | struct pie_params params; | |
74 | struct pie_vars vars; | |
75 | struct pie_stats stats; | |
76 | struct timer_list adapt_timer; | |
cdeabbb8 | 77 | struct Qdisc *sch; |
d4b36210 VS |
78 | }; |
79 | ||
80 | static void pie_params_init(struct pie_params *params) | |
81 | { | |
82 | params->alpha = 2; | |
83 | params->beta = 20; | |
29daa855 | 84 | params->tupdate = usecs_to_jiffies(15 * USEC_PER_MSEC); /* 15 ms */ |
d4b36210 | 85 | params->limit = 1000; /* default of 1000 packets */ |
abde7920 | 86 | params->target = PSCHED_NS2TICKS(15 * NSEC_PER_MSEC); /* 15 ms */ |
d4b36210 VS |
87 | params->ecn = false; |
88 | params->bytemode = false; | |
89 | } | |
90 | ||
91 | static void pie_vars_init(struct pie_vars *vars) | |
92 | { | |
93 | vars->dq_count = DQCOUNT_INVALID; | |
95400b97 | 94 | vars->accu_prob = 0; |
d4b36210 | 95 | vars->avg_dq_rate = 0; |
30a92ad7 MT |
96 | /* default of 150 ms in pschedtime */ |
97 | vars->burst_time = PSCHED_NS2TICKS(150 * NSEC_PER_MSEC); | |
95400b97 | 98 | vars->accu_prob_overflows = 0; |
d4b36210 VS |
99 | } |
100 | ||
101 | static bool drop_early(struct Qdisc *sch, u32 packet_size) | |
102 | { | |
103 | struct pie_sched_data *q = qdisc_priv(sch); | |
3f7ae5f3 MT |
104 | u64 rnd; |
105 | u64 local_prob = q->vars.prob; | |
d4b36210 VS |
106 | u32 mtu = psched_mtu(qdisc_dev(sch)); |
107 | ||
108 | /* If there is still burst allowance left skip random early drop */ | |
109 | if (q->vars.burst_time > 0) | |
110 | return false; | |
111 | ||
112 | /* If current delay is less than half of target, and | |
113 | * if drop prob is low already, disable early_drop | |
114 | */ | |
ac4a02c5 LM |
115 | if ((q->vars.qdelay < q->params.target / 2) && |
116 | (q->vars.prob < MAX_PROB / 5)) | |
d4b36210 VS |
117 | return false; |
118 | ||
119 | /* If we have fewer than 2 mtu-sized packets, disable drop_early, | |
120 | * similar to min_th in RED | |
121 | */ | |
122 | if (sch->qstats.backlog < 2 * mtu) | |
123 | return false; | |
124 | ||
125 | /* If bytemode is turned on, use packet size to compute new | |
126 | * probablity. Smaller packets will have lower drop prob in this case | |
127 | */ | |
128 | if (q->params.bytemode && packet_size <= mtu) | |
3f7ae5f3 | 129 | local_prob = (u64)packet_size * div_u64(local_prob, mtu); |
d4b36210 VS |
130 | else |
131 | local_prob = q->vars.prob; | |
132 | ||
95400b97 MT |
133 | if (local_prob == 0) { |
134 | q->vars.accu_prob = 0; | |
135 | q->vars.accu_prob_overflows = 0; | |
136 | } | |
137 | ||
138 | if (local_prob > MAX_PROB - q->vars.accu_prob) | |
139 | q->vars.accu_prob_overflows++; | |
140 | ||
141 | q->vars.accu_prob += local_prob; | |
142 | ||
143 | if (q->vars.accu_prob_overflows == 0 && | |
144 | q->vars.accu_prob < (MAX_PROB / 100) * 85) | |
145 | return false; | |
146 | if (q->vars.accu_prob_overflows == 8 && | |
147 | q->vars.accu_prob >= MAX_PROB / 2) | |
148 | return true; | |
149 | ||
3f7ae5f3 | 150 | prandom_bytes(&rnd, 8); |
95400b97 MT |
151 | if (rnd < local_prob) { |
152 | q->vars.accu_prob = 0; | |
153 | q->vars.accu_prob_overflows = 0; | |
d4b36210 | 154 | return true; |
95400b97 | 155 | } |
d4b36210 VS |
156 | |
157 | return false; | |
158 | } | |
159 | ||
520ac30f ED |
160 | static int pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch, |
161 | struct sk_buff **to_free) | |
d4b36210 VS |
162 | { |
163 | struct pie_sched_data *q = qdisc_priv(sch); | |
164 | bool enqueue = false; | |
165 | ||
166 | if (unlikely(qdisc_qlen(sch) >= sch->limit)) { | |
167 | q->stats.overlimit++; | |
168 | goto out; | |
169 | } | |
170 | ||
171 | if (!drop_early(sch, skb->len)) { | |
172 | enqueue = true; | |
173 | } else if (q->params.ecn && (q->vars.prob <= MAX_PROB / 10) && | |
174 | INET_ECN_set_ce(skb)) { | |
175 | /* If packet is ecn capable, mark it if drop probability | |
176 | * is lower than 10%, else drop it. | |
177 | */ | |
178 | q->stats.ecn_mark++; | |
179 | enqueue = true; | |
180 | } | |
181 | ||
182 | /* we can enqueue the packet */ | |
183 | if (enqueue) { | |
184 | q->stats.packets_in++; | |
185 | if (qdisc_qlen(sch) > q->stats.maxq) | |
186 | q->stats.maxq = qdisc_qlen(sch); | |
187 | ||
188 | return qdisc_enqueue_tail(skb, sch); | |
189 | } | |
190 | ||
191 | out: | |
192 | q->stats.dropped++; | |
95400b97 MT |
193 | q->vars.accu_prob = 0; |
194 | q->vars.accu_prob_overflows = 0; | |
520ac30f | 195 | return qdisc_drop(skb, sch, to_free); |
d4b36210 VS |
196 | } |
197 | ||
198 | static const struct nla_policy pie_policy[TCA_PIE_MAX + 1] = { | |
199 | [TCA_PIE_TARGET] = {.type = NLA_U32}, | |
200 | [TCA_PIE_LIMIT] = {.type = NLA_U32}, | |
201 | [TCA_PIE_TUPDATE] = {.type = NLA_U32}, | |
202 | [TCA_PIE_ALPHA] = {.type = NLA_U32}, | |
203 | [TCA_PIE_BETA] = {.type = NLA_U32}, | |
204 | [TCA_PIE_ECN] = {.type = NLA_U32}, | |
205 | [TCA_PIE_BYTEMODE] = {.type = NLA_U32}, | |
206 | }; | |
207 | ||
2030721c AA |
208 | static int pie_change(struct Qdisc *sch, struct nlattr *opt, |
209 | struct netlink_ext_ack *extack) | |
d4b36210 VS |
210 | { |
211 | struct pie_sched_data *q = qdisc_priv(sch); | |
212 | struct nlattr *tb[TCA_PIE_MAX + 1]; | |
2ccccf5f | 213 | unsigned int qlen, dropped = 0; |
d4b36210 VS |
214 | int err; |
215 | ||
216 | if (!opt) | |
217 | return -EINVAL; | |
218 | ||
fceb6435 | 219 | err = nla_parse_nested(tb, TCA_PIE_MAX, opt, pie_policy, NULL); |
d4b36210 VS |
220 | if (err < 0) |
221 | return err; | |
222 | ||
223 | sch_tree_lock(sch); | |
224 | ||
225 | /* convert from microseconds to pschedtime */ | |
226 | if (tb[TCA_PIE_TARGET]) { | |
227 | /* target is in us */ | |
228 | u32 target = nla_get_u32(tb[TCA_PIE_TARGET]); | |
229 | ||
230 | /* convert to pschedtime */ | |
231 | q->params.target = PSCHED_NS2TICKS((u64)target * NSEC_PER_USEC); | |
232 | } | |
233 | ||
234 | /* tupdate is in jiffies */ | |
235 | if (tb[TCA_PIE_TUPDATE]) | |
ac4a02c5 LM |
236 | q->params.tupdate = |
237 | usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE])); | |
d4b36210 VS |
238 | |
239 | if (tb[TCA_PIE_LIMIT]) { | |
240 | u32 limit = nla_get_u32(tb[TCA_PIE_LIMIT]); | |
241 | ||
242 | q->params.limit = limit; | |
243 | sch->limit = limit; | |
244 | } | |
245 | ||
246 | if (tb[TCA_PIE_ALPHA]) | |
247 | q->params.alpha = nla_get_u32(tb[TCA_PIE_ALPHA]); | |
248 | ||
249 | if (tb[TCA_PIE_BETA]) | |
250 | q->params.beta = nla_get_u32(tb[TCA_PIE_BETA]); | |
251 | ||
252 | if (tb[TCA_PIE_ECN]) | |
253 | q->params.ecn = nla_get_u32(tb[TCA_PIE_ECN]); | |
254 | ||
255 | if (tb[TCA_PIE_BYTEMODE]) | |
256 | q->params.bytemode = nla_get_u32(tb[TCA_PIE_BYTEMODE]); | |
257 | ||
258 | /* Drop excess packets if new limit is lower */ | |
259 | qlen = sch->q.qlen; | |
260 | while (sch->q.qlen > sch->limit) { | |
ed760cb8 | 261 | struct sk_buff *skb = __qdisc_dequeue_head(&sch->q); |
d4b36210 | 262 | |
2ccccf5f | 263 | dropped += qdisc_pkt_len(skb); |
25331d6c | 264 | qdisc_qstats_backlog_dec(sch, skb); |
db4879d9 | 265 | rtnl_qdisc_drop(skb, sch); |
d4b36210 | 266 | } |
2ccccf5f | 267 | qdisc_tree_reduce_backlog(sch, qlen - sch->q.qlen, dropped); |
d4b36210 VS |
268 | |
269 | sch_tree_unlock(sch); | |
270 | return 0; | |
271 | } | |
272 | ||
273 | static void pie_process_dequeue(struct Qdisc *sch, struct sk_buff *skb) | |
274 | { | |
d4b36210 VS |
275 | struct pie_sched_data *q = qdisc_priv(sch); |
276 | int qlen = sch->qstats.backlog; /* current queue size in bytes */ | |
277 | ||
278 | /* If current queue is about 10 packets or more and dq_count is unset | |
279 | * we have enough packets to calculate the drain rate. Save | |
280 | * current time as dq_tstamp and start measurement cycle. | |
281 | */ | |
282 | if (qlen >= QUEUE_THRESHOLD && q->vars.dq_count == DQCOUNT_INVALID) { | |
283 | q->vars.dq_tstamp = psched_get_time(); | |
284 | q->vars.dq_count = 0; | |
285 | } | |
286 | ||
287 | /* Calculate the average drain rate from this value. If queue length | |
288 | * has receded to a small value viz., <= QUEUE_THRESHOLD bytes,reset | |
289 | * the dq_count to -1 as we don't have enough packets to calculate the | |
290 | * drain rate anymore The following if block is entered only when we | |
291 | * have a substantial queue built up (QUEUE_THRESHOLD bytes or more) | |
292 | * and we calculate the drain rate for the threshold here. dq_count is | |
293 | * in bytes, time difference in psched_time, hence rate is in | |
294 | * bytes/psched_time. | |
295 | */ | |
296 | if (q->vars.dq_count != DQCOUNT_INVALID) { | |
297 | q->vars.dq_count += skb->len; | |
298 | ||
299 | if (q->vars.dq_count >= QUEUE_THRESHOLD) { | |
300 | psched_time_t now = psched_get_time(); | |
301 | u32 dtime = now - q->vars.dq_tstamp; | |
302 | u32 count = q->vars.dq_count << PIE_SCALE; | |
303 | ||
304 | if (dtime == 0) | |
305 | return; | |
306 | ||
307 | count = count / dtime; | |
308 | ||
309 | if (q->vars.avg_dq_rate == 0) | |
310 | q->vars.avg_dq_rate = count; | |
311 | else | |
312 | q->vars.avg_dq_rate = | |
313 | (q->vars.avg_dq_rate - | |
314 | (q->vars.avg_dq_rate >> 3)) + (count >> 3); | |
315 | ||
316 | /* If the queue has receded below the threshold, we hold | |
317 | * on to the last drain rate calculated, else we reset | |
318 | * dq_count to 0 to re-enter the if block when the next | |
319 | * packet is dequeued | |
320 | */ | |
ac4a02c5 | 321 | if (qlen < QUEUE_THRESHOLD) { |
d4b36210 | 322 | q->vars.dq_count = DQCOUNT_INVALID; |
ac4a02c5 | 323 | } else { |
d4b36210 VS |
324 | q->vars.dq_count = 0; |
325 | q->vars.dq_tstamp = psched_get_time(); | |
326 | } | |
327 | ||
328 | if (q->vars.burst_time > 0) { | |
329 | if (q->vars.burst_time > dtime) | |
330 | q->vars.burst_time -= dtime; | |
331 | else | |
332 | q->vars.burst_time = 0; | |
333 | } | |
334 | } | |
335 | } | |
336 | } | |
337 | ||
338 | static void calculate_probability(struct Qdisc *sch) | |
339 | { | |
340 | struct pie_sched_data *q = qdisc_priv(sch); | |
341 | u32 qlen = sch->qstats.backlog; /* queue size in bytes */ | |
342 | psched_time_t qdelay = 0; /* in pschedtime */ | |
343 | psched_time_t qdelay_old = q->vars.qdelay; /* in pschedtime */ | |
3f7ae5f3 MT |
344 | s64 delta = 0; /* determines the change in probability */ |
345 | u64 oldprob; | |
346 | u64 alpha, beta; | |
347 | u32 power; | |
d4b36210 VS |
348 | bool update_prob = true; |
349 | ||
350 | q->vars.qdelay_old = q->vars.qdelay; | |
351 | ||
352 | if (q->vars.avg_dq_rate > 0) | |
353 | qdelay = (qlen << PIE_SCALE) / q->vars.avg_dq_rate; | |
354 | else | |
355 | qdelay = 0; | |
356 | ||
357 | /* If qdelay is zero and qlen is not, it means qlen is very small, less | |
358 | * than dequeue_rate, so we do not update probabilty in this round | |
359 | */ | |
360 | if (qdelay == 0 && qlen != 0) | |
361 | update_prob = false; | |
362 | ||
219e288e VS |
363 | /* In the algorithm, alpha and beta are between 0 and 2 with typical |
364 | * value for alpha as 0.125. In this implementation, we use values 0-32 | |
365 | * passed from user space to represent this. Also, alpha and beta have | |
366 | * unit of HZ and need to be scaled before they can used to update | |
3f7ae5f3 MT |
367 | * probability. alpha/beta are updated locally below by scaling down |
368 | * by 16 to come to 0-2 range. | |
d4b36210 | 369 | */ |
3f7ae5f3 MT |
370 | alpha = ((u64)q->params.alpha * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 4; |
371 | beta = ((u64)q->params.beta * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 4; | |
372 | ||
373 | /* We scale alpha and beta differently depending on how heavy the | |
374 | * congestion is. Please see RFC 8033 for details. | |
375 | */ | |
376 | if (q->vars.prob < MAX_PROB / 10) { | |
377 | alpha >>= 1; | |
378 | beta >>= 1; | |
379 | ||
380 | power = 100; | |
381 | while (q->vars.prob < div_u64(MAX_PROB, power) && | |
382 | power <= 1000000) { | |
383 | alpha >>= 2; | |
384 | beta >>= 2; | |
385 | power *= 10; | |
386 | } | |
d4b36210 VS |
387 | } |
388 | ||
389 | /* alpha and beta should be between 0 and 32, in multiples of 1/16 */ | |
3f7ae5f3 MT |
390 | delta += alpha * (u64)(qdelay - q->params.target); |
391 | delta += beta * (u64)(qdelay - qdelay_old); | |
d4b36210 VS |
392 | |
393 | oldprob = q->vars.prob; | |
394 | ||
395 | /* to ensure we increase probability in steps of no more than 2% */ | |
3f7ae5f3 | 396 | if (delta > (s64)(MAX_PROB / (100 / 2)) && |
d4b36210 VS |
397 | q->vars.prob >= MAX_PROB / 10) |
398 | delta = (MAX_PROB / 100) * 2; | |
399 | ||
400 | /* Non-linear drop: | |
401 | * Tune drop probability to increase quickly for high delays(>= 250ms) | |
402 | * 250ms is derived through experiments and provides error protection | |
403 | */ | |
404 | ||
405 | if (qdelay > (PSCHED_NS2TICKS(250 * NSEC_PER_MSEC))) | |
406 | delta += MAX_PROB / (100 / 2); | |
407 | ||
408 | q->vars.prob += delta; | |
409 | ||
410 | if (delta > 0) { | |
411 | /* prevent overflow */ | |
412 | if (q->vars.prob < oldprob) { | |
413 | q->vars.prob = MAX_PROB; | |
414 | /* Prevent normalization error. If probability is at | |
415 | * maximum value already, we normalize it here, and | |
416 | * skip the check to do a non-linear drop in the next | |
417 | * section. | |
418 | */ | |
419 | update_prob = false; | |
420 | } | |
421 | } else { | |
422 | /* prevent underflow */ | |
423 | if (q->vars.prob > oldprob) | |
424 | q->vars.prob = 0; | |
425 | } | |
426 | ||
427 | /* Non-linear drop in probability: Reduce drop probability quickly if | |
428 | * delay is 0 for 2 consecutive Tupdate periods. | |
429 | */ | |
430 | ||
ac4a02c5 | 431 | if (qdelay == 0 && qdelay_old == 0 && update_prob) |
6c97da14 LM |
432 | /* Reduce drop probability to 98.4% */ |
433 | q->vars.prob -= q->vars.prob / 64u; | |
d4b36210 VS |
434 | |
435 | q->vars.qdelay = qdelay; | |
436 | q->vars.qlen_old = qlen; | |
437 | ||
438 | /* We restart the measurement cycle if the following conditions are met | |
439 | * 1. If the delay has been low for 2 consecutive Tupdate periods | |
440 | * 2. Calculated drop probability is zero | |
441 | * 3. We have atleast one estimate for the avg_dq_rate ie., | |
442 | * is a non-zero value | |
443 | */ | |
444 | if ((q->vars.qdelay < q->params.target / 2) && | |
445 | (q->vars.qdelay_old < q->params.target / 2) && | |
ac4a02c5 LM |
446 | q->vars.prob == 0 && |
447 | q->vars.avg_dq_rate > 0) | |
d4b36210 VS |
448 | pie_vars_init(&q->vars); |
449 | } | |
450 | ||
cdeabbb8 | 451 | static void pie_timer(struct timer_list *t) |
d4b36210 | 452 | { |
cdeabbb8 KC |
453 | struct pie_sched_data *q = from_timer(q, t, adapt_timer); |
454 | struct Qdisc *sch = q->sch; | |
d4b36210 VS |
455 | spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch)); |
456 | ||
457 | spin_lock(root_lock); | |
458 | calculate_probability(sch); | |
459 | ||
460 | /* reset the timer to fire after 'tupdate'. tupdate is in jiffies. */ | |
461 | if (q->params.tupdate) | |
462 | mod_timer(&q->adapt_timer, jiffies + q->params.tupdate); | |
463 | spin_unlock(root_lock); | |
d4b36210 VS |
464 | } |
465 | ||
e63d7dfd AA |
466 | static int pie_init(struct Qdisc *sch, struct nlattr *opt, |
467 | struct netlink_ext_ack *extack) | |
d4b36210 VS |
468 | { |
469 | struct pie_sched_data *q = qdisc_priv(sch); | |
470 | ||
471 | pie_params_init(&q->params); | |
472 | pie_vars_init(&q->vars); | |
473 | sch->limit = q->params.limit; | |
474 | ||
cdeabbb8 KC |
475 | q->sch = sch; |
476 | timer_setup(&q->adapt_timer, pie_timer, 0); | |
d4b36210 VS |
477 | |
478 | if (opt) { | |
2030721c | 479 | int err = pie_change(sch, opt, extack); |
d4b36210 VS |
480 | |
481 | if (err) | |
482 | return err; | |
483 | } | |
484 | ||
d5610902 | 485 | mod_timer(&q->adapt_timer, jiffies + HZ / 2); |
d4b36210 VS |
486 | return 0; |
487 | } | |
488 | ||
489 | static int pie_dump(struct Qdisc *sch, struct sk_buff *skb) | |
490 | { | |
491 | struct pie_sched_data *q = qdisc_priv(sch); | |
492 | struct nlattr *opts; | |
493 | ||
494 | opts = nla_nest_start(skb, TCA_OPTIONS); | |
ac4a02c5 | 495 | if (!opts) |
d4b36210 VS |
496 | goto nla_put_failure; |
497 | ||
498 | /* convert target from pschedtime to us */ | |
499 | if (nla_put_u32(skb, TCA_PIE_TARGET, | |
ac4a02c5 | 500 | ((u32)PSCHED_TICKS2NS(q->params.target)) / |
d4b36210 VS |
501 | NSEC_PER_USEC) || |
502 | nla_put_u32(skb, TCA_PIE_LIMIT, sch->limit) || | |
ac4a02c5 LM |
503 | nla_put_u32(skb, TCA_PIE_TUPDATE, |
504 | jiffies_to_usecs(q->params.tupdate)) || | |
d4b36210 VS |
505 | nla_put_u32(skb, TCA_PIE_ALPHA, q->params.alpha) || |
506 | nla_put_u32(skb, TCA_PIE_BETA, q->params.beta) || | |
507 | nla_put_u32(skb, TCA_PIE_ECN, q->params.ecn) || | |
508 | nla_put_u32(skb, TCA_PIE_BYTEMODE, q->params.bytemode)) | |
509 | goto nla_put_failure; | |
510 | ||
511 | return nla_nest_end(skb, opts); | |
512 | ||
513 | nla_put_failure: | |
514 | nla_nest_cancel(skb, opts); | |
515 | return -1; | |
d4b36210 VS |
516 | } |
517 | ||
518 | static int pie_dump_stats(struct Qdisc *sch, struct gnet_dump *d) | |
519 | { | |
520 | struct pie_sched_data *q = qdisc_priv(sch); | |
521 | struct tc_pie_xstats st = { | |
522 | .prob = q->vars.prob, | |
ac4a02c5 | 523 | .delay = ((u32)PSCHED_TICKS2NS(q->vars.qdelay)) / |
d4b36210 VS |
524 | NSEC_PER_USEC, |
525 | /* unscale and return dq_rate in bytes per sec */ | |
526 | .avg_dq_rate = q->vars.avg_dq_rate * | |
527 | (PSCHED_TICKS_PER_SEC) >> PIE_SCALE, | |
528 | .packets_in = q->stats.packets_in, | |
529 | .overlimit = q->stats.overlimit, | |
530 | .maxq = q->stats.maxq, | |
531 | .dropped = q->stats.dropped, | |
532 | .ecn_mark = q->stats.ecn_mark, | |
533 | }; | |
534 | ||
535 | return gnet_stats_copy_app(d, &st, sizeof(st)); | |
536 | } | |
537 | ||
538 | static struct sk_buff *pie_qdisc_dequeue(struct Qdisc *sch) | |
539 | { | |
ac4a02c5 | 540 | struct sk_buff *skb = qdisc_dequeue_head(sch); |
d4b36210 VS |
541 | |
542 | if (!skb) | |
543 | return NULL; | |
544 | ||
545 | pie_process_dequeue(sch, skb); | |
546 | return skb; | |
547 | } | |
548 | ||
549 | static void pie_reset(struct Qdisc *sch) | |
550 | { | |
551 | struct pie_sched_data *q = qdisc_priv(sch); | |
ac4a02c5 | 552 | |
d4b36210 VS |
553 | qdisc_reset_queue(sch); |
554 | pie_vars_init(&q->vars); | |
555 | } | |
556 | ||
557 | static void pie_destroy(struct Qdisc *sch) | |
558 | { | |
559 | struct pie_sched_data *q = qdisc_priv(sch); | |
ac4a02c5 | 560 | |
d4b36210 VS |
561 | q->params.tupdate = 0; |
562 | del_timer_sync(&q->adapt_timer); | |
563 | } | |
564 | ||
565 | static struct Qdisc_ops pie_qdisc_ops __read_mostly = { | |
566 | .id = "pie", | |
567 | .priv_size = sizeof(struct pie_sched_data), | |
568 | .enqueue = pie_qdisc_enqueue, | |
569 | .dequeue = pie_qdisc_dequeue, | |
570 | .peek = qdisc_peek_dequeued, | |
571 | .init = pie_init, | |
572 | .destroy = pie_destroy, | |
573 | .reset = pie_reset, | |
574 | .change = pie_change, | |
575 | .dump = pie_dump, | |
576 | .dump_stats = pie_dump_stats, | |
577 | .owner = THIS_MODULE, | |
578 | }; | |
579 | ||
580 | static int __init pie_module_init(void) | |
581 | { | |
582 | return register_qdisc(&pie_qdisc_ops); | |
583 | } | |
584 | ||
585 | static void __exit pie_module_exit(void) | |
586 | { | |
587 | unregister_qdisc(&pie_qdisc_ops); | |
588 | } | |
589 | ||
590 | module_init(pie_module_init); | |
591 | module_exit(pie_module_exit); | |
592 | ||
593 | MODULE_DESCRIPTION("Proportional Integral controller Enhanced (PIE) scheduler"); | |
594 | MODULE_AUTHOR("Vijay Subramanian"); | |
595 | MODULE_AUTHOR("Mythili Prabhu"); | |
596 | MODULE_LICENSE("GPL"); |