kernel: backport patches improving fq_codel drop behavior
[openwrt/openwrt.git] / target / linux / generic / patches-4.4 / 030-net_sched-introduce-qdisc_replace-helper.patch
1 From: WANG Cong <xiyou.wangcong@gmail.com>
2 Date: Thu, 25 Feb 2016 14:55:00 -0800
3 Subject: [PATCH] net_sched: introduce qdisc_replace() helper
4
5 Remove nearly duplicated code and prepare for the following patch.
6
7 Cc: Jamal Hadi Salim <jhs@mojatatu.com>
8 Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
9 Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
10 Signed-off-by: David S. Miller <davem@davemloft.net>
11 ---
12
13 --- a/include/net/sch_generic.h
14 +++ b/include/net/sch_generic.h
15 @@ -698,6 +698,23 @@ static inline void qdisc_reset_queue(str
16 sch->qstats.backlog = 0;
17 }
18
19 +static inline struct Qdisc *qdisc_replace(struct Qdisc *sch, struct Qdisc *new,
20 + struct Qdisc **pold)
21 +{
22 + struct Qdisc *old;
23 +
24 + sch_tree_lock(sch);
25 + old = *pold;
26 + *pold = new;
27 + if (old != NULL) {
28 + qdisc_tree_decrease_qlen(old, old->q.qlen);
29 + qdisc_reset(old);
30 + }
31 + sch_tree_unlock(sch);
32 +
33 + return old;
34 +}
35 +
36 static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
37 struct sk_buff_head *list)
38 {
39 --- a/net/sched/sch_cbq.c
40 +++ b/net/sched/sch_cbq.c
41 @@ -1624,13 +1624,8 @@ static int cbq_graft(struct Qdisc *sch,
42 new->reshape_fail = cbq_reshape_fail;
43 #endif
44 }
45 - sch_tree_lock(sch);
46 - *old = cl->q;
47 - cl->q = new;
48 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
49 - qdisc_reset(*old);
50 - sch_tree_unlock(sch);
51
52 + *old = qdisc_replace(sch, new, &cl->q);
53 return 0;
54 }
55
56 --- a/net/sched/sch_drr.c
57 +++ b/net/sched/sch_drr.c
58 @@ -226,11 +226,7 @@ static int drr_graft_class(struct Qdisc
59 new = &noop_qdisc;
60 }
61
62 - sch_tree_lock(sch);
63 - drr_purge_queue(cl);
64 - *old = cl->qdisc;
65 - cl->qdisc = new;
66 - sch_tree_unlock(sch);
67 + *old = qdisc_replace(sch, new, &cl->qdisc);
68 return 0;
69 }
70
71 --- a/net/sched/sch_dsmark.c
72 +++ b/net/sched/sch_dsmark.c
73 @@ -73,13 +73,7 @@ static int dsmark_graft(struct Qdisc *sc
74 new = &noop_qdisc;
75 }
76
77 - sch_tree_lock(sch);
78 - *old = p->q;
79 - p->q = new;
80 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
81 - qdisc_reset(*old);
82 - sch_tree_unlock(sch);
83 -
84 + *old = qdisc_replace(sch, new, &p->q);
85 return 0;
86 }
87
88 --- a/net/sched/sch_hfsc.c
89 +++ b/net/sched/sch_hfsc.c
90 @@ -1215,11 +1215,7 @@ hfsc_graft_class(struct Qdisc *sch, unsi
91 new = &noop_qdisc;
92 }
93
94 - sch_tree_lock(sch);
95 - hfsc_purge_queue(sch, cl);
96 - *old = cl->qdisc;
97 - cl->qdisc = new;
98 - sch_tree_unlock(sch);
99 + *old = qdisc_replace(sch, new, &cl->qdisc);
100 return 0;
101 }
102
103 --- a/net/sched/sch_htb.c
104 +++ b/net/sched/sch_htb.c
105 @@ -1163,14 +1163,7 @@ static int htb_graft(struct Qdisc *sch,
106 cl->common.classid)) == NULL)
107 return -ENOBUFS;
108
109 - sch_tree_lock(sch);
110 - *old = cl->un.leaf.q;
111 - cl->un.leaf.q = new;
112 - if (*old != NULL) {
113 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
114 - qdisc_reset(*old);
115 - }
116 - sch_tree_unlock(sch);
117 + *old = qdisc_replace(sch, new, &cl->un.leaf.q);
118 return 0;
119 }
120
121 --- a/net/sched/sch_multiq.c
122 +++ b/net/sched/sch_multiq.c
123 @@ -303,13 +303,7 @@ static int multiq_graft(struct Qdisc *sc
124 if (new == NULL)
125 new = &noop_qdisc;
126
127 - sch_tree_lock(sch);
128 - *old = q->queues[band];
129 - q->queues[band] = new;
130 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
131 - qdisc_reset(*old);
132 - sch_tree_unlock(sch);
133 -
134 + *old = qdisc_replace(sch, new, &q->queues[band]);
135 return 0;
136 }
137
138 --- a/net/sched/sch_netem.c
139 +++ b/net/sched/sch_netem.c
140 @@ -1037,15 +1037,7 @@ static int netem_graft(struct Qdisc *sch
141 {
142 struct netem_sched_data *q = qdisc_priv(sch);
143
144 - sch_tree_lock(sch);
145 - *old = q->qdisc;
146 - q->qdisc = new;
147 - if (*old) {
148 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
149 - qdisc_reset(*old);
150 - }
151 - sch_tree_unlock(sch);
152 -
153 + *old = qdisc_replace(sch, new, &q->qdisc);
154 return 0;
155 }
156
157 --- a/net/sched/sch_prio.c
158 +++ b/net/sched/sch_prio.c
159 @@ -268,13 +268,7 @@ static int prio_graft(struct Qdisc *sch,
160 if (new == NULL)
161 new = &noop_qdisc;
162
163 - sch_tree_lock(sch);
164 - *old = q->queues[band];
165 - q->queues[band] = new;
166 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
167 - qdisc_reset(*old);
168 - sch_tree_unlock(sch);
169 -
170 + *old = qdisc_replace(sch, new, &q->queues[band]);
171 return 0;
172 }
173
174 --- a/net/sched/sch_qfq.c
175 +++ b/net/sched/sch_qfq.c
176 @@ -617,11 +617,7 @@ static int qfq_graft_class(struct Qdisc
177 new = &noop_qdisc;
178 }
179
180 - sch_tree_lock(sch);
181 - qfq_purge_queue(cl);
182 - *old = cl->qdisc;
183 - cl->qdisc = new;
184 - sch_tree_unlock(sch);
185 + *old = qdisc_replace(sch, new, &cl->qdisc);
186 return 0;
187 }
188
189 --- a/net/sched/sch_red.c
190 +++ b/net/sched/sch_red.c
191 @@ -313,12 +313,7 @@ static int red_graft(struct Qdisc *sch,
192 if (new == NULL)
193 new = &noop_qdisc;
194
195 - sch_tree_lock(sch);
196 - *old = q->qdisc;
197 - q->qdisc = new;
198 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
199 - qdisc_reset(*old);
200 - sch_tree_unlock(sch);
201 + *old = qdisc_replace(sch, new, &q->qdisc);
202 return 0;
203 }
204
205 --- a/net/sched/sch_sfb.c
206 +++ b/net/sched/sch_sfb.c
207 @@ -606,12 +606,7 @@ static int sfb_graft(struct Qdisc *sch,
208 if (new == NULL)
209 new = &noop_qdisc;
210
211 - sch_tree_lock(sch);
212 - *old = q->qdisc;
213 - q->qdisc = new;
214 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
215 - qdisc_reset(*old);
216 - sch_tree_unlock(sch);
217 + *old = qdisc_replace(sch, new, &q->qdisc);
218 return 0;
219 }
220
221 --- a/net/sched/sch_tbf.c
222 +++ b/net/sched/sch_tbf.c
223 @@ -502,13 +502,7 @@ static int tbf_graft(struct Qdisc *sch,
224 if (new == NULL)
225 new = &noop_qdisc;
226
227 - sch_tree_lock(sch);
228 - *old = q->qdisc;
229 - q->qdisc = new;
230 - qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
231 - qdisc_reset(*old);
232 - sch_tree_unlock(sch);
233 -
234 + *old = qdisc_replace(sch, new, &q->qdisc);
235 return 0;
236 }
237