提交 12d3952f 编写于 作者: F Felix Fietkau 提交者: John W. Linville

mac80211: optimize aggregation session timeout handling

Calling mod_timer from the rx/tx hotpath is somewhat expensive, and the
timeout doesn't need to be so precise.

Switch to a different strategy: Schedule the timer initially, store jiffies
of all last rx/tx activity which would previously modify the timer, and
let the timer re-arm itself after checking the last rx/tx timestamp.
Make the session timers deferrable to avoid causing extra wakeups on systems
running on battery.
This visibly reduces CPU load under high network load on small embedded
systems.
Signed-off-by: NFelix Fietkau <nbd@openwrt.org>
Signed-off-by: NJohn W. Linville <linville@tuxdriver.com>
上级 fcb2c9e1
...@@ -142,6 +142,18 @@ static void sta_rx_agg_session_timer_expired(unsigned long data) ...@@ -142,6 +142,18 @@ static void sta_rx_agg_session_timer_expired(unsigned long data)
u8 *timer_to_id = ptid - *ptid; u8 *timer_to_id = ptid - *ptid;
struct sta_info *sta = container_of(timer_to_id, struct sta_info, struct sta_info *sta = container_of(timer_to_id, struct sta_info,
timer_to_tid[0]); timer_to_tid[0]);
struct tid_ampdu_rx *tid_rx;
unsigned long timeout;
tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[*ptid]);
if (!tid_rx)
return;
timeout = tid_rx->last_rx + TU_TO_JIFFIES(tid_rx->timeout);
if (time_is_after_jiffies(timeout)) {
mod_timer(&tid_rx->session_timer, timeout);
return;
}
#ifdef CONFIG_MAC80211_HT_DEBUG #ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid); printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
...@@ -291,7 +303,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local, ...@@ -291,7 +303,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
/* rx timer */ /* rx timer */
tid_agg_rx->session_timer.function = sta_rx_agg_session_timer_expired; tid_agg_rx->session_timer.function = sta_rx_agg_session_timer_expired;
tid_agg_rx->session_timer.data = (unsigned long)&sta->timer_to_tid[tid]; tid_agg_rx->session_timer.data = (unsigned long)&sta->timer_to_tid[tid];
init_timer(&tid_agg_rx->session_timer); init_timer_deferrable(&tid_agg_rx->session_timer);
/* rx reorder timer */ /* rx reorder timer */
tid_agg_rx->reorder_timer.function = sta_rx_agg_reorder_timer_expired; tid_agg_rx->reorder_timer.function = sta_rx_agg_reorder_timer_expired;
...@@ -335,8 +347,10 @@ void ieee80211_process_addba_request(struct ieee80211_local *local, ...@@ -335,8 +347,10 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
/* activate it for RX */ /* activate it for RX */
rcu_assign_pointer(sta->ampdu_mlme.tid_rx[tid], tid_agg_rx); rcu_assign_pointer(sta->ampdu_mlme.tid_rx[tid], tid_agg_rx);
if (timeout) if (timeout) {
mod_timer(&tid_agg_rx->session_timer, TU_TO_EXP_TIME(timeout)); mod_timer(&tid_agg_rx->session_timer, TU_TO_EXP_TIME(timeout));
tid_agg_rx->last_rx = jiffies;
}
end: end:
mutex_unlock(&sta->ampdu_mlme.mtx); mutex_unlock(&sta->ampdu_mlme.mtx);
......
...@@ -417,6 +417,18 @@ static void sta_tx_agg_session_timer_expired(unsigned long data) ...@@ -417,6 +417,18 @@ static void sta_tx_agg_session_timer_expired(unsigned long data)
u8 *timer_to_id = ptid - *ptid; u8 *timer_to_id = ptid - *ptid;
struct sta_info *sta = container_of(timer_to_id, struct sta_info, struct sta_info *sta = container_of(timer_to_id, struct sta_info,
timer_to_tid[0]); timer_to_tid[0]);
struct tid_ampdu_tx *tid_tx;
unsigned long timeout;
tid_tx = rcu_dereference_protected_tid_tx(sta, *ptid);
if (!tid_tx)
return;
timeout = tid_tx->last_tx + TU_TO_JIFFIES(tid_tx->timeout);
if (time_is_after_jiffies(timeout)) {
mod_timer(&tid_tx->session_timer, timeout);
return;
}
#ifdef CONFIG_MAC80211_HT_DEBUG #ifdef CONFIG_MAC80211_HT_DEBUG
printk(KERN_DEBUG "tx session timer expired on tid %d\n", (u16)*ptid); printk(KERN_DEBUG "tx session timer expired on tid %d\n", (u16)*ptid);
...@@ -542,7 +554,7 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid, ...@@ -542,7 +554,7 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
/* tx timer */ /* tx timer */
tid_tx->session_timer.function = sta_tx_agg_session_timer_expired; tid_tx->session_timer.function = sta_tx_agg_session_timer_expired;
tid_tx->session_timer.data = (unsigned long)&sta->timer_to_tid[tid]; tid_tx->session_timer.data = (unsigned long)&sta->timer_to_tid[tid];
init_timer(&tid_tx->session_timer); init_timer_deferrable(&tid_tx->session_timer);
/* assign a dialog token */ /* assign a dialog token */
sta->ampdu_mlme.dialog_token_allocator++; sta->ampdu_mlme.dialog_token_allocator++;
...@@ -884,9 +896,11 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local, ...@@ -884,9 +896,11 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
sta->ampdu_mlme.addba_req_num[tid] = 0; sta->ampdu_mlme.addba_req_num[tid] = 0;
if (tid_tx->timeout) if (tid_tx->timeout) {
mod_timer(&tid_tx->session_timer, mod_timer(&tid_tx->session_timer,
TU_TO_EXP_TIME(tid_tx->timeout)); TU_TO_EXP_TIME(tid_tx->timeout));
tid_tx->last_tx = jiffies;
}
} else { } else {
___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR, ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR,
......
...@@ -52,7 +52,8 @@ struct ieee80211_local; ...@@ -52,7 +52,8 @@ struct ieee80211_local;
* increased memory use (about 2 kB of RAM per entry). */ * increased memory use (about 2 kB of RAM per entry). */
#define IEEE80211_FRAGMENT_MAX 4 #define IEEE80211_FRAGMENT_MAX 4
#define TU_TO_EXP_TIME(x) (jiffies + usecs_to_jiffies((x) * 1024)) #define TU_TO_JIFFIES(x) (usecs_to_jiffies((x) * 1024))
#define TU_TO_EXP_TIME(x) (jiffies + TU_TO_JIFFIES(x))
#define IEEE80211_DEFAULT_UAPSD_QUEUES \ #define IEEE80211_DEFAULT_UAPSD_QUEUES \
(IEEE80211_WMM_IE_STA_QOSINFO_AC_BK | \ (IEEE80211_WMM_IE_STA_QOSINFO_AC_BK | \
......
...@@ -793,8 +793,7 @@ static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx) ...@@ -793,8 +793,7 @@ static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx)
/* reset session timer */ /* reset session timer */
if (tid_agg_rx->timeout) if (tid_agg_rx->timeout)
mod_timer(&tid_agg_rx->session_timer, tid_agg_rx->last_rx = jiffies;
TU_TO_EXP_TIME(tid_agg_rx->timeout));
/* if this mpdu is fragmented - terminate rx aggregation session */ /* if this mpdu is fragmented - terminate rx aggregation session */
sc = le16_to_cpu(hdr->seq_ctrl); sc = le16_to_cpu(hdr->seq_ctrl);
......
...@@ -101,6 +101,7 @@ enum ieee80211_sta_info_flags { ...@@ -101,6 +101,7 @@ enum ieee80211_sta_info_flags {
* @dialog_token: dialog token for aggregation session * @dialog_token: dialog token for aggregation session
* @timeout: session timeout value to be filled in ADDBA requests * @timeout: session timeout value to be filled in ADDBA requests
* @state: session state (see above) * @state: session state (see above)
* @last_tx: jiffies of last tx activity
* @stop_initiator: initiator of a session stop * @stop_initiator: initiator of a session stop
* @tx_stop: TX DelBA frame when stopping * @tx_stop: TX DelBA frame when stopping
* @buf_size: reorder buffer size at receiver * @buf_size: reorder buffer size at receiver
...@@ -122,6 +123,7 @@ struct tid_ampdu_tx { ...@@ -122,6 +123,7 @@ struct tid_ampdu_tx {
struct timer_list addba_resp_timer; struct timer_list addba_resp_timer;
struct sk_buff_head pending; struct sk_buff_head pending;
unsigned long state; unsigned long state;
unsigned long last_tx;
u16 timeout; u16 timeout;
u8 dialog_token; u8 dialog_token;
u8 stop_initiator; u8 stop_initiator;
...@@ -139,6 +141,7 @@ struct tid_ampdu_tx { ...@@ -139,6 +141,7 @@ struct tid_ampdu_tx {
* @reorder_time: jiffies when skb was added * @reorder_time: jiffies when skb was added
* @session_timer: check if peer keeps Tx-ing on the TID (by timeout value) * @session_timer: check if peer keeps Tx-ing on the TID (by timeout value)
* @reorder_timer: releases expired frames from the reorder buffer. * @reorder_timer: releases expired frames from the reorder buffer.
* @last_rx: jiffies of last rx activity
* @head_seq_num: head sequence number in reordering buffer. * @head_seq_num: head sequence number in reordering buffer.
* @stored_mpdu_num: number of MPDUs in reordering buffer * @stored_mpdu_num: number of MPDUs in reordering buffer
* @ssn: Starting Sequence Number expected to be aggregated. * @ssn: Starting Sequence Number expected to be aggregated.
...@@ -163,6 +166,7 @@ struct tid_ampdu_rx { ...@@ -163,6 +166,7 @@ struct tid_ampdu_rx {
unsigned long *reorder_time; unsigned long *reorder_time;
struct timer_list session_timer; struct timer_list session_timer;
struct timer_list reorder_timer; struct timer_list reorder_timer;
unsigned long last_rx;
u16 head_seq_num; u16 head_seq_num;
u16 stored_mpdu_num; u16 stored_mpdu_num;
u16 ssn; u16 ssn;
......
...@@ -1118,8 +1118,7 @@ static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx, ...@@ -1118,8 +1118,7 @@ static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
/* reset session timer */ /* reset session timer */
if (reset_agg_timer && tid_tx->timeout) if (reset_agg_timer && tid_tx->timeout)
mod_timer(&tid_tx->session_timer, tid_tx->last_tx = jiffies;
TU_TO_EXP_TIME(tid_tx->timeout));
return queued; return queued;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册