forked from zeplios/atheros-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
593-thro-read-for-rate-ctrl.patch
238 lines (227 loc) · 6.11 KB
/
593-thro-read-for-rate-ctrl.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
--- a/drivers/net/wireless/ath/ath9k/debug.c 2013-04-18 20:50:19.000000000 +0800
+++ b/drivers/net/wireless/ath/ath9k/debug.c 2013-04-18 20:38:56.000000000 +0800
@@ -26,6 +26,8 @@
#define REG_READ_D(_ah, _reg) \
ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
+extern bool recv_tp_paused;
+
static int ath9k_debugfs_open(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;
@@ -1723,6 +1725,79 @@
.llseek = default_llseek,
};
+/**
+ * @author zhfch 2012-11-15
+ * @source add by zs @ 2012-6-7
+ */
+static ssize_t read_file_pkt_record(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct ath_softc *sc = file->private_data;
+ char *buf;
+ ssize_t retval;
+ unsigned int len = 0, size = 0;
+
+ recv_tp_paused = true;
+
+ struct list_head *tp_list = &sc->debug.recv_tp_list;
+ struct throughput *cursor;
+ list_for_each_entry(cursor, tp_list, list){
+ size += 75;
+ }
+
+ buf = kmalloc(size, GFP_KERNEL);
+ if (!buf){
+ printk("Can't allocate %u bytes space\n", size);
+ return -ENOMEM;
+ }
+
+ list_for_each_entry(cursor, tp_list, list){
+ u16 tp = cursor->tp * 8 * 10 / 1024 / 1024;
+ u8 rssi = cursor->rssi / cursor->rssi_counter;
+ len += snprintf(buf + len, size - len,
+ "%4u%10u%10u%8u%8d%5u%6u%6u%5uMbps%5u\n", cursor->sec,
+ cursor->tp, cursor->tp_noretry, cursor->rssi, cursor->noise, cursor->rssi_counter,
+ cursor->diff_seq, cursor->pkt_counter, tp, rssi);
+ }
+
+ if (len > size)
+ len = size;
+
+ recv_tp_paused = false;
+
+ retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
+ kfree(buf);
+ return retval;
+}
+
+static ssize_t write_file_pkt_record(struct file *file, const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct ath_softc *sc = file->private_data;
+ struct list_head *tp_list = &sc->debug.recv_tp_list;
+
+ recv_tp_paused = true;
+
+ if (count > 0 && !list_empty(tp_list)){
+ struct throughput *cursor;
+ struct throughput *next;
+ list_for_each_entry_safe(cursor, next, tp_list, list){
+ list_del(&cursor->list);
+ kfree(cursor);
+ }
+ }
+
+ recv_tp_paused = false;
+ return count;
+}
+
+static const struct file_operations fops_pkt_record = {
+ .read = read_file_pkt_record,
+ .write = write_file_pkt_record,
+ .open = ath9k_debugfs_open,
+ .owner = THIS_MODULE,
+ .llseek = default_llseek,
+};
int ath9k_init_debug(struct ath_hw *ah)
{
@@ -1797,6 +1872,10 @@
debugfs_create_file("chanbw", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy,
sc, &fops_chanbw);
+ debugfs_create_file("pkt_record", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
+ &fops_pkt_record);
+
+ INIT_LIST_HEAD(&sc->debug.recv_tp_list);
sc->debug.regidx = 0;
memset(&sc->debug.bb_mac_samp, 0, sizeof(sc->debug.bb_mac_samp));
sc->debug.sampidx = 0;
--- a/drivers/net/wireless/ath/ath9k/debug.h 2013-04-18 20:50:19.000000000 +0800
+++ b/drivers/net/wireless/ath/ath9k/debug.h 2013-04-18 20:40:37.000000000 +0800
@@ -222,6 +222,22 @@
struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
};
+/**
+ * @author zhfch 2012-11-15
+ */
+struct throughput{
+ struct list_head list;
+ u16 sec; /* based 0 */
+ u32 tp; /* all-rx-bytes in this second */
+ u32 tp_noretry;
+ u32 rssi; /* total rssi */
+ int noise;
+ u32 rssi_counter;
+ int diff_seq;
+ unsigned long jiff; /* the lastest time of the current second */
+ u32 pkt_counter;
+};
+
struct ath9k_debug {
struct dentry *debugfs_phy;
u32 regidx;
@@ -231,6 +247,8 @@
u8 sampidx;
u8 tsidx;
u8 rsidx;
+
+ struct list_head recv_tp_list;
};
int ath9k_init_debug(struct ath_hw *ah);
--- a/drivers/net/wireless/ath/ath9k/recv.c 2013-04-18 20:50:19.000000000 +0800
+++ b/drivers/net/wireless/ath/ath9k/recv.c 2013-04-18 20:48:55.000000000 +0800
@@ -20,6 +20,10 @@
#define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb))
+bool recv_tp_paused = false;
+int pre_seqno = -1;
+static void record_pkt(struct ath_softc *sc, struct sk_buff *skb, struct ath_rx_status *rs);
+
static inline bool ath_is_alt_ant_ratio_better(int alt_ratio, int maxdelta,
int mindelta, int main_rssi_avg,
int alt_rssi_avg, int pkt_count)
@@ -1976,6 +1980,7 @@
if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
ath_ant_comb_scan(sc, &rs);
+ record_pkt(sc, skb, &rs);
ieee80211_rx(hw, skb);
requeue_drop_frag:
@@ -2004,3 +2009,80 @@
return 0;
}
+
+/**
+ * @author zhfch 2012-11-15
+ * @source zs 2012-6-7
+ */
+static void record_pkt(struct ath_softc *sc, struct sk_buff *skb, struct ath_rx_status *rs){
+ if (recv_tp_paused)
+ return;
+
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
+ __le16 fc = hdr->frame_control;
+ if (!ieee80211_is_data_qos(fc) || skb->len < 1000)
+ return;
+
+ u16 seqno = ((le16_to_cpu(hdr->seq_ctrl)) & IEEE80211_SCTL_SEQ) >> 4;
+ struct list_head *tp_list = &sc->debug.recv_tp_list;
+
+ if(pre_seqno == -1)
+ pre_seqno = seqno - 1;
+
+ struct throughput *cur;
+ if (!list_empty(tp_list))
+ cur = list_entry(tp_list->prev, struct throughput, list);
+ else
+ cur = NULL;
+
+ unsigned long jiff = jiffies;
+ bool need_new_item = false;
+ if (!cur || time_after(jiff, cur->jiff))
+ need_new_item = true;
+
+ while (need_new_item){
+ unsigned long next_jiff;
+ u16 sec;
+ if (cur){
+ next_jiff = cur->jiff + HZ / 10;
+ sec = cur->sec + 1;
+ }
+ else{
+ next_jiff = jiff + HZ / 10;
+ sec = 0;
+ }
+ cur = kmalloc(sizeof(struct throughput), GFP_KERNEL);
+ if (!cur){
+ printk("Can't alloc new struct throughput!\n");
+ return;
+ }
+ cur->sec = sec;
+ cur->jiff = next_jiff;
+ cur->tp = 0;
+ cur->tp_noretry = 0;
+ cur->rssi = 0;
+ cur->noise = 0;
+ cur->rssi_counter = 0;
+ cur->pkt_counter = 0;
+ cur->diff_seq = 0;
+ if (time_after(jiff, cur->jiff))
+ list_add_tail(&cur->list, tp_list);
+ else
+ break;
+ }
+ int8_t rssi = rs->rs_rssi;
+ if(!rs->rs_moreaggr && rssi != ATH9K_RSSI_BAD){
+ cur->rssi += rssi;
+ cur->noise += sc->sc_ah->noise;
+ cur->rssi_counter++;
+ }
+ cur->pkt_counter++;
+ cur->tp += skb->len;
+ if (!ieee80211_has_retry(fc)){
+ cur->tp_noretry += skb->len;
+ cur->diff_seq += (seqno - pre_seqno - 1) & 0xff;
+ pre_seqno = seqno;
+ }
+ if (need_new_item)
+ list_add_tail(&cur->list, tp_list);
+}