Skip to contentSkip to conversation

nl80211/mac80211 Add support for per-rate rx statistics

RFC Superseded Sriram R 3 participants 8 messages May 15, 2018 – May 21, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sriram R

author
#0 lore raw

cover nl80211/mac80211 Add support for per-rate rx statistics

This patchset adds support for the collection and propagating of per-rate, per-station rx statistics when enabled by a userspace application.

These statistics can be useful in understanding the quality of communication with our peers and in evaluating how different peers
are communicating in different MCS/BW/NSS during different time periods and environment.

Sriram R (2):
nl80211: Add support for collection of per rate rx statistics
mac80211: Add support for per-rate rx statistics

 include/net/cfg80211.h       |  25 +++++++
 include/uapi/linux/nl80211.h |  50 +++++++++++++
 net/mac80211/cfg.c           |  47 ++++++++++++
 net/mac80211/rx.c            |  10 ++-
 net/mac80211/sta_info.c      | 165 +++++++++++++++++++++++++++++++++++++++++
 net/mac80211/sta_info.h      |  17 +++++
 net/wireless/nl80211.c       | 172 +++++++++++++++++++++++++++++++++++++++++++
 net/wireless/rdev-ops.h      |  30 ++++++++
 net/wireless/trace.h         |  26 +++++++
 9 files changed, 540 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

RFC 1/2 nl80211: Add support for collection of per rate rx statistics

RX Statistics per rate, per station can be useful in understanding the quality of communication with our peers and can be helpful in evaluating the consistency at which a specific peer has been communicating in different MCS/BW/NSS after association at different time periods and in varied environments.

This patch adds support for collecting the rx statistics from the kernel and providing it to the userspace.

---
 include/net/cfg80211.h       |  25 +++++++
 include/uapi/linux/nl80211.h |  50 +++++++++++++
 net/wireless/nl80211.c       | 172 +++++++++++++++++++++++++++++++++++++++++++
 net/wireless/rdev-ops.h      |  30 ++++++++
 net/wireless/trace.h         |  26 +++++++
 5 files changed, 303 insertions(+)
include/net/cfg80211.h +25 -0
index 8db6071..8bd818f 100644
@@ -1235,6 +1235,19 @@ struct station_info {
 	s8 avg_ack_signal;
 };
 
+/**
+ * struct sta_rate_stats - per rate statistics of station
+ *
+ * @rate: encoded rate value
+ * @packets: Packet count received at this @rate
+ * @bytes: Total number of bytes received at this @rate
+ */
+struct sta_rate_stats {
+	u32 rate;
+	u32 packets;
+	u64 bytes;
+};
+
 #if IS_ENABLED(CONFIG_CFG80211)
 /**
  * cfg80211_get_station - retrieve information about a given station
@@ -3018,6 +3031,9 @@ struct cfg80211_external_auth_params {
  *
  * @tx_control_port: TX a control port frame (EAPoL).  The noencrypt parameter
  *	tells the driver that the frame should not be encrypted.
+ *
+ * @get_sta_rate_stats: get per-rate stats of the station identified by @mac
+ * @dump_sta_rate_stats: get per-rate stats dump of stations from index @idx
  */
 struct cfg80211_ops {
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -3323,6 +3339,15 @@ struct cfg80211_ops {
 				   const u8 *buf, size_t len,
 				   const u8 *dest, const __be16 proto,
 				   const bool noencrypt);
+
+	int	(*get_sta_rate_stats)(struct wiphy *wiphy,
+				      struct net_device *dev, const u8 *mac,
+				      struct sta_rate_stats **rate_stats_buf,
+				      int *len);
+	int	(*dump_sta_rate_stats)(struct wiphy *wiphy,
+				struct net_device *dev,	int idx, u8 *mac,
+				struct sta_rate_stats **rate_stats_buf,
+				int *len);
 };
 
 /*
include/uapi/linux/nl80211.h +50 -0

80 lines not on this page · raw message

net/wireless/nl80211.c +172 -0

184 lines not on this page · raw message

net/wireless/rdev-ops.h +30 -0
index 364f5d6..1564ad8 100644
@@ -222,6 +222,36 @@ static inline int rdev_dump_station(struct cfg80211_registered_device *rdev,
 	return ret;
 }
 
+static inline int
+rdev_get_sta_rate_stats(struct cfg80211_registered_device *rdev,
+			struct net_device *dev, const u8 *mac,
+			struct sta_rate_stats **rate_stats_buf,
+			int *len)
+{
+	int ret;
+
+	trace_rdev_get_sta_rate_stats(&rdev->wiphy, dev, mac);
+	ret = rdev->ops->get_sta_rate_stats(&rdev->wiphy, dev, mac,
+					rate_stats_buf, len);
+	trace_rdev_return_int(&rdev->wiphy, ret);
+	return ret;
+}
+
+static inline int
+rdev_dump_sta_rate_stats(struct cfg80211_registered_device *rdev,
+			 struct net_device *dev, int idx, u8 *mac,
+			 struct sta_rate_stats **rate_stats_buf,
+			 int *len)
+{
+	int ret;
+
+	trace_rdev_dump_sta_rate_stats(&rdev->wiphy, dev, idx, mac);
+	ret = rdev->ops->dump_sta_rate_stats(&rdev->wiphy, dev, idx, mac,
+					 rate_stats_buf, len);
+	trace_rdev_return_int(&rdev->wiphy, ret);
+	return ret;
+}
+
 static inline int rdev_add_mpath(struct cfg80211_registered_device *rdev,
 				 struct net_device *dev, u8 *dst, u8 *next_hop)
 {
net/wireless/trace.h +26 -0
index 2b417a2..09dd69b 100644
@@ -759,6 +759,11 @@ DEFINE_EVENT(wiphy_netdev_mac_evt, rdev_get_station,
 	TP_ARGS(wiphy, netdev, mac)
 );
 
+DEFINE_EVENT(wiphy_netdev_mac_evt, rdev_get_sta_rate_stats,
+	TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, const u8 *mac),
+	TP_ARGS(wiphy, netdev, mac)
+);
+
 DEFINE_EVENT(wiphy_netdev_mac_evt, rdev_del_mpath,
 	TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, const u8 *mac),
 	TP_ARGS(wiphy, netdev, mac)
@@ -790,6 +795,27 @@ TRACE_EVENT(rdev_dump_station,
 		  __entry->idx)
 );
 
+TRACE_EVENT(rdev_dump_sta_rate_stats,
+	TP_PROTO(struct wiphy *wiphy, struct net_device *netdev, int idx,
+		 u8 *mac),
+	TP_ARGS(wiphy, netdev, idx, mac),
+	TP_STRUCT__entry(
+		WIPHY_ENTRY
+		NETDEV_ENTRY
+		MAC_ENTRY(sta_mac)
+		__field(int, idx)
+	),
+	TP_fast_assign(
+		WIPHY_ASSIGN;
+		NETDEV_ASSIGN;
+		MAC_ASSIGN(sta_mac, mac);
+		__entry->idx = idx;
+	),
+	TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", station mac: " MAC_PR_FMT ", idx: %d",
+		  WIPHY_PR_ARG, NETDEV_PR_ARG, MAC_PR_ARG(sta_mac),
+		  __entry->idx)
+);
+
 TRACE_EVENT(rdev_return_int_station_info,
 	TP_PROTO(struct wiphy *wiphy, int ret, struct station_info *sinfo),
 	TP_ARGS(wiphy, ret, sinfo),
Signature · 1 line
2.7.4
author
#2 lore raw

RFC 2/2 mac80211: Add support for per-rate rx statistics

In reply to Sriram R

This patch adds support for the mac80211 to collect rx statistics (Packet count and total bytes received) per-rate, per-station when enabled by a user space application.

Note that the rate field passed on to the userspace from mac80211 is an encoded value where different rate attributes such as type(VHT/HT/Legacy), MCS, BW, NSS, GI are collectively used to encode to this rate and the userspace has to take care of decoding it.This is done so as to allow scalability in future.

Once statistics collection is enabled, each packet received is recorded per rate and stored as an entry(per rate) in a hashtable with the encoded rate being the key for the hashtable.As the rate changes, new entries gets added into this table and this information will be populated and sent back to userspace when requested. The lifetime of this table is from the enabling of the per-rate stats feature to disabling it or when the sta gets disconnected.

Memory usage(on a 32-bit machine) by this feature would be,
96 bytes (static value, per STA for hash table usage)
+28 bytes (increases per rate entry)
+ 4 bytes (increases per hash bucket and rate is used as key. Default is 16 buckets)

---
 net/mac80211/cfg.c      |  47 ++++++++++++++
 net/mac80211/rx.c       |  10 ++-
 net/mac80211/sta_info.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/mac80211/sta_info.h |  17 +++++
 4 files changed, 237 insertions(+), 2 deletions(-)
net/mac80211/cfg.c +47 -0
index 5ce9d12..abee3ff 100644
@@ -703,6 +703,30 @@ static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
 	return ret;
 }
 
+static int
+ieee80211_dump_sta_rate_stats(struct wiphy *wiphy, struct net_device *dev,
+			      int idx, u8 *mac,
+			      struct sta_rate_stats **rate_stats_buf, int *len)
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct ieee80211_local *local = sdata->local;
+	struct sta_info *sta;
+	int ret = -ENOENT;
+
+	mutex_lock(&local->sta_mtx);
+
+	sta = sta_info_get_by_idx(sdata, idx);
+	if (sta) {
+		memcpy(mac, sta->sta.addr, ETH_ALEN);
+		ret = ieee80211_sta_get_rate_stats_report(sta, rate_stats_buf,
+							  len);
+	}
+
+	mutex_unlock(&local->sta_mtx);
+
+	return ret;
+}
+
 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
 				 int idx, struct survey_info *survey)
 {
@@ -732,6 +756,27 @@ static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
 	return ret;
 }
 
+static int
+ieee80211_get_sta_rate_stats(struct wiphy *wiphy, struct net_device *dev,
+			     const u8 *mac,
+			     struct sta_rate_stats **rate_stats_buf, int *len)
+{
+	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct ieee80211_local *local = sdata->local;
+	struct sta_info *sta;
+	int ret = -ENOENT;
+
+	mutex_lock(&local->sta_mtx);
+
+	sta = sta_info_get_bss(sdata, mac);
+	if (sta)
+		ret = ieee80211_sta_get_rate_stats_report(sta, rate_stats_buf,
+							  len);
+	mutex_unlock(&local->sta_mtx);
+
+	return ret;
+}
+
 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
 					 struct cfg80211_chan_def *chandef)
 {
@@ -3822,6 +3867,8 @@ const struct cfg80211_ops mac80211_config_ops = {
 	.change_station = ieee80211_change_station,
 	.get_station = ieee80211_get_station,
 	.dump_station = ieee80211_dump_station,
+	.get_sta_rate_stats = ieee80211_get_sta_rate_stats,
+	.dump_sta_rate_stats = ieee80211_dump_sta_rate_stats,
 	.dump_survey = ieee80211_dump_survey,
 #ifdef CONFIG_MAC80211_MESH
 	.add_mpath = ieee80211_add_mpath,
net/mac80211/rx.c +8 -2
index 0a38cc1..0f63b18 100644
@@ -1561,9 +1561,11 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
 		    test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
 			sta->rx_stats.last_rx = jiffies;
 			if (ieee80211_is_data(hdr->frame_control) &&
-			    !is_multicast_ether_addr(hdr->addr1))
+			    !is_multicast_ether_addr(hdr->addr1)) {
 				sta->rx_stats.last_rate =
 					sta_stats_encode_rate(status);
+				ieee80211_sta_update_rate_stats(&sta);
+			}
 		}
 	} else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
 		sta->rx_stats.last_rx = jiffies;
@@ -1573,8 +1575,10 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
 		 * match the current local configuration when processed.
 		 */
 		sta->rx_stats.last_rx = jiffies;
-		if (ieee80211_is_data(hdr->frame_control))
+		if (ieee80211_is_data(hdr->frame_control)) {
 			sta->rx_stats.last_rate = sta_stats_encode_rate(status);
+			ieee80211_sta_update_rate_stats(&sta);
+		}
 	}
 
 	if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
@@ -4067,6 +4071,8 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
 	stats->last_rx = jiffies;
 	stats->last_rate = sta_stats_encode_rate(status);
 
+	ieee80211_sta_update_rate_stats(&sta);
+
 	stats->fragments++;
 	stats->packets++;
 
net/mac80211/sta_info.c +165 -0

186 lines not on this page · raw message

net/mac80211/sta_info.h +17 -0
index d79bd6e..ff3dcea 100644
@@ -583,10 +583,22 @@ struct sta_info {
 
 	struct cfg80211_chan_def tdls_chandef;
 
+	struct rhashtable *rate_table;
+
 	/* keep last! */
 	struct ieee80211_sta sta;
 };
 
+#define IEEE80211_ENCODED_RATE_LEN 4
+
+struct ieee80211_sta_rate_entry {
+	u32 rate;
+	u32 packets;
+	u64 bytes;
+	struct rcu_head rcu;
+	struct rhash_head rhash;
+};
+
 static inline enum nl80211_plink_state sta_plink_state(struct sta_info *sta)
 {
 #ifdef CONFIG_MAC80211_MESH
@@ -758,6 +770,11 @@ void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta);
 
 unsigned long ieee80211_sta_last_active(struct sta_info *sta);
 
+int ieee80211_sta_get_rate_stats_report(struct sta_info *sta,
+					struct sta_rate_stats **report_buf,
+					int *len);
+void ieee80211_sta_update_rate_stats(struct sta_info **sta_ptr);
+
 enum sta_stats_type {
 	STA_STATS_RATE_TYPE_INVALID = 0,
 	STA_STATS_RATE_TYPE_LEGACY,
Signature · 1 line
2.7.4
maintainer
#3 lore raw
In reply to Sriram R
Quoted 6 lines · Sriram R

This patchset adds support for the collection and propagating of per-rate, per-station rx statistics when enabled by a userspace application.

These statistics can be useful in understanding the quality of communication with our peers and in evaluating how different peers
are communicating in different MCS/BW/NSS during different time periods and environment.

So ... I know that you're aware of my rate statistics collection code (at least you should be, I showed it to Jouni), so I think you should state why that approach isn't suitable.

In particular, I don't like the idea that you implement here of allowing unresponsive (or dead) userspace to let the data pile up indefinitely. I think we should be sending it out upon reaching a threshold to limit the memory consumption in the kernel more reliably.

johannes

#7 lore raw
In reply to Sriram R
Quoted 3 lines · Sriram R

This patchset adds support for the collection and propagating of per-rate, per-station rx statistics when enabled by a userspace application.

Why not report TX rate statistics as well, when it is available? Minstrel already collects this, and it is available via debugfs (the rc_stats file); so if you're adding a netlink API, it seems odd to not include TX stats as well...

-Toke

author
#4 lore raw
In reply to Johannes Berg
Quoted 4 lines · Johannes Berg
Quoted 3 lines · Sriram R

This patchset adds support for the collection and propagating of per-rate, per-station rx statistics when enabled by a userspace application.

Quoted 8 lines
Quoted 3 lines

These statistics can be useful in understanding the quality of communication with our peers and in evaluating how different peers
are communicating in different MCS/BW/NSS during different time periods and environment.

So ... I know that you're aware of my rate statistics collection code (at least you should be, I showed it to Jouni), so I think you should state why that approach isn't suitable.

Hi Johannes,

I really liked your approach of publishing the rate statistics only
when subscribers exist and to push the data when we hit some limits (pkt count nearing UINT16_MAX or when 'escape' entries gets used).

But, I wanted to avoid,
1. Static indexing and memory allocation based on MCS count((8x3)24
entries for HT and (10x3)30 for VHT within allocated 36 entries) so that it's scalable.
2. Remote chance of dropping a stats(Though it does not have much
impact)

And to allow,
1. A 'station dump' kind of interface to dump the complete collected
stats instead of returning only current snapshot of the stats within kernel.

Quoted 4 lines

In particular, I don't like the idea that you implement here of allowing unresponsive (or dead) userspace to let the data pile up indefinitely. I think we should be sending it out upon reaching a threshold to limit the memory consumption in the kernel more reliably.

I agree with you that this does not allow deterministic memory allocation within kernel (when rate stats are enabled).

I'll revisit this approach to address your concern and to allow a data aggregator kind of usersapce application to collect info and provide complete stats.

Also, do you feel it would be good to have both ,i.e complete stats collection within kernel(this approach) and dump+clear of stats on reaching threshold(your approach) and have one of these two modes selected based on the requirement.

Thanks,
Sriram.R

Quoted 2 lines

johannes

maintainer
#5 lore raw
Quoted 4 lines · Sriram R

But, I wanted to avoid,
1. Static indexing and memory allocation based on MCS count((8x3)24
entries for HT and (10x3)30 for VHT within allocated 36 entries) so that it's scalable.

Do you expect that the rate control on the other side flips through MCSes so fast that this little cache will need to be flushed significantly?

Quoted 2 lines

2. Remote chance of dropping a stats(Though it does not have much
impact)

Yeah this doesn't seem like a concern either way. How many packets and how little time ... :)

Quoted 4 lines

And to allow,
1. A 'station dump' kind of interface to dump the complete collected
stats instead of returning only current snapshot of the stats within kernel.

This *completely* contradict keeping limits on the kernel memory consumed, so basically I don't think this is feasible.

Quoted 4 lines

Also, do you feel it would be good to have both ,i.e complete stats collection within kernel(this approach) and dump+clear of stats on reaching threshold(your approach) and have one of these two modes selected based on the requirement.

No, honestly, I don't. If an application wants these statistics, then I feel that we can impose *some* requirements and not leave it at "let me just enable it and have the kernel do all the work for me".

johannes

author
#6 lore raw
Quoted 10 lines · Johannes Berg
Quoted 4 lines · Sriram R

But, I wanted to avoid,
1. Static indexing and memory allocation based on MCS count((8x3)24
entries for HT and (10x3)30 for VHT within allocated 36 entries) so that it's scalable.

Do you expect that the rate control on the other side flips through MCSes so fast that this little cache will need to be flushed significantly?

Not really Johannes. Dynamic allocation (with indexing based on encoded rate)was tried out in this patch so as to have the rate table independent of MCS Count(so that it works without changes when new mcs's is used in HE).

Quoted 6 lines
Quoted 3 lines

2. Remote chance of dropping a stats(Though it does not have much
impact)

Yeah this doesn't seem like a concern either way. How many packets and how little time ... :)

Right!

Quoted 8 lines
Quoted 5 lines

And to allow,
1. A 'station dump' kind of interface to dump the complete collected
stats instead of returning only current snapshot of the stats within kernel.

This *completely* contradict keeping limits on the kernel memory consumed, so basically I don't think this is feasible.

Ok,Understood.

Quoted 9 lines
Quoted 5 lines

Also, do you feel it would be good to have both ,i.e complete stats collection within kernel(this approach) and dump+clear of stats on reaching threshold(your approach) and have one of these two modes selected based on the requirement.

No, honestly, I don't. If an application wants these statistics, then I feel that we can impose *some* requirements and not leave it at "let me just enable it and have the kernel do all the work for me".

Right, Thanks for the suggestions. I'll send the next revision based on your approach of flushing the rate table(whenever its' requested or when we hit a limit) Thanks and Regards,
Sriram.R

Quoted 2 lines

johannes