6c80eaa4beb5480b496ed9b78cd34feaf2e0a09d
[openwrt/openwrt.git] / target / linux / generic / backport-4.14 / 025-tcp-allow-drivers-to-tweak-TSQ-logic.patch
1 From: Eric Dumazet <edumazet@google.com>
2 Date: Sat, 11 Nov 2017 15:54:12 -0800
3 Subject: [PATCH] tcp: allow drivers to tweak TSQ logic
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 I had many reports that TSQ logic breaks wifi aggregation.
9
10 Current logic is to allow up to 1 ms of bytes to be queued into qdisc
11 and drivers queues.
12
13 But Wifi aggregation needs a bigger budget to allow bigger rates to
14 be discovered by various TCP Congestion Controls algorithms.
15
16 This patch adds an extra socket field, allowing wifi drivers to select
17 another log scale to derive TCP Small Queue credit from current pacing
18 rate.
19
20 Initial value is 10, meaning that this patch does not change current
21 behavior.
22
23 We expect wifi drivers to set this field to smaller values (tests have
24 been done with values from 6 to 9)
25
26 They would have to use following template :
27
28 if (skb->sk && skb->sk->sk_pacing_shift != MY_PACING_SHIFT)
29 skb->sk->sk_pacing_shift = MY_PACING_SHIFT;
30
31 Ref: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1670041
32 Signed-off-by: Eric Dumazet <edumazet@google.com>
33 Cc: Johannes Berg <johannes.berg@intel.com>
34 Cc: Toke Høiland-Jørgensen <toke@toke.dk>
35 Cc: Kir Kolyshkin <kir@openvz.org>
36 ---
37 --- a/include/net/sock.h
38 +++ b/include/net/sock.h
39 @@ -267,6 +267,7 @@ struct sock_common {
40 * @sk_gso_type: GSO type (e.g. %SKB_GSO_TCPV4)
41 * @sk_gso_max_size: Maximum GSO segment size to build
42 * @sk_gso_max_segs: Maximum number of GSO segments
43 + * @sk_pacing_shift: scaling factor for TCP Small Queues
44 * @sk_lingertime: %SO_LINGER l_linger setting
45 * @sk_backlog: always used with the per-socket spinlock held
46 * @sk_callback_lock: used with the callbacks in the end of this struct
47 @@ -448,6 +449,8 @@ struct sock {
48 kmemcheck_bitfield_end(flags);
49
50 u16 sk_gso_max_segs;
51 +#define sk_pacing_shift sk_pacing_shift /* for backport checks */
52 + u8 sk_pacing_shift;
53 unsigned long sk_lingertime;
54 struct proto *sk_prot_creator;
55 rwlock_t sk_callback_lock;
56 --- a/net/core/sock.c
57 +++ b/net/core/sock.c
58 @@ -2741,6 +2741,7 @@ void sock_init_data(struct socket *sock,
59
60 sk->sk_max_pacing_rate = ~0U;
61 sk->sk_pacing_rate = ~0U;
62 + sk->sk_pacing_shift = 10;
63 sk->sk_incoming_cpu = -1;
64 /*
65 * Before updating sk_refcnt, we must commit prior changes to memory
66 --- a/net/ipv4/tcp_output.c
67 +++ b/net/ipv4/tcp_output.c
68 @@ -1671,7 +1671,7 @@ u32 tcp_tso_autosize(const struct sock *
69 {
70 u32 bytes, segs;
71
72 - bytes = min(sk->sk_pacing_rate >> 10,
73 + bytes = min(sk->sk_pacing_rate >> sk->sk_pacing_shift,
74 sk->sk_gso_max_size - 1 - MAX_TCP_HEADER);
75
76 /* Goal is to send at least one packet per ms,
77 @@ -2145,7 +2145,7 @@ static bool tcp_small_queue_check(struct
78 {
79 unsigned int limit;
80
81 - limit = max(2 * skb->truesize, sk->sk_pacing_rate >> 10);
82 + limit = max(2 * skb->truesize, sk->sk_pacing_rate >> sk->sk_pacing_shift);
83 limit = min_t(u32, limit, sysctl_tcp_limit_output_bytes);
84 limit <<= factor;
85