mac80211: Update to version 4.19.221
[librecmc/librecmc.git] / package / kernel / mac80211 / patches / subsys / 354-mac80211-calculate-hash-for-fq-without-holding-fq-lo.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 16 Mar 2019 17:57:38 +0100
3 Subject: [PATCH] mac80211: calculate hash for fq without holding fq->lock
4  in itxq enqueue
5
6 Reduces lock contention on enqueue/dequeue of iTXQ packets
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10
11 --- a/include/net/fq_impl.h
12 +++ b/include/net/fq_impl.h
13 @@ -107,29 +107,31 @@ begin:
14         return skb;
15  }
16  
17 -static struct fq_flow *fq_flow_classify(struct fq *fq,
18 -                                       struct fq_tin *tin,
19 -                                       struct sk_buff *skb,
20 -                                       fq_flow_get_default_t get_default_func)
21 +static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb)
22  {
23 -       struct fq_flow *flow;
24 -       u32 hash;
25 -       u32 idx;
26 -
27 -       lockdep_assert_held(&fq->lock);
28 -
29  #if LINUX_VERSION_IS_GEQ(5,3,10) || \
30      LINUX_VERSION_IN_RANGE(4,19,83, 4,20,0) || \
31      LINUX_VERSION_IN_RANGE(4,14,153, 4,15,0) || \
32      LINUX_VERSION_IN_RANGE(4,9,200, 4,10,0) || \
33      LINUX_VERSION_IN_RANGE(4,4,200, 4,5,0)
34 -       hash = skb_get_hash_perturb(skb, &fq->perturbation);
35 +       u32 hash = skb_get_hash_perturb(skb, &fq->perturbation);
36  #else
37 -       hash = skb_get_hash_perturb(skb, fq->perturbation);
38 +       u32 hash = skb_get_hash_perturb(skb, fq->perturbation);
39  #endif
40 -       idx = reciprocal_scale(hash, fq->flows_cnt);
41 -       flow = &fq->flows[idx];
42  
43 +       return reciprocal_scale(hash, fq->flows_cnt);
44 +}
45 +
46 +static struct fq_flow *fq_flow_classify(struct fq *fq,
47 +                                       struct fq_tin *tin, u32 idx,
48 +                                       struct sk_buff *skb,
49 +                                       fq_flow_get_default_t get_default_func)
50 +{
51 +       struct fq_flow *flow;
52 +
53 +       lockdep_assert_held(&fq->lock);
54 +
55 +       flow = &fq->flows[idx];
56         if (flow->tin && flow->tin != tin) {
57                 flow = get_default_func(fq, tin, idx, skb);
58                 tin->collisions++;
59 @@ -161,7 +163,7 @@ static void fq_recalc_backlog(struct fq
60  }
61  
62  static void fq_tin_enqueue(struct fq *fq,
63 -                          struct fq_tin *tin,
64 +                          struct fq_tin *tin, u32 idx,
65                            struct sk_buff *skb,
66                            fq_skb_free_t free_func,
67                            fq_flow_get_default_t get_default_func)
68 @@ -171,7 +173,7 @@ static void fq_tin_enqueue(struct fq *fq
69  
70         lockdep_assert_held(&fq->lock);
71  
72 -       flow = fq_flow_classify(fq, tin, skb, get_default_func);
73 +       flow = fq_flow_classify(fq, tin, idx, skb, get_default_func);
74  
75         flow->tin = tin;
76         flow->backlog += skb->len;
77 --- a/net/mac80211/tx.c
78 +++ b/net/mac80211/tx.c
79 @@ -1396,11 +1396,15 @@ static void ieee80211_txq_enqueue(struct
80  {
81         struct fq *fq = &local->fq;
82         struct fq_tin *tin = &txqi->tin;
83 +       u32 flow_idx = fq_flow_idx(fq, skb);
84  
85         ieee80211_set_skb_enqueue_time(skb);
86 -       fq_tin_enqueue(fq, tin, skb,
87 +
88 +       spin_lock_bh(&fq->lock);
89 +       fq_tin_enqueue(fq, tin, flow_idx, skb,
90                        fq_skb_free_func,
91                        fq_flow_get_default_func);
92 +       spin_unlock_bh(&fq->lock);
93  }
94  
95  static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
96 @@ -1570,7 +1574,6 @@ static bool ieee80211_queue_skb(struct i
97                                 struct sta_info *sta,
98                                 struct sk_buff *skb)
99  {
100 -       struct fq *fq = &local->fq;
101         struct ieee80211_vif *vif;
102         struct txq_info *txqi;
103  
104 @@ -1588,9 +1591,7 @@ static bool ieee80211_queue_skb(struct i
105         if (!txqi)
106                 return false;
107  
108 -       spin_lock_bh(&fq->lock);
109         ieee80211_txq_enqueue(local, txqi, skb);
110 -       spin_unlock_bh(&fq->lock);
111  
112         schedule_and_wake_txq(local, txqi);
113  
114 @@ -3223,6 +3224,7 @@ static bool ieee80211_amsdu_aggregate(st
115         u8 max_subframes = sta->sta.max_amsdu_subframes;
116         int max_frags = local->hw.max_tx_fragments;
117         int max_amsdu_len = sta->sta.max_amsdu_len;
118 +       u32 flow_idx;
119         int orig_truesize;
120         __be16 len;
121         void *data;
122 @@ -3245,6 +3247,8 @@ static bool ieee80211_amsdu_aggregate(st
123                 max_amsdu_len = min_t(int, max_amsdu_len,
124                                       sta->sta.max_rc_amsdu_len);
125  
126 +       flow_idx = fq_flow_idx(fq, skb);
127 +
128         spin_lock_bh(&fq->lock);
129  
130         /* TODO: Ideally aggregation should be done on dequeue to remain
131 @@ -3252,7 +3256,8 @@ static bool ieee80211_amsdu_aggregate(st
132          */
133  
134         tin = &txqi->tin;
135 -       flow = fq_flow_classify(fq, tin, skb, fq_flow_get_default_func);
136 +       flow = fq_flow_classify(fq, tin, flow_idx, skb,
137 +                               fq_flow_get_default_func);
138         head = skb_peek_tail(&flow->queue);
139         if (!head)
140                 goto out;