Skip to contentSkip to conversation

cfg80211: add channel utilization stats to the survey command

PATCH In review Felix Fietkau 2 participants 9 messages Oct 9, 2010 – Oct 10, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 cfg80211: add channel utilization stats to the survey command

Using these, user space can calculate a relative channel utilization with arbitrary intervals by regularly taking snapshots of the survey results.

---
 include/linux/nl80211.h |   15 +++++++++++++++
 include/net/cfg80211.h  |   20 ++++++++++++++++++++
 net/wireless/nl80211.c  |   15 +++++++++++++++
 3 files changed, 50 insertions(+), 0 deletions(-)
include/linux/nl80211.h +15 -0
index c08709f..0edb256 100644
@@ -1413,6 +1413,16 @@ enum nl80211_reg_rule_flags {
  * @NL80211_SURVEY_INFO_FREQUENCY: center frequency of channel
  * @NL80211_SURVEY_INFO_NOISE: noise level of channel (u8, dBm)
  * @NL80211_SURVEY_INFO_IN_USE: channel is currently being used
+ * @NL80211_SURVEY_INFO_CHANNEL_TIME: amount of time (in ms) that the radio
+ *	spent on this channel
+ * @NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY: amount of the time the primary
+ *	channel was sensed busy (either due to activity or energy detect)
+ * @NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY: amount of time the extension
+ *	channel was sensed busy
+ * @NL80211_SURVEY_INFO_CHANNEL_TIME_RX: amount of time the radio spent
+ *	receiving data
+ * @NL80211_SURVEY_INFO_CHANNEL_TIME_TX: amount of time the radio spent
+ *	transmitting data
  * @NL80211_SURVEY_INFO_MAX: highest survey info attribute number
  *	currently defined
  * @__NL80211_SURVEY_INFO_AFTER_LAST: internal use
@@ -1422,6 +1432,11 @@ enum nl80211_survey_info {
 	NL80211_SURVEY_INFO_FREQUENCY,
 	NL80211_SURVEY_INFO_NOISE,
 	NL80211_SURVEY_INFO_IN_USE,
+	NL80211_SURVEY_INFO_CHANNEL_TIME,
+	NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
+	NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
+	NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
+	NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
 
 	/* keep last */
 	__NL80211_SURVEY_INFO_AFTER_LAST,
include/net/cfg80211.h +20 -0
index 0778d04..a2cf04f 100644
@@ -294,6 +294,11 @@ struct key_params {
  *
  * @SURVEY_INFO_NOISE_DBM: noise (in dBm) was filled in
  * @SURVEY_INFO_IN_USE: channel is currently being used
+ * @SURVEY_INFO_CHANNEL_TIME: channel active time (in ms) was filled in
+ * @SURVEY_INFO_CHANNEL_TIME_BUSY: channel busy time was filled in
+ * @SURVEY_INFO_CHANNEL_TIME_EXT_BUSY: extension channel busy time was filled in
+ * @SURVEY_INFO_CHANNEL_TIME_RX: channel receive time was filled in
+ * @SURVEY_INFO_CHANNEL_TIME_TX: channel transmit time was filled in
  *
  * Used by the driver to indicate which info in &struct survey_info
  * it has filled in during the get_survey().
@@ -301,6 +306,11 @@ struct key_params {
 enum survey_info_flags {
 	SURVEY_INFO_NOISE_DBM = 1<<0,
 	SURVEY_INFO_IN_USE = 1<<1,
+	SURVEY_INFO_CHANNEL_TIME = 1<<2,
+	SURVEY_INFO_CHANNEL_TIME_BUSY = 1<<3,
+	SURVEY_INFO_CHANNEL_TIME_EXT_BUSY = 1<<4,
+	SURVEY_INFO_CHANNEL_TIME_RX = 1<<5,
+	SURVEY_INFO_CHANNEL_TIME_TX = 1<<6,
 };
 
 /**
@@ -310,6 +320,11 @@ enum survey_info_flags {
  * @filled: bitflag of flags from &enum survey_info_flags
  * @noise: channel noise in dBm. This and all following fields are
  *     optional
+ * @channel_time: amount of time in ms the radio spent on the channel
+ * @channel_time_busy: amount of time the primary channel was sensed busy
+ * @channel_time_ext_busy: amount of time the extension channel was sensed busy
+ * @channel_time_rx: amount of time the radio spent receiving data
+ * @channel_time_tx: amount of time the radio spent transmitting data
  *
  * Used by dump_survey() to report back per-channel survey information.
  *
@@ -318,6 +333,11 @@ enum survey_info_flags {
  */
 struct survey_info {
 	struct ieee80211_channel *channel;
+	u64 channel_time;
+	u64 channel_time_busy;
+	u64 channel_time_ext_busy;
+	u64 channel_time_rx;
+	u64 channel_time_tx;
 	u32 filled;
 	s8 noise;
 };
net/wireless/nl80211.c +15 -0
index 882dc92..c506241 100644
@@ -3153,6 +3153,21 @@ static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
 			    survey->noise);
 	if (survey->filled & SURVEY_INFO_IN_USE)
 		NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
+	if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
+		NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
+			    survey->channel_time);
+	if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
+		NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
+			    survey->channel_time_busy);
+	if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
+		NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
+			    survey->channel_time_ext_busy);
+	if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
+		NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
+			    survey->channel_time_rx);
+	if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
+		NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
+			    survey->channel_time_tx);
 
 	nla_nest_end(msg, infoattr);
 
Signature · 1 line
1.7.2.2
#1 lore raw

PATCH 2/3 ath9k: add compile time checking for the size of the channel list

This prevents random memory corruption if the number of channels ever gets changed without an update to the internal channel array size.

---
 drivers/net/wireless/ath/ath9k/hw.h   |    4 +++-
 drivers/net/wireless/ath/ath9k/init.c |    4 ++++
 2 files changed, 7 insertions(+), 1 deletions(-)
drivers/net/wireless/ath/ath9k/hw.h +3 -1
index 7f696c8..6b92334 100644
@@ -61,6 +61,8 @@
 
 #define ATH9K_RSSI_BAD			-128
 
+#define ATH9K_NUM_CHANNELS	38
+
 /* Register read/write primitives */
 #define REG_WRITE(_ah, _reg, _val) \
 	ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
@@ -618,7 +620,7 @@ struct ath_hw {
 	struct ath9k_hw_version hw_version;
 	struct ath9k_ops_config config;
 	struct ath9k_hw_capabilities caps;
-	struct ath9k_channel channels[38];
+	struct ath9k_channel channels[ATH9K_NUM_CHANNELS];
 	struct ath9k_channel *curchan;
 
 	union {
drivers/net/wireless/ath/ath9k/init.c +4 -0
index d76003c..a4c5ed4 100644
@@ -481,6 +481,10 @@ static int ath9k_init_channels_rates(struct ath_softc *sc)
 {
 	void *channels;
 
+	BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
+		     ARRAY_SIZE(ath9k_5ghz_chantable) !=
+		     ATH9K_NUM_CHANNELS);
+
 	if (test_bit(ATH9K_MODE_11G, sc->sc_ah->caps.wireless_modes)) {
 		channels = kmemdup(ath9k_2ghz_chantable,
 			sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
Signature · 1 line
1.7.2.2
#2 lore raw

PATCH 3/3 ath9k: implement channel utilization stats for survey

Results for the active channel are updated whenever a new survey dump is requested, the old data is kept to allow multiple processes to make their own channel utilization averages.
All other channels only contain the data for the last time that the hardware was on the channel, i.e. the last scan result or other off-channel activity.
Running a background scan does not clear the data for the active channel.

---
 drivers/net/wireless/ath/ath9k/ath9k.h |    2 +
 drivers/net/wireless/ath/ath9k/main.c  |  103 +++++++++++++++++++++++++++----
 2 files changed, 91 insertions(+), 14 deletions(-)
drivers/net/wireless/ath/ath9k/ath9k.h +2 -0
index de2b18e..4e81fe3 100644
@@ -593,6 +593,8 @@ struct ath_softc {
 	struct delayed_work wiphy_work;
 	unsigned long wiphy_scheduler_int;
 	int wiphy_scheduler_index;
+	struct survey_info *cur_survey;
+	struct survey_info survey[ATH9K_NUM_CHANNELS];
 
 	struct tasklet_struct intr_tq;
 	struct tasklet_struct bcon_tasklet;
drivers/net/wireless/ath/ath9k/main.c +89 -14

146 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#3 lore raw

PATCH v2 3/3 ath9k: implement channel utilization stats for survey

Results for the active channel are updated whenever a new survey dump is requested, the old data is kept to allow multiple processes to make their own channel utilization averages.
All other channels only contain the data for the last time that the hardware was on the channel, i.e. the last scan result or other off-channel activity.
Running a background scan does not clear the data for the active channel.

---
v2: fix counter overflow by reading and clearing counters after the
ani monitor function. fix a survey data locking issue

drivers/net/wireless/ath/ath9k/ath9k.h +2 -0
@@ -594,6 +594,8 @@ struct ath_softc {
 	struct delayed_work wiphy_work;
 	unsigned long wiphy_scheduler_int;
 	int wiphy_scheduler_index;
+	struct survey_info *cur_survey;
+	struct survey_info survey[ATH9K_NUM_CHANNELS];
 
 	struct tasklet_struct intr_tq;
 	struct tasklet_struct bcon_tasklet;
drivers/net/wireless/ath/ath9k/main.c +96 -16

163 lines not on this page · raw message

#4 lore raw
In reply to Felix Fietkau

Am Samstag 09 Oktober 2010 schrieb Felix Fietkau:

Quoted 3 lines

Using these, user space can calculate a relative channel utilization with arbitrary intervals by regularly taking snapshots of the survey results.

What if you've got multiple consumers, wouldn't that mess up the survey results?

I mean, for example mac80211 and/or hostapd might want to use the busy time statistics for the BSS load IE while a different userspace process might want to monitor the channel utilization in order to detect a worsening channel condition.

If the consumers happen to use the same interval and request the survey very soon after each other one consumer will get the values on a nice (close to the query interval) time base while the other one will get the values based on a very small interval (which might lower the value's representativeness).

Helmut

#5 lore raw
Quoted 13 lines · Helmut Schaa

Am Samstag 09 Oktober 2010 schrieb Felix Fietkau:

Quoted 3 lines

Using these, user space can calculate a relative channel utilization with arbitrary intervals by regularly taking snapshots of the survey results.

What if you've got multiple consumers, wouldn't that mess up the survey results?

I mean, for example mac80211 and/or hostapd might want to use the busy time statistics for the BSS load IE while a different userspace process might want to monitor the channel utilization in order to detect a worsening channel condition.

Quoted 5 lines

If the consumers happen to use the same interval and request the survey very soon after each other one consumer will get the values on a nice (close to the query interval) time base while the other one will get the values based on a very small interval (which might lower the value's representativeness).

Multiple consumers work just fine, since the survey results are relative to the time the hardware started using the channel, not relative to the last request. Maybe my description was a bit unclear on that part.

- Felix

#6 lore raw

Am Samstag 09 Oktober 2010 schrieb Felix Fietkau:

Quoted 14 lines · Helmut Schaa
Quoted 13 lines

Am Samstag 09 Oktober 2010 schrieb Felix Fietkau:

Quoted 3 lines

Using these, user space can calculate a relative channel utilization with arbitrary intervals by regularly taking snapshots of the survey results.

What if you've got multiple consumers, wouldn't that mess up the survey results?

I mean, for example mac80211 and/or hostapd might want to use the busy time statistics for the BSS load IE while a different userspace process might want to monitor the channel utilization in order to detect a worsening channel condition.

Quoted 8 lines
Quoted 5 lines

If the consumers happen to use the same interval and request the survey very soon after each other one consumer will get the values on a nice (close to the query interval) time base while the other one will get the values based on a very small interval (which might lower the value's representativeness).

Multiple consumers work just fine, since the survey results are relative to the time the hardware started using the channel, not relative to the last request. Maybe my description was a bit unclear on that part.

Ah, thanks Felix, I only read the comment, not the code :)

So, the busy time statistics for channel i are gathered starting with the switch to i. Hence, if a user space process would like to measure multiple channels it will just switch through all of them and call get survey right before switching to the next one, right?

However, if we think about the BSS load IE we might want to measure the busy times without switching the channel? But we'd like have a somewhat actual value and not an average throughout the last minute/hour or so. Any ideas how to integrate that into your approach?

Helmut

#7 lore raw
Quoted 24 lines · Helmut Schaa

Am Samstag 09 Oktober 2010 schrieb Felix Fietkau:

Quoted 14 lines · Helmut Schaa
Quoted 13 lines

Am Samstag 09 Oktober 2010 schrieb Felix Fietkau:

Quoted 3 lines

Using these, user space can calculate a relative channel utilization with arbitrary intervals by regularly taking snapshots of the survey results.

What if you've got multiple consumers, wouldn't that mess up the survey results?

I mean, for example mac80211 and/or hostapd might want to use the busy time statistics for the BSS load IE while a different userspace process might want to monitor the channel utilization in order to detect a worsening channel condition.

Quoted 8 lines
Quoted 5 lines

If the consumers happen to use the same interval and request the survey very soon after each other one consumer will get the values on a nice (close to the query interval) time base while the other one will get the values based on a very small interval (which might lower the value's representativeness).

Multiple consumers work just fine, since the survey results are relative to the time the hardware started using the channel, not relative to the last request. Maybe my description was a bit unclear on that part.

Quoted 6 lines

Ah, thanks Felix, I only read the comment, not the code :)

So, the busy time statistics for channel i are gathered starting with the switch to i. Hence, if a user space process would like to measure multiple channels it will just switch through all of them and call get survey right before switching to the next one, right?

In the current ath9k implementation that I posted, the stats are reset immediately when switching to a channel, with one exception: switching back to the operating channel after off-channel activity. That way, you get sane, readable stats for all channels when dumping the survey list after a scan.

Quoted 4 lines

However, if we think about the BSS load IE we might want to measure the busy times without switching the channel? But we'd like have a somewhat actual value and not an average throughout the last minute/hour or so. Any ideas how to integrate that into your approach?

Just grab a survey dump when starting up, then another after a minute/hour, and subtract the values of the last one.
Right now there's still an overflow issue in the internal counters in the current ath9k implementation, so the stats are off unless you poll survey stats regularly. I'll send a fix for that later.

- Felix

#8 lore raw

Am Samstag 09 Oktober 2010 schrieb Felix Fietkau:

Quoted 10 lines · Helmut Schaa
Quoted 4 lines

However, if we think about the BSS load IE we might want to measure the busy times without switching the channel? But we'd like have a somewhat actual value and not an average throughout the last minute/hour or so. Any ideas how to integrate that into your approach?

Just grab a survey dump when starting up, then another after a minute/hour, and subtract the values of the last one.
Right now there's still an overflow issue in the internal counters in the current ath9k implementation, so the stats are off unless you poll survey stats regularly. I'll send a fix for that later.

Thanks, looks alright to me then. I'll try to add a similar implementation for rt2800 once these patches go in.

Helmut