diff options
Diffstat (limited to 'net/dccp/ccids')
-rw-r--r-- | net/dccp/ccids/ccid3.c | 337 | ||||
-rw-r--r-- | net/dccp/ccids/ccid3.h | 119 |
2 files changed, 218 insertions, 238 deletions
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c index 3b8bd7ca6761..2f026ce27148 100644 --- a/net/dccp/ccids/ccid3.c +++ b/net/dccp/ccids/ccid3.c | |||
@@ -67,13 +67,13 @@ static void ccid3_hc_tx_set_state(struct sock *sk, | |||
67 | enum ccid3_hc_tx_states state) | 67 | enum ccid3_hc_tx_states state) |
68 | { | 68 | { |
69 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 69 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
70 | enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; | 70 | enum ccid3_hc_tx_states oldstate = hctx->state; |
71 | 71 | ||
72 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", | 72 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", |
73 | dccp_role(sk), sk, ccid3_tx_state_name(oldstate), | 73 | dccp_role(sk), sk, ccid3_tx_state_name(oldstate), |
74 | ccid3_tx_state_name(state)); | 74 | ccid3_tx_state_name(state)); |
75 | WARN_ON(state == oldstate); | 75 | WARN_ON(state == oldstate); |
76 | hctx->ccid3hctx_state = state; | 76 | hctx->state = state; |
77 | } | 77 | } |
78 | 78 | ||
79 | /* | 79 | /* |
@@ -88,10 +88,9 @@ static void ccid3_hc_tx_set_state(struct sock *sk, | |||
88 | static inline u64 rfc3390_initial_rate(struct sock *sk) | 88 | static inline u64 rfc3390_initial_rate(struct sock *sk) |
89 | { | 89 | { |
90 | const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 90 | const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
91 | const __u32 w_init = clamp_t(__u32, 4380U, | 91 | const __u32 w_init = clamp_t(__u32, 4380U, 2 * hctx->s, 4 * hctx->s); |
92 | 2 * hctx->ccid3hctx_s, 4 * hctx->ccid3hctx_s); | ||
93 | 92 | ||
94 | return scaled_div(w_init << 6, hctx->ccid3hctx_rtt); | 93 | return scaled_div(w_init << 6, hctx->rtt); |
95 | } | 94 | } |
96 | 95 | ||
97 | /* | 96 | /* |
@@ -100,24 +99,20 @@ static inline u64 rfc3390_initial_rate(struct sock *sk) | |||
100 | static void ccid3_update_send_interval(struct ccid3_hc_tx_sock *hctx) | 99 | static void ccid3_update_send_interval(struct ccid3_hc_tx_sock *hctx) |
101 | { | 100 | { |
102 | /* Calculate new t_ipi = s / X_inst (X_inst is in 64 * bytes/second) */ | 101 | /* Calculate new t_ipi = s / X_inst (X_inst is in 64 * bytes/second) */ |
103 | hctx->ccid3hctx_t_ipi = scaled_div32(((u64)hctx->ccid3hctx_s) << 6, | 102 | hctx->t_ipi = scaled_div32(((u64)hctx->s) << 6, hctx->x); |
104 | hctx->ccid3hctx_x); | ||
105 | 103 | ||
106 | /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */ | 104 | /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */ |
107 | hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2, | 105 | hctx->delta = min_t(u32, hctx->t_ipi / 2, TFRC_OPSYS_HALF_TIME_GRAN); |
108 | TFRC_OPSYS_HALF_TIME_GRAN); | ||
109 | |||
110 | ccid3_pr_debug("t_ipi=%u, delta=%u, s=%u, X=%u\n", | ||
111 | hctx->ccid3hctx_t_ipi, hctx->ccid3hctx_delta, | ||
112 | hctx->ccid3hctx_s, (unsigned)(hctx->ccid3hctx_x >> 6)); | ||
113 | 106 | ||
107 | ccid3_pr_debug("t_ipi=%u, delta=%u, s=%u, X=%u\n", hctx->t_ipi, | ||
108 | hctx->delta, hctx->s, (unsigned)(hctx->x >> 6)); | ||
114 | } | 109 | } |
115 | 110 | ||
116 | static u32 ccid3_hc_tx_idle_rtt(struct ccid3_hc_tx_sock *hctx, ktime_t now) | 111 | static u32 ccid3_hc_tx_idle_rtt(struct ccid3_hc_tx_sock *hctx, ktime_t now) |
117 | { | 112 | { |
118 | u32 delta = ktime_us_delta(now, hctx->ccid3hctx_t_last_win_count); | 113 | u32 delta = ktime_us_delta(now, hctx->t_last_win_count); |
119 | 114 | ||
120 | return delta / hctx->ccid3hctx_rtt; | 115 | return delta / hctx->rtt; |
121 | } | 116 | } |
122 | 117 | ||
123 | /** | 118 | /** |
@@ -133,8 +128,8 @@ static u32 ccid3_hc_tx_idle_rtt(struct ccid3_hc_tx_sock *hctx, ktime_t now) | |||
133 | static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp) | 128 | static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp) |
134 | { | 129 | { |
135 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 130 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
136 | __u64 min_rate = 2 * hctx->ccid3hctx_x_recv; | 131 | u64 min_rate = 2 * hctx->x_recv; |
137 | const __u64 old_x = hctx->ccid3hctx_x; | 132 | const u64 old_x = hctx->x; |
138 | ktime_t now = stamp ? *stamp : ktime_get_real(); | 133 | ktime_t now = stamp ? *stamp : ktime_get_real(); |
139 | 134 | ||
140 | /* | 135 | /* |
@@ -145,33 +140,27 @@ static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp) | |||
145 | */ | 140 | */ |
146 | if (ccid3_hc_tx_idle_rtt(hctx, now) >= 2) { | 141 | if (ccid3_hc_tx_idle_rtt(hctx, now) >= 2) { |
147 | min_rate = rfc3390_initial_rate(sk); | 142 | min_rate = rfc3390_initial_rate(sk); |
148 | min_rate = max(min_rate, 2 * hctx->ccid3hctx_x_recv); | 143 | min_rate = max(min_rate, 2 * hctx->x_recv); |
149 | } | 144 | } |
150 | 145 | ||
151 | if (hctx->ccid3hctx_p > 0) { | 146 | if (hctx->p > 0) { |
152 | 147 | ||
153 | hctx->ccid3hctx_x = min(((__u64)hctx->ccid3hctx_x_calc) << 6, | 148 | hctx->x = min(((u64)hctx->x_calc) << 6, min_rate); |
154 | min_rate); | 149 | hctx->x = max(hctx->x, (((u64)hctx->s) << 6) / TFRC_T_MBI); |
155 | hctx->ccid3hctx_x = max(hctx->ccid3hctx_x, | ||
156 | (((__u64)hctx->ccid3hctx_s) << 6) / | ||
157 | TFRC_T_MBI); | ||
158 | 150 | ||
159 | } else if (ktime_us_delta(now, hctx->ccid3hctx_t_ld) | 151 | } else if (ktime_us_delta(now, hctx->t_ld) - (s64)hctx->rtt >= 0) { |
160 | - (s64)hctx->ccid3hctx_rtt >= 0) { | ||
161 | 152 | ||
162 | hctx->ccid3hctx_x = min(2 * hctx->ccid3hctx_x, min_rate); | 153 | hctx->x = min(2 * hctx->x, min_rate); |
163 | hctx->ccid3hctx_x = max(hctx->ccid3hctx_x, | 154 | hctx->x = max(hctx->x, |
164 | scaled_div(((__u64)hctx->ccid3hctx_s) << 6, | 155 | scaled_div(((u64)hctx->s) << 6, hctx->rtt)); |
165 | hctx->ccid3hctx_rtt)); | 156 | hctx->t_ld = now; |
166 | hctx->ccid3hctx_t_ld = now; | ||
167 | } | 157 | } |
168 | 158 | ||
169 | if (hctx->ccid3hctx_x != old_x) { | 159 | if (hctx->x != old_x) { |
170 | ccid3_pr_debug("X_prev=%u, X_now=%u, X_calc=%u, " | 160 | ccid3_pr_debug("X_prev=%u, X_now=%u, X_calc=%u, " |
171 | "X_recv=%u\n", (unsigned)(old_x >> 6), | 161 | "X_recv=%u\n", (unsigned)(old_x >> 6), |
172 | (unsigned)(hctx->ccid3hctx_x >> 6), | 162 | (unsigned)(hctx->x >> 6), hctx->x_calc, |
173 | hctx->ccid3hctx_x_calc, | 163 | (unsigned)(hctx->x_recv >> 6)); |
174 | (unsigned)(hctx->ccid3hctx_x_recv >> 6)); | ||
175 | 164 | ||
176 | ccid3_update_send_interval(hctx); | 165 | ccid3_update_send_interval(hctx); |
177 | } | 166 | } |
@@ -183,11 +172,11 @@ static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp) | |||
183 | */ | 172 | */ |
184 | static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len) | 173 | static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len) |
185 | { | 174 | { |
186 | const u16 old_s = hctx->ccid3hctx_s; | 175 | const u16 old_s = hctx->s; |
187 | 176 | ||
188 | hctx->ccid3hctx_s = tfrc_ewma(hctx->ccid3hctx_s, len, 9); | 177 | hctx->s = tfrc_ewma(hctx->s, len, 9); |
189 | 178 | ||
190 | if (hctx->ccid3hctx_s != old_s) | 179 | if (hctx->s != old_s) |
191 | ccid3_update_send_interval(hctx); | 180 | ccid3_update_send_interval(hctx); |
192 | } | 181 | } |
193 | 182 | ||
@@ -198,13 +187,13 @@ static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len) | |||
198 | static inline void ccid3_hc_tx_update_win_count(struct ccid3_hc_tx_sock *hctx, | 187 | static inline void ccid3_hc_tx_update_win_count(struct ccid3_hc_tx_sock *hctx, |
199 | ktime_t now) | 188 | ktime_t now) |
200 | { | 189 | { |
201 | u32 delta = ktime_us_delta(now, hctx->ccid3hctx_t_last_win_count), | 190 | u32 delta = ktime_us_delta(now, hctx->t_last_win_count), |
202 | quarter_rtts = (4 * delta) / hctx->ccid3hctx_rtt; | 191 | quarter_rtts = (4 * delta) / hctx->rtt; |
203 | 192 | ||
204 | if (quarter_rtts > 0) { | 193 | if (quarter_rtts > 0) { |
205 | hctx->ccid3hctx_t_last_win_count = now; | 194 | hctx->t_last_win_count = now; |
206 | hctx->ccid3hctx_last_win_count += min(quarter_rtts, 5U); | 195 | hctx->last_win_count += min(quarter_rtts, 5U); |
207 | hctx->ccid3hctx_last_win_count &= 0xF; /* mod 16 */ | 196 | hctx->last_win_count &= 0xF; /* mod 16 */ |
208 | } | 197 | } |
209 | } | 198 | } |
210 | 199 | ||
@@ -222,23 +211,21 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data) | |||
222 | } | 211 | } |
223 | 212 | ||
224 | ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk, | 213 | ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk, |
225 | ccid3_tx_state_name(hctx->ccid3hctx_state)); | 214 | ccid3_tx_state_name(hctx->state)); |
226 | 215 | ||
227 | if (hctx->ccid3hctx_state == TFRC_SSTATE_FBACK) | 216 | if (hctx->state == TFRC_SSTATE_FBACK) |
228 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); | 217 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); |
229 | else if (hctx->ccid3hctx_state != TFRC_SSTATE_NO_FBACK) | 218 | else if (hctx->state != TFRC_SSTATE_NO_FBACK) |
230 | goto out; | 219 | goto out; |
231 | 220 | ||
232 | /* | 221 | /* |
233 | * Determine new allowed sending rate X as per draft rfc3448bis-00, 4.4 | 222 | * Determine new allowed sending rate X as per draft rfc3448bis-00, 4.4 |
223 | * RTO is 0 if and only if no feedback has been received yet. | ||
234 | */ | 224 | */ |
235 | if (hctx->ccid3hctx_t_rto == 0 || /* no feedback received yet */ | 225 | if (hctx->t_rto == 0 || hctx->p == 0) { |
236 | hctx->ccid3hctx_p == 0) { | ||
237 | 226 | ||
238 | /* halve send rate directly */ | 227 | /* halve send rate directly */ |
239 | hctx->ccid3hctx_x = max(hctx->ccid3hctx_x / 2, | 228 | hctx->x = max(hctx->x / 2, (((u64)hctx->s) << 6) / TFRC_T_MBI); |
240 | (((__u64)hctx->ccid3hctx_s) << 6) / | ||
241 | TFRC_T_MBI); | ||
242 | ccid3_update_send_interval(hctx); | 229 | ccid3_update_send_interval(hctx); |
243 | } else { | 230 | } else { |
244 | /* | 231 | /* |
@@ -251,33 +238,32 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data) | |||
251 | * | 238 | * |
252 | * Note that X_recv is scaled by 2^6 while X_calc is not | 239 | * Note that X_recv is scaled by 2^6 while X_calc is not |
253 | */ | 240 | */ |
254 | BUG_ON(hctx->ccid3hctx_p && !hctx->ccid3hctx_x_calc); | 241 | BUG_ON(hctx->p && !hctx->x_calc); |
255 | 242 | ||
256 | if (hctx->ccid3hctx_x_calc > (hctx->ccid3hctx_x_recv >> 5)) | 243 | if (hctx->x_calc > (hctx->x_recv >> 5)) |
257 | hctx->ccid3hctx_x_recv = | 244 | hctx->x_recv = |
258 | max(hctx->ccid3hctx_x_recv / 2, | 245 | max(hctx->x_recv / 2, |
259 | (((__u64)hctx->ccid3hctx_s) << 6) / | 246 | (((__u64)hctx->s) << 6) / (2 * TFRC_T_MBI)); |
260 | (2 * TFRC_T_MBI)); | ||
261 | else { | 247 | else { |
262 | hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc; | 248 | hctx->x_recv = hctx->x_calc; |
263 | hctx->ccid3hctx_x_recv <<= 4; | 249 | hctx->x_recv <<= 4; |
264 | } | 250 | } |
265 | ccid3_hc_tx_update_x(sk, NULL); | 251 | ccid3_hc_tx_update_x(sk, NULL); |
266 | } | 252 | } |
267 | ccid3_pr_debug("Reduced X to %llu/64 bytes/sec\n", | 253 | ccid3_pr_debug("Reduced X to %llu/64 bytes/sec\n", |
268 | (unsigned long long)hctx->ccid3hctx_x); | 254 | (unsigned long long)hctx->x); |
269 | 255 | ||
270 | /* | 256 | /* |
271 | * Set new timeout for the nofeedback timer. | 257 | * Set new timeout for the nofeedback timer. |
272 | * See comments in packet_recv() regarding the value of t_RTO. | 258 | * See comments in packet_recv() regarding the value of t_RTO. |
273 | */ | 259 | */ |
274 | if (unlikely(hctx->ccid3hctx_t_rto == 0)) /* no feedback yet */ | 260 | if (unlikely(hctx->t_rto == 0)) /* no feedback received yet */ |
275 | t_nfb = TFRC_INITIAL_TIMEOUT; | 261 | t_nfb = TFRC_INITIAL_TIMEOUT; |
276 | else | 262 | else |
277 | t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi); | 263 | t_nfb = max(hctx->t_rto, 2 * hctx->t_ipi); |
278 | 264 | ||
279 | restart_timer: | 265 | restart_timer: |
280 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, | 266 | sk_reset_timer(sk, &hctx->no_feedback_timer, |
281 | jiffies + usecs_to_jiffies(t_nfb)); | 267 | jiffies + usecs_to_jiffies(t_nfb)); |
282 | out: | 268 | out: |
283 | bh_unlock_sock(sk); | 269 | bh_unlock_sock(sk); |
@@ -305,18 +291,17 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) | |||
305 | if (unlikely(skb->len == 0)) | 291 | if (unlikely(skb->len == 0)) |
306 | return -EBADMSG; | 292 | return -EBADMSG; |
307 | 293 | ||
308 | switch (hctx->ccid3hctx_state) { | 294 | switch (hctx->state) { |
309 | case TFRC_SSTATE_NO_SENT: | 295 | case TFRC_SSTATE_NO_SENT: |
310 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, | 296 | sk_reset_timer(sk, &hctx->no_feedback_timer, (jiffies + |
311 | (jiffies + | ||
312 | usecs_to_jiffies(TFRC_INITIAL_TIMEOUT))); | 297 | usecs_to_jiffies(TFRC_INITIAL_TIMEOUT))); |
313 | hctx->ccid3hctx_last_win_count = 0; | 298 | hctx->last_win_count = 0; |
314 | hctx->ccid3hctx_t_last_win_count = now; | 299 | hctx->t_last_win_count = now; |
315 | 300 | ||
316 | /* Set t_0 for initial packet */ | 301 | /* Set t_0 for initial packet */ |
317 | hctx->ccid3hctx_t_nom = now; | 302 | hctx->t_nom = now; |
318 | 303 | ||
319 | hctx->ccid3hctx_s = skb->len; | 304 | hctx->s = skb->len; |
320 | 305 | ||
321 | /* | 306 | /* |
322 | * Use initial RTT sample when available: recommended by erratum | 307 | * Use initial RTT sample when available: recommended by erratum |
@@ -325,9 +310,9 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) | |||
325 | */ | 310 | */ |
326 | if (dp->dccps_syn_rtt) { | 311 | if (dp->dccps_syn_rtt) { |
327 | ccid3_pr_debug("SYN RTT = %uus\n", dp->dccps_syn_rtt); | 312 | ccid3_pr_debug("SYN RTT = %uus\n", dp->dccps_syn_rtt); |
328 | hctx->ccid3hctx_rtt = dp->dccps_syn_rtt; | 313 | hctx->rtt = dp->dccps_syn_rtt; |
329 | hctx->ccid3hctx_x = rfc3390_initial_rate(sk); | 314 | hctx->x = rfc3390_initial_rate(sk); |
330 | hctx->ccid3hctx_t_ld = now; | 315 | hctx->t_ld = now; |
331 | } else { | 316 | } else { |
332 | /* | 317 | /* |
333 | * Sender does not have RTT sample: | 318 | * Sender does not have RTT sample: |
@@ -335,9 +320,9 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) | |||
335 | * is needed in several parts (e.g. window counter); | 320 | * is needed in several parts (e.g. window counter); |
336 | * - set sending rate X_pps = 1pps as per RFC 3448, 4.2. | 321 | * - set sending rate X_pps = 1pps as per RFC 3448, 4.2. |
337 | */ | 322 | */ |
338 | hctx->ccid3hctx_rtt = DCCP_FALLBACK_RTT; | 323 | hctx->rtt = DCCP_FALLBACK_RTT; |
339 | hctx->ccid3hctx_x = hctx->ccid3hctx_s; | 324 | hctx->x = hctx->s; |
340 | hctx->ccid3hctx_x <<= 6; | 325 | hctx->x <<= 6; |
341 | } | 326 | } |
342 | ccid3_update_send_interval(hctx); | 327 | ccid3_update_send_interval(hctx); |
343 | 328 | ||
@@ -345,7 +330,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) | |||
345 | break; | 330 | break; |
346 | case TFRC_SSTATE_NO_FBACK: | 331 | case TFRC_SSTATE_NO_FBACK: |
347 | case TFRC_SSTATE_FBACK: | 332 | case TFRC_SSTATE_FBACK: |
348 | delay = ktime_us_delta(hctx->ccid3hctx_t_nom, now); | 333 | delay = ktime_us_delta(hctx->t_nom, now); |
349 | ccid3_pr_debug("delay=%ld\n", (long)delay); | 334 | ccid3_pr_debug("delay=%ld\n", (long)delay); |
350 | /* | 335 | /* |
351 | * Scheduling of packet transmissions [RFC 3448, 4.6] | 336 | * Scheduling of packet transmissions [RFC 3448, 4.6] |
@@ -355,7 +340,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) | |||
355 | * else | 340 | * else |
356 | * // send the packet in (t_nom - t_now) milliseconds. | 341 | * // send the packet in (t_nom - t_now) milliseconds. |
357 | */ | 342 | */ |
358 | if (delay - (s64)hctx->ccid3hctx_delta >= 1000) | 343 | if (delay - (s64)hctx->delta >= 1000) |
359 | return (u32)delay / 1000L; | 344 | return (u32)delay / 1000L; |
360 | 345 | ||
361 | ccid3_hc_tx_update_win_count(hctx, now); | 346 | ccid3_hc_tx_update_win_count(hctx, now); |
@@ -367,11 +352,10 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) | |||
367 | 352 | ||
368 | /* prepare to send now (add options etc.) */ | 353 | /* prepare to send now (add options etc.) */ |
369 | dp->dccps_hc_tx_insert_options = 1; | 354 | dp->dccps_hc_tx_insert_options = 1; |
370 | DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; | 355 | DCCP_SKB_CB(skb)->dccpd_ccval = hctx->last_win_count; |
371 | 356 | ||
372 | /* set the nominal send time for the next following packet */ | 357 | /* set the nominal send time for the next following packet */ |
373 | hctx->ccid3hctx_t_nom = ktime_add_us(hctx->ccid3hctx_t_nom, | 358 | hctx->t_nom = ktime_add_us(hctx->t_nom, hctx->t_ipi); |
374 | hctx->ccid3hctx_t_ipi); | ||
375 | return 0; | 359 | return 0; |
376 | } | 360 | } |
377 | 361 | ||
@@ -382,14 +366,14 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, | |||
382 | 366 | ||
383 | ccid3_hc_tx_update_s(hctx, len); | 367 | ccid3_hc_tx_update_s(hctx, len); |
384 | 368 | ||
385 | if (tfrc_tx_hist_add(&hctx->ccid3hctx_hist, dccp_sk(sk)->dccps_gss)) | 369 | if (tfrc_tx_hist_add(&hctx->hist, dccp_sk(sk)->dccps_gss)) |
386 | DCCP_CRIT("packet history - out of memory!"); | 370 | DCCP_CRIT("packet history - out of memory!"); |
387 | } | 371 | } |
388 | 372 | ||
389 | static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | 373 | static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) |
390 | { | 374 | { |
391 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 375 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
392 | struct ccid3_options_received *opt_recv; | 376 | struct ccid3_options_received *opt_recv = &hctx->options_received; |
393 | ktime_t now; | 377 | ktime_t now; |
394 | unsigned long t_nfb; | 378 | unsigned long t_nfb; |
395 | u32 pinv, r_sample; | 379 | u32 pinv, r_sample; |
@@ -399,15 +383,14 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
399 | DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) | 383 | DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) |
400 | return; | 384 | return; |
401 | /* ... and only in the established state */ | 385 | /* ... and only in the established state */ |
402 | if (hctx->ccid3hctx_state != TFRC_SSTATE_FBACK && | 386 | if (hctx->state != TFRC_SSTATE_FBACK && |
403 | hctx->ccid3hctx_state != TFRC_SSTATE_NO_FBACK) | 387 | hctx->state != TFRC_SSTATE_NO_FBACK) |
404 | return; | 388 | return; |
405 | 389 | ||
406 | opt_recv = &hctx->ccid3hctx_options_received; | ||
407 | now = ktime_get_real(); | 390 | now = ktime_get_real(); |
408 | 391 | ||
409 | /* Estimate RTT from history if ACK number is valid */ | 392 | /* Estimate RTT from history if ACK number is valid */ |
410 | r_sample = tfrc_tx_hist_rtt(hctx->ccid3hctx_hist, | 393 | r_sample = tfrc_tx_hist_rtt(hctx->hist, |
411 | DCCP_SKB_CB(skb)->dccpd_ack_seq, now); | 394 | DCCP_SKB_CB(skb)->dccpd_ack_seq, now); |
412 | if (r_sample == 0) { | 395 | if (r_sample == 0) { |
413 | DCCP_WARN("%s(%p): %s with bogus ACK-%llu\n", dccp_role(sk), sk, | 396 | DCCP_WARN("%s(%p): %s with bogus ACK-%llu\n", dccp_role(sk), sk, |
@@ -417,37 +400,37 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
417 | } | 400 | } |
418 | 401 | ||
419 | /* Update receive rate in units of 64 * bytes/second */ | 402 | /* Update receive rate in units of 64 * bytes/second */ |
420 | hctx->ccid3hctx_x_recv = opt_recv->ccid3or_receive_rate; | 403 | hctx->x_recv = opt_recv->ccid3or_receive_rate; |
421 | hctx->ccid3hctx_x_recv <<= 6; | 404 | hctx->x_recv <<= 6; |
422 | 405 | ||
423 | /* Update loss event rate (which is scaled by 1e6) */ | 406 | /* Update loss event rate (which is scaled by 1e6) */ |
424 | pinv = opt_recv->ccid3or_loss_event_rate; | 407 | pinv = opt_recv->ccid3or_loss_event_rate; |
425 | if (pinv == ~0U || pinv == 0) /* see RFC 4342, 8.5 */ | 408 | if (pinv == ~0U || pinv == 0) /* see RFC 4342, 8.5 */ |
426 | hctx->ccid3hctx_p = 0; | 409 | hctx->p = 0; |
427 | else /* can not exceed 100% */ | 410 | else /* can not exceed 100% */ |
428 | hctx->ccid3hctx_p = scaled_div(1, pinv); | 411 | hctx->p = scaled_div(1, pinv); |
429 | /* | 412 | /* |
430 | * Validate new RTT sample and update moving average | 413 | * Validate new RTT sample and update moving average |
431 | */ | 414 | */ |
432 | r_sample = dccp_sample_rtt(sk, r_sample); | 415 | r_sample = dccp_sample_rtt(sk, r_sample); |
433 | hctx->ccid3hctx_rtt = tfrc_ewma(hctx->ccid3hctx_rtt, r_sample, 9); | 416 | hctx->rtt = tfrc_ewma(hctx->rtt, r_sample, 9); |
434 | /* | 417 | /* |
435 | * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3 | 418 | * Update allowed sending rate X as per draft rfc3448bis-00, 4.2/3 |
436 | */ | 419 | */ |
437 | if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) { | 420 | if (hctx->state == TFRC_SSTATE_NO_FBACK) { |
438 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); | 421 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); |
439 | 422 | ||
440 | if (hctx->ccid3hctx_t_rto == 0) { | 423 | if (hctx->t_rto == 0) { |
441 | /* | 424 | /* |
442 | * Initial feedback packet: Larger Initial Windows (4.2) | 425 | * Initial feedback packet: Larger Initial Windows (4.2) |
443 | */ | 426 | */ |
444 | hctx->ccid3hctx_x = rfc3390_initial_rate(sk); | 427 | hctx->x = rfc3390_initial_rate(sk); |
445 | hctx->ccid3hctx_t_ld = now; | 428 | hctx->t_ld = now; |
446 | 429 | ||
447 | ccid3_update_send_interval(hctx); | 430 | ccid3_update_send_interval(hctx); |
448 | 431 | ||
449 | goto done_computing_x; | 432 | goto done_computing_x; |
450 | } else if (hctx->ccid3hctx_p == 0) { | 433 | } else if (hctx->p == 0) { |
451 | /* | 434 | /* |
452 | * First feedback after nofeedback timer expiry (4.3) | 435 | * First feedback after nofeedback timer expiry (4.3) |
453 | */ | 436 | */ |
@@ -456,25 +439,20 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
456 | } | 439 | } |
457 | 440 | ||
458 | /* Update sending rate (step 4 of [RFC 3448, 4.3]) */ | 441 | /* Update sending rate (step 4 of [RFC 3448, 4.3]) */ |
459 | if (hctx->ccid3hctx_p > 0) | 442 | if (hctx->p > 0) |
460 | hctx->ccid3hctx_x_calc = | 443 | hctx->x_calc = tfrc_calc_x(hctx->s, hctx->rtt, hctx->p); |
461 | tfrc_calc_x(hctx->ccid3hctx_s, | ||
462 | hctx->ccid3hctx_rtt, | ||
463 | hctx->ccid3hctx_p); | ||
464 | ccid3_hc_tx_update_x(sk, &now); | 444 | ccid3_hc_tx_update_x(sk, &now); |
465 | 445 | ||
466 | done_computing_x: | 446 | done_computing_x: |
467 | ccid3_pr_debug("%s(%p), RTT=%uus (sample=%uus), s=%u, " | 447 | ccid3_pr_debug("%s(%p), RTT=%uus (sample=%uus), s=%u, " |
468 | "p=%u, X_calc=%u, X_recv=%u, X=%u\n", | 448 | "p=%u, X_calc=%u, X_recv=%u, X=%u\n", |
469 | dccp_role(sk), | 449 | dccp_role(sk), sk, hctx->rtt, r_sample, |
470 | sk, hctx->ccid3hctx_rtt, r_sample, | 450 | hctx->s, hctx->p, hctx->x_calc, |
471 | hctx->ccid3hctx_s, hctx->ccid3hctx_p, | 451 | (unsigned)(hctx->x_recv >> 6), |
472 | hctx->ccid3hctx_x_calc, | 452 | (unsigned)(hctx->x >> 6)); |
473 | (unsigned)(hctx->ccid3hctx_x_recv >> 6), | ||
474 | (unsigned)(hctx->ccid3hctx_x >> 6)); | ||
475 | 453 | ||
476 | /* unschedule no feedback timer */ | 454 | /* unschedule no feedback timer */ |
477 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); | 455 | sk_stop_timer(sk, &hctx->no_feedback_timer); |
478 | 456 | ||
479 | /* | 457 | /* |
480 | * As we have calculated new ipi, delta, t_nom it is possible | 458 | * As we have calculated new ipi, delta, t_nom it is possible |
@@ -488,21 +466,19 @@ done_computing_x: | |||
488 | * This can help avoid triggering the nofeedback timer too | 466 | * This can help avoid triggering the nofeedback timer too |
489 | * often ('spinning') on LANs with small RTTs. | 467 | * often ('spinning') on LANs with small RTTs. |
490 | */ | 468 | */ |
491 | hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, | 469 | hctx->t_rto = max_t(u32, 4 * hctx->rtt, (CONFIG_IP_DCCP_CCID3_RTO * |
492 | (CONFIG_IP_DCCP_CCID3_RTO * | 470 | (USEC_PER_SEC / 1000))); |
493 | (USEC_PER_SEC / 1000))); | ||
494 | /* | 471 | /* |
495 | * Schedule no feedback timer to expire in | 472 | * Schedule no feedback timer to expire in |
496 | * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi) | 473 | * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi) |
497 | */ | 474 | */ |
498 | t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi); | 475 | t_nfb = max(hctx->t_rto, 2 * hctx->t_ipi); |
499 | 476 | ||
500 | ccid3_pr_debug("%s(%p), Scheduled no feedback timer to " | 477 | ccid3_pr_debug("%s(%p), Scheduled no feedback timer to " |
501 | "expire in %lu jiffies (%luus)\n", | 478 | "expire in %lu jiffies (%luus)\n", |
502 | dccp_role(sk), | 479 | dccp_role(sk), sk, usecs_to_jiffies(t_nfb), t_nfb); |
503 | sk, usecs_to_jiffies(t_nfb), t_nfb); | ||
504 | 480 | ||
505 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, | 481 | sk_reset_timer(sk, &hctx->no_feedback_timer, |
506 | jiffies + usecs_to_jiffies(t_nfb)); | 482 | jiffies + usecs_to_jiffies(t_nfb)); |
507 | } | 483 | } |
508 | 484 | ||
@@ -513,11 +489,9 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, | |||
513 | int rc = 0; | 489 | int rc = 0; |
514 | const struct dccp_sock *dp = dccp_sk(sk); | 490 | const struct dccp_sock *dp = dccp_sk(sk); |
515 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 491 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
516 | struct ccid3_options_received *opt_recv; | 492 | struct ccid3_options_received *opt_recv = &hctx->options_received; |
517 | __be32 opt_val; | 493 | __be32 opt_val; |
518 | 494 | ||
519 | opt_recv = &hctx->ccid3hctx_options_received; | ||
520 | |||
521 | if (opt_recv->ccid3or_seqno != dp->dccps_gsr) { | 495 | if (opt_recv->ccid3or_seqno != dp->dccps_gsr) { |
522 | opt_recv->ccid3or_seqno = dp->dccps_gsr; | 496 | opt_recv->ccid3or_seqno = dp->dccps_gsr; |
523 | opt_recv->ccid3or_loss_event_rate = ~0; | 497 | opt_recv->ccid3or_loss_event_rate = ~0; |
@@ -572,11 +546,10 @@ static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk) | |||
572 | { | 546 | { |
573 | struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid); | 547 | struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid); |
574 | 548 | ||
575 | hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; | 549 | hctx->state = TFRC_SSTATE_NO_SENT; |
576 | hctx->ccid3hctx_hist = NULL; | 550 | hctx->hist = NULL; |
577 | setup_timer(&hctx->ccid3hctx_no_feedback_timer, | 551 | setup_timer(&hctx->no_feedback_timer, |
578 | ccid3_hc_tx_no_feedback_timer, (unsigned long)sk); | 552 | ccid3_hc_tx_no_feedback_timer, (unsigned long)sk); |
579 | |||
580 | return 0; | 553 | return 0; |
581 | } | 554 | } |
582 | 555 | ||
@@ -585,9 +558,9 @@ static void ccid3_hc_tx_exit(struct sock *sk) | |||
585 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 558 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
586 | 559 | ||
587 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); | 560 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); |
588 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); | 561 | sk_stop_timer(sk, &hctx->no_feedback_timer); |
589 | 562 | ||
590 | tfrc_tx_hist_purge(&hctx->ccid3hctx_hist); | 563 | tfrc_tx_hist_purge(&hctx->hist); |
591 | } | 564 | } |
592 | 565 | ||
593 | static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) | 566 | static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) |
@@ -599,14 +572,15 @@ static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) | |||
599 | return; | 572 | return; |
600 | 573 | ||
601 | hctx = ccid3_hc_tx_sk(sk); | 574 | hctx = ccid3_hc_tx_sk(sk); |
602 | info->tcpi_rto = hctx->ccid3hctx_t_rto; | 575 | info->tcpi_rto = hctx->t_rto; |
603 | info->tcpi_rtt = hctx->ccid3hctx_rtt; | 576 | info->tcpi_rtt = hctx->rtt; |
604 | } | 577 | } |
605 | 578 | ||
606 | static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len, | 579 | static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len, |
607 | u32 __user *optval, int __user *optlen) | 580 | u32 __user *optval, int __user *optlen) |
608 | { | 581 | { |
609 | const struct ccid3_hc_tx_sock *hctx; | 582 | const struct ccid3_hc_tx_sock *hctx; |
583 | struct tfrc_tx_info tfrc; | ||
610 | const void *val; | 584 | const void *val; |
611 | 585 | ||
612 | /* Listen socks doesn't have a private CCID block */ | 586 | /* Listen socks doesn't have a private CCID block */ |
@@ -616,10 +590,17 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len, | |||
616 | hctx = ccid3_hc_tx_sk(sk); | 590 | hctx = ccid3_hc_tx_sk(sk); |
617 | switch (optname) { | 591 | switch (optname) { |
618 | case DCCP_SOCKOPT_CCID_TX_INFO: | 592 | case DCCP_SOCKOPT_CCID_TX_INFO: |
619 | if (len < sizeof(hctx->ccid3hctx_tfrc)) | 593 | if (len < sizeof(tfrc)) |
620 | return -EINVAL; | 594 | return -EINVAL; |
621 | len = sizeof(hctx->ccid3hctx_tfrc); | 595 | tfrc.tfrctx_x = hctx->x; |
622 | val = &hctx->ccid3hctx_tfrc; | 596 | tfrc.tfrctx_x_recv = hctx->x_recv; |
597 | tfrc.tfrctx_x_calc = hctx->x_calc; | ||
598 | tfrc.tfrctx_rtt = hctx->rtt; | ||
599 | tfrc.tfrctx_p = hctx->p; | ||
600 | tfrc.tfrctx_rto = hctx->t_rto; | ||
601 | tfrc.tfrctx_ipi = hctx->t_ipi; | ||
602 | len = sizeof(tfrc); | ||
603 | val = &tfrc; | ||
623 | break; | 604 | break; |
624 | default: | 605 | default: |
625 | return -ENOPROTOOPT; | 606 | return -ENOPROTOOPT; |
@@ -660,13 +641,13 @@ static void ccid3_hc_rx_set_state(struct sock *sk, | |||
660 | enum ccid3_hc_rx_states state) | 641 | enum ccid3_hc_rx_states state) |
661 | { | 642 | { |
662 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); | 643 | struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); |
663 | enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; | 644 | enum ccid3_hc_rx_states oldstate = hcrx->state; |
664 | 645 | ||
665 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", | 646 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", |
666 | dccp_role(sk), sk, ccid3_rx_state_name(oldstate), | 647 | dccp_role(sk), sk, ccid3_rx_state_name(oldstate), |
667 | ccid3_rx_state_name(state)); | 648 | ccid3_rx_state_name(state)); |
668 | WARN_ON(state == oldstate); | 649 | WARN_ON(state == oldstate); |
669 | hcrx->ccid3hcrx_state = state; | 650 | hcrx->state = state; |
670 | } | 651 | } |
671 | 652 | ||
672 | static void ccid3_hc_rx_send_feedback(struct sock *sk, | 653 | static void ccid3_hc_rx_send_feedback(struct sock *sk, |
@@ -678,15 +659,15 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk, | |||
678 | ktime_t now; | 659 | ktime_t now; |
679 | s64 delta = 0; | 660 | s64 delta = 0; |
680 | 661 | ||
681 | if (unlikely(hcrx->ccid3hcrx_state == TFRC_RSTATE_TERM)) | 662 | if (unlikely(hcrx->state == TFRC_RSTATE_TERM)) |
682 | return; | 663 | return; |
683 | 664 | ||
684 | now = ktime_get_real(); | 665 | now = ktime_get_real(); |
685 | 666 | ||
686 | switch (fbtype) { | 667 | switch (fbtype) { |
687 | case CCID3_FBACK_INITIAL: | 668 | case CCID3_FBACK_INITIAL: |
688 | hcrx->ccid3hcrx_x_recv = 0; | 669 | hcrx->x_recv = 0; |
689 | hcrx->ccid3hcrx_pinv = ~0U; /* see RFC 4342, 8.5 */ | 670 | hcrx->p_inverse = ~0U; /* see RFC 4342, 8.5 */ |
690 | break; | 671 | break; |
691 | case CCID3_FBACK_PARAM_CHANGE: | 672 | case CCID3_FBACK_PARAM_CHANGE: |
692 | /* | 673 | /* |
@@ -699,27 +680,26 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk, | |||
699 | * the number of bytes since last feedback. | 680 | * the number of bytes since last feedback. |
700 | * This is a safe fallback, since X is bounded above by X_calc. | 681 | * This is a safe fallback, since X is bounded above by X_calc. |
701 | */ | 682 | */ |
702 | if (hcrx->ccid3hcrx_x_recv > 0) | 683 | if (hcrx->x_recv > 0) |
703 | break; | 684 | break; |
704 | /* fall through */ | 685 | /* fall through */ |
705 | case CCID3_FBACK_PERIODIC: | 686 | case CCID3_FBACK_PERIODIC: |
706 | delta = ktime_us_delta(now, hcrx->ccid3hcrx_tstamp_last_feedback); | 687 | delta = ktime_us_delta(now, hcrx->tstamp_last_feedback); |
707 | if (delta <= 0) | 688 | if (delta <= 0) |
708 | DCCP_BUG("delta (%ld) <= 0", (long)delta); | 689 | DCCP_BUG("delta (%ld) <= 0", (long)delta); |
709 | else | 690 | else |
710 | hcrx->ccid3hcrx_x_recv = | 691 | hcrx->x_recv = scaled_div32(hcrx->bytes_recv, delta); |
711 | scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta); | ||
712 | break; | 692 | break; |
713 | default: | 693 | default: |
714 | return; | 694 | return; |
715 | } | 695 | } |
716 | 696 | ||
717 | ccid3_pr_debug("Interval %ldusec, X_recv=%u, 1/p=%u\n", (long)delta, | 697 | ccid3_pr_debug("Interval %ldusec, X_recv=%u, 1/p=%u\n", |
718 | hcrx->ccid3hcrx_x_recv, hcrx->ccid3hcrx_pinv); | 698 | (long)delta, hcrx->x_recv, hcrx->p_inverse); |
719 | 699 | ||
720 | hcrx->ccid3hcrx_tstamp_last_feedback = now; | 700 | hcrx->tstamp_last_feedback = now; |
721 | hcrx->ccid3hcrx_last_counter = dccp_hdr(skb)->dccph_ccval; | 701 | hcrx->last_counter = dccp_hdr(skb)->dccph_ccval; |
722 | hcrx->ccid3hcrx_bytes_recv = 0; | 702 | hcrx->bytes_recv = 0; |
723 | 703 | ||
724 | dp->dccps_hc_rx_insert_options = 1; | 704 | dp->dccps_hc_rx_insert_options = 1; |
725 | dccp_send_ack(sk); | 705 | dccp_send_ack(sk); |
@@ -738,8 +718,8 @@ static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) | |||
738 | if (dccp_packet_without_ack(skb)) | 718 | if (dccp_packet_without_ack(skb)) |
739 | return 0; | 719 | return 0; |
740 | 720 | ||
741 | x_recv = htonl(hcrx->ccid3hcrx_x_recv); | 721 | x_recv = htonl(hcrx->x_recv); |
742 | pinv = htonl(hcrx->ccid3hcrx_pinv); | 722 | pinv = htonl(hcrx->p_inverse); |
743 | 723 | ||
744 | if (dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, | 724 | if (dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, |
745 | &pinv, sizeof(pinv)) || | 725 | &pinv, sizeof(pinv)) || |
@@ -765,22 +745,23 @@ static u32 ccid3_first_li(struct sock *sk) | |||
765 | u32 x_recv, p, delta; | 745 | u32 x_recv, p, delta; |
766 | u64 fval; | 746 | u64 fval; |
767 | 747 | ||
768 | if (hcrx->ccid3hcrx_rtt == 0) { | 748 | if (hcrx->rtt == 0) { |
769 | DCCP_WARN("No RTT estimate available, using fallback RTT\n"); | 749 | DCCP_WARN("No RTT estimate available, using fallback RTT\n"); |
770 | hcrx->ccid3hcrx_rtt = DCCP_FALLBACK_RTT; | 750 | hcrx->rtt = DCCP_FALLBACK_RTT; |
771 | } | 751 | } |
772 | 752 | ||
773 | delta = ktime_to_us(net_timedelta(hcrx->ccid3hcrx_tstamp_last_feedback)); | 753 | delta = ktime_to_us(net_timedelta(hcrx->tstamp_last_feedback)); |
774 | x_recv = scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta); | 754 | x_recv = scaled_div32(hcrx->bytes_recv, delta); |
775 | if (x_recv == 0) { /* would also trigger divide-by-zero */ | 755 | if (x_recv == 0) { /* would also trigger divide-by-zero */ |
776 | DCCP_WARN("X_recv==0\n"); | 756 | DCCP_WARN("X_recv==0\n"); |
777 | if ((x_recv = hcrx->ccid3hcrx_x_recv) == 0) { | 757 | if (hcrx->x_recv == 0) { |
778 | DCCP_BUG("stored value of X_recv is zero"); | 758 | DCCP_BUG("stored value of X_recv is zero"); |
779 | return ~0U; | 759 | return ~0U; |
780 | } | 760 | } |
761 | x_recv = hcrx->x_recv; | ||
781 | } | 762 | } |
782 | 763 | ||
783 | fval = scaled_div(hcrx->ccid3hcrx_s, hcrx->ccid3hcrx_rtt); | 764 | fval = scaled_div(hcrx->s, hcrx->rtt); |
784 | fval = scaled_div32(fval, x_recv); | 765 | fval = scaled_div32(fval, x_recv); |
785 | p = tfrc_calc_x_reverse_lookup(fval); | 766 | p = tfrc_calc_x_reverse_lookup(fval); |
786 | 767 | ||
@@ -797,14 +778,14 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
797 | const u64 ndp = dccp_sk(sk)->dccps_options_received.dccpor_ndp; | 778 | const u64 ndp = dccp_sk(sk)->dccps_options_received.dccpor_ndp; |
798 | const bool is_data_packet = dccp_data_packet(skb); | 779 | const bool is_data_packet = dccp_data_packet(skb); |
799 | 780 | ||
800 | if (unlikely(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)) { | 781 | if (unlikely(hcrx->state == TFRC_RSTATE_NO_DATA)) { |
801 | if (is_data_packet) { | 782 | if (is_data_packet) { |
802 | const u32 payload = skb->len - dccp_hdr(skb)->dccph_doff * 4; | 783 | const u32 payload = skb->len - dccp_hdr(skb)->dccph_doff * 4; |
803 | do_feedback = CCID3_FBACK_INITIAL; | 784 | do_feedback = CCID3_FBACK_INITIAL; |
804 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); | 785 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); |
805 | hcrx->ccid3hcrx_s = payload; | 786 | hcrx->s = payload; |
806 | /* | 787 | /* |
807 | * Not necessary to update ccid3hcrx_bytes_recv here, | 788 | * Not necessary to update bytes_recv here, |
808 | * since X_recv = 0 for the first feedback packet (cf. | 789 | * since X_recv = 0 for the first feedback packet (cf. |
809 | * RFC 3448, 6.3) -- gerrit | 790 | * RFC 3448, 6.3) -- gerrit |
810 | */ | 791 | */ |
@@ -812,7 +793,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
812 | goto update_records; | 793 | goto update_records; |
813 | } | 794 | } |
814 | 795 | ||
815 | if (tfrc_rx_hist_duplicate(&hcrx->ccid3hcrx_hist, skb)) | 796 | if (tfrc_rx_hist_duplicate(&hcrx->hist, skb)) |
816 | return; /* done receiving */ | 797 | return; /* done receiving */ |
817 | 798 | ||
818 | if (is_data_packet) { | 799 | if (is_data_packet) { |
@@ -820,20 +801,20 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
820 | /* | 801 | /* |
821 | * Update moving-average of s and the sum of received payload bytes | 802 | * Update moving-average of s and the sum of received payload bytes |
822 | */ | 803 | */ |
823 | hcrx->ccid3hcrx_s = tfrc_ewma(hcrx->ccid3hcrx_s, payload, 9); | 804 | hcrx->s = tfrc_ewma(hcrx->s, payload, 9); |
824 | hcrx->ccid3hcrx_bytes_recv += payload; | 805 | hcrx->bytes_recv += payload; |
825 | } | 806 | } |
826 | 807 | ||
827 | /* | 808 | /* |
828 | * Perform loss detection and handle pending losses | 809 | * Perform loss detection and handle pending losses |
829 | */ | 810 | */ |
830 | if (tfrc_rx_handle_loss(&hcrx->ccid3hcrx_hist, &hcrx->ccid3hcrx_li_hist, | 811 | if (tfrc_rx_handle_loss(&hcrx->hist, &hcrx->li_hist, |
831 | skb, ndp, ccid3_first_li, sk)) { | 812 | skb, ndp, ccid3_first_li, sk)) { |
832 | do_feedback = CCID3_FBACK_PARAM_CHANGE; | 813 | do_feedback = CCID3_FBACK_PARAM_CHANGE; |
833 | goto done_receiving; | 814 | goto done_receiving; |
834 | } | 815 | } |
835 | 816 | ||
836 | if (tfrc_rx_hist_loss_pending(&hcrx->ccid3hcrx_hist)) | 817 | if (tfrc_rx_hist_loss_pending(&hcrx->hist)) |
837 | return; /* done receiving */ | 818 | return; /* done receiving */ |
838 | 819 | ||
839 | /* | 820 | /* |
@@ -842,17 +823,17 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
842 | if (unlikely(!is_data_packet)) | 823 | if (unlikely(!is_data_packet)) |
843 | goto update_records; | 824 | goto update_records; |
844 | 825 | ||
845 | if (!tfrc_lh_is_initialised(&hcrx->ccid3hcrx_li_hist)) { | 826 | if (!tfrc_lh_is_initialised(&hcrx->li_hist)) { |
846 | const u32 sample = tfrc_rx_hist_sample_rtt(&hcrx->ccid3hcrx_hist, skb); | 827 | const u32 sample = tfrc_rx_hist_sample_rtt(&hcrx->hist, skb); |
847 | /* | 828 | /* |
848 | * Empty loss history: no loss so far, hence p stays 0. | 829 | * Empty loss history: no loss so far, hence p stays 0. |
849 | * Sample RTT values, since an RTT estimate is required for the | 830 | * Sample RTT values, since an RTT estimate is required for the |
850 | * computation of p when the first loss occurs; RFC 3448, 6.3.1. | 831 | * computation of p when the first loss occurs; RFC 3448, 6.3.1. |
851 | */ | 832 | */ |
852 | if (sample != 0) | 833 | if (sample != 0) |
853 | hcrx->ccid3hcrx_rtt = tfrc_ewma(hcrx->ccid3hcrx_rtt, sample, 9); | 834 | hcrx->rtt = tfrc_ewma(hcrx->rtt, sample, 9); |
854 | 835 | ||
855 | } else if (tfrc_lh_update_i_mean(&hcrx->ccid3hcrx_li_hist, skb)) { | 836 | } else if (tfrc_lh_update_i_mean(&hcrx->li_hist, skb)) { |
856 | /* | 837 | /* |
857 | * Step (3) of [RFC 3448, 6.1]: Recompute I_mean and, if I_mean | 838 | * Step (3) of [RFC 3448, 6.1]: Recompute I_mean and, if I_mean |
858 | * has decreased (resp. p has increased), send feedback now. | 839 | * has decreased (resp. p has increased), send feedback now. |
@@ -863,11 +844,11 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
863 | /* | 844 | /* |
864 | * Check if the periodic once-per-RTT feedback is due; RFC 4342, 10.3 | 845 | * Check if the periodic once-per-RTT feedback is due; RFC 4342, 10.3 |
865 | */ | 846 | */ |
866 | if (SUB16(dccp_hdr(skb)->dccph_ccval, hcrx->ccid3hcrx_last_counter) > 3) | 847 | if (SUB16(dccp_hdr(skb)->dccph_ccval, hcrx->last_counter) > 3) |
867 | do_feedback = CCID3_FBACK_PERIODIC; | 848 | do_feedback = CCID3_FBACK_PERIODIC; |
868 | 849 | ||
869 | update_records: | 850 | update_records: |
870 | tfrc_rx_hist_add_packet(&hcrx->ccid3hcrx_hist, skb, ndp); | 851 | tfrc_rx_hist_add_packet(&hcrx->hist, skb, ndp); |
871 | 852 | ||
872 | done_receiving: | 853 | done_receiving: |
873 | if (do_feedback) | 854 | if (do_feedback) |
@@ -878,9 +859,9 @@ static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk) | |||
878 | { | 859 | { |
879 | struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid); | 860 | struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid); |
880 | 861 | ||
881 | hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; | 862 | hcrx->state = TFRC_RSTATE_NO_DATA; |
882 | tfrc_lh_init(&hcrx->ccid3hcrx_li_hist); | 863 | tfrc_lh_init(&hcrx->li_hist); |
883 | return tfrc_rx_hist_alloc(&hcrx->ccid3hcrx_hist); | 864 | return tfrc_rx_hist_alloc(&hcrx->hist); |
884 | } | 865 | } |
885 | 866 | ||
886 | static void ccid3_hc_rx_exit(struct sock *sk) | 867 | static void ccid3_hc_rx_exit(struct sock *sk) |
@@ -889,8 +870,8 @@ static void ccid3_hc_rx_exit(struct sock *sk) | |||
889 | 870 | ||
890 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); | 871 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); |
891 | 872 | ||
892 | tfrc_rx_hist_purge(&hcrx->ccid3hcrx_hist); | 873 | tfrc_rx_hist_purge(&hcrx->hist); |
893 | tfrc_lh_cleanup(&hcrx->ccid3hcrx_li_hist); | 874 | tfrc_lh_cleanup(&hcrx->li_hist); |
894 | } | 875 | } |
895 | 876 | ||
896 | static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) | 877 | static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) |
@@ -902,9 +883,9 @@ static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) | |||
902 | return; | 883 | return; |
903 | 884 | ||
904 | hcrx = ccid3_hc_rx_sk(sk); | 885 | hcrx = ccid3_hc_rx_sk(sk); |
905 | info->tcpi_ca_state = hcrx->ccid3hcrx_state; | 886 | info->tcpi_ca_state = hcrx->state; |
906 | info->tcpi_options |= TCPI_OPT_TIMESTAMPS; | 887 | info->tcpi_options |= TCPI_OPT_TIMESTAMPS; |
907 | info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt; | 888 | info->tcpi_rcv_rtt = hcrx->rtt; |
908 | } | 889 | } |
909 | 890 | ||
910 | static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len, | 891 | static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len, |
@@ -923,10 +904,10 @@ static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len, | |||
923 | case DCCP_SOCKOPT_CCID_RX_INFO: | 904 | case DCCP_SOCKOPT_CCID_RX_INFO: |
924 | if (len < sizeof(rx_info)) | 905 | if (len < sizeof(rx_info)) |
925 | return -EINVAL; | 906 | return -EINVAL; |
926 | rx_info.tfrcrx_x_recv = hcrx->ccid3hcrx_x_recv; | 907 | rx_info.tfrcrx_x_recv = hcrx->x_recv; |
927 | rx_info.tfrcrx_rtt = hcrx->ccid3hcrx_rtt; | 908 | rx_info.tfrcrx_rtt = hcrx->rtt; |
928 | rx_info.tfrcrx_p = hcrx->ccid3hcrx_pinv == 0 ? ~0U : | 909 | rx_info.tfrcrx_p = hcrx->p_inverse == 0 ? ~0U : |
929 | scaled_div(1, hcrx->ccid3hcrx_pinv); | 910 | scaled_div(1, hcrx->p_inverse); |
930 | len = sizeof(rx_info); | 911 | len = sizeof(rx_info); |
931 | val = &rx_info; | 912 | val = &rx_info; |
932 | break; | 913 | break; |
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h index 49ca32bd7e79..0cfcfff8f5fb 100644 --- a/net/dccp/ccids/ccid3.h +++ b/net/dccp/ccids/ccid3.h | |||
@@ -77,44 +77,43 @@ enum ccid3_hc_tx_states { | |||
77 | 77 | ||
78 | /** struct ccid3_hc_tx_sock - CCID3 sender half-connection socket | 78 | /** struct ccid3_hc_tx_sock - CCID3 sender half-connection socket |
79 | * | 79 | * |
80 | * @ccid3hctx_x - Current sending rate in 64 * bytes per second | 80 | * @x - Current sending rate in 64 * bytes per second |
81 | * @ccid3hctx_x_recv - Receive rate in 64 * bytes per second | 81 | * @x_recv - Receive rate in 64 * bytes per second |
82 | * @ccid3hctx_x_calc - Calculated rate in bytes per second | 82 | * @x_calc - Calculated rate in bytes per second |
83 | * @ccid3hctx_rtt - Estimate of current round trip time in usecs | 83 | * @rtt - Estimate of current round trip time in usecs |
84 | * @ccid3hctx_p - Current loss event rate (0-1) scaled by 1000000 | 84 | * @p - Current loss event rate (0-1) scaled by 1000000 |
85 | * @ccid3hctx_s - Packet size in bytes | 85 | * @s - Packet size in bytes |
86 | * @ccid3hctx_t_rto - Nofeedback Timer setting in usecs | 86 | * @t_rto - Nofeedback Timer setting in usecs |
87 | * @ccid3hctx_t_ipi - Interpacket (send) interval (RFC 3448, 4.6) in usecs | 87 | * @t_ipi - Interpacket (send) interval (RFC 3448, 4.6) in usecs |
88 | * @ccid3hctx_state - Sender state, one of %ccid3_hc_tx_states | 88 | * @state - Sender state, one of %ccid3_hc_tx_states |
89 | * @ccid3hctx_last_win_count - Last window counter sent | 89 | * @last_win_count - Last window counter sent |
90 | * @ccid3hctx_t_last_win_count - Timestamp of earliest packet | 90 | * @t_last_win_count - Timestamp of earliest packet with |
91 | * with last_win_count value sent | 91 | * last_win_count value sent |
92 | * @ccid3hctx_no_feedback_timer - Handle to no feedback timer | 92 | * @no_feedback_timer - Handle to no feedback timer |
93 | * @ccid3hctx_t_ld - Time last doubled during slow start | 93 | * @t_ld - Time last doubled during slow start |
94 | * @ccid3hctx_t_nom - Nominal send time of next packet | 94 | * @t_nom - Nominal send time of next packet |
95 | * @ccid3hctx_delta - Send timer delta (RFC 3448, 4.6) in usecs | 95 | * @delta - Send timer delta (RFC 3448, 4.6) in usecs |
96 | * @ccid3hctx_hist - Packet history | 96 | * @hist - Packet history |
97 | * @ccid3hctx_options_received - Parsed set of retrieved options | 97 | * @options_received - Parsed set of retrieved options |
98 | */ | 98 | */ |
99 | struct ccid3_hc_tx_sock { | 99 | struct ccid3_hc_tx_sock { |
100 | struct tfrc_tx_info ccid3hctx_tfrc; | 100 | u64 x; |
101 | #define ccid3hctx_x ccid3hctx_tfrc.tfrctx_x | 101 | u64 x_recv; |
102 | #define ccid3hctx_x_recv ccid3hctx_tfrc.tfrctx_x_recv | 102 | u32 x_calc; |
103 | #define ccid3hctx_x_calc ccid3hctx_tfrc.tfrctx_x_calc | 103 | u32 rtt; |
104 | #define ccid3hctx_rtt ccid3hctx_tfrc.tfrctx_rtt | 104 | u32 p; |
105 | #define ccid3hctx_p ccid3hctx_tfrc.tfrctx_p | 105 | u32 t_rto; |
106 | #define ccid3hctx_t_rto ccid3hctx_tfrc.tfrctx_rto | 106 | u32 t_ipi; |
107 | #define ccid3hctx_t_ipi ccid3hctx_tfrc.tfrctx_ipi | 107 | u16 s; |
108 | u16 ccid3hctx_s; | 108 | enum ccid3_hc_tx_states state:8; |
109 | enum ccid3_hc_tx_states ccid3hctx_state:8; | 109 | u8 last_win_count; |
110 | u8 ccid3hctx_last_win_count; | 110 | ktime_t t_last_win_count; |
111 | ktime_t ccid3hctx_t_last_win_count; | 111 | struct timer_list no_feedback_timer; |
112 | struct timer_list ccid3hctx_no_feedback_timer; | 112 | ktime_t t_ld; |
113 | ktime_t ccid3hctx_t_ld; | 113 | ktime_t t_nom; |
114 | ktime_t ccid3hctx_t_nom; | 114 | u32 delta; |
115 | u32 ccid3hctx_delta; | 115 | struct tfrc_tx_hist_entry *hist; |
116 | struct tfrc_tx_hist_entry *ccid3hctx_hist; | 116 | struct ccid3_options_received options_received; |
117 | struct ccid3_options_received ccid3hctx_options_received; | ||
118 | }; | 117 | }; |
119 | 118 | ||
120 | static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) | 119 | static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) |
@@ -133,32 +132,32 @@ enum ccid3_hc_rx_states { | |||
133 | 132 | ||
134 | /** struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket | 133 | /** struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket |
135 | * | 134 | * |
136 | * @ccid3hcrx_x_recv - Receiver estimate of send rate (RFC 3448 4.3) | 135 | * @x_recv - Receiver estimate of send rate (RFC 3448 4.3) |
137 | * @ccid3hcrx_rtt - Receiver estimate of rtt (non-standard) | 136 | * @rtt - Receiver estimate of rtt (non-standard) |
138 | * @ccid3hcrx_p - Current loss event rate (RFC 3448 5.4) | 137 | * @p - Current loss event rate (RFC 3448 5.4) |
139 | * @ccid3hcrx_last_counter - Tracks window counter (RFC 4342, 8.1) | 138 | * @last_counter - Tracks window counter (RFC 4342, 8.1) |
140 | * @ccid3hcrx_state - Receiver state, one of %ccid3_hc_rx_states | 139 | * @state - Receiver state, one of %ccid3_hc_rx_states |
141 | * @ccid3hcrx_bytes_recv - Total sum of DCCP payload bytes | 140 | * @bytes_recv - Total sum of DCCP payload bytes |
142 | * @ccid3hcrx_x_recv - Receiver estimate of send rate (RFC 3448, sec. 4.3) | 141 | * @x_recv - Receiver estimate of send rate (RFC 3448, sec. 4.3) |
143 | * @ccid3hcrx_rtt - Receiver estimate of RTT | 142 | * @rtt - Receiver estimate of RTT |
144 | * @ccid3hcrx_tstamp_last_feedback - Time at which last feedback was sent | 143 | * @tstamp_last_feedback - Time at which last feedback was sent |
145 | * @ccid3hcrx_tstamp_last_ack - Time at which last feedback was sent | 144 | * @tstamp_last_ack - Time at which last feedback was sent |
146 | * @ccid3hcrx_hist - Packet history (loss detection + RTT sampling) | 145 | * @hist - Packet history (loss detection + RTT sampling) |
147 | * @ccid3hcrx_li_hist - Loss Interval database | 146 | * @li_hist - Loss Interval database |
148 | * @ccid3hcrx_s - Received packet size in bytes | 147 | * @s - Received packet size in bytes |
149 | * @ccid3hcrx_pinv - Inverse of Loss Event Rate (RFC 4342, sec. 8.5) | 148 | * @p_inverse - Inverse of Loss Event Rate (RFC 4342, sec. 8.5) |
150 | */ | 149 | */ |
151 | struct ccid3_hc_rx_sock { | 150 | struct ccid3_hc_rx_sock { |
152 | u8 ccid3hcrx_last_counter:4; | 151 | u8 last_counter:4; |
153 | enum ccid3_hc_rx_states ccid3hcrx_state:8; | 152 | enum ccid3_hc_rx_states state:8; |
154 | u32 ccid3hcrx_bytes_recv; | 153 | u32 bytes_recv; |
155 | u32 ccid3hcrx_x_recv; | 154 | u32 x_recv; |
156 | u32 ccid3hcrx_rtt; | 155 | u32 rtt; |
157 | ktime_t ccid3hcrx_tstamp_last_feedback; | 156 | ktime_t tstamp_last_feedback; |
158 | struct tfrc_rx_hist ccid3hcrx_hist; | 157 | struct tfrc_rx_hist hist; |
159 | struct tfrc_loss_hist ccid3hcrx_li_hist; | 158 | struct tfrc_loss_hist li_hist; |
160 | u16 ccid3hcrx_s; | 159 | u16 s; |
161 | #define ccid3hcrx_pinv ccid3hcrx_li_hist.i_mean | 160 | #define p_inverse li_hist.i_mean |
162 | }; | 161 | }; |
163 | 162 | ||
164 | static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) | 163 | static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) |