Skip to content

Commit ad38bfc

Browse files
mattigotjmberg-intel
authored andcommitted
mac80211: Tx frame latency statistics
Measure TX latency and jitter statistics per station per TID. These Measurements are disabled by default and can be enabled via debugfs. Features included for each station's TID: 1. Keep count of the maximum and average latency of Tx frames. 2. Keep track of many frames arrived in a specific time range (need to enable through debugfs and configure the bins ranges) Signed-off-by: Matti Gottlieb <matti.gottlieb@intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 1d940aa commit ad38bfc

8 files changed

Lines changed: 486 additions & 0 deletions

File tree

‎net/mac80211/debugfs.c‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,172 @@
1717

1818
#define DEBUGFS_FORMAT_BUFFER_SIZE 100
1919

20+
#define TX_LATENCY_BIN_DELIMTER_C ','
21+
#define TX_LATENCY_BIN_DELIMTER_S ","
22+
#define TX_LATENCY_BINS_DISABLED "enable(bins disabled)\n"
23+
#define TX_LATENCY_DISABLED "disable\n"
24+
25+
26+
/*
27+
* Display if Tx latency statistics & bins are enabled/disabled
28+
*/
29+
static ssize_t sta_tx_latency_stat_read(struct file *file,
30+
char __user *userbuf,
31+
size_t count, loff_t *ppos)
32+
{
33+
struct ieee80211_local *local = file->private_data;
34+
struct ieee80211_tx_latency_bin_ranges *tx_latency;
35+
char *buf;
36+
int bufsz, i, ret;
37+
int pos = 0;
38+
39+
rcu_read_lock();
40+
41+
tx_latency = rcu_dereference(local->tx_latency);
42+
43+
if (tx_latency && tx_latency->n_ranges) {
44+
bufsz = tx_latency->n_ranges * 15;
45+
buf = kzalloc(bufsz, GFP_ATOMIC);
46+
if (!buf)
47+
goto err;
48+
49+
for (i = 0; i < tx_latency->n_ranges; i++)
50+
pos += scnprintf(buf + pos, bufsz - pos, "%d,",
51+
tx_latency->ranges[i]);
52+
pos += scnprintf(buf + pos, bufsz - pos, "\n");
53+
} else if (tx_latency) {
54+
bufsz = sizeof(TX_LATENCY_BINS_DISABLED) + 1;
55+
buf = kzalloc(bufsz, GFP_ATOMIC);
56+
if (!buf)
57+
goto err;
58+
59+
pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
60+
TX_LATENCY_BINS_DISABLED);
61+
} else {
62+
bufsz = sizeof(TX_LATENCY_DISABLED) + 1;
63+
buf = kzalloc(bufsz, GFP_ATOMIC);
64+
if (!buf)
65+
goto err;
66+
67+
pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
68+
TX_LATENCY_DISABLED);
69+
}
70+
71+
rcu_read_unlock();
72+
73+
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
74+
kfree(buf);
75+
76+
return ret;
77+
err:
78+
rcu_read_unlock();
79+
return -ENOMEM;
80+
}
81+
82+
/*
83+
* Receive input from user regarding Tx latency statistics
84+
* The input should indicate if Tx latency statistics and bins are
85+
* enabled/disabled.
86+
* If bins are enabled input should indicate the amount of different bins and
87+
* their ranges. Each bin will count how many Tx frames transmitted within the
88+
* appropriate latency.
89+
* Legal input is:
90+
* a) "enable(bins disabled)" - to enable only general statistics
91+
* b) "a,b,c,d,...z" - to enable general statistics and bins, where all are
92+
* numbers and a < b < c < d.. < z
93+
* c) "disable" - disable all statistics
94+
* NOTE: must configure Tx latency statistics bins before stations connected.
95+
*/
96+
97+
static ssize_t sta_tx_latency_stat_write(struct file *file,
98+
const char __user *userbuf,
99+
size_t count, loff_t *ppos)
100+
{
101+
struct ieee80211_local *local = file->private_data;
102+
char buf[128] = {};
103+
char *bins = buf;
104+
char *token;
105+
int buf_size, i, alloc_size;
106+
int prev_bin = 0;
107+
int n_ranges = 0;
108+
int ret = count;
109+
struct ieee80211_tx_latency_bin_ranges *tx_latency;
110+
111+
if (sizeof(buf) <= count)
112+
return -EINVAL;
113+
buf_size = count;
114+
if (copy_from_user(buf, userbuf, buf_size))
115+
return -EFAULT;
116+
117+
mutex_lock(&local->sta_mtx);
118+
119+
/* cannot change config once we have stations */
120+
if (local->num_sta)
121+
goto unlock;
122+
123+
tx_latency =
124+
rcu_dereference_protected(local->tx_latency,
125+
lockdep_is_held(&local->sta_mtx));
126+
127+
/* disable Tx statistics */
128+
if (!strcmp(buf, TX_LATENCY_DISABLED)) {
129+
if (!tx_latency)
130+
goto unlock;
131+
rcu_assign_pointer(local->tx_latency, NULL);
132+
synchronize_rcu();
133+
kfree(tx_latency);
134+
goto unlock;
135+
}
136+
137+
/* Tx latency already enabled */
138+
if (tx_latency)
139+
goto unlock;
140+
141+
if (strcmp(TX_LATENCY_BINS_DISABLED, buf)) {
142+
/* check how many bins and between what ranges user requested */
143+
token = buf;
144+
while (*token != '\0') {
145+
if (*token == TX_LATENCY_BIN_DELIMTER_C)
146+
n_ranges++;
147+
token++;
148+
}
149+
n_ranges++;
150+
}
151+
152+
alloc_size = sizeof(struct ieee80211_tx_latency_bin_ranges) +
153+
n_ranges * sizeof(u32);
154+
tx_latency = kzalloc(alloc_size, GFP_ATOMIC);
155+
if (!tx_latency) {
156+
ret = -ENOMEM;
157+
goto unlock;
158+
}
159+
tx_latency->n_ranges = n_ranges;
160+
for (i = 0; i < n_ranges; i++) { /* setting bin ranges */
161+
token = strsep(&bins, TX_LATENCY_BIN_DELIMTER_S);
162+
sscanf(token, "%d", &tx_latency->ranges[i]);
163+
/* bins values should be in ascending order */
164+
if (prev_bin >= tx_latency->ranges[i]) {
165+
ret = -EINVAL;
166+
kfree(tx_latency);
167+
goto unlock;
168+
}
169+
prev_bin = tx_latency->ranges[i];
170+
}
171+
rcu_assign_pointer(local->tx_latency, tx_latency);
172+
173+
unlock:
174+
mutex_unlock(&local->sta_mtx);
175+
176+
return ret;
177+
}
178+
179+
static const struct file_operations stats_tx_latency_ops = {
180+
.write = sta_tx_latency_stat_write,
181+
.read = sta_tx_latency_stat_read,
182+
.open = simple_open,
183+
.llseek = generic_file_llseek,
184+
};
185+
20186
int mac80211_format_buffer(char __user *userbuf, size_t count,
21187
loff_t *ppos, char *fmt, ...)
22188
{
@@ -315,4 +481,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
315481
DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
316482
DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
317483
DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
484+
485+
DEBUGFS_DEVSTATS_ADD(tx_latency);
318486
}

‎net/mac80211/debugfs_sta.c‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ static const struct file_operations sta_ ##name## _ops = { \
3838
.llseek = generic_file_llseek, \
3939
}
4040

41+
#define STA_OPS_W(name) \
42+
static const struct file_operations sta_ ##name## _ops = { \
43+
.write = sta_##name##_write, \
44+
.open = simple_open, \
45+
.llseek = generic_file_llseek, \
46+
}
47+
4148
#define STA_OPS_RW(name) \
4249
static const struct file_operations sta_ ##name## _ops = { \
4350
.read = sta_##name##_read, \
@@ -388,6 +395,131 @@ static ssize_t sta_last_rx_rate_read(struct file *file, char __user *userbuf,
388395
}
389396
STA_OPS(last_rx_rate);
390397

398+
static int
399+
sta_tx_latency_stat_header(struct ieee80211_tx_latency_bin_ranges *tx_latency,
400+
char *buf, int pos, int bufsz)
401+
{
402+
int i;
403+
int range_count = tx_latency->n_ranges;
404+
u32 *bin_ranges = tx_latency->ranges;
405+
406+
pos += scnprintf(buf + pos, bufsz - pos,
407+
"Station\t\t\tTID\tMax\tAvg");
408+
if (range_count) {
409+
pos += scnprintf(buf + pos, bufsz - pos,
410+
"\t<=%d", bin_ranges[0]);
411+
for (i = 0; i < range_count - 1; i++)
412+
pos += scnprintf(buf + pos, bufsz - pos, "\t%d-%d",
413+
bin_ranges[i], bin_ranges[i+1]);
414+
pos += scnprintf(buf + pos, bufsz - pos,
415+
"\t%d<", bin_ranges[range_count - 1]);
416+
}
417+
418+
pos += scnprintf(buf + pos, bufsz - pos, "\n");
419+
420+
return pos;
421+
}
422+
423+
static int
424+
sta_tx_latency_stat_table(struct ieee80211_tx_latency_bin_ranges *tx_lat_range,
425+
struct ieee80211_tx_latency_stat *tx_lat,
426+
char *buf, int pos, int bufsz, int tid)
427+
{
428+
u32 avg = 0;
429+
int j;
430+
int bin_count = tx_lat->bin_count;
431+
432+
pos += scnprintf(buf + pos, bufsz - pos, "\t\t\t%d", tid);
433+
/* make sure you don't divide in 0 */
434+
if (tx_lat->counter)
435+
avg = tx_lat->sum / tx_lat->counter;
436+
437+
pos += scnprintf(buf + pos, bufsz - pos, "\t%d\t%d",
438+
tx_lat->max, avg);
439+
440+
if (tx_lat_range->n_ranges && tx_lat->bins)
441+
for (j = 0; j < bin_count; j++)
442+
pos += scnprintf(buf + pos, bufsz - pos,
443+
"\t%d", tx_lat->bins[j]);
444+
pos += scnprintf(buf + pos, bufsz - pos, "\n");
445+
446+
return pos;
447+
}
448+
449+
/*
450+
* Output Tx latency statistics station && restart all statistics information
451+
*/
452+
static ssize_t sta_tx_latency_stat_read(struct file *file,
453+
char __user *userbuf,
454+
size_t count, loff_t *ppos)
455+
{
456+
struct sta_info *sta = file->private_data;
457+
struct ieee80211_local *local = sta->local;
458+
struct ieee80211_tx_latency_bin_ranges *tx_latency;
459+
char *buf;
460+
int bufsz, ret, i;
461+
int pos = 0;
462+
463+
bufsz = 20 * IEEE80211_NUM_TIDS *
464+
sizeof(struct ieee80211_tx_latency_stat);
465+
buf = kzalloc(bufsz, GFP_KERNEL);
466+
if (!buf)
467+
return -ENOMEM;
468+
469+
rcu_read_lock();
470+
471+
tx_latency = rcu_dereference(local->tx_latency);
472+
473+
if (!sta->tx_lat) {
474+
pos += scnprintf(buf + pos, bufsz - pos,
475+
"Tx latency statistics are not enabled\n");
476+
goto unlock;
477+
}
478+
479+
pos = sta_tx_latency_stat_header(tx_latency, buf, pos, bufsz);
480+
481+
pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", sta->sta.addr);
482+
for (i = 0; i < IEEE80211_NUM_TIDS; i++)
483+
pos = sta_tx_latency_stat_table(tx_latency, &sta->tx_lat[i],
484+
buf, pos, bufsz, i);
485+
unlock:
486+
rcu_read_unlock();
487+
488+
ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
489+
kfree(buf);
490+
491+
return ret;
492+
}
493+
STA_OPS(tx_latency_stat);
494+
495+
static ssize_t sta_tx_latency_stat_reset_write(struct file *file,
496+
const char __user *userbuf,
497+
size_t count, loff_t *ppos)
498+
{
499+
u32 *bins;
500+
int bin_count;
501+
struct sta_info *sta = file->private_data;
502+
int i;
503+
504+
if (!sta->tx_lat)
505+
return -EINVAL;
506+
507+
for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
508+
bins = sta->tx_lat[i].bins;
509+
bin_count = sta->tx_lat[i].bin_count;
510+
511+
sta->tx_lat[i].max = 0;
512+
sta->tx_lat[i].sum = 0;
513+
sta->tx_lat[i].counter = 0;
514+
515+
if (bin_count)
516+
memset(bins, 0, bin_count * sizeof(u32));
517+
}
518+
519+
return count;
520+
}
521+
STA_OPS_W(tx_latency_stat_reset);
522+
391523
#define DEBUGFS_ADD(name) \
392524
debugfs_create_file(#name, 0400, \
393525
sta->debugfs.dir, sta, &sta_ ##name## _ops);
@@ -441,6 +573,8 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
441573
DEBUGFS_ADD(last_ack_signal);
442574
DEBUGFS_ADD(current_tx_rate);
443575
DEBUGFS_ADD(last_rx_rate);
576+
DEBUGFS_ADD(tx_latency_stat);
577+
DEBUGFS_ADD(tx_latency_stat_reset);
444578

445579
DEBUGFS_ADD_COUNTER(rx_packets, rx_packets);
446580
DEBUGFS_ADD_COUNTER(tx_packets, tx_packets);

‎net/mac80211/ieee80211_i.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,24 @@ struct tpt_led_trigger {
898898
};
899899
#endif
900900

901+
/*
902+
* struct ieee80211_tx_latency_bin_ranges - Tx latency statistics bins ranges
903+
*
904+
* Measuring Tx latency statistics. Counts how many Tx frames transmitted in a
905+
* certain latency range (in Milliseconds). Each station that uses these
906+
* ranges will have bins to count the amount of frames received in that range.
907+
* The user can configure the ranges via debugfs.
908+
* If ranges is NULL then Tx latency statistics bins are disabled for all
909+
* stations.
910+
*
911+
* @n_ranges: number of ranges that are taken in account
912+
* @ranges: the ranges that the user requested or NULL if disabled.
913+
*/
914+
struct ieee80211_tx_latency_bin_ranges {
915+
int n_ranges;
916+
u32 ranges[];
917+
};
918+
901919
/**
902920
* mac80211 scan flags - currently active scan mode
903921
*
@@ -1050,6 +1068,12 @@ struct ieee80211_local {
10501068
struct timer_list sta_cleanup;
10511069
int sta_generation;
10521070

1071+
/*
1072+
* Tx latency statistics parameters for all stations.
1073+
* Can enable via debugfs (NULL when disabled).
1074+
*/
1075+
struct ieee80211_tx_latency_bin_ranges __rcu *tx_latency;
1076+
10531077
struct sk_buff_head pending[IEEE80211_MAX_QUEUES];
10541078
struct tasklet_struct tx_pending_tasklet;
10551079

‎net/mac80211/main.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,8 @@ void ieee80211_free_hw(struct ieee80211_hw *hw)
11421142
ieee80211_free_ack_frame, NULL);
11431143
idr_destroy(&local->ack_status_frames);
11441144

1145+
kfree(rcu_access_pointer(local->tx_latency));
1146+
11451147
wiphy_free(local->hw.wiphy);
11461148
}
11471149
EXPORT_SYMBOL(ieee80211_free_hw);

0 commit comments

Comments
 (0)