.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* 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 | 3 | * |
---|
13 | 4 | * Author: Vijay Subramanian <vijaynsu@cisco.com> |
---|
14 | 5 | * Author: Mythili Prabhu <mysuryan@cisco.com> |
---|
.. | .. |
---|
17 | 8 | * University of Oslo, Norway. |
---|
18 | 9 | * |
---|
19 | 10 | * References: |
---|
20 | | - * IETF draft submission: http://tools.ietf.org/html/draft-pan-aqm-pie-00 |
---|
21 | | - * IEEE Conference on High Performance Switching and Routing 2013 : |
---|
22 | | - * "PIE: A * Lightweight Control Scheme to Address the Bufferbloat Problem" |
---|
| 11 | + * RFC 8033: https://tools.ietf.org/html/rfc8033 |
---|
23 | 12 | */ |
---|
24 | 13 | |
---|
25 | 14 | #include <linux/module.h> |
---|
.. | .. |
---|
30 | 19 | #include <linux/skbuff.h> |
---|
31 | 20 | #include <net/pkt_sched.h> |
---|
32 | 21 | #include <net/inet_ecn.h> |
---|
33 | | - |
---|
34 | | -#define QUEUE_THRESHOLD 10000 |
---|
35 | | -#define DQCOUNT_INVALID -1 |
---|
36 | | -#define MAX_PROB 0xffffffff |
---|
37 | | -#define PIE_SCALE 8 |
---|
38 | | - |
---|
39 | | -/* parameters used */ |
---|
40 | | -struct pie_params { |
---|
41 | | - psched_time_t target; /* user specified target delay in pschedtime */ |
---|
42 | | - u32 tupdate; /* timer frequency (in jiffies) */ |
---|
43 | | - u32 limit; /* number of packets that can be enqueued */ |
---|
44 | | - u32 alpha; /* alpha and beta are between 0 and 32 */ |
---|
45 | | - u32 beta; /* and are used for shift relative to 1 */ |
---|
46 | | - bool ecn; /* true if ecn is enabled */ |
---|
47 | | - bool bytemode; /* to scale drop early prob based on pkt size */ |
---|
48 | | -}; |
---|
49 | | - |
---|
50 | | -/* variables used */ |
---|
51 | | -struct pie_vars { |
---|
52 | | - u32 prob; /* probability but scaled by u32 limit. */ |
---|
53 | | - psched_time_t burst_time; |
---|
54 | | - psched_time_t qdelay; |
---|
55 | | - psched_time_t qdelay_old; |
---|
56 | | - u64 dq_count; /* measured in bytes */ |
---|
57 | | - psched_time_t dq_tstamp; /* drain rate */ |
---|
58 | | - u32 avg_dq_rate; /* bytes per pschedtime tick,scaled */ |
---|
59 | | - u32 qlen_old; /* in bytes */ |
---|
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 | | -}; |
---|
| 22 | +#include <net/pie.h> |
---|
70 | 23 | |
---|
71 | 24 | /* private data for the Qdisc */ |
---|
72 | 25 | struct pie_sched_data { |
---|
73 | | - struct pie_params params; |
---|
74 | 26 | struct pie_vars vars; |
---|
| 27 | + struct pie_params params; |
---|
75 | 28 | struct pie_stats stats; |
---|
76 | 29 | struct timer_list adapt_timer; |
---|
77 | 30 | struct Qdisc *sch; |
---|
78 | 31 | }; |
---|
79 | 32 | |
---|
80 | | -static void pie_params_init(struct pie_params *params) |
---|
| 33 | +bool pie_drop_early(struct Qdisc *sch, struct pie_params *params, |
---|
| 34 | + struct pie_vars *vars, u32 backlog, u32 packet_size) |
---|
81 | 35 | { |
---|
82 | | - params->alpha = 2; |
---|
83 | | - params->beta = 20; |
---|
84 | | - params->tupdate = usecs_to_jiffies(30 * USEC_PER_MSEC); /* 30 ms */ |
---|
85 | | - params->limit = 1000; /* default of 1000 packets */ |
---|
86 | | - params->target = PSCHED_NS2TICKS(20 * NSEC_PER_MSEC); /* 20 ms */ |
---|
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; |
---|
94 | | - vars->avg_dq_rate = 0; |
---|
95 | | - /* default of 100 ms in pschedtime */ |
---|
96 | | - vars->burst_time = PSCHED_NS2TICKS(100 * NSEC_PER_MSEC); |
---|
97 | | -} |
---|
98 | | - |
---|
99 | | -static bool drop_early(struct Qdisc *sch, u32 packet_size) |
---|
100 | | -{ |
---|
101 | | - struct pie_sched_data *q = qdisc_priv(sch); |
---|
102 | | - u32 rnd; |
---|
103 | | - u32 local_prob = q->vars.prob; |
---|
| 36 | + u64 rnd; |
---|
| 37 | + u64 local_prob = vars->prob; |
---|
104 | 38 | u32 mtu = psched_mtu(qdisc_dev(sch)); |
---|
105 | 39 | |
---|
106 | 40 | /* If there is still burst allowance left skip random early drop */ |
---|
107 | | - if (q->vars.burst_time > 0) |
---|
| 41 | + if (vars->burst_time > 0) |
---|
108 | 42 | return false; |
---|
109 | 43 | |
---|
110 | 44 | /* If current delay is less than half of target, and |
---|
111 | 45 | * if drop prob is low already, disable early_drop |
---|
112 | 46 | */ |
---|
113 | | - if ((q->vars.qdelay < q->params.target / 2) |
---|
114 | | - && (q->vars.prob < MAX_PROB / 5)) |
---|
| 47 | + if ((vars->qdelay < params->target / 2) && |
---|
| 48 | + (vars->prob < MAX_PROB / 5)) |
---|
115 | 49 | return false; |
---|
116 | 50 | |
---|
117 | | - /* If we have fewer than 2 mtu-sized packets, disable drop_early, |
---|
| 51 | + /* If we have fewer than 2 mtu-sized packets, disable pie_drop_early, |
---|
118 | 52 | * similar to min_th in RED |
---|
119 | 53 | */ |
---|
120 | | - if (sch->qstats.backlog < 2 * mtu) |
---|
| 54 | + if (backlog < 2 * mtu) |
---|
121 | 55 | return false; |
---|
122 | 56 | |
---|
123 | 57 | /* If bytemode is turned on, use packet size to compute new |
---|
124 | 58 | * probablity. Smaller packets will have lower drop prob in this case |
---|
125 | 59 | */ |
---|
126 | | - if (q->params.bytemode && packet_size <= mtu) |
---|
127 | | - local_prob = (local_prob / mtu) * packet_size; |
---|
| 60 | + if (params->bytemode && packet_size <= mtu) |
---|
| 61 | + local_prob = (u64)packet_size * div_u64(local_prob, mtu); |
---|
128 | 62 | else |
---|
129 | | - local_prob = q->vars.prob; |
---|
| 63 | + local_prob = vars->prob; |
---|
130 | 64 | |
---|
131 | | - rnd = prandom_u32(); |
---|
132 | | - if (rnd < local_prob) |
---|
| 65 | + if (local_prob == 0) |
---|
| 66 | + vars->accu_prob = 0; |
---|
| 67 | + else |
---|
| 68 | + vars->accu_prob += local_prob; |
---|
| 69 | + |
---|
| 70 | + if (vars->accu_prob < (MAX_PROB / 100) * 85) |
---|
| 71 | + return false; |
---|
| 72 | + if (vars->accu_prob >= (MAX_PROB / 2) * 17) |
---|
133 | 73 | return true; |
---|
| 74 | + |
---|
| 75 | + prandom_bytes(&rnd, 8); |
---|
| 76 | + if ((rnd >> BITS_PER_BYTE) < local_prob) { |
---|
| 77 | + vars->accu_prob = 0; |
---|
| 78 | + return true; |
---|
| 79 | + } |
---|
134 | 80 | |
---|
135 | 81 | return false; |
---|
136 | 82 | } |
---|
| 83 | +EXPORT_SYMBOL_GPL(pie_drop_early); |
---|
137 | 84 | |
---|
138 | 85 | static int pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch, |
---|
139 | 86 | struct sk_buff **to_free) |
---|
.. | .. |
---|
146 | 93 | goto out; |
---|
147 | 94 | } |
---|
148 | 95 | |
---|
149 | | - if (!drop_early(sch, skb->len)) { |
---|
| 96 | + if (!pie_drop_early(sch, &q->params, &q->vars, sch->qstats.backlog, |
---|
| 97 | + skb->len)) { |
---|
150 | 98 | enqueue = true; |
---|
151 | 99 | } else if (q->params.ecn && (q->vars.prob <= MAX_PROB / 10) && |
---|
152 | 100 | INET_ECN_set_ce(skb)) { |
---|
.. | .. |
---|
159 | 107 | |
---|
160 | 108 | /* we can enqueue the packet */ |
---|
161 | 109 | if (enqueue) { |
---|
| 110 | + /* Set enqueue time only when dq_rate_estimator is disabled. */ |
---|
| 111 | + if (!q->params.dq_rate_estimator) |
---|
| 112 | + pie_set_enqueue_time(skb); |
---|
| 113 | + |
---|
162 | 114 | q->stats.packets_in++; |
---|
163 | 115 | if (qdisc_qlen(sch) > q->stats.maxq) |
---|
164 | 116 | q->stats.maxq = qdisc_qlen(sch); |
---|
.. | .. |
---|
168 | 120 | |
---|
169 | 121 | out: |
---|
170 | 122 | q->stats.dropped++; |
---|
| 123 | + q->vars.accu_prob = 0; |
---|
171 | 124 | return qdisc_drop(skb, sch, to_free); |
---|
172 | 125 | } |
---|
173 | 126 | |
---|
174 | 127 | static const struct nla_policy pie_policy[TCA_PIE_MAX + 1] = { |
---|
175 | | - [TCA_PIE_TARGET] = {.type = NLA_U32}, |
---|
176 | | - [TCA_PIE_LIMIT] = {.type = NLA_U32}, |
---|
177 | | - [TCA_PIE_TUPDATE] = {.type = NLA_U32}, |
---|
178 | | - [TCA_PIE_ALPHA] = {.type = NLA_U32}, |
---|
179 | | - [TCA_PIE_BETA] = {.type = NLA_U32}, |
---|
180 | | - [TCA_PIE_ECN] = {.type = NLA_U32}, |
---|
181 | | - [TCA_PIE_BYTEMODE] = {.type = NLA_U32}, |
---|
| 128 | + [TCA_PIE_TARGET] = {.type = NLA_U32}, |
---|
| 129 | + [TCA_PIE_LIMIT] = {.type = NLA_U32}, |
---|
| 130 | + [TCA_PIE_TUPDATE] = {.type = NLA_U32}, |
---|
| 131 | + [TCA_PIE_ALPHA] = {.type = NLA_U32}, |
---|
| 132 | + [TCA_PIE_BETA] = {.type = NLA_U32}, |
---|
| 133 | + [TCA_PIE_ECN] = {.type = NLA_U32}, |
---|
| 134 | + [TCA_PIE_BYTEMODE] = {.type = NLA_U32}, |
---|
| 135 | + [TCA_PIE_DQ_RATE_ESTIMATOR] = {.type = NLA_U32}, |
---|
182 | 136 | }; |
---|
183 | 137 | |
---|
184 | 138 | static int pie_change(struct Qdisc *sch, struct nlattr *opt, |
---|
.. | .. |
---|
192 | 146 | if (!opt) |
---|
193 | 147 | return -EINVAL; |
---|
194 | 148 | |
---|
195 | | - err = nla_parse_nested(tb, TCA_PIE_MAX, opt, pie_policy, NULL); |
---|
| 149 | + err = nla_parse_nested_deprecated(tb, TCA_PIE_MAX, opt, pie_policy, |
---|
| 150 | + NULL); |
---|
196 | 151 | if (err < 0) |
---|
197 | 152 | return err; |
---|
198 | 153 | |
---|
.. | .. |
---|
209 | 164 | |
---|
210 | 165 | /* tupdate is in jiffies */ |
---|
211 | 166 | if (tb[TCA_PIE_TUPDATE]) |
---|
212 | | - q->params.tupdate = usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE])); |
---|
| 167 | + q->params.tupdate = |
---|
| 168 | + usecs_to_jiffies(nla_get_u32(tb[TCA_PIE_TUPDATE])); |
---|
213 | 169 | |
---|
214 | 170 | if (tb[TCA_PIE_LIMIT]) { |
---|
215 | 171 | u32 limit = nla_get_u32(tb[TCA_PIE_LIMIT]); |
---|
.. | .. |
---|
230 | 186 | if (tb[TCA_PIE_BYTEMODE]) |
---|
231 | 187 | q->params.bytemode = nla_get_u32(tb[TCA_PIE_BYTEMODE]); |
---|
232 | 188 | |
---|
| 189 | + if (tb[TCA_PIE_DQ_RATE_ESTIMATOR]) |
---|
| 190 | + q->params.dq_rate_estimator = |
---|
| 191 | + nla_get_u32(tb[TCA_PIE_DQ_RATE_ESTIMATOR]); |
---|
| 192 | + |
---|
233 | 193 | /* Drop excess packets if new limit is lower */ |
---|
234 | 194 | qlen = sch->q.qlen; |
---|
235 | 195 | while (sch->q.qlen > sch->limit) { |
---|
.. | .. |
---|
245 | 205 | return 0; |
---|
246 | 206 | } |
---|
247 | 207 | |
---|
248 | | -static void pie_process_dequeue(struct Qdisc *sch, struct sk_buff *skb) |
---|
| 208 | +void pie_process_dequeue(struct sk_buff *skb, struct pie_params *params, |
---|
| 209 | + struct pie_vars *vars, u32 backlog) |
---|
249 | 210 | { |
---|
| 211 | + psched_time_t now = psched_get_time(); |
---|
| 212 | + u32 dtime = 0; |
---|
250 | 213 | |
---|
251 | | - struct pie_sched_data *q = qdisc_priv(sch); |
---|
252 | | - int qlen = sch->qstats.backlog; /* current queue size in bytes */ |
---|
| 214 | + /* If dq_rate_estimator is disabled, calculate qdelay using the |
---|
| 215 | + * packet timestamp. |
---|
| 216 | + */ |
---|
| 217 | + if (!params->dq_rate_estimator) { |
---|
| 218 | + vars->qdelay = now - pie_get_enqueue_time(skb); |
---|
| 219 | + |
---|
| 220 | + if (vars->dq_tstamp != DTIME_INVALID) |
---|
| 221 | + dtime = now - vars->dq_tstamp; |
---|
| 222 | + |
---|
| 223 | + vars->dq_tstamp = now; |
---|
| 224 | + |
---|
| 225 | + if (backlog == 0) |
---|
| 226 | + vars->qdelay = 0; |
---|
| 227 | + |
---|
| 228 | + if (dtime == 0) |
---|
| 229 | + return; |
---|
| 230 | + |
---|
| 231 | + goto burst_allowance_reduction; |
---|
| 232 | + } |
---|
253 | 233 | |
---|
254 | 234 | /* If current queue is about 10 packets or more and dq_count is unset |
---|
255 | 235 | * we have enough packets to calculate the drain rate. Save |
---|
256 | 236 | * current time as dq_tstamp and start measurement cycle. |
---|
257 | 237 | */ |
---|
258 | | - if (qlen >= QUEUE_THRESHOLD && q->vars.dq_count == DQCOUNT_INVALID) { |
---|
259 | | - q->vars.dq_tstamp = psched_get_time(); |
---|
260 | | - q->vars.dq_count = 0; |
---|
| 238 | + if (backlog >= QUEUE_THRESHOLD && vars->dq_count == DQCOUNT_INVALID) { |
---|
| 239 | + vars->dq_tstamp = psched_get_time(); |
---|
| 240 | + vars->dq_count = 0; |
---|
261 | 241 | } |
---|
262 | 242 | |
---|
263 | | - /* Calculate the average drain rate from this value. If queue length |
---|
264 | | - * has receded to a small value viz., <= QUEUE_THRESHOLD bytes,reset |
---|
| 243 | + /* Calculate the average drain rate from this value. If queue length |
---|
| 244 | + * has receded to a small value viz., <= QUEUE_THRESHOLD bytes, reset |
---|
265 | 245 | * the dq_count to -1 as we don't have enough packets to calculate the |
---|
266 | | - * drain rate anymore The following if block is entered only when we |
---|
| 246 | + * drain rate anymore. The following if block is entered only when we |
---|
267 | 247 | * have a substantial queue built up (QUEUE_THRESHOLD bytes or more) |
---|
268 | 248 | * and we calculate the drain rate for the threshold here. dq_count is |
---|
269 | 249 | * in bytes, time difference in psched_time, hence rate is in |
---|
270 | 250 | * bytes/psched_time. |
---|
271 | 251 | */ |
---|
272 | | - if (q->vars.dq_count != DQCOUNT_INVALID) { |
---|
273 | | - q->vars.dq_count += skb->len; |
---|
| 252 | + if (vars->dq_count != DQCOUNT_INVALID) { |
---|
| 253 | + vars->dq_count += skb->len; |
---|
274 | 254 | |
---|
275 | | - if (q->vars.dq_count >= QUEUE_THRESHOLD) { |
---|
276 | | - psched_time_t now = psched_get_time(); |
---|
277 | | - u32 dtime = now - q->vars.dq_tstamp; |
---|
278 | | - u32 count = q->vars.dq_count << PIE_SCALE; |
---|
| 255 | + if (vars->dq_count >= QUEUE_THRESHOLD) { |
---|
| 256 | + u32 count = vars->dq_count << PIE_SCALE; |
---|
| 257 | + |
---|
| 258 | + dtime = now - vars->dq_tstamp; |
---|
279 | 259 | |
---|
280 | 260 | if (dtime == 0) |
---|
281 | 261 | return; |
---|
282 | 262 | |
---|
283 | 263 | count = count / dtime; |
---|
284 | 264 | |
---|
285 | | - if (q->vars.avg_dq_rate == 0) |
---|
286 | | - q->vars.avg_dq_rate = count; |
---|
| 265 | + if (vars->avg_dq_rate == 0) |
---|
| 266 | + vars->avg_dq_rate = count; |
---|
287 | 267 | else |
---|
288 | | - q->vars.avg_dq_rate = |
---|
289 | | - (q->vars.avg_dq_rate - |
---|
290 | | - (q->vars.avg_dq_rate >> 3)) + (count >> 3); |
---|
| 268 | + vars->avg_dq_rate = |
---|
| 269 | + (vars->avg_dq_rate - |
---|
| 270 | + (vars->avg_dq_rate >> 3)) + (count >> 3); |
---|
291 | 271 | |
---|
292 | 272 | /* If the queue has receded below the threshold, we hold |
---|
293 | 273 | * on to the last drain rate calculated, else we reset |
---|
294 | 274 | * dq_count to 0 to re-enter the if block when the next |
---|
295 | 275 | * packet is dequeued |
---|
296 | 276 | */ |
---|
297 | | - if (qlen < QUEUE_THRESHOLD) |
---|
298 | | - q->vars.dq_count = DQCOUNT_INVALID; |
---|
299 | | - else { |
---|
300 | | - q->vars.dq_count = 0; |
---|
301 | | - q->vars.dq_tstamp = psched_get_time(); |
---|
| 277 | + if (backlog < QUEUE_THRESHOLD) { |
---|
| 278 | + vars->dq_count = DQCOUNT_INVALID; |
---|
| 279 | + } else { |
---|
| 280 | + vars->dq_count = 0; |
---|
| 281 | + vars->dq_tstamp = psched_get_time(); |
---|
302 | 282 | } |
---|
303 | 283 | |
---|
304 | | - if (q->vars.burst_time > 0) { |
---|
305 | | - if (q->vars.burst_time > dtime) |
---|
306 | | - q->vars.burst_time -= dtime; |
---|
307 | | - else |
---|
308 | | - q->vars.burst_time = 0; |
---|
309 | | - } |
---|
| 284 | + goto burst_allowance_reduction; |
---|
310 | 285 | } |
---|
311 | 286 | } |
---|
312 | | -} |
---|
313 | 287 | |
---|
314 | | -static void calculate_probability(struct Qdisc *sch) |
---|
| 288 | + return; |
---|
| 289 | + |
---|
| 290 | +burst_allowance_reduction: |
---|
| 291 | + if (vars->burst_time > 0) { |
---|
| 292 | + if (vars->burst_time > dtime) |
---|
| 293 | + vars->burst_time -= dtime; |
---|
| 294 | + else |
---|
| 295 | + vars->burst_time = 0; |
---|
| 296 | + } |
---|
| 297 | +} |
---|
| 298 | +EXPORT_SYMBOL_GPL(pie_process_dequeue); |
---|
| 299 | + |
---|
| 300 | +void pie_calculate_probability(struct pie_params *params, struct pie_vars *vars, |
---|
| 301 | + u32 backlog) |
---|
315 | 302 | { |
---|
316 | | - struct pie_sched_data *q = qdisc_priv(sch); |
---|
317 | | - u32 qlen = sch->qstats.backlog; /* queue size in bytes */ |
---|
318 | 303 | psched_time_t qdelay = 0; /* in pschedtime */ |
---|
319 | | - psched_time_t qdelay_old = q->vars.qdelay; /* in pschedtime */ |
---|
320 | | - s32 delta = 0; /* determines the change in probability */ |
---|
321 | | - u32 oldprob; |
---|
322 | | - u32 alpha, beta; |
---|
| 304 | + psched_time_t qdelay_old = 0; /* in pschedtime */ |
---|
| 305 | + s64 delta = 0; /* determines the change in probability */ |
---|
| 306 | + u64 oldprob; |
---|
| 307 | + u64 alpha, beta; |
---|
| 308 | + u32 power; |
---|
323 | 309 | bool update_prob = true; |
---|
324 | 310 | |
---|
325 | | - q->vars.qdelay_old = q->vars.qdelay; |
---|
| 311 | + if (params->dq_rate_estimator) { |
---|
| 312 | + qdelay_old = vars->qdelay; |
---|
| 313 | + vars->qdelay_old = vars->qdelay; |
---|
326 | 314 | |
---|
327 | | - if (q->vars.avg_dq_rate > 0) |
---|
328 | | - qdelay = (qlen << PIE_SCALE) / q->vars.avg_dq_rate; |
---|
329 | | - else |
---|
330 | | - qdelay = 0; |
---|
| 315 | + if (vars->avg_dq_rate > 0) |
---|
| 316 | + qdelay = (backlog << PIE_SCALE) / vars->avg_dq_rate; |
---|
| 317 | + else |
---|
| 318 | + qdelay = 0; |
---|
| 319 | + } else { |
---|
| 320 | + qdelay = vars->qdelay; |
---|
| 321 | + qdelay_old = vars->qdelay_old; |
---|
| 322 | + } |
---|
331 | 323 | |
---|
332 | | - /* If qdelay is zero and qlen is not, it means qlen is very small, less |
---|
333 | | - * than dequeue_rate, so we do not update probabilty in this round |
---|
| 324 | + /* If qdelay is zero and backlog is not, it means backlog is very small, |
---|
| 325 | + * so we do not update probabilty in this round. |
---|
334 | 326 | */ |
---|
335 | | - if (qdelay == 0 && qlen != 0) |
---|
| 327 | + if (qdelay == 0 && backlog != 0) |
---|
336 | 328 | update_prob = false; |
---|
337 | 329 | |
---|
338 | 330 | /* In the algorithm, alpha and beta are between 0 and 2 with typical |
---|
339 | 331 | * value for alpha as 0.125. In this implementation, we use values 0-32 |
---|
340 | 332 | * passed from user space to represent this. Also, alpha and beta have |
---|
341 | 333 | * unit of HZ and need to be scaled before they can used to update |
---|
342 | | - * probability. alpha/beta are updated locally below by 1) scaling them |
---|
343 | | - * appropriately 2) scaling down by 16 to come to 0-2 range. |
---|
344 | | - * Please see paper for details. |
---|
345 | | - * |
---|
346 | | - * We scale alpha and beta differently depending on whether we are in |
---|
347 | | - * light, medium or high dropping mode. |
---|
| 334 | + * probability. alpha/beta are updated locally below by scaling down |
---|
| 335 | + * by 16 to come to 0-2 range. |
---|
348 | 336 | */ |
---|
349 | | - if (q->vars.prob < MAX_PROB / 100) { |
---|
350 | | - alpha = |
---|
351 | | - (q->params.alpha * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 7; |
---|
352 | | - beta = |
---|
353 | | - (q->params.beta * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 7; |
---|
354 | | - } else if (q->vars.prob < MAX_PROB / 10) { |
---|
355 | | - alpha = |
---|
356 | | - (q->params.alpha * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 5; |
---|
357 | | - beta = |
---|
358 | | - (q->params.beta * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 5; |
---|
359 | | - } else { |
---|
360 | | - alpha = |
---|
361 | | - (q->params.alpha * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 4; |
---|
362 | | - beta = |
---|
363 | | - (q->params.beta * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 4; |
---|
| 337 | + alpha = ((u64)params->alpha * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 4; |
---|
| 338 | + beta = ((u64)params->beta * (MAX_PROB / PSCHED_TICKS_PER_SEC)) >> 4; |
---|
| 339 | + |
---|
| 340 | + /* We scale alpha and beta differently depending on how heavy the |
---|
| 341 | + * congestion is. Please see RFC 8033 for details. |
---|
| 342 | + */ |
---|
| 343 | + if (vars->prob < MAX_PROB / 10) { |
---|
| 344 | + alpha >>= 1; |
---|
| 345 | + beta >>= 1; |
---|
| 346 | + |
---|
| 347 | + power = 100; |
---|
| 348 | + while (vars->prob < div_u64(MAX_PROB, power) && |
---|
| 349 | + power <= 1000000) { |
---|
| 350 | + alpha >>= 2; |
---|
| 351 | + beta >>= 2; |
---|
| 352 | + power *= 10; |
---|
| 353 | + } |
---|
364 | 354 | } |
---|
365 | 355 | |
---|
366 | 356 | /* alpha and beta should be between 0 and 32, in multiples of 1/16 */ |
---|
367 | | - delta += alpha * ((qdelay - q->params.target)); |
---|
368 | | - delta += beta * ((qdelay - qdelay_old)); |
---|
| 357 | + delta += alpha * (qdelay - params->target); |
---|
| 358 | + delta += beta * (qdelay - qdelay_old); |
---|
369 | 359 | |
---|
370 | | - oldprob = q->vars.prob; |
---|
| 360 | + oldprob = vars->prob; |
---|
371 | 361 | |
---|
372 | 362 | /* to ensure we increase probability in steps of no more than 2% */ |
---|
373 | | - if (delta > (s32) (MAX_PROB / (100 / 2)) && |
---|
374 | | - q->vars.prob >= MAX_PROB / 10) |
---|
| 363 | + if (delta > (s64)(MAX_PROB / (100 / 2)) && |
---|
| 364 | + vars->prob >= MAX_PROB / 10) |
---|
375 | 365 | delta = (MAX_PROB / 100) * 2; |
---|
376 | 366 | |
---|
377 | 367 | /* Non-linear drop: |
---|
.. | .. |
---|
382 | 372 | if (qdelay > (PSCHED_NS2TICKS(250 * NSEC_PER_MSEC))) |
---|
383 | 373 | delta += MAX_PROB / (100 / 2); |
---|
384 | 374 | |
---|
385 | | - q->vars.prob += delta; |
---|
| 375 | + vars->prob += delta; |
---|
386 | 376 | |
---|
387 | 377 | if (delta > 0) { |
---|
388 | 378 | /* prevent overflow */ |
---|
389 | | - if (q->vars.prob < oldprob) { |
---|
390 | | - q->vars.prob = MAX_PROB; |
---|
| 379 | + if (vars->prob < oldprob) { |
---|
| 380 | + vars->prob = MAX_PROB; |
---|
391 | 381 | /* Prevent normalization error. If probability is at |
---|
392 | 382 | * maximum value already, we normalize it here, and |
---|
393 | 383 | * skip the check to do a non-linear drop in the next |
---|
.. | .. |
---|
397 | 387 | } |
---|
398 | 388 | } else { |
---|
399 | 389 | /* prevent underflow */ |
---|
400 | | - if (q->vars.prob > oldprob) |
---|
401 | | - q->vars.prob = 0; |
---|
| 390 | + if (vars->prob > oldprob) |
---|
| 391 | + vars->prob = 0; |
---|
402 | 392 | } |
---|
403 | 393 | |
---|
404 | 394 | /* Non-linear drop in probability: Reduce drop probability quickly if |
---|
405 | 395 | * delay is 0 for 2 consecutive Tupdate periods. |
---|
406 | 396 | */ |
---|
407 | 397 | |
---|
408 | | - if ((qdelay == 0) && (qdelay_old == 0) && update_prob) |
---|
409 | | - q->vars.prob = (q->vars.prob * 98) / 100; |
---|
| 398 | + if (qdelay == 0 && qdelay_old == 0 && update_prob) |
---|
| 399 | + /* Reduce drop probability to 98.4% */ |
---|
| 400 | + vars->prob -= vars->prob / 64; |
---|
410 | 401 | |
---|
411 | | - q->vars.qdelay = qdelay; |
---|
412 | | - q->vars.qlen_old = qlen; |
---|
| 402 | + vars->qdelay = qdelay; |
---|
| 403 | + vars->backlog_old = backlog; |
---|
413 | 404 | |
---|
414 | 405 | /* We restart the measurement cycle if the following conditions are met |
---|
415 | 406 | * 1. If the delay has been low for 2 consecutive Tupdate periods |
---|
416 | 407 | * 2. Calculated drop probability is zero |
---|
417 | | - * 3. We have atleast one estimate for the avg_dq_rate ie., |
---|
418 | | - * is a non-zero value |
---|
| 408 | + * 3. If average dq_rate_estimator is enabled, we have atleast one |
---|
| 409 | + * estimate for the avg_dq_rate ie., is a non-zero value |
---|
419 | 410 | */ |
---|
420 | | - if ((q->vars.qdelay < q->params.target / 2) && |
---|
421 | | - (q->vars.qdelay_old < q->params.target / 2) && |
---|
422 | | - (q->vars.prob == 0) && |
---|
423 | | - (q->vars.avg_dq_rate > 0)) |
---|
424 | | - pie_vars_init(&q->vars); |
---|
| 411 | + if ((vars->qdelay < params->target / 2) && |
---|
| 412 | + (vars->qdelay_old < params->target / 2) && |
---|
| 413 | + vars->prob == 0 && |
---|
| 414 | + (!params->dq_rate_estimator || vars->avg_dq_rate > 0)) { |
---|
| 415 | + pie_vars_init(vars); |
---|
| 416 | + } |
---|
| 417 | + |
---|
| 418 | + if (!params->dq_rate_estimator) |
---|
| 419 | + vars->qdelay_old = qdelay; |
---|
425 | 420 | } |
---|
| 421 | +EXPORT_SYMBOL_GPL(pie_calculate_probability); |
---|
426 | 422 | |
---|
427 | 423 | static void pie_timer(struct timer_list *t) |
---|
428 | 424 | { |
---|
.. | .. |
---|
431 | 427 | spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch)); |
---|
432 | 428 | |
---|
433 | 429 | spin_lock(root_lock); |
---|
434 | | - calculate_probability(sch); |
---|
| 430 | + pie_calculate_probability(&q->params, &q->vars, sch->qstats.backlog); |
---|
435 | 431 | |
---|
436 | 432 | /* reset the timer to fire after 'tupdate'. tupdate is in jiffies. */ |
---|
437 | 433 | if (q->params.tupdate) |
---|
438 | 434 | mod_timer(&q->adapt_timer, jiffies + q->params.tupdate); |
---|
439 | 435 | spin_unlock(root_lock); |
---|
440 | | - |
---|
441 | 436 | } |
---|
442 | 437 | |
---|
443 | 438 | static int pie_init(struct Qdisc *sch, struct nlattr *opt, |
---|
.. | .. |
---|
468 | 463 | struct pie_sched_data *q = qdisc_priv(sch); |
---|
469 | 464 | struct nlattr *opts; |
---|
470 | 465 | |
---|
471 | | - opts = nla_nest_start(skb, TCA_OPTIONS); |
---|
472 | | - if (opts == NULL) |
---|
| 466 | + opts = nla_nest_start_noflag(skb, TCA_OPTIONS); |
---|
| 467 | + if (!opts) |
---|
473 | 468 | goto nla_put_failure; |
---|
474 | 469 | |
---|
475 | 470 | /* convert target from pschedtime to us */ |
---|
476 | 471 | if (nla_put_u32(skb, TCA_PIE_TARGET, |
---|
477 | | - ((u32) PSCHED_TICKS2NS(q->params.target)) / |
---|
| 472 | + ((u32)PSCHED_TICKS2NS(q->params.target)) / |
---|
478 | 473 | NSEC_PER_USEC) || |
---|
479 | 474 | nla_put_u32(skb, TCA_PIE_LIMIT, sch->limit) || |
---|
480 | | - nla_put_u32(skb, TCA_PIE_TUPDATE, jiffies_to_usecs(q->params.tupdate)) || |
---|
| 475 | + nla_put_u32(skb, TCA_PIE_TUPDATE, |
---|
| 476 | + jiffies_to_usecs(q->params.tupdate)) || |
---|
481 | 477 | nla_put_u32(skb, TCA_PIE_ALPHA, q->params.alpha) || |
---|
482 | 478 | nla_put_u32(skb, TCA_PIE_BETA, q->params.beta) || |
---|
483 | 479 | nla_put_u32(skb, TCA_PIE_ECN, q->params.ecn) || |
---|
484 | | - nla_put_u32(skb, TCA_PIE_BYTEMODE, q->params.bytemode)) |
---|
| 480 | + nla_put_u32(skb, TCA_PIE_BYTEMODE, q->params.bytemode) || |
---|
| 481 | + nla_put_u32(skb, TCA_PIE_DQ_RATE_ESTIMATOR, |
---|
| 482 | + q->params.dq_rate_estimator)) |
---|
485 | 483 | goto nla_put_failure; |
---|
486 | 484 | |
---|
487 | 485 | return nla_nest_end(skb, opts); |
---|
.. | .. |
---|
489 | 487 | nla_put_failure: |
---|
490 | 488 | nla_nest_cancel(skb, opts); |
---|
491 | 489 | return -1; |
---|
492 | | - |
---|
493 | 490 | } |
---|
494 | 491 | |
---|
495 | 492 | static int pie_dump_stats(struct Qdisc *sch, struct gnet_dump *d) |
---|
496 | 493 | { |
---|
497 | 494 | struct pie_sched_data *q = qdisc_priv(sch); |
---|
498 | 495 | struct tc_pie_xstats st = { |
---|
499 | | - .prob = q->vars.prob, |
---|
500 | | - .delay = ((u32) PSCHED_TICKS2NS(q->vars.qdelay)) / |
---|
| 496 | + .prob = q->vars.prob << BITS_PER_BYTE, |
---|
| 497 | + .delay = ((u32)PSCHED_TICKS2NS(q->vars.qdelay)) / |
---|
501 | 498 | NSEC_PER_USEC, |
---|
502 | | - /* unscale and return dq_rate in bytes per sec */ |
---|
503 | | - .avg_dq_rate = q->vars.avg_dq_rate * |
---|
504 | | - (PSCHED_TICKS_PER_SEC) >> PIE_SCALE, |
---|
505 | 499 | .packets_in = q->stats.packets_in, |
---|
506 | 500 | .overlimit = q->stats.overlimit, |
---|
507 | 501 | .maxq = q->stats.maxq, |
---|
.. | .. |
---|
509 | 503 | .ecn_mark = q->stats.ecn_mark, |
---|
510 | 504 | }; |
---|
511 | 505 | |
---|
| 506 | + /* avg_dq_rate is only valid if dq_rate_estimator is enabled */ |
---|
| 507 | + st.dq_rate_estimating = q->params.dq_rate_estimator; |
---|
| 508 | + |
---|
| 509 | + /* unscale and return dq_rate in bytes per sec */ |
---|
| 510 | + if (q->params.dq_rate_estimator) |
---|
| 511 | + st.avg_dq_rate = q->vars.avg_dq_rate * |
---|
| 512 | + (PSCHED_TICKS_PER_SEC) >> PIE_SCALE; |
---|
| 513 | + |
---|
512 | 514 | return gnet_stats_copy_app(d, &st, sizeof(st)); |
---|
513 | 515 | } |
---|
514 | 516 | |
---|
515 | 517 | static struct sk_buff *pie_qdisc_dequeue(struct Qdisc *sch) |
---|
516 | 518 | { |
---|
517 | | - struct sk_buff *skb; |
---|
518 | | - skb = qdisc_dequeue_head(sch); |
---|
| 519 | + struct pie_sched_data *q = qdisc_priv(sch); |
---|
| 520 | + struct sk_buff *skb = qdisc_dequeue_head(sch); |
---|
519 | 521 | |
---|
520 | 522 | if (!skb) |
---|
521 | 523 | return NULL; |
---|
522 | 524 | |
---|
523 | | - pie_process_dequeue(sch, skb); |
---|
| 525 | + pie_process_dequeue(skb, &q->params, &q->vars, sch->qstats.backlog); |
---|
524 | 526 | return skb; |
---|
525 | 527 | } |
---|
526 | 528 | |
---|
527 | 529 | static void pie_reset(struct Qdisc *sch) |
---|
528 | 530 | { |
---|
529 | 531 | struct pie_sched_data *q = qdisc_priv(sch); |
---|
| 532 | + |
---|
530 | 533 | qdisc_reset_queue(sch); |
---|
531 | 534 | pie_vars_init(&q->vars); |
---|
532 | 535 | } |
---|
.. | .. |
---|
534 | 537 | static void pie_destroy(struct Qdisc *sch) |
---|
535 | 538 | { |
---|
536 | 539 | struct pie_sched_data *q = qdisc_priv(sch); |
---|
| 540 | + |
---|
537 | 541 | q->params.tupdate = 0; |
---|
538 | 542 | del_timer_sync(&q->adapt_timer); |
---|
539 | 543 | } |
---|
540 | 544 | |
---|
541 | 545 | static struct Qdisc_ops pie_qdisc_ops __read_mostly = { |
---|
542 | | - .id = "pie", |
---|
| 546 | + .id = "pie", |
---|
543 | 547 | .priv_size = sizeof(struct pie_sched_data), |
---|
544 | 548 | .enqueue = pie_qdisc_enqueue, |
---|
545 | 549 | .dequeue = pie_qdisc_dequeue, |
---|