Commit 8610c29a2c9f273886b1c31ae4d92c69d4326262

Authored by Felix Fietkau
Committed by John W. Linville
1 parent 15943a72c7

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.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

Showing 3 changed files with 50 additions and 0 deletions Side-by-side Diff

include/linux/nl80211.h
... ... @@ -1413,6 +1413,16 @@
1413 1413 * @NL80211_SURVEY_INFO_FREQUENCY: center frequency of channel
1414 1414 * @NL80211_SURVEY_INFO_NOISE: noise level of channel (u8, dBm)
1415 1415 * @NL80211_SURVEY_INFO_IN_USE: channel is currently being used
  1416 + * @NL80211_SURVEY_INFO_CHANNEL_TIME: amount of time (in ms) that the radio
  1417 + * spent on this channel
  1418 + * @NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY: amount of the time the primary
  1419 + * channel was sensed busy (either due to activity or energy detect)
  1420 + * @NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY: amount of time the extension
  1421 + * channel was sensed busy
  1422 + * @NL80211_SURVEY_INFO_CHANNEL_TIME_RX: amount of time the radio spent
  1423 + * receiving data
  1424 + * @NL80211_SURVEY_INFO_CHANNEL_TIME_TX: amount of time the radio spent
  1425 + * transmitting data
1416 1426 * @NL80211_SURVEY_INFO_MAX: highest survey info attribute number
1417 1427 * currently defined
1418 1428 * @__NL80211_SURVEY_INFO_AFTER_LAST: internal use
... ... @@ -1422,6 +1432,11 @@
1422 1432 NL80211_SURVEY_INFO_FREQUENCY,
1423 1433 NL80211_SURVEY_INFO_NOISE,
1424 1434 NL80211_SURVEY_INFO_IN_USE,
  1435 + NL80211_SURVEY_INFO_CHANNEL_TIME,
  1436 + NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
  1437 + NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
  1438 + NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
  1439 + NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
1425 1440  
1426 1441 /* keep last */
1427 1442 __NL80211_SURVEY_INFO_AFTER_LAST,
include/net/cfg80211.h
... ... @@ -294,6 +294,11 @@
294 294 *
295 295 * @SURVEY_INFO_NOISE_DBM: noise (in dBm) was filled in
296 296 * @SURVEY_INFO_IN_USE: channel is currently being used
  297 + * @SURVEY_INFO_CHANNEL_TIME: channel active time (in ms) was filled in
  298 + * @SURVEY_INFO_CHANNEL_TIME_BUSY: channel busy time was filled in
  299 + * @SURVEY_INFO_CHANNEL_TIME_EXT_BUSY: extension channel busy time was filled in
  300 + * @SURVEY_INFO_CHANNEL_TIME_RX: channel receive time was filled in
  301 + * @SURVEY_INFO_CHANNEL_TIME_TX: channel transmit time was filled in
297 302 *
298 303 * Used by the driver to indicate which info in &struct survey_info
299 304 * it has filled in during the get_survey().
... ... @@ -301,6 +306,11 @@
301 306 enum survey_info_flags {
302 307 SURVEY_INFO_NOISE_DBM = 1<<0,
303 308 SURVEY_INFO_IN_USE = 1<<1,
  309 + SURVEY_INFO_CHANNEL_TIME = 1<<2,
  310 + SURVEY_INFO_CHANNEL_TIME_BUSY = 1<<3,
  311 + SURVEY_INFO_CHANNEL_TIME_EXT_BUSY = 1<<4,
  312 + SURVEY_INFO_CHANNEL_TIME_RX = 1<<5,
  313 + SURVEY_INFO_CHANNEL_TIME_TX = 1<<6,
304 314 };
305 315  
306 316 /**
... ... @@ -310,6 +320,11 @@
310 320 * @filled: bitflag of flags from &enum survey_info_flags
311 321 * @noise: channel noise in dBm. This and all following fields are
312 322 * optional
  323 + * @channel_time: amount of time in ms the radio spent on the channel
  324 + * @channel_time_busy: amount of time the primary channel was sensed busy
  325 + * @channel_time_ext_busy: amount of time the extension channel was sensed busy
  326 + * @channel_time_rx: amount of time the radio spent receiving data
  327 + * @channel_time_tx: amount of time the radio spent transmitting data
313 328 *
314 329 * Used by dump_survey() to report back per-channel survey information.
315 330 *
... ... @@ -318,6 +333,11 @@
318 333 */
319 334 struct survey_info {
320 335 struct ieee80211_channel *channel;
  336 + u64 channel_time;
  337 + u64 channel_time_busy;
  338 + u64 channel_time_ext_busy;
  339 + u64 channel_time_rx;
  340 + u64 channel_time_tx;
321 341 u32 filled;
322 342 s8 noise;
323 343 };
net/wireless/nl80211.c
... ... @@ -3153,6 +3153,21 @@
3153 3153 survey->noise);
3154 3154 if (survey->filled & SURVEY_INFO_IN_USE)
3155 3155 NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
  3156 + if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
  3157 + NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
  3158 + survey->channel_time);
  3159 + if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
  3160 + NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
  3161 + survey->channel_time_busy);
  3162 + if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
  3163 + NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
  3164 + survey->channel_time_ext_busy);
  3165 + if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
  3166 + NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
  3167 + survey->channel_time_rx);
  3168 + if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
  3169 + NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
  3170 + survey->channel_time_tx);
3156 3171  
3157 3172 nla_nest_end(msg, infoattr);
3158 3173