Skip to contentSkip to conversation

cfg80211: add local BSS receive time to survey information

PATCH In review Felix Fietkau 3 participants 7 messages Aug 28, 2019 802.11 (including cfg80211/NL80211)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cfg80211: add local BSS receive time to survey information

This is useful for checking how much airtime is being used up by other transmissions on the channel, e.g. by calculating (time_rx - time_bss_rx) or (time_busy - time_bss_rx - time_tx)

---
 include/net/cfg80211.h       | 4 ++++
 include/uapi/linux/nl80211.h | 3 +++
 net/wireless/nl80211.c       | 4 ++++
 3 files changed, 11 insertions(+)
include/net/cfg80211.h +4 -0
index 35ec1f0a2bf9..bf97c4f805d3 100644
@@ -694,6 +694,7 @@ ieee80211_chandef_max_power(struct cfg80211_chan_def *chandef)
  * @SURVEY_INFO_TIME_RX: receive time was filled in
  * @SURVEY_INFO_TIME_TX: transmit time was filled in
  * @SURVEY_INFO_TIME_SCAN: scan time was filled in
+ * @SURVEY_INFO_TIME_BSS_RX: local BSS receive time was filled in
  *
  * Used by the driver to indicate which info in &struct survey_info
  * it has filled in during the get_survey().
@@ -707,6 +708,7 @@ enum survey_info_flags {
 	SURVEY_INFO_TIME_RX		= BIT(5),
 	SURVEY_INFO_TIME_TX		= BIT(6),
 	SURVEY_INFO_TIME_SCAN		= BIT(7),
+	SURVEY_INFO_TIME_BSS_RX		= BIT(8),
 };
 
 /**
@@ -723,6 +725,7 @@ enum survey_info_flags {
  * @time_rx: amount of time the radio spent receiving data
  * @time_tx: amount of time the radio spent transmitting data
  * @time_scan: amount of time the radio spent for scanning
+ * @time_bss_rx: amount of time the radio spent receiving data on a local BSS
  *
  * Used by dump_survey() to report back per-channel survey information.
  *
@@ -737,6 +740,7 @@ struct survey_info {
 	u64 time_rx;
 	u64 time_tx;
 	u64 time_scan;
+	u64 time_bss_rx;
 	u32 filled;
 	s8 noise;
 };
include/uapi/linux/nl80211.h +3 -0
index 822851d369ab..e74cf4daad02 100644
@@ -3843,6 +3843,8 @@ enum nl80211_user_reg_hint_type {
  * @NL80211_SURVEY_INFO_TIME_SCAN: time the radio spent for scan
  *	(on this channel or globally)
  * @NL80211_SURVEY_INFO_PAD: attribute used for padding for 64-bit alignment
+ * @NL80211_SURVEY_INFO_TIME_BSS_RX: amount of time the radio spent
+ *	receiving local BSS data
  * @NL80211_SURVEY_INFO_MAX: highest survey info attribute number
  *	currently defined
  * @__NL80211_SURVEY_INFO_AFTER_LAST: internal use
@@ -3859,6 +3861,7 @@ enum nl80211_survey_info {
 	NL80211_SURVEY_INFO_TIME_TX,
 	NL80211_SURVEY_INFO_TIME_SCAN,
 	NL80211_SURVEY_INFO_PAD,
+	NL80211_SURVEY_INFO_TIME_BSS_RX,
 
 	/* keep last */
 	__NL80211_SURVEY_INFO_AFTER_LAST,
net/wireless/nl80211.c +4 -0
index 1a107f29016b..3eea7a6f9070 100644
@@ -8777,6 +8777,10 @@ static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
 	    nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
 			      survey->time_scan, NL80211_SURVEY_INFO_PAD))
 		goto nla_put_failure;
+	if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
+	    nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
+			      survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
+		goto nla_put_failure;
 
 	nla_nest_end(msg, infoattr);
 
Signature · 1 line
2.17.0
#1 lore raw

Hi Felix,

Quoted 61 lines

This is useful for checking how much airtime is being used up by other transmissions on the channel, e.g. by calculating (time_rx - time_bss_rx) or (time_busy - time_bss_rx - time_tx)

---

include/net/cfg80211.h       | 4 ++++
include/uapi/linux/nl80211.h | 3 +++
net/wireless/nl80211.c       | 4 ++++
3 files changed, 11 insertions(+)
include/net/cfg80211.h +4 -0
index 35ec1f0a2bf9..bf97c4f805d3 100644
@@ -694,6 +694,7 @@ ieee80211_chandef_max_power(struct cfg80211_chan_def *chandef)
 * @SURVEY_INFO_TIME_RX: receive time was filled in
 * @SURVEY_INFO_TIME_TX: transmit time was filled in
 * @SURVEY_INFO_TIME_SCAN: scan time was filled in
+ * @SURVEY_INFO_TIME_BSS_RX: local BSS receive time was filled in
 *
 * Used by the driver to indicate which info in &struct survey_info
 * it has filled in during the get_survey().
@@ -707,6 +708,7 @@ enum survey_info_flags {
 	SURVEY_INFO_TIME_RX		= BIT(5),
 	SURVEY_INFO_TIME_TX		= BIT(6),
 	SURVEY_INFO_TIME_SCAN		= BIT(7),
+	SURVEY_INFO_TIME_BSS_RX		= BIT(8),
 };
 
 /**
@@ -723,6 +725,7 @@ enum survey_info_flags {
 * @time_rx: amount of time the radio spent receiving data
 * @time_tx: amount of time the radio spent transmitting data
 * @time_scan: amount of time the radio spent for scanning
+ * @time_bss_rx: amount of time the radio spent receiving data on a local BSS
 *
 * Used by dump_survey() to report back per-channel survey information.
 *
@@ -737,6 +740,7 @@ struct survey_info {
 	u64 time_rx;
 	u64 time_tx;
 	u64 time_scan;
+	u64 time_bss_rx;
 	u32 filled;
 	s8 noise;
 };
include/uapi/linux/nl80211.h +2 -0
index 822851d369ab..e74cf4daad02 100644
@@ -3843,6 +3843,8 @@ enum nl80211_user_reg_hint_type {
 * @NL80211_SURVEY_INFO_TIME_SCAN: time the radio spent for scan
 *	(on this channel or globally)
 * @NL80211_SURVEY_INFO_PAD: attribute used for padding for 64-bit alignment
+ * @NL80211_SURVEY_INFO_TIME_BSS_RX: amount of time the radio spent
+ *	receiving local BSS data
 * @NL80211_SURVEY_INFO_MAX: highest survey info attribute number
 *	currently defined
 * @__NL80211_SURVEY_INFO_AFTER_LAST: internal use

include/uapi/linux/nl80211.h enum nl80211_survey_info { · line 3864

Quoted 4 lines
include/uapi/linux/nl80211.h +1 -0
@@ -3859,6 +3861,7 @@ enum nl80211_survey_info {
 	NL80211_SURVEY_INFO_TIME_TX,
 	NL80211_SURVEY_INFO_TIME_SCAN,
 	NL80211_SURVEY_INFO_PAD,
+	NL80211_SURVEY_INFO_TIME_BSS_RX,

wouldn’t this go before the PAD attribute?

Regards

Marcel

maintainer
#2 lore raw

Hi Marcel,

Quoted 1 line

... [snip]

Please trim quotes a bit.

Quoted 4 lines

include/uapi/linux/nl80211.h enum nl80211_survey_info { · line 3864

Quoted 2 lines
	NL80211_SURVEY_INFO_PAD,
include/uapi/linux/nl80211.h +1 -0
+	NL80211_SURVEY_INFO_TIME_BSS_RX,

wouldn’t this go before the PAD attribute?

No, as usual, that would break ABI. PAD is a regular attribute, just empty and ignored for aligning 64-bit values.

johannes

#3 lore raw

Hi Johannes,

Quoted 11 lines
Quoted 1 line

... [snip]

Please trim quotes a bit.

Quoted 4 lines

include/uapi/linux/nl80211.h enum nl80211_survey_info { · line 3864

Quoted 2 lines
	NL80211_SURVEY_INFO_PAD,
include/uapi/linux/nl80211.h +1 -0
+	NL80211_SURVEY_INFO_TIME_BSS_RX,

wouldn’t this go before the PAD attribute?

No, as usual, that would break ABI. PAD is a regular attribute, just empty and ignored for aligning 64-bit values.

then I do not grok on how the nla_put_u64_64bit works, but that is fine.

I assumed these are similar to the NL80211_SURVEY_INFO_MAX which we also always move, but also not expected to be part of the API as a fixed value.

Regards

Marcel

maintainer
#4 lore raw

Hi Marcel,

Quoted 9 lines
Quoted 2 lines

No, as usual, that would break ABI. PAD is a regular attribute, just empty and ignored for aligning 64-bit values.

then I do not grok on how the nla_put_u64_64bit works, but that is fine.

I assumed these are similar to the NL80211_SURVEY_INFO_MAX which we also always move, but also not expected to be part of the API as a fixed value.

No no, the _MAX is just the token we use for knowing what we want as the maximum when parsing etc.

The _PAD is actually a real attribute, basically nla_put_u64_64bit() will do "nla_put_flag(_PAD)" if and only if "offset % 8 == 0", in order to actually 64-bit align the 64-bit value in the following attribute.

(Note that offset % 8 can only be 0 or 4, due to the way netlink attributes work.)

johannes

#5 lore raw

Hi Johannes,

Quoted 13 lines
Quoted 9 lines
Quoted 2 lines

No, as usual, that would break ABI. PAD is a regular attribute, just empty and ignored for aligning 64-bit values.

then I do not grok on how the nla_put_u64_64bit works, but that is fine.

I assumed these are similar to the NL80211_SURVEY_INFO_MAX which we also always move, but also not expected to be part of the API as a fixed value.

No no, the _MAX is just the token we use for knowing what we want as the maximum when parsing etc.

Quoted 6 lines

The _PAD is actually a real attribute, basically nla_put_u64_64bit() will do "nla_put_flag(_PAD)" if and only if "offset % 8 == 0", in order to actually 64-bit align the 64-bit value in the following attribute.

(Note that offset % 8 can only be 0 or 4, due to the way netlink attributes work.)

I get that part now. So the kernel is inserting a _PAD, but userspace is still not doing that. So for NL80211_ATTR_WDEV we should be doing the same actually?

Regards

Marcel

maintainer
#6 lore raw
Quoted 19 lines · Marcel Holtmann

Hi Johannes,

Quoted 17 lines
Quoted 9 lines
Quoted 2 lines

No, as usual, that would break ABI. PAD is a regular attribute, just empty and ignored for aligning 64-bit values.

then I do not grok on how the nla_put_u64_64bit works, but that is fine.

I assumed these are similar to the NL80211_SURVEY_INFO_MAX which we also always move, but also not expected to be part of the API as a fixed value.

No no, the _MAX is just the token we use for knowing what we want as the maximum when parsing etc.

The _PAD is actually a real attribute, basically nla_put_u64_64bit() will do "nla_put_flag(_PAD)" if and only if "offset % 8 == 0", in order to actually 64-bit align the 64-bit value in the following attribute.

Quoted 5 lines
Quoted 2 lines

(Note that offset % 8 can only be 0 or 4, due to the way netlink attributes work.)

I get that part now. So the kernel is inserting a _PAD, but userspace is still not doing that.

Yeah, and I forgot to say - if we renumbered _PAD, then newer userspace would think old kernel's _PAD is really _BSS_RX, so things would break.

Quoted 1 line

So for NL80211_ATTR_WDEV we should be doing the same actually?

Not really. The kernel doesn't rely on it, nla_get_u64() uses nla_memcpy() so doesn't care about alignment.

Even userspace doesn't (usually) rely on the alignment, it also typically uses nla_get_u64() from libnl which also uses nla_memcpy() or memcpy() (depending on the version), so it's all not really necessary.

I think some libraries or tools like maybe iproute2 didn't do it correctly and just dereferenced a pointer there, causing alignment violations, and so basically the decision was to get rid of unaligned 64-bit attributes to prevent that once and for all.

johannes