mac80211: Add per-sdata station hash, and sdata hash.
RFC 1/2 mac80211: Add per-sdata station hash, and sdata hash.
From: Ben Greear <[email protected]>
Add sdata hash (based on sdata->vif.addr) to local structure.
Add sta_vhash (based on sta->sta.addr) to sdata struct.
Make STA_HASH give a better hash spread more often.
Use new hashes where we can. Might be able to completely get rid of the local->sta_hash, but didn't want to try that quite yet.
This significantly improves performance when using lots of station VIFs connected to the same AP. It will likely help other cases where the old hash logic failed to create a decent spread.
---
:100644 100644 5672533... 41a6d20... M net/mac80211/ieee80211_i.h
:100644 100644 abcf363... 0969732... M net/mac80211/iface.c
:100644 100644 c6844ad... 362e126... M net/mac80211/rx.c
:100644 100644 238a0cc... 6b0fe74... M net/mac80211/sta_info.c
:100644 100644 4947341... c509423... M net/mac80211/sta_info.h
:100644 100644 4343920... 0ecab1a... M net/mac80211/status.c
net/mac80211/ieee80211_i.h | 34 ++++++++++++++++ net/mac80211/iface.c | 50 +++++++++++++++++++++++- net/mac80211/rx.c | 16 +++++++ net/mac80211/sta_info.c | 94 ++++++++++++++++++++++++++++++++++++-------- net/mac80211/sta_info.h | 17 +++++++- net/mac80211/status.c | 6 +++ 6 files changed, 197 insertions(+), 20 deletions(-)
net/mac80211/ieee80211_i.h +34 -0
@@ -675,6 +675,10 @@ struct ieee80211_chanctx {struct ieee80211_sub_if_data {struct list_head list; +struct ieee80211_sub_if_data *hnext;/* sdata hash list pointer */ + +/* Protected by local->sta_mtx */ +struct sta_info __rcu *sta_vhash[STA_HASH_SIZE ];/* By station addr */ struct wireless_dev wdev;
@@ -780,6 +784,34 @@ struct ieee80211_sub_if_data *vif_to_sdata(struct ieee80211_vif *p) return container_of(p, struct ieee80211_sub_if_data, vif); } +static inline +void for_each_sdata_type_check (struct ieee80211_local *local, +const u8 *addr, +struct ieee80211_sub_if_data *sdata, +struct ieee80211_sub_if_data *nxt) +{ +} + +/* This deals with multiple sdata having same MAC */ +#define for_each_sdata (local, _addr, _sdata, nxt) \ + for (/* initialise loop */ \ + _sdata =rcu_dereference (local->sdata_hash[STA_HASH (_addr)]), \ + nxt = _sdata ?rcu_dereference (_sdata->hnext) :NULL ; \ +/* typecheck */ \ +for_each_sdata_type_check (local, (_addr), _sdata, nxt), \ +/* continue condition */ \ + _sdata; \ +/* advance loop */ \ + _sdata = nxt, \ + nxt = _sdata ? rcu_dereference(_sdata->hnext) : NULL \ + ) \ +/* compare address and run code only if it matches */ \ +if (ether_addr_equal (_sdata->vif.addr, (_addr))) + + +struct ieee80211_sub_if_data* +ieee80211_find_sdata (struct ieee80211_local *local,const u8 *vif_addr); +static inline enum ieee80211_band ieee80211_get_sdata_band (struct ieee80211_sub_if_data *sdata) {
@@ -999,6 +1031,8 @@ struct ieee80211_local {u32 wep_iv;/* see iface.c */ +/* Hash interfaces by VIF mac addr */ +struct ieee80211_sub_if_data __rcu *sdata_hash[STA_HASH_SIZE ];struct list_head interfaces;struct mutex iflist_mtx;
net/mac80211/iface.c +49 -1
75 lines not on this page · raw message
net/mac80211/rx.c +16 -0
@@ -3152,6 +3152,21 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,if (ieee80211_is_data (fc)) { prev_sta =NULL ; +/* Check for Station VIFS by hashing on the destination MAC +* (ie, local sdata MAC). This changes 'promisc' behaviour, +* but not sure that is a bad thing. +*/ +if ((!is_multicast_ether_addr (hdr->addr1)) && + (local->monitors ==0 ) && (local->cooked_mntrs ==0 )) { + sta =sta_info_get_by_vif (local, hdr->addr1, + hdr->addr2); +if (sta) { + rx.sta = sta; + rx.sdata = sta->sdata; + goto rx_and_done; + } + } +for_each_sta_info (local, hdr->addr2, sta, tmp) {if (!prev_sta) { prev_sta = sta;
@@ -3169,6 +3184,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, rx.sta = prev_sta; rx.sdata = prev_sta->sdata; +rx_and_done:if (ieee80211_prepare_and_rx_handle (&rx, skb, true))return ; goto out;
net/mac80211/sta_info.c +77 -17
148 lines not on this page · raw message
net/mac80211/sta_info.h +15 -2
@@ -15,6 +15,7 @@#include <linux/workqueue.h> #include <linux/average.h> #include <linux/etherdevice.h> +#include <linux/hash.h> #include "key.h" /**
@@ -227,7 +228,8 @@ struct sta_ampdu_mlme {* mac80211 is communicating with. * * @list: global linked list entry -* @hnext: hash table linked list pointer +* @hnext: hash table linked list pointer, used by local->sta_hash +* @vnext: hash table linked list pointer, used by sdata->sta_vhash. * @local: pointer to the global information * @sdata: virtual interface this station belongs to * @ptk: peer key negotiated with this station, if any
@@ -304,6 +306,7 @@ struct sta_info {struct list_head list;struct rcu_head rcu_head;struct sta_info __rcu *hnext; +struct sta_info __rcu *vnext;struct ieee80211_local *local;struct ieee80211_sub_if_data *sdata;struct ieee80211_key __rcu *gtk[NUM_DEFAULT_KEYS +NUM_DEFAULT_MGMT_KEYS ];
@@ -484,7 +487,11 @@ rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid) }#define STA_HASH_SIZE 256 -#define STA_HASH (sta) (sta[5]) +static inline u32 STA_HASH (const unsigned char * addr) { +u32 v = (addr[0 ] <<8 ) | addr[1 ]; + v ^= (addr[2 ] <<24 ) | (addr[3 ] <<16 ) | (addr[4 ] <<8 ) | addr[5 ]; +return hash_32 (v,8 ); +}/* Maximum number of frames to buffer per power saving station per AC */
@@ -506,6 +513,12 @@ struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,struct sta_info *sta_info_get_bss (struct ieee80211_sub_if_data *sdata,const u8 *addr); +/* +* Uses the local->sdata hash and sdata->sta_hash for fast lookup +* base on VIF (sdata) address and remote station address. +*/ +struct sta_info *sta_info_get_by_vif (struct ieee80211_local *local, +const u8 *vif_addr,const u8 *sta_addr); static inline void for_each_sta_info_type_check(struct ieee80211_local *local,
net/mac80211/status.c +6 -0
@@ -453,11 +453,16 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) sband = local->hw.wiphy->bands[info->band]; fc = hdr->frame_control; + sta =sta_info_get_by_vif (local, hdr->addr2, hdr->addr1); +if (sta) + goto found_it; +for_each_sta_info (local, hdr->addr1, sta, tmp) {/* skip wrong virtual interface */ if (!ether_addr_equal (hdr->addr2, sta->sdata->vif.addr))continue ; +found_it:if (info->flags &IEEE80211_TX_STATUS_EOSP )clear_sta_flag (sta,WLAN_STA_SP );
@@ -553,6 +558,7 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)if (acked) sta->last_ack_signal = info->status.ack_signal; +break ; }rcu_read_unlock ();
Signature · 1 line
1.7.3.4
RFC 2/2 mac80211: Add debugfs for sdata and sdata->sta_vhash
From: Ben Greear <[email protected]>
This gives the user some idea how well the hash functions are working.
---
:100644 100644 2bbe377... c18a6d1... M net/mac80211/debugfs.c
:100644 100644 234576c... 51269c5... M net/mac80211/debugfs_netdev.c
net/mac80211/debugfs.c | 43 ++++++++++++++++++++++++++++++++ net/mac80211/debugfs_netdev.c | 54 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-)
net/mac80211/debugfs.c +43 -0
@@ -210,9 +210,51 @@ static ssize_t sta_hash_read(struct file *file, char __user *user_buf,return q; } +static ssize_t sdata_hash_read (struct file *file,char __user *user_buf, +size_t count,loff_t *ppos) +{ +struct ieee80211_local *local = file->private_data; +int mxln =15000 ; +char *buf =kzalloc (mxln,GFP_KERNEL ); +int q, res =0 ; +struct ieee80211_sub_if_data *s; + +if (!buf) +return 0 ; + +mutex_lock (&local->iflist_mtx); +for (q =0 ; q <STA_HASH_SIZE ; q++) { + s = local->sdata_hash[q]; +if (s) { + res +=snprintf (buf + res, mxln - res,"%i: " , q); +if (res >= mxln) + goto done; + } +while (s) { + res +=snprintf (buf + res, mxln - res," %pM" , + s->vif.addr); +if (res >= mxln) + goto done; + s = s->hnext; + } +if (local->sdata_hash[q]) { + res +=snprintf (buf + res, mxln - res,"\n" ); +if (res >= mxln) + goto done; + } + } +done: +mutex_unlock (&local->iflist_mtx); + + q =simple_read_from_buffer (user_buf, count, ppos, buf, res); +kfree (buf); +return q; +} +DEBUGFS_READONLY_FILE_OPS (hwflags);DEBUGFS_READONLY_FILE_OPS (queues);DEBUGFS_READONLY_FILE_OPS (sta_hash); +DEBUGFS_READONLY_FILE_OPS (sdata_hash);/* statistics stuff */
@@ -282,6 +324,7 @@ void debugfs_hw_add(struct ieee80211_local *local)DEBUGFS_ADD (wep_iv);DEBUGFS_ADD (queues);DEBUGFS_ADD (sta_hash); +DEBUGFS_ADD (sdata_hash);#ifdef CONFIG_PM DEBUGFS_ADD_MODE (reset,0200 );#endif
net/mac80211/debugfs_netdev.c +52 -2
81 lines not on this page · raw message
Signature · 1 line
1.7.3.4