2022-09-14 11:27:36

by Venkat Ch

[permalink] [raw]
Subject: [PATCH] wifi: mac80211: Fix performance issue with mutex_lock

From: Venkat Chimata <[email protected]>

OpenWiFi's ucentral agent periodically (typically 120 seconds)
issues nl80211 call to get associated client list from the
WLAN driver. Somehow this operation was causing tx/rx delays
sometimes and the video calls on connected clients are experiencing
jitter. The associated client list was protected by
a mutex lock. I saw that ieee80211_check_fast_xmit_all uses
rcu_read_lock and rcu_read_unlock to iterate through sta_list.
I took it as a refernce and changed the lock to rcu_read lock
from mutex.
Also saw this this comment just above sta_mutex declaration.
/* Station data */
/*
* The mutex only protects the list, hash table and
* counter, reads are done with RCU.
*/
struct mutex sta_mtx;

Hence tried changing mutex_lock(/unlock) in ieee80211_dump_station
to rcu_read_lock(/unlock) and it resolved the jitter issue in the
video calls.

Tests:
We had this issue show up consistently and the patch fixed the issue.
We spent a good part of 2 weeks following up on this and with this
fix, the video calls are smooth.

Also tested if this could cause any crashes with below mentioned
process.

1. Connect 3 clients
2. A script running dumping clients in an infinite loop
3. Continuously disconnect / connect one client to see if
there is any crash. No crash was observed.

Signed-off-by: Venkat Chimata <[email protected]>
---
net/mac80211/cfg.c | 6 ++----
net/mac80211/sta_info.c | 3 +--
2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 6a8350d..0b526b5 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -794,16 +794,14 @@ static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
struct sta_info *sta;
int ret = -ENOENT;

- mutex_lock(&local->sta_mtx);
-
+ rcu_read_lock();
sta = sta_info_get_by_idx(sdata, idx);
if (sta) {
ret = 0;
memcpy(mac, sta->sta.addr, ETH_ALEN);
sta_set_sinfo(sta, sinfo, true);
}
-
- mutex_unlock(&local->sta_mtx);
+ rcu_read_unlock();

return ret;
}
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 550a610..af6fa75 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -231,8 +231,7 @@ struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
struct sta_info *sta;
int i = 0;

- list_for_each_entry_rcu(sta, &local->sta_list, list,
- lockdep_is_held(&local->sta_mtx)) {
+ list_for_each_entry_rcu(sta, &local->sta_list, list) {
if (sdata != sta->sdata)
continue;
if (i < idx) {
--
2.34.1


2022-09-14 18:46:04

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] wifi: mac80211: Fix performance issue with mutex_lock

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on wireless-next/main]
[also build test WARNING on wireless/main linus/master v6.0-rc5 next-20220914]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/venkatch-gmail-com/wifi-mac80211-Fix-performance-issue-with-mutex_lock/20220914-191154
base: https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git main
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20220915/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/1d98b164c14462b445f932d0183b56ee716e1c41
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review venkatch-gmail-com/wifi-mac80211-Fix-performance-issue-with-mutex_lock/20220914-191154
git checkout 1d98b164c14462b445f932d0183b56ee716e1c41
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash net/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

net/mac80211/cfg.c: In function 'ieee80211_dump_station':
>> net/mac80211/cfg.c:858:33: warning: unused variable 'local' [-Wunused-variable]
858 | struct ieee80211_local *local = sdata->local;
| ^~~~~


vim +/local +858 net/mac80211/cfg.c

6b62bf326393de Thomas Pedersen 2012-03-05 853
c5dd9c2bd0b242 Luis Carlos Cobo 2008-02-23 854 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
c5dd9c2bd0b242 Luis Carlos Cobo 2008-02-23 855 int idx, u8 *mac, struct station_info *sinfo)
c5dd9c2bd0b242 Luis Carlos Cobo 2008-02-23 856 {
3b53fde8ac40c4 Johannes Berg 2009-11-16 857 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
66572cfc30a4b7 Victor Goldenshtein 2012-06-21 @858 struct ieee80211_local *local = sdata->local;
c5dd9c2bd0b242 Luis Carlos Cobo 2008-02-23 859 struct sta_info *sta;
d0709a65181beb Johannes Berg 2008-02-25 860 int ret = -ENOENT;
c5dd9c2bd0b242 Luis Carlos Cobo 2008-02-23 861
1d98b164c14462 Venkat Chimata 2022-09-14 862 rcu_read_lock();
3b53fde8ac40c4 Johannes Berg 2009-11-16 863 sta = sta_info_get_by_idx(sdata, idx);
d0709a65181beb Johannes Berg 2008-02-25 864 if (sta) {
d0709a65181beb Johannes Berg 2008-02-25 865 ret = 0;
17741cdc264e4d Johannes Berg 2008-09-11 866 memcpy(mac, sta->sta.addr, ETH_ALEN);
0fdf1493b41eb6 Johannes Berg 2018-05-18 867 sta_set_sinfo(sta, sinfo, true);
d0709a65181beb Johannes Berg 2008-02-25 868 }
1d98b164c14462 Venkat Chimata 2022-09-14 869 rcu_read_unlock();
d0709a65181beb Johannes Berg 2008-02-25 870
d0709a65181beb Johannes Berg 2008-02-25 871 return ret;
c5dd9c2bd0b242 Luis Carlos Cobo 2008-02-23 872 }
c5dd9c2bd0b242 Luis Carlos Cobo 2008-02-23 873

--
0-DAY CI Kernel Test Service
https://01.org/lkp