* [PATCH v2 0/8] rate control rework
@ 2007-12-19 0:02 Stefano Brivio
0 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:02 UTC (permalink / raw)
To: John W. Linville; +Cc: Johannes Berg, Mattias Nissler, linux-wireless
This patchset is the result of my recent joint-venture with Mattias. It
introduces a new rate control algorithm based on a PID controller. First
tests show it works much better than the old simple rate control
algorithm.
I think that this should really go into 2.6.25, as the current rate control
algorithm was just written for reference and performs very poorly.
Johannes' and John's concerns have been addressed here.
Patches 1 to 3 introduce the PID controller algorithm. Patches 4 and 5 are
algorithm enhancements, while 6 to 8 are meant for debugging and tuning.
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/8] mac80211: clean up rate selection
[not found] <20071218233749.871878037@polimi.it>
@ 2007-12-19 0:02 ` Stefano Brivio
2007-12-19 0:03 ` [PATCH v2 2/8] mac80211: add PID controller based rate control algorithm Stefano Brivio
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:02 UTC (permalink / raw)
To: John W. Linville; +Cc: Johannes Berg, Mattias Nissler, linux-wireless
From: Mattias Nissler <mattias.nissler@gmx.de>
Move some code out of rc80211_simple since it's probably needed for all rate
selection algorithms, and fix iwlwifi accordingly. While at it, clean up the
rate_control_get_rate() interface.
Signed-off-by: Mattias Nissler <mattias.nissler@gmx.de>
---
drivers/net/wireless/iwlwifi/iwl-3945-rs.c | 44 ++---------------
drivers/net/wireless/iwlwifi/iwl-4965-rs.c | 47 +++---------------
net/mac80211/ieee80211.c | 6 --
net/mac80211/ieee80211_rate.c | 47 ++++++++++++++++++
net/mac80211/ieee80211_rate.h | 73
++++++++++++++++++----------- net/mac80211/ieee80211_sta.c
| 13 +---- net/mac80211/rc80211_simple.c | 64
++++--------------------- net/mac80211/tx.c | 42
+++++++--------- 8 files changed, 146 insertions(+), 190 deletions(-)
Index: wireless-2.6/net/mac80211/ieee80211.c
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211.c
+++ wireless-2.6/net/mac80211/ieee80211.c
@@ -860,10 +860,8 @@ void ieee80211_tx_status(struct ieee8021
sta_info_put(sta);
return;
}
- } else {
- /* FIXME: STUPID to call this with both local and
local->mdev */
- rate_control_tx_status(local, local->mdev, skb, status);
- }
+ } else
+ rate_control_tx_status(local->mdev, skb, status);
ieee80211_led_tx(local, 0);
Index: wireless-2.6/net/mac80211/ieee80211_rate.c
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211_rate.c
+++ wireless-2.6/net/mac80211/ieee80211_rate.c
@@ -147,6 +147,53 @@ static void rate_control_release(struct
kfree(ctrl_ref);
}
+void rate_control_get_rate(struct net_device *dev,
+ struct ieee80211_hw_mode *mode, struct sk_buff
*skb,
+ struct rate_selection *sel)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct rate_control_ref *ref = local->rate_ctrl;
+ struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ struct sta_info *sta = sta_info_get(local, hdr->addr1);
+ int i;
+ u16 fc;
+
+ memset(sel, 0, sizeof(struct rate_selection));
+
+ /* Send management frames and broadcast/multicast data using lowest
+ * rate. */
+ fc = le16_to_cpu(hdr->frame_control);
+ if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
+ is_multicast_ether_addr(hdr->addr1))
+ sel->rate = rate_lowest(local, mode, sta);
+
+ /* If a forced rate is in effect, select it. */
+ sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
+ sel->rate =
&mode->rates[sdata->bss->force_unicast_rateidx]; +
+ /* If we haven't found the rate yet, ask the rate control algo. */
+ if (!sel->rate)
+ ref->ops->get_rate(ref->priv, dev, mode, skb, sel);
+
+ /* Select a non-ERP backup rate. */
+ if (!sel->nonerp) {
+ for (i = 0; i < mode->num_rates - 1; i++) {
+ struct ieee80211_rate *rate = &mode->rates[i];
+ if (sel->rate->rate < rate->rate)
+ break;
+
+ if (rate_supported(sta, mode, i) &&
+ !(rate->flags & IEEE80211_RATE_ERP))
+ sel->nonerp = rate;
+ }
+ }
+
+ if (sta)
+ sta_info_put(sta);
+}
+
struct rate_control_ref *rate_control_get(struct rate_control_ref *ref)
{
kref_get(&ref->kref);
Index: wireless-2.6/net/mac80211/ieee80211_rate.h
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211_rate.h
+++ wireless-2.6/net/mac80211/ieee80211_rate.h
@@ -18,31 +18,24 @@
#include "ieee80211_i.h"
#include "sta_info.h"
-#define RATE_CONTROL_NUM_DOWN 20
-#define RATE_CONTROL_NUM_UP 15
-
-
-struct rate_control_extra {
- /* values from rate_control_get_rate() to the caller: */
- struct ieee80211_rate *probe; /* probe with this rate, or NULL for
no
- * probing */
+struct rate_selection {
+ /* Selected transmission rate */
+ struct ieee80211_rate *rate;
+ /* Non-ERP rate to use if mac80211 decides it cannot use an ERP
rate */ struct ieee80211_rate *nonerp;
-
- /* parameters from the caller to rate_control_get_rate(): */
- struct ieee80211_hw_mode *mode;
- u16 ethertype;
+ /* probe with this rate, or NULL for no probing */
+ struct ieee80211_rate *probe;
};
-
struct rate_control_ops {
struct module *module;
const char *name;
void (*tx_status)(void *priv, struct net_device *dev,
struct sk_buff *skb,
struct ieee80211_tx_status *status);
- struct ieee80211_rate *(*get_rate)(void *priv, struct net_device
*dev,
- struct sk_buff *skb,
- struct rate_control_extra
*extra);
+ void (*get_rate)(void *priv, struct net_device *dev,
+ struct ieee80211_hw_mode *mode, struct sk_buff
*skb,
+ struct rate_selection *sel);
void (*rate_init)(void *priv, void *priv_sta,
struct ieee80211_local *local, struct sta_info
*sta); void (*clear)(void *priv);
@@ -75,25 +68,20 @@ void ieee80211_rate_control_unregister(s
* first available algorithm. */
struct rate_control_ref *rate_control_alloc(const char *name,
struct ieee80211_local *local);
+void rate_control_get_rate(struct net_device *dev,
+ struct ieee80211_hw_mode *mode, struct sk_buff
*skb,
+ struct rate_selection *sel);
struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
void rate_control_put(struct rate_control_ref *ref);
-static inline void rate_control_tx_status(struct ieee80211_local *local,
- struct net_device *dev,
+static inline void rate_control_tx_status(struct net_device *dev,
struct sk_buff *skb,
struct ieee80211_tx_status
*status) {
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct rate_control_ref *ref = local->rate_ctrl;
- ref->ops->tx_status(ref->priv, dev, skb, status);
-}
-
-static inline struct ieee80211_rate *
-rate_control_get_rate(struct ieee80211_local *local, struct net_device
*dev,
- struct sk_buff *skb, struct rate_control_extra
*extra) -{
- struct rate_control_ref *ref = local->rate_ctrl;
- return ref->ops->get_rate(ref->priv, dev, skb, extra);
+ ref->ops->tx_status(ref->priv, dev, skb, status);
}
@@ -142,6 +130,37 @@ static inline void rate_control_remove_s
#endif
}
+static inline int
+rate_supported(struct sta_info *sta, struct ieee80211_hw_mode *mode, int
index) +{
+ return (sta == NULL || sta->supp_rates & BIT(index)) &&
+ (mode->rates[index].flags & IEEE80211_RATE_SUPPORTED);
+}
+
+static inline int
+rate_lowest_index(struct ieee80211_local *local, struct ieee80211_hw_mode
*mode,
+ struct sta_info *sta)
+{
+ int i;
+
+ for (i = 0; i < mode->num_rates; i++) {
+ if (rate_supported(sta, mode, i))
+ return i;
+ }
+
+ /* warn when we cannot find a rate. */
+ WARN_ON(i == 0);
+
+ return 0;
+}
+
+static inline struct ieee80211_rate *
+rate_lowest(struct ieee80211_local *local, struct ieee80211_hw_mode *mode,
+ struct sta_info *sta)
+{
+ return &mode->rates[rate_lowest_index(local, mode, sta)];
+}
+
/* functions for rate control related to a device */
int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
Index: wireless-2.6/net/mac80211/ieee80211_sta.c
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211_sta.c
+++ wireless-2.6/net/mac80211/ieee80211_sta.c
@@ -2467,9 +2467,8 @@ static int ieee80211_sta_join_ibss(struc
struct sk_buff *skb;
struct ieee80211_mgmt *mgmt;
struct ieee80211_tx_control control;
- struct ieee80211_rate *rate;
struct ieee80211_hw_mode *mode;
- struct rate_control_extra extra;
+ struct rate_selection ratesel;
u8 *pos;
struct ieee80211_sub_if_data *sdata;
@@ -2554,18 +2553,16 @@ static int ieee80211_sta_join_ibss(struc
}
memset(&control, 0, sizeof(control));
- memset(&extra, 0, sizeof(extra));
- extra.mode = local->oper_hw_mode;
- rate = rate_control_get_rate(local, dev, skb, &extra);
- if (!rate) {
+ rate_control_get_rate(dev, local->oper_hw_mode, skb,
&ratesel);
+ if (!ratesel.rate) {
printk(KERN_DEBUG "%s: Failed to determine TX rate
" "for IBSS beacon\n", dev->name);
break;
}
control.tx_rate =
((sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE) &&
- (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
- rate->val2 : rate->val;
+ (ratesel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
+ ratesel.rate->val2 : ratesel.rate->val;
control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
control.power_level = local->hw.conf.power_level;
control.flags |= IEEE80211_TXCTL_NO_ACK;
Index: wireless-2.6/net/mac80211/rc80211_simple.c
===================================================================
--- wireless-2.6.orig/net/mac80211/rc80211_simple.c
+++ wireless-2.6/net/mac80211/rc80211_simple.c
@@ -23,6 +23,8 @@
/* This is a minimal implementation of TX rate controlling that can be used
* as the default when no improved mechanisms are available. */
+#define RATE_CONTROL_NUM_DOWN 20
+#define RATE_CONTROL_NUM_UP 15
#define RATE_CONTROL_EMERG_DEC 2
#define RATE_CONTROL_INTERVAL (HZ / 20)
@@ -87,26 +89,6 @@ static void rate_control_rate_dec(struct
}
}
-
-static struct ieee80211_rate *
-rate_control_lowest_rate(struct ieee80211_local *local,
- struct ieee80211_hw_mode *mode)
-{
- int i;
-
- for (i = 0; i < mode->num_rates; i++) {
- struct ieee80211_rate *rate = &mode->rates[i];
-
- if (rate->flags & IEEE80211_RATE_SUPPORTED)
- return rate;
- }
-
- printk(KERN_DEBUG "rate_control_lowest_rate - no supported rates "
- "found\n");
- return &mode->rates[0];
-}
-
-
struct global_rate_control {
int dummy;
};
@@ -216,56 +198,32 @@ static void rate_control_simple_tx_statu
}
-static struct ieee80211_rate *
+static void
rate_control_simple_get_rate(void *priv, struct net_device *dev,
+ struct ieee80211_hw_mode *mode,
struct sk_buff *skb,
- struct rate_control_extra *extra)
+ struct rate_selection *sel)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_sub_if_data *sdata;
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
- struct ieee80211_hw_mode *mode = extra->mode;
struct sta_info *sta;
- int rateidx, nonerp_idx;
- u16 fc;
-
- memset(extra, 0, sizeof(*extra));
-
- fc = le16_to_cpu(hdr->frame_control);
- if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
- (hdr->addr1[0] & 0x01)) {
- /* Send management frames and broadcast/multicast data
using
- * lowest rate. */
- /* TODO: this could probably be improved.. */
- return rate_control_lowest_rate(local, mode);
- }
+ int rateidx;
sta = sta_info_get(local, hdr->addr1);
- if (!sta)
- return rate_control_lowest_rate(local, mode);
-
- sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
- sta->txrate = sdata->bss->force_unicast_rateidx;
+ if (!sta) {
+ sel->rate = rate_lowest(local, mode, NULL);
+ return;
+ }
rateidx = sta->txrate;
if (rateidx >= mode->num_rates)
rateidx = mode->num_rates - 1;
- sta->last_txrate = rateidx;
- nonerp_idx = rateidx;
- while (nonerp_idx > 0 &&
- ((mode->rates[nonerp_idx].flags & IEEE80211_RATE_ERP) ||
- !(mode->rates[nonerp_idx].flags &
IEEE80211_RATE_SUPPORTED) ||
- !(sta->supp_rates & BIT(nonerp_idx))))
- nonerp_idx--;
- extra->nonerp = &mode->rates[nonerp_idx];
-
sta_info_put(sta);
- return &mode->rates[rateidx];
+ sel->rate = &mode->rates[rateidx];
}
Index: wireless-2.6/net/mac80211/tx.c
===================================================================
--- wireless-2.6.orig/net/mac80211/tx.c
+++ wireless-2.6/net/mac80211/tx.c
@@ -569,21 +569,17 @@ ieee80211_tx_h_encrypt(struct ieee80211_
static ieee80211_txrx_result
ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
{
- struct rate_control_extra extra;
+ struct rate_selection rsel;
if (likely(!tx->u.tx.rate)) {
- memset(&extra, 0, sizeof(extra));
- extra.mode = tx->u.tx.mode;
- extra.ethertype = tx->ethertype;
-
- tx->u.tx.rate = rate_control_get_rate(tx->local, tx->dev,
- tx->skb, &extra);
- if (unlikely(extra.probe != NULL)) {
+ rate_control_get_rate(tx->dev, tx->u.tx.mode, tx->skb,
&rsel);
+ tx->u.tx.rate = rsel.rate;
+ if (unlikely(rsel.probe != NULL)) {
tx->u.tx.control->flags |=
IEEE80211_TXCTL_RATE_CTRL_PROBE;
tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
tx->u.tx.control->alt_retry_rate =
tx->u.tx.rate->val;
- tx->u.tx.rate = extra.probe;
+ tx->u.tx.rate = rsel.probe;
} else
tx->u.tx.control->alt_retry_rate = -1;
@@ -594,14 +590,14 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
if (tx->u.tx.mode->mode == MODE_IEEE80211G &&
(tx->sdata->flags & IEEE80211_SDATA_USE_PROTECTION) &&
- (tx->flags & IEEE80211_TXRXD_FRAGMENTED) && extra.nonerp) {
+ (tx->flags & IEEE80211_TXRXD_FRAGMENTED) && rsel.nonerp) {
tx->u.tx.last_frag_rate = tx->u.tx.rate;
- if (extra.probe)
+ if (rsel.probe)
tx->flags &= ~IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
else
tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
- tx->u.tx.rate = extra.nonerp;
- tx->u.tx.control->rate = extra.nonerp;
+ tx->u.tx.rate = rsel.nonerp;
+ tx->u.tx.control->rate = rsel.nonerp;
tx->u.tx.control->flags &=
~IEEE80211_TXCTL_RATE_CTRL_PROBE; } else {
tx->u.tx.last_frag_rate = tx->u.tx.rate;
@@ -1667,8 +1663,7 @@ struct sk_buff *ieee80211_beacon_get(str
struct net_device *bdev;
struct ieee80211_sub_if_data *sdata = NULL;
struct ieee80211_if_ap *ap = NULL;
- struct ieee80211_rate *rate;
- struct rate_control_extra extra;
+ struct rate_selection rsel;
u8 *b_head, *b_tail;
int bh_len, bt_len;
@@ -1712,14 +1707,13 @@ struct sk_buff *ieee80211_beacon_get(str
}
if (control) {
- memset(&extra, 0, sizeof(extra));
- extra.mode = local->oper_hw_mode;
-
- rate = rate_control_get_rate(local, local->mdev, skb,
&extra);
- if (!rate) {
+ rate_control_get_rate(local->mdev, local->oper_hw_mode,
skb,
+ &rsel);
+ if (!rsel.rate) {
if (net_ratelimit()) {
- printk(KERN_DEBUG "%s:
ieee80211_beacon_get: no rate "
- "found\n",
wiphy_name(local->hw.wiphy));
+ printk(KERN_DEBUG "%s:
ieee80211_beacon_get: "
+ "no rate found\n",
+ wiphy_name(local->hw.wiphy));
}
dev_kfree_skb(skb);
return NULL;
@@ -1727,8 +1721,8 @@ struct sk_buff *ieee80211_beacon_get(str
control->tx_rate =
((sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE) &&
- (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
- rate->val2 : rate->val;
+ (rsel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
+ rsel.rate->val2 : rsel.rate->val;
control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
control->power_level = local->hw.conf.power_level;
control->flags |= IEEE80211_TXCTL_NO_ACK;
Index: wireless-2.6/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
===================================================================
--- wireless-2.6.orig/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ wireless-2.6/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -560,22 +560,6 @@ static void rs_tx_status(void *priv_rate
return;
}
-static struct ieee80211_rate *iwl3945_get_lowest_rate(struct
ieee80211_local
- *local)
-{
- struct ieee80211_hw_mode *mode = local->oper_hw_mode;
- int i;
-
- for (i = 0; i < mode->num_rates; i++) {
- struct ieee80211_rate *rate = &mode->rates[i];
-
- if (rate->flags & IEEE80211_RATE_SUPPORTED)
- return rate;
- }
-
- return &mode->rates[0];
-}
-
static u16 iwl3945_get_adjacent_rate(struct iwl3945_rate_scale_priv
*rs_priv, u8 index, u16 rate_mask, int phymode)
{
@@ -654,10 +638,9 @@ static u16 iwl3945_get_adjacent_rate(str
* rate table and must reference the driver allocated rate table
*
*/
-static struct ieee80211_rate *rs_get_rate(void *priv_rate,
- struct net_device *dev,
- struct sk_buff *skb,
- struct rate_control_extra *extra)
+static void rs_get_rate(void *priv_rate, struct net_device *dev,
+ struct ieee80211_hw_mode *mode, struct sk_buff
*skb,
+ struct rate_selection *sel)
{
u8 low = IWL_RATE_INVALID;
u8 high = IWL_RATE_INVALID;
@@ -674,32 +657,19 @@ static struct ieee80211_rate *rs_get_rat
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
struct sta_info *sta;
- u16 fc, rate_mask;
+ u16 rate_mask;
struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate;
DECLARE_MAC_BUF(mac);
IWL_DEBUG_RATE("enter\n");
- memset(extra, 0, sizeof(*extra));
-
- fc = le16_to_cpu(hdr->frame_control);
- if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
- (is_multicast_ether_addr(hdr->addr1))) {
- /* Send management frames and broadcast/multicast data
using
- * lowest rate. */
- /* TODO: this could probably be improved.. */
- IWL_DEBUG_RATE("leave: lowest rate (not data or is "
- "multicast)\n");
-
- return iwl3945_get_lowest_rate(local);
- }
-
sta = sta_info_get(local, hdr->addr1);
if (!sta || !sta->rate_ctrl_priv) {
IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
+ sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
if (sta)
sta_info_put(sta);
- return NULL;
+ return;
}
rate_mask = sta->supp_rates;
@@ -844,7 +814,7 @@ static struct ieee80211_rate *rs_get_rat
IWL_DEBUG_RATE("leave: %d\n", index);
- return &priv->ieee_rates[index];
+ sel->rate = &priv->ieee_rates[index];
}
static struct rate_control_ops rs_ops = {
Index: wireless-2.6/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
===================================================================
--- wireless-2.6.orig/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
+++ wireless-2.6/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
@@ -2007,56 +2007,27 @@ static void rs_initialize_lq(struct iwl4
return;
}
-static struct ieee80211_rate *rs_get_lowest_rate(struct ieee80211_local
- *local)
+static void rs_get_rate(void *priv_rate, struct net_device *dev,
+ struct ieee80211_hw_mode *mode, struct sk_buff
*skb,
+ struct rate_selection *sel)
{
- struct ieee80211_hw_mode *mode = local->oper_hw_mode;
- int i;
-
- for (i = 0; i < mode->num_rates; i++) {
- struct ieee80211_rate *rate = &mode->rates[i];
-
- if (rate->flags & IEEE80211_RATE_SUPPORTED)
- return rate;
- }
-
- return &mode->rates[0];
-}
-
-static struct ieee80211_rate *rs_get_rate(void *priv_rate,
- struct net_device *dev,
- struct sk_buff *skb,
- struct rate_control_extra
- *extra)
-{
-
int i;
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_conf *conf = &local->hw.conf;
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
struct sta_info *sta;
- u16 fc;
struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate;
struct iwl4965_rate_scale_priv *lq;
IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n");
- memset(extra, 0, sizeof(*extra));
-
- fc = le16_to_cpu(hdr->frame_control);
- if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
{
- /* Send management frames and broadcast/multicast data
using
- * lowest rate. */
- /* TODO: this could probably be improved.. */
- return rs_get_lowest_rate(local);
- }
-
sta = sta_info_get(local, hdr->addr1);
if (!sta || !sta->rate_ctrl_priv) {
+ sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
if (sta)
sta_info_put(sta);
- return rs_get_lowest_rate(local);
+ return;
}
lq = (struct iwl4965_rate_scale_priv *)sta->rate_ctrl_priv;
@@ -2083,11 +2054,13 @@ static struct ieee80211_rate *rs_get_rat
}
done:
+ if ((i < 0) || (i > IWL_RATE_COUNT)) {
+ sel->rate = rate_lowest(local, local->oper_hw_mode, sta);
+ return;
+ }
sta_info_put(sta);
- if ((i < 0) || (i > IWL_RATE_COUNT))
- return rs_get_lowest_rate(local);
- return &priv->ieee_rates[i];
+ sel->rate = &priv->ieee_rates[i];
}
static void *rs_alloc_sta(void *priv, gfp_t gfp)
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/8] mac80211: add PID controller based rate control algorithm
[not found] <20071218233749.871878037@polimi.it>
2007-12-19 0:02 ` [PATCH v2 1/8] mac80211: clean up rate selection Stefano Brivio
@ 2007-12-19 0:03 ` Stefano Brivio
2007-12-19 0:03 ` [PATCH v2 3/8] mac80211: make PID rate control algorithm the default Stefano Brivio
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:03 UTC (permalink / raw)
To: John W. Linville; +Cc: Johannes Berg, Mattias Nissler, linux-wireless
From: Mattias Nissler <mattias.nissler@gmx.de>
Add a new rate control algorithm based on a PID controller. It samples the
percentage of failed frames over time, feeds the result into the controller
and uses its output to control the TX rate.
Signed-off-by: Mattias Nissler <mattias.nissler@gmx.de>
---
Kconfig | 12 +
Makefile | 1
ieee80211.c | 27 +++-
ieee80211_rate.h | 3
rc80211_pid.c | 365
+++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed,
403 insertions(+), 5 deletions(-)
Index: wireless-2.6/net/mac80211/Kconfig
===================================================================
--- wireless-2.6.orig/net/mac80211/Kconfig
+++ wireless-2.6/net/mac80211/Kconfig
@@ -25,6 +25,18 @@ config MAC80211_RCSIMPLE
Say Y unless you know you will have another algorithm
available.
+config MAC80211_RCPID
+ bool "'PID' rate control algorithm" if EMBEDDED
+ default y
+ depends on MAC80211
+ help
+ This option enables a TX rate control algorithm for
+ mac80211 that uses a PID controller to select the TX
+ rate.
+
+ Say Y unless you're sure you want to use a different
+ rate control algorithm.
+
config MAC80211_LEDS
bool "Enable LED triggers"
depends on MAC80211 && LEDS_TRIGGERS
Index: wireless-2.6/net/mac80211/Makefile
===================================================================
--- wireless-2.6.orig/net/mac80211/Makefile
+++ wireless-2.6/net/mac80211/Makefile
@@ -4,6 +4,7 @@ mac80211-objs-$(CONFIG_MAC80211_LEDS) +=
mac80211-objs-$(CONFIG_MAC80211_DEBUGFS) += debugfs.o debugfs_sta.o
debugfs_netdev.o debugfs_key.o mac80211-objs-$(CONFIG_NET_SCHED) += wme.o
mac80211-objs-$(CONFIG_MAC80211_RCSIMPLE) += rc80211_simple.o
+mac80211-objs-$(CONFIG_MAC80211_RCPID) += rc80211_pid.o
mac80211-objs := \
ieee80211.o \
Index: wireless-2.6/net/mac80211/ieee80211.c
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211.c
+++ wireless-2.6/net/mac80211/ieee80211.c
@@ -1316,23 +1316,37 @@ static int __init ieee80211_init(void)
#ifdef CONFIG_MAC80211_RCSIMPLE
ret = ieee80211_rate_control_register(&mac80211_rcsimple);
if (ret)
- return ret;
+ goto fail;
+#endif
+
+#ifdef CONFIG_MAC80211_RCPID
+ ret = ieee80211_rate_control_register(&mac80211_rcpid);
+ if (ret)
+ goto fail;
#endif
ret = ieee80211_wme_register();
if (ret) {
-#ifdef CONFIG_MAC80211_RCSIMPLE
- ieee80211_rate_control_unregister(&mac80211_rcsimple);
-#endif
printk(KERN_DEBUG "ieee80211_init: failed to "
"initialize WME (err=%d)\n", ret);
- return ret;
+ goto fail;
}
ieee80211_debugfs_netdev_init();
ieee80211_regdomain_init();
return 0;
+
+fail:
+
+#ifdef CONFIG_MAC80211_RCSIMPLE
+ ieee80211_rate_control_unregister(&mac80211_rcsimple);
+#endif
+#ifdef CONFIG_MAC80211_RCPID
+ ieee80211_rate_control_unregister(&mac80211_rcpid);
+#endif
+
+ return ret;
}
static void __exit ieee80211_exit(void)
@@ -1340,6 +1354,9 @@ static void __exit ieee80211_exit(void)
#ifdef CONFIG_MAC80211_RCSIMPLE
ieee80211_rate_control_unregister(&mac80211_rcsimple);
#endif
+#ifdef CONFIG_MAC80211_RCPID
+ ieee80211_rate_control_unregister(&mac80211_rcpid);
+#endif
ieee80211_wme_unregister();
ieee80211_debugfs_netdev_exit();
Index: wireless-2.6/net/mac80211/ieee80211_rate.h
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211_rate.h
+++ wireless-2.6/net/mac80211/ieee80211_rate.h
@@ -61,6 +61,9 @@ struct rate_control_ref {
/* default 'simple' algorithm */
extern struct rate_control_ops mac80211_rcsimple;
+/* 'PID' algorithm */
+extern struct rate_control_ops mac80211_rcpid;
+
int ieee80211_rate_control_register(struct rate_control_ops *ops);
void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
Index: wireless-2.6/net/mac80211/rc80211_pid.c
===================================================================
--- /dev/null
+++ wireless-2.6/net/mac80211/rc80211_pid.c
@@ -0,0 +1,365 @@
+/*
+ * Copyright 2002-2005, Instant802 Networks, Inc.
+ * Copyright 2005, Devicescape Software, Inc.
+ * Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/netdevice.h>
+#include <linux/types.h>
+#include <linux/skbuff.h>
+
+#include <net/mac80211.h>
+#include "ieee80211_rate.h"
+
+
+/* This is an implementation of a TX rate control algorithm that uses a PID
+ * controller. Given a target failed frames rate, the controller decides
about
+ * TX rate changes to meet the target failed frames rate.
+ *
+ * The controller basically computes the following:
+ *
+ * adj = CP * err + CI * err_avg + CD * (err - last_err)
+ *
+ * where
+ * adj adjustment value that is used to switch TX rate (see
below)
+ * err current error: target vs. current failed frames
percentage
+ * last_err last error
+ * err_avg average (i.e. poor man's integral) of recent
errors
+ * CP Proportional coefficient
+ * CI Integral coefficient
+ * CD Derivative coefficient
+ *
+ * CP, CI, CD are subject to careful tuning.
+ *
+ * The integral component uses a exponential moving average approach
instead of
+ * an actual sliding window. The advantage is that we don't need to keep an
+ * array of the last N error values and computation is easier.
+ *
+ * Once we have the adj value, we need to map it to a TX rate to be
selected.
+ * For now, we depend on the rates to be ordered in a way such that more
robust
+ * rates (i.e. such that exhibit a lower framed failed percentage) come
first.
+ * E.g. for the 802.11b/g case, we first have the b rates in ascending
order,
+ * then the g rates. The adj simply decides the index of the TX rate in
the list
+ * to switch to (relative to the current TX rate entry).
+ *
+ * Note that for the computations we use a fixed-point representation to
avoid
+ * floating point arithmetic. Hence, all values are shifted left by
+ * RC_PID_ARITH_SHIFT.
+ */
+
+/* Sampling period for measuring percentage of failed frames. */
+#define RC_PID_INTERVAL (HZ / 8)
+
+/* Exponential averaging smoothness (used for I part of PID controller) */
+#define RC_PID_SMOOTHING_SHIFT 3
+#define RC_PID_SMOOTHING (1 << RC_PID_SMOOTHING_SHIFT)
+
+/* Fixed point arithmetic shifting amount. */
+#define RC_PID_ARITH_SHIFT 8
+
+/* Fixed point arithmetic factor. */
+#define RC_PID_ARITH_FACTOR (1 << RC_PID_ARITH_SHIFT)
+
+/* Proportional PID component coefficient. */
+#define RC_PID_COEFF_P 15
+/* Integral PID component coefficient. */
+#define RC_PID_COEFF_I 9
+/* Derivative PID component coefficient. */
+#define RC_PID_COEFF_D 15
+
+/* Target failed frames rate for the PID controller. NB: This effectively
gives
+ * maximum failed frames percentage we're willing to accept. If the
wireless
+ * link quality is good, the controller will fail to adjust failed frames
+ * percentage to the target. This is intentional.
+ */
+#define RC_PID_TARGET_PF (11 << RC_PID_ARITH_SHIFT)
+
+struct rc_pid_sta_info {
+ unsigned long last_change;
+ unsigned long last_sample;
+
+ u32 tx_num_failed;
+ u32 tx_num_xmit;
+
+ /* Average failed frames percentage error (i.e. actual vs. target
+ * percentage), scaled by RC_PID_SMOOTHING. This value is computed
+ * using using an exponential weighted average technique:
+ *
+ * (RC_PID_SMOOTHING - 1) * err_avg_old + err
+ * err_avg = ------------------------------------------
+ * RC_PID_SMOOTHING
+ *
+ * where err_avg is the new approximation, err_avg_old the
previous one
+ * and err is the error w.r.t. to the current failed frames
percentage
+ * sample. Note that the bigger RC_PID_SMOOTHING the more weight is
+ * given to the previous estimate, resulting in smoother behavior
(i.e.
+ * corresponding to a longer integration window).
+ *
+ * For computation, we actually don't use the above formula, but
this
+ * one:
+ *
+ * err_avg_scaled = err_avg_old_scaled - err_avg_old + err
+ *
+ * where:
+ * err_avg_scaled = err * RC_PID_SMOOTHING
+ * err_avg_old_scaled = err_avg_old * RC_PID_SMOOTHING
+ *
+ * This avoids floating point numbers and the per_failed_old value
can
+ * easily be obtained by shifting per_failed_old_scaled right by
+ * RC_PID_SMOOTHING_SHIFT.
+ */
+ s32 err_avg_sc;
+
+ /* Last framed failes percentage sample */
+ u32 last_pf;
+};
+
+/* Algorithm parameters. We keep them on a per-algorithm approach, so they
can
+ * be tuned individually for each interface.
+ */
+struct rc_pid_info {
+
+ /* The failed frames percentage target. */
+ u32 target;
+
+ /* P, I and D coefficients. */
+ s32 coeff_p;
+ s32 coeff_i;
+ s32 coeff_d;
+};
+
+
+static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
+ struct sta_info *sta, int adj)
+{
+ struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_hw_mode *mode;
+ int newidx = sta->txrate + adj;
+ int maxrate;
+ int back = (adj > 0) ? 1 : -1;
+
+ sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+ if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
+ /* forced unicast rate - do not change STA rate */
+ return;
+ }
+
+ mode = local->oper_hw_mode;
+ maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
+
+ if (newidx < 0)
+ newidx = 0;
+ else if (newidx >= mode->num_rates)
+ newidx = mode->num_rates - 1;
+
+ while (newidx != sta->txrate) {
+ if (rate_supported(sta, mode, newidx) &&
+ (maxrate < 0 || newidx <= maxrate)) {
+ sta->txrate = newidx;
+ break;
+ }
+
+ newidx += back;
+ }
+}
+
+static void rate_control_pid_sample(struct rc_pid_info *pinfo,
+ struct ieee80211_local *local,
+ struct sta_info *sta)
+{
+ struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
+ u32 pf;
+ s32 err_avg;
+ s32 err_prop;
+ s32 err_int;
+ s32 err_der;
+ int adj;
+
+ spinfo = sta->rate_ctrl_priv;
+ spinfo->last_sample = jiffies;
+
+ /* If no frames were transmitted, we assume the old sample is
+ * still a good measurement and copy it. */
+ if (spinfo->tx_num_xmit == 0)
+ pf = spinfo->last_pf;
+ else {
+ pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
+ pf <<= RC_PID_ARITH_SHIFT;
+
+ spinfo->tx_num_xmit = 0;
+ spinfo->tx_num_failed = 0;
+ }
+
+ /* Compute the proportional, integral and derivative errors. */
+ err_prop = RC_PID_TARGET_PF - pf;
+
+ err_avg = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
+ spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
+ err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
+
+ err_der = pf - spinfo->last_pf;
+ spinfo->last_pf = pf;
+
+ /* Compute the controller output. */
+ adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i
+ + err_der * pinfo->coeff_d);
+
+ /* We need to do an arithmetic right shift. ISO C says this is
+ * implementation defined for negative left operands. Hence, be
+ * careful to get it right, also for negative values. */
+ adj = (adj < 0) ? -((-adj) >> (2 * RC_PID_ARITH_SHIFT)) :
+ adj >> (2 * RC_PID_ARITH_SHIFT);
+
+ /* Change rate. */
+ if (adj)
+ rate_control_pid_adjust_rate(local, sta, adj);
+}
+
+static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
+ struct sk_buff *skb,
+ struct ieee80211_tx_status *status)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ struct rc_pid_info *pinfo = priv;
+ struct sta_info *sta;
+ struct rc_pid_sta_info *spinfo;
+
+ sta = sta_info_get(local, hdr->addr1);
+
+ if (!sta)
+ return;
+
+ /* Ignore all frames that were sent with a different rate than the
rate
+ * we currently advise mac80211 to use. */
+ if (status->control.rate !=
&local->oper_hw_mode->rates[sta->txrate])
+ return;
+
+ spinfo = sta->rate_ctrl_priv;
+ spinfo->tx_num_xmit++;
+
+ /* We count frames that totally failed to be transmitted as two bad
+ * frames, those that made it out but had some retries as one good
and
+ * one bad frame. */
+ if (status->excessive_retries) {
+ spinfo->tx_num_failed += 2;
+ spinfo->tx_num_xmit++;
+ } else if (status->retry_count) {
+ spinfo->tx_num_failed++;
+ spinfo->tx_num_xmit++;
+ }
+
+ if (status->excessive_retries) {
+ sta->tx_retry_failed++;
+ sta->tx_num_consecutive_failures++;
+ sta->tx_num_mpdu_fail++;
+ } else {
+ sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
+ sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
+ sta->last_ack_rssi[2] = status->ack_signal;
+ sta->tx_num_consecutive_failures = 0;
+ sta->tx_num_mpdu_ok++;
+ }
+ sta->tx_retry_count += status->retry_count;
+ sta->tx_num_mpdu_fail += status->retry_count;
+
+ /* Update PID controller state. */
+ if (time_after(jiffies, spinfo->last_sample + RC_PID_INTERVAL))
+ rate_control_pid_sample(pinfo, local, sta);
+
+ sta_info_put(sta);
+}
+
+static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
+ struct ieee80211_hw_mode *mode,
+ struct sk_buff *skb,
+ struct rate_selection *sel)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ struct sta_info *sta;
+ int rateidx;
+
+ sta = sta_info_get(local, hdr->addr1);
+
+ if (!sta) {
+ sel->rate = rate_lowest(local, mode, NULL);
+ sta_info_put(sta);
+ return;
+ }
+
+ rateidx = sta->txrate;
+
+ if (rateidx >= mode->num_rates)
+ rateidx = mode->num_rates - 1;
+
+ sta_info_put(sta);
+
+ sel->rate = &mode->rates[rateidx];
+}
+
+static void rate_control_pid_rate_init(void *priv, void *priv_sta,
+ struct ieee80211_local *local,
+ struct sta_info *sta)
+{
+ /* TODO: This routine should consider using RSSI from previous
packets
+ * as we need to have IEEE 802.1X auth succeed immediately after
assoc..
+ * Until that method is implemented, we will use the lowest
supported
+ * rate as a workaround. */
+ sta->txrate = rate_lowest_index(local, local->oper_hw_mode, sta);
+}
+
+static void *rate_control_pid_alloc(struct ieee80211_local *local)
+{
+ struct rc_pid_info *pinfo;
+
+ pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC);
+
+ pinfo->target = RC_PID_TARGET_PF;
+ pinfo->coeff_p = RC_PID_COEFF_P;
+ pinfo->coeff_i = RC_PID_COEFF_I;
+ pinfo->coeff_d = RC_PID_COEFF_D;
+
+ return pinfo;
+}
+
+static void rate_control_pid_free(void *priv)
+{
+ struct rc_pid_info *pinfo = priv;
+ kfree(pinfo);
+}
+
+static void rate_control_pid_clear(void *priv)
+{
+}
+
+static void *rate_control_pid_alloc_sta(void *priv, gfp_t gfp)
+{
+ struct rc_pid_sta_info *spinfo;
+
+ spinfo = kzalloc(sizeof(*spinfo), gfp);
+
+ return spinfo;
+}
+
+static void rate_control_pid_free_sta(void *priv, void *priv_sta)
+{
+ struct rc_pid_sta_info *spinfo = priv_sta;
+ kfree(spinfo);
+}
+
+struct rate_control_ops mac80211_rcpid = {
+ .name = "pid",
+ .tx_status = rate_control_pid_tx_status,
+ .get_rate = rate_control_pid_get_rate,
+ .rate_init = rate_control_pid_rate_init,
+ .clear = rate_control_pid_clear,
+ .alloc = rate_control_pid_alloc,
+ .free = rate_control_pid_free,
+ .alloc_sta = rate_control_pid_alloc_sta,
+ .free_sta = rate_control_pid_free_sta,
+};
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/8] mac80211: make PID rate control algorithm the default
[not found] <20071218233749.871878037@polimi.it>
2007-12-19 0:02 ` [PATCH v2 1/8] mac80211: clean up rate selection Stefano Brivio
2007-12-19 0:03 ` [PATCH v2 2/8] mac80211: add PID controller based rate control algorithm Stefano Brivio
@ 2007-12-19 0:03 ` Stefano Brivio
2007-12-19 0:03 ` [PATCH v2 4/8] rc80211-pid: add rate behaviour learning algorithm Stefano Brivio
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:03 UTC (permalink / raw)
To: John W. Linville; +Cc: Johannes Berg, Mattias Nissler, linux-wireless
This makes the new PID TX rate control algorithm the default instead of the
rc80211_simple rate control algorithm. The simple algorithm was flawed in
several ways: it wasn't responsive at all and didn't age the information it
was relying on properly. The PID algorithm allows us to tune
characteristics such as responsiveness by adjusting parameters and was
found to generally behave better.
Two separate modules are created, however we force users to build
rc80211-simple into mac80211 if rc80211-pid isn't built-in, so that this
won't break for users who disable module autoloading. The default algorithm
can be set through a modparam. While at it, mark rc80211-simple as
deprecated, and schedule it for removal.
Signed-off-by: Stefano Brivio <stefano.brivio@polimi.it>
---
Documentation/feature-removal-schedule.txt | 8 +++
net/mac80211/Kconfig | 61
+++++++++++++++++++++++------ net/mac80211/Makefile
| 10 +++- net/mac80211/ieee80211.c | 32
--------------- net/mac80211/ieee80211_rate.c | 12 +++++
net/mac80211/ieee80211_rate.h | 6 --
6 files changed, 77 insertions(+), 52 deletions(-)
Index: wireless-2.6/net/mac80211/Kconfig
===================================================================
--- wireless-2.6.orig/net/mac80211/Kconfig
+++ wireless-2.6/net/mac80211/Kconfig
@@ -13,20 +13,45 @@ config MAC80211
This option enables the hardware independent IEEE 802.11
networking stack.
-config MAC80211_RCSIMPLE
- bool "'simple' rate control algorithm" if EMBEDDED
- default y
+choice
+ prompt "Default rate control algorithm"
+ default MAC80211_RC_DEFAULT_PID
+ depends on MAC80211
+ help
+ This option selects the default rate control algorithm
+ mac80211 will use. Note that this default can still be
+ overriden through the ieee80211_default_rc_algo module
+ parameter.
+
+config MAC80211_RC_DEFAULT_PID
+ bool "PID controller based rate control algorithm"
+ depends on MAC80211
+ select MAC80211_RC_PID
+ help
+ Select the PID controller based rate control as the
+ default rate control algorithm. You should choose
+ this unless you know what you are doing.
+
+config MAC80211_RC_DEFAULT_SIMPLE
+ bool "Simple rate control algorithm"
depends on MAC80211
+ select MAC80211_RC_SIMPLE
help
- This option allows you to turn off the 'simple' rate
- control algorithm in mac80211. If you do turn it off,
- you absolutely need another rate control algorithm.
+ Select the simple rate control as the default rate
+ control algorithm. Note that this is a non-responsive,
+ dumb algorithm. You should choose the PID rate control
+ instead.
- Say Y unless you know you will have another algorithm
- available.
+endchoice
-config MAC80211_RCPID
- bool "'PID' rate control algorithm" if EMBEDDED
+config MAC80211_RC_DEFAULT
+ string
+ depends on MAC80211
+ default "pid" if MAC80211_RC_DEFAULT_PID
+ default "simple" if MAC80211_RC_DEFAULT_SIMPLE
+
+config MAC80211_RC_PID
+ tristate "PID controller based rate control algorithm"
default y
depends on MAC80211
help
@@ -34,8 +59,20 @@ config MAC80211_RCPID
mac80211 that uses a PID controller to select the TX
rate.
- Say Y unless you're sure you want to use a different
- rate control algorithm.
+ Say Y or M unless you're sure you want to use a
+ different rate control algorithm.
+
+config MAC80211_RC_SIMPLE
+ tristate "Simple rate control algorithm (DEPRECATED)"
+ default n
+ depends on MAC80211
+ help
+ This option enables a very simple, non-responsive TX
+ rate control algorithm. This algorithm is deprecated
+ and will be removed from the kernel in near future.
+ It has been replaced by the PID algorithm.
+
+ Say N unless you know what you are doing.
config MAC80211_LEDS
bool "Enable LED triggers"
Index: wireless-2.6/net/mac80211/Makefile
===================================================================
--- wireless-2.6.orig/net/mac80211/Makefile
+++ wireless-2.6/net/mac80211/Makefile
@@ -1,10 +1,12 @@
obj-$(CONFIG_MAC80211) += mac80211.o
+obj-$(CONFIG_MAC80211_RC_PID) += rc80211_pid.o
+ifeq ($(CONFIG_MAC80211_RC_PID),y)
+ obj-$(CONFIG_MAC80211_RC_SIMPLE) += rc80211_simple.o
+endif
mac80211-objs-$(CONFIG_MAC80211_LEDS) += ieee80211_led.o
mac80211-objs-$(CONFIG_MAC80211_DEBUGFS) += debugfs.o debugfs_sta.o
debugfs_netdev.o debugfs_key.o mac80211-objs-$(CONFIG_NET_SCHED) += wme.o
-mac80211-objs-$(CONFIG_MAC80211_RCSIMPLE) += rc80211_simple.o
-mac80211-objs-$(CONFIG_MAC80211_RCPID) += rc80211_pid.o
mac80211-objs := \
ieee80211.o \
@@ -26,3 +28,7 @@ mac80211-objs := \
util.o \
event.o \
$(mac80211-objs-y)
+
+ifneq ($(CONFIG_MAC80211_RC_PID),y)
+ mac80211-objs += rc80211_simple.o
+endif
Index: wireless-2.6/net/mac80211/ieee80211.c
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211.c
+++ wireless-2.6/net/mac80211/ieee80211.c
@@ -1313,51 +1313,21 @@ static int __init ieee80211_init(void)
BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) >
sizeof(skb->cb));
-#ifdef CONFIG_MAC80211_RCSIMPLE
- ret = ieee80211_rate_control_register(&mac80211_rcsimple);
- if (ret)
- goto fail;
-#endif
-
-#ifdef CONFIG_MAC80211_RCPID
- ret = ieee80211_rate_control_register(&mac80211_rcpid);
- if (ret)
- goto fail;
-#endif
-
ret = ieee80211_wme_register();
if (ret) {
printk(KERN_DEBUG "ieee80211_init: failed to "
"initialize WME (err=%d)\n", ret);
- goto fail;
+ return ret;
}
ieee80211_debugfs_netdev_init();
ieee80211_regdomain_init();
return 0;
-
-fail:
-
-#ifdef CONFIG_MAC80211_RCSIMPLE
- ieee80211_rate_control_unregister(&mac80211_rcsimple);
-#endif
-#ifdef CONFIG_MAC80211_RCPID
- ieee80211_rate_control_unregister(&mac80211_rcpid);
-#endif
-
- return ret;
}
static void __exit ieee80211_exit(void)
{
-#ifdef CONFIG_MAC80211_RCSIMPLE
- ieee80211_rate_control_unregister(&mac80211_rcsimple);
-#endif
-#ifdef CONFIG_MAC80211_RCPID
- ieee80211_rate_control_unregister(&mac80211_rcpid);
-#endif
-
ieee80211_wme_unregister();
ieee80211_debugfs_netdev_exit();
}
Index: wireless-2.6/net/mac80211/ieee80211_rate.c
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211_rate.c
+++ wireless-2.6/net/mac80211/ieee80211_rate.c
@@ -21,6 +21,11 @@ struct rate_control_alg {
static LIST_HEAD(rate_ctrl_algs);
static DEFINE_MUTEX(rate_ctrl_mutex);
+static char *ieee80211_default_rc_algo = CONFIG_MAC80211_RC_DEFAULT;
+module_param(ieee80211_default_rc_algo, charp, 0644);
+MODULE_PARM_DESC(ieee80211_default_rc_algo,
+ "Default rate control algorithm for mac80211 to use");
+
int ieee80211_rate_control_register(struct rate_control_ops *ops)
{
struct rate_control_alg *alg;
@@ -97,13 +102,17 @@ ieee80211_rate_control_ops_get(const cha
struct rate_control_ops *ops;
if (!name)
- name = "simple";
+ name = ieee80211_default_rc_algo;
ops = ieee80211_try_rate_control_ops_get(name);
if (!ops) {
request_module("rc80211_%s", name);
ops = ieee80211_try_rate_control_ops_get(name);
}
+ if (!ops)
+ /* If we get here, rc80211_simple must be built into
mac80211. */
+ ops = ieee80211_try_rate_control_ops_get("simple");
+
return ops;
}
@@ -244,3 +253,4 @@ void rate_control_deinitialize(struct ie
local->rate_ctrl = NULL;
rate_control_put(ref);
}
+
Index: wireless-2.6/net/mac80211/ieee80211_rate.h
===================================================================
--- wireless-2.6.orig/net/mac80211/ieee80211_rate.h
+++ wireless-2.6/net/mac80211/ieee80211_rate.h
@@ -58,12 +58,6 @@ struct rate_control_ref {
struct kref kref;
};
-/* default 'simple' algorithm */
-extern struct rate_control_ops mac80211_rcsimple;
-
-/* 'PID' algorithm */
-extern struct rate_control_ops mac80211_rcpid;
-
int ieee80211_rate_control_register(struct rate_control_ops *ops);
void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
Index: wireless-2.6/Documentation/feature-removal-schedule.txt
===================================================================
--- wireless-2.6.orig/Documentation/feature-removal-schedule.txt
+++ wireless-2.6/Documentation/feature-removal-schedule.txt
@@ -350,3 +350,11 @@ Why: No in-kernel drivers will depend on
Who: John W. Linville <linville@tuxdriver.com>
---------------------------
+
+What: rc80211-simple rate control algorithm for mac80211
+When: 2.6.26
+Files: net/mac80211/rc80211-simple.c
+Why: This algorithm was provided for reference but always exhibited
bad
+ responsiveness and performance and has some serious flaws. It has
been
+ replaced by rc80211-pid.
+Who: Stefano Brivio <stefano.brivio@polimi.it>
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 4/8] rc80211-pid: add rate behaviour learning algorithm
[not found] <20071218233749.871878037@polimi.it>
` (2 preceding siblings ...)
2007-12-19 0:03 ` [PATCH v2 3/8] mac80211: make PID rate control algorithm the default Stefano Brivio
@ 2007-12-19 0:03 ` Stefano Brivio
2007-12-19 0:04 ` [PATCH v2 5/8] rc80211-pid: add sharpening factor Stefano Brivio
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:03 UTC (permalink / raw)
To: John W. Linville; +Cc: Johannes Berg, Mattias Nissler, linux-wireless
This patch introduces a learning algorithm in order for the PID controller
to learn how to map adjustment values to rates. This is better described in
code comments.
Signed-off-by: Stefano Brivio <stefano.brivio@polimi.it>
---
rc80211_pid.c | 181
+++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed,
161 insertions(+), 20 deletions(-)
Index: wireless-2.6/net/mac80211/rc80211_pid.c
===================================================================
--- wireless-2.6.orig/net/mac80211/rc80211_pid.c
+++ wireless-2.6/net/mac80211/rc80211_pid.c
@@ -2,6 +2,7 @@
* Copyright 2002-2005, Instant802 Networks, Inc.
* Copyright 2005, Devicescape Software, Inc.
* Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
+ * Copyright 2007, Stefano Brivio <stefano.brivio@polimi.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -39,12 +40,18 @@
* an actual sliding window. The advantage is that we don't need to keep an
* array of the last N error values and computation is easier.
*
- * Once we have the adj value, we need to map it to a TX rate to be
selected.
- * For now, we depend on the rates to be ordered in a way such that more
robust
- * rates (i.e. such that exhibit a lower framed failed percentage) come
first.
- * E.g. for the 802.11b/g case, we first have the b rates in ascending
order,
- * then the g rates. The adj simply decides the index of the TX rate in
the list
- * to switch to (relative to the current TX rate entry).
+ * Once we have the adj value, we map it to a rate by means of a learning
+ * algorithm. This algorithm keeps the state of the percentual failed
frames
+ * difference between rates. The behaviour of the lowest available rate is
kept
+ * as a reference value, and every time we switch between two rates, we
compute
+ * the difference between the failed frames each rate exhibited. By doing
so,
+ * we compare behaviours which different rates exhibited in adjacent
timeslices,
+ * thus the comparison is minimally affected by external conditions. This
+ * difference gets propagated to the whole set of measurements, so that the
+ * reference is always the same. Periodically, we normalize this set so
that
+ * recent events weigh the most. By comparing the adj value with this set,
we
+ * avoid pejorative switches to lower rates and allow for switches to
higher
+ * rates if they behaved well.
*
* Note that for the computations we use a fixed-point representation to
avoid
* floating point arithmetic. Hence, all values are shifted left by
@@ -78,6 +85,16 @@
*/
#define RC_PID_TARGET_PF (11 << RC_PID_ARITH_SHIFT)
+/* Rate behaviour normalization quantity over time. */
+#define RC_PID_NORM_OFFSET 3
+
+/* Push high rates right after loading. */
+#define RC_PID_FAST_START 0
+
+/* Arithmetic right shift for positive and negative values for ISO C. */
+#define RC_PID_DO_ARITH_RIGHT_SHIFT(x, y) \
+ (x) < 0 ? -((-(x)) >> (y)) : (x) >> (y)
+
struct rc_pid_sta_info {
unsigned long last_change;
unsigned long last_sample;
@@ -121,6 +138,18 @@ struct rc_pid_sta_info {
/* Algorithm parameters. We keep them on a per-algorithm approach, so they
can
* be tuned individually for each interface.
*/
+struct rc_pid_rateinfo {
+
+ /* Map sorted rates to rates in ieee80211_hw_mode. */
+ int index;
+
+ /* Map rates in ieee80211_hw_mode to sorted rates. */
+ int rev_index;
+
+ /* Comparison with the lowest rate. */
+ int diff;
+};
+
struct rc_pid_info {
/* The failed frames percentage target. */
@@ -130,15 +159,56 @@ struct rc_pid_info {
s32 coeff_p;
s32 coeff_i;
s32 coeff_d;
+
+ /* Rates information. */
+ struct rc_pid_rateinfo *rinfo;
+
+ /* Index of the last used rate. */
+ int oldrate;
};
+/* Shift the adjustment so that we won't switch to a lower rate if it
exhibited
+ * a worse failed frames behaviour and we'll choose the highest rate whose
+ * failed frames behaviour is not worse than the one of the original rate
+ * target. While at it, check that the adjustment is within the ranges.
Then,
+ * provide the new rate index. */
+static int rate_control_pid_shift_adjust(struct rc_pid_rateinfo *r,
+ int adj, int cur, int l)
+{
+ int i, j, k, tmp;
+
+ if (cur + adj < 0)
+ return 0;
+ if (cur + adj >= l)
+ return l - 1;
+
+ i = r[cur + adj].rev_index;
+
+ j = r[cur].rev_index;
+
+ if (adj < 0) {
+ tmp = i;
+ for (k = j; k >= i; k--)
+ if (r[k].diff <= r[j].diff)
+ tmp = k;
+ return r[tmp].index;
+ } else if (adj > 0) {
+ tmp = i;
+ for (k = i + 1; k + i < l; k++)
+ if (r[k].diff <= r[i].diff)
+ tmp = k;
+ return r[tmp].index;
+ }
+ return cur + adj;
+}
static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
- struct sta_info *sta, int adj)
+ struct sta_info *sta, int adj,
+ struct rc_pid_rateinfo *rinfo)
{
struct ieee80211_sub_if_data *sdata;
struct ieee80211_hw_mode *mode;
- int newidx = sta->txrate + adj;
+ int newidx;
int maxrate;
int back = (adj > 0) ? 1 : -1;
@@ -151,10 +221,8 @@ static void rate_control_pid_adjust_rate
mode = local->oper_hw_mode;
maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
- if (newidx < 0)
- newidx = 0;
- else if (newidx >= mode->num_rates)
- newidx = mode->num_rates - 1;
+ newidx = rate_control_pid_shift_adjust(rinfo, adj, sta->txrate,
+ mode->num_rates);
while (newidx != sta->txrate) {
if (rate_supported(sta, mode, newidx) &&
@@ -167,18 +235,37 @@ static void rate_control_pid_adjust_rate
}
}
+/* Normalize the failed frames per-rate differences. */
+static void rate_control_pid_normalize(struct rc_pid_rateinfo *r, int l)
+{
+ int i;
+
+ if (r[0].diff > RC_PID_NORM_OFFSET)
+ r[0].diff -= RC_PID_NORM_OFFSET;
+ else if (r[0].diff < -RC_PID_NORM_OFFSET)
+ r[0].diff += RC_PID_NORM_OFFSET;
+ for (i = 0; i < l - 1; i++)
+ if (r[i + 1].diff > r[i].diff + RC_PID_NORM_OFFSET)
+ r[i + 1].diff -= RC_PID_NORM_OFFSET;
+ else if (r[i + 1].diff <= r[i].diff)
+ r[i + 1].diff += RC_PID_NORM_OFFSET;
+}
+
static void rate_control_pid_sample(struct rc_pid_info *pinfo,
struct ieee80211_local *local,
struct sta_info *sta)
{
struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
+ struct rc_pid_rateinfo *rinfo = pinfo->rinfo;
+ struct ieee80211_hw_mode *mode;
u32 pf;
s32 err_avg;
s32 err_prop;
s32 err_int;
s32 err_der;
- int adj;
+ int adj, i, j, tmp;
+ mode = local->oper_hw_mode;
spinfo = sta->rate_ctrl_priv;
spinfo->last_sample = jiffies;
@@ -194,6 +281,20 @@ static void rate_control_pid_sample(stru
spinfo->tx_num_failed = 0;
}
+ /* If we just switched rate, update the rate behaviour info. */
+ if (pinfo->oldrate != sta->txrate) {
+
+ i = rinfo[pinfo->oldrate].rev_index;
+ j = rinfo[sta->txrate].rev_index;
+
+ tmp = (pf - spinfo->last_pf);
+ tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT);
+
+ rinfo[j].diff = rinfo[i].diff + tmp;
+ pinfo->oldrate = sta->txrate;
+ }
+ rate_control_pid_normalize(rinfo, mode->num_rates);
+
/* Compute the proportional, integral and derivative errors. */
err_prop = RC_PID_TARGET_PF - pf;
@@ -207,16 +308,11 @@ static void rate_control_pid_sample(stru
/* Compute the controller output. */
adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i
+ err_der * pinfo->coeff_d);
-
- /* We need to do an arithmetic right shift. ISO C says this is
- * implementation defined for negative left operands. Hence, be
- * careful to get it right, also for negative values. */
- adj = (adj < 0) ? -((-adj) >> (2 * RC_PID_ARITH_SHIFT)) :
- adj >> (2 * RC_PID_ARITH_SHIFT);
+ adj = RC_PID_DO_ARITH_RIGHT_SHIFT(adj, 2 * RC_PID_ARITH_SHIFT);
/* Change rate. */
if (adj)
- rate_control_pid_adjust_rate(local, sta, adj);
+ rate_control_pid_adjust_rate(local, sta, adj, rinfo);
}
static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
@@ -316,13 +412,57 @@ static void rate_control_pid_rate_init(v
static void *rate_control_pid_alloc(struct ieee80211_local *local)
{
struct rc_pid_info *pinfo;
+ struct rc_pid_rateinfo *rinfo;
+ struct ieee80211_hw_mode *mode;
+ int i, j, tmp;
+ bool s;
pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC);
+ if (!pinfo)
+ return NULL;
+
+ /* We can safely assume that oper_hw_mode won't change unless we
get
+ * reinitialized. */
+ mode = local->oper_hw_mode;
+ rinfo = kmalloc(sizeof(*rinfo) * mode->num_rates, GFP_ATOMIC);
+ if (!rinfo) {
+ kfree(pinfo);
+ return NULL;
+ }
+
+ /* Sort the rates. This is optimized for the most common case (i.e.
+ * almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed
+ * mapping too. */
+ for (i = 0; i < mode->num_rates; i++) {
+ rinfo[i].index = i;
+ rinfo[i].rev_index = i;
+ if (RC_PID_FAST_START)
+ rinfo[i].diff = 0;
+ else
+ rinfo[i].diff = i * RC_PID_NORM_OFFSET;
+ }
+ for (i = 1; i < mode->num_rates; i++) {
+ s = 0;
+ for (j = 0; j < mode->num_rates - i; j++)
+ if (unlikely(mode->rates[rinfo[j].index].rate >
+ mode->rates[rinfo[j +
1].index].rate)) {
+ tmp = rinfo[j].index;
+ rinfo[j].index = rinfo[j + 1].index;
+ rinfo[j + 1].index = tmp;
+ rinfo[rinfo[j].index].rev_index = j;
+ rinfo[rinfo[j + 1].index].rev_index = j +
1;
+ s = 1;
+ }
+ if (!s)
+ break;
+ }
pinfo->target = RC_PID_TARGET_PF;
pinfo->coeff_p = RC_PID_COEFF_P;
pinfo->coeff_i = RC_PID_COEFF_I;
pinfo->coeff_d = RC_PID_COEFF_D;
+ pinfo->rinfo = rinfo;
+ pinfo->oldrate = 0;
return pinfo;
}
@@ -330,6 +470,7 @@ static void *rate_control_pid_alloc(stru
static void rate_control_pid_free(void *priv)
{
struct rc_pid_info *pinfo = priv;
+ kfree(pinfo->rinfo);
kfree(pinfo);
}
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 5/8] rc80211-pid: add sharpening factor
[not found] <20071218233749.871878037@polimi.it>
` (3 preceding siblings ...)
2007-12-19 0:03 ` [PATCH v2 4/8] rc80211-pid: add rate behaviour learning algorithm Stefano Brivio
@ 2007-12-19 0:04 ` Stefano Brivio
2007-12-19 0:04 ` [PATCH v2 6/8] rc80211-pid: add debugging Stefano Brivio
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:04 UTC (permalink / raw)
To: John W. Linville; +Cc: Johannes Berg, Mattias Nissler, linux-wireless
This patch introduces a PID sharpening factor for faster response after
association and low activity events.
Signed-off-by: Stefano Brivio <stefano.brivio@polimi.it>
Signed-off-by: Mattias Nissler <mattias.nissler@gmx.de>
---
rc80211_pid.c | 35 +++++++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 8 deletions(-)
Index: wireless-2.6/net/mac80211/rc80211_pid.c
===================================================================
--- wireless-2.6.orig/net/mac80211/rc80211_pid.c
+++ wireless-2.6/net/mac80211/rc80211_pid.c
@@ -23,13 +23,16 @@
*
* The controller basically computes the following:
*
- * adj = CP * err + CI * err_avg + CD * (err - last_err)
+ * adj = CP * err + CI * err_avg + CD * (err - last_err) * (1 + sharpening)
*
* where
* adj adjustment value that is used to switch TX rate (see
below)
* err current error: target vs. current failed frames
percentage
* last_err last error
* err_avg average (i.e. poor man's integral) of recent
errors
+ * sharpening non-zero when fast response is needed (i.e.
right after
+ * association or no frames sent for a long time),
heading
+ * to zero over time
* CP Proportional coefficient
* CI Integral coefficient
* CD Derivative coefficient
@@ -65,6 +68,10 @@
#define RC_PID_SMOOTHING_SHIFT 3
#define RC_PID_SMOOTHING (1 << RC_PID_SMOOTHING_SHIFT)
+/* Sharpening factor (used for D part of PID controller) */
+#define RC_PID_SHARPENING_FACTOR 0
+#define RC_PID_SHARPENING_DURATION 0
+
/* Fixed point arithmetic shifting amount. */
#define RC_PID_ARITH_SHIFT 8
@@ -131,8 +138,11 @@ struct rc_pid_sta_info {
*/
s32 err_avg_sc;
- /* Last framed failes percentage sample */
+ /* Last framed failes percentage sample. */
u32 last_pf;
+
+ /* Sharpening needed. */
+ u8 sharp_cnt;
};
/* Algorithm parameters. We keep them on a per-algorithm approach, so they
can @@ -267,20 +277,26 @@ static void rate_control_pid_sample(stru
mode = local->oper_hw_mode;
spinfo = sta->rate_ctrl_priv;
+
+ /* In case nothing happened during the previous control interval,
turn
+ * the sharpening factor on. */
+ if (jiffies - spinfo->last_sample > 2 * RC_PID_INTERVAL)
+ spinfo->sharp_cnt = RC_PID_SHARPENING_DURATION;
+
spinfo->last_sample = jiffies;
- /* If no frames were transmitted, we assume the old sample is
+ /* This should never happen, but in case, we assume the old sample
is
* still a good measurement and copy it. */
- if (spinfo->tx_num_xmit == 0)
+ if (unlikely(spinfo->tx_num_xmit == 0))
pf = spinfo->last_pf;
else {
pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
pf <<= RC_PID_ARITH_SHIFT;
-
- spinfo->tx_num_xmit = 0;
- spinfo->tx_num_failed = 0;
}
+ spinfo->tx_num_xmit = 0;
+ spinfo->tx_num_failed = 0;
+
/* If we just switched rate, update the rate behaviour info. */
if (pinfo->oldrate != sta->txrate) {
@@ -302,8 +318,11 @@ static void rate_control_pid_sample(stru
spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
- err_der = pf - spinfo->last_pf;
+ err_der = pf - spinfo->last_pf
+ * (1 + RC_PID_SHARPENING_FACTOR * spinfo->sharp_cnt);
spinfo->last_pf = pf;
+ if (spinfo->sharp_cnt)
+ spinfo->sharp_cnt--;
/* Compute the controller output. */
adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 6/8] rc80211-pid: add debugging
[not found] <20071218233749.871878037@polimi.it>
` (4 preceding siblings ...)
2007-12-19 0:04 ` [PATCH v2 5/8] rc80211-pid: add sharpening factor Stefano Brivio
@ 2007-12-19 0:04 ` Stefano Brivio
2007-12-19 0:04 ` [PATCH v2 7/8] debugfs: allow access to signed values Stefano Brivio
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:04 UTC (permalink / raw)
To: John W. Linville; +Cc: Johannes Berg, Mattias Nissler, linux-wireless
From: Mattias Nissler <mattias.nissler@gmx.de>
This adds a new debugfs file from which rate control relevant events can be
read one event per line. The output includes the current time, so graphs
can be created showing the rate control parameters. This helps in
evaluating and tuning rate control parameters. While at it, we split
headers and code for better readability.
Signed-off-by: Mattias Nissler <mattias.nissler@gmx.de>
Signed-off-by: Stefano Brivio <stefano.brivio@polimi.it>
---
net/mac80211/rc80211_pid.c | 525
------------------------ wireless-2.6/net/mac80211/Makefile
| 7 wireless-2.6/net/mac80211/rc80211_pid.h | 242 +++++++++++
wireless-2.6/net/mac80211/rc80211_pid_algo.c | 444 ++++++++++++++++++++
wireless-2.6/net/mac80211/rc80211_pid_debugfs.c | 223 ++++++++++
5 files changed, 916 insertions(+), 525 deletions(-)
Index: wireless-2.6/net/mac80211/rc80211_pid.c
===================================================================
--- wireless-2.6.orig/net/mac80211/rc80211_pid.c
+++ /dev/null
@@ -1,525 +0,0 @@
-/*
- * Copyright 2002-2005, Instant802 Networks, Inc.
- * Copyright 2005, Devicescape Software, Inc.
- * Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
- * Copyright 2007, Stefano Brivio <stefano.brivio@polimi.it>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/netdevice.h>
-#include <linux/types.h>
-#include <linux/skbuff.h>
-
-#include <net/mac80211.h>
-#include "ieee80211_rate.h"
-
-
-/* This is an implementation of a TX rate control algorithm that uses a PID
- * controller. Given a target failed frames rate, the controller decides
about
- * TX rate changes to meet the target failed frames rate.
- *
- * The controller basically computes the following:
- *
- * adj = CP * err + CI * err_avg + CD * (err - last_err) * (1 + sharpening)
- *
- * where
- * adj adjustment value that is used to switch TX rate (see
below)
- * err current error: target vs. current failed frames
percentage
- * last_err last error
- * err_avg average (i.e. poor man's integral) of recent
errors
- * sharpening non-zero when fast response is needed (i.e.
right after
- * association or no frames sent for a long time),
heading
- * to zero over time
- * CP Proportional coefficient
- * CI Integral coefficient
- * CD Derivative coefficient
- *
- * CP, CI, CD are subject to careful tuning.
- *
- * The integral component uses a exponential moving average approach
instead of
- * an actual sliding window. The advantage is that we don't need to keep an
- * array of the last N error values and computation is easier.
- *
- * Once we have the adj value, we map it to a rate by means of a learning
- * algorithm. This algorithm keeps the state of the percentual failed
frames
- * difference between rates. The behaviour of the lowest available rate is
kept
- * as a reference value, and every time we switch between two rates, we
compute
- * the difference between the failed frames each rate exhibited. By doing
so,
- * we compare behaviours which different rates exhibited in adjacent
timeslices,
- * thus the comparison is minimally affected by external conditions. This
- * difference gets propagated to the whole set of measurements, so that the
- * reference is always the same. Periodically, we normalize this set so
that
- * recent events weigh the most. By comparing the adj value with this set,
we
- * avoid pejorative switches to lower rates and allow for switches to
higher
- * rates if they behaved well.
- *
- * Note that for the computations we use a fixed-point representation to
avoid
- * floating point arithmetic. Hence, all values are shifted left by
- * RC_PID_ARITH_SHIFT.
- */
-
-/* Sampling period for measuring percentage of failed frames. */
-#define RC_PID_INTERVAL (HZ / 8)
-
-/* Exponential averaging smoothness (used for I part of PID controller) */
-#define RC_PID_SMOOTHING_SHIFT 3
-#define RC_PID_SMOOTHING (1 << RC_PID_SMOOTHING_SHIFT)
-
-/* Sharpening factor (used for D part of PID controller) */
-#define RC_PID_SHARPENING_FACTOR 0
-#define RC_PID_SHARPENING_DURATION 0
-
-/* Fixed point arithmetic shifting amount. */
-#define RC_PID_ARITH_SHIFT 8
-
-/* Fixed point arithmetic factor. */
-#define RC_PID_ARITH_FACTOR (1 << RC_PID_ARITH_SHIFT)
-
-/* Proportional PID component coefficient. */
-#define RC_PID_COEFF_P 15
-/* Integral PID component coefficient. */
-#define RC_PID_COEFF_I 9
-/* Derivative PID component coefficient. */
-#define RC_PID_COEFF_D 15
-
-/* Target failed frames rate for the PID controller. NB: This effectively
gives
- * maximum failed frames percentage we're willing to accept. If the
wireless
- * link quality is good, the controller will fail to adjust failed frames
- * percentage to the target. This is intentional.
- */
-#define RC_PID_TARGET_PF (11 << RC_PID_ARITH_SHIFT)
-
-/* Rate behaviour normalization quantity over time. */
-#define RC_PID_NORM_OFFSET 3
-
-/* Push high rates right after loading. */
-#define RC_PID_FAST_START 0
-
-/* Arithmetic right shift for positive and negative values for ISO C. */
-#define RC_PID_DO_ARITH_RIGHT_SHIFT(x, y) \
- (x) < 0 ? -((-(x)) >> (y)) : (x) >> (y)
-
-struct rc_pid_sta_info {
- unsigned long last_change;
- unsigned long last_sample;
-
- u32 tx_num_failed;
- u32 tx_num_xmit;
-
- /* Average failed frames percentage error (i.e. actual vs. target
- * percentage), scaled by RC_PID_SMOOTHING. This value is computed
- * using using an exponential weighted average technique:
- *
- * (RC_PID_SMOOTHING - 1) * err_avg_old + err
- * err_avg = ------------------------------------------
- * RC_PID_SMOOTHING
- *
- * where err_avg is the new approximation, err_avg_old the
previous one
- * and err is the error w.r.t. to the current failed frames
percentage
- * sample. Note that the bigger RC_PID_SMOOTHING the more weight is
- * given to the previous estimate, resulting in smoother behavior
(i.e.
- * corresponding to a longer integration window).
- *
- * For computation, we actually don't use the above formula, but
this
- * one:
- *
- * err_avg_scaled = err_avg_old_scaled - err_avg_old + err
- *
- * where:
- * err_avg_scaled = err * RC_PID_SMOOTHING
- * err_avg_old_scaled = err_avg_old * RC_PID_SMOOTHING
- *
- * This avoids floating point numbers and the per_failed_old value
can
- * easily be obtained by shifting per_failed_old_scaled right by
- * RC_PID_SMOOTHING_SHIFT.
- */
- s32 err_avg_sc;
-
- /* Last framed failes percentage sample. */
- u32 last_pf;
-
- /* Sharpening needed. */
- u8 sharp_cnt;
-};
-
-/* Algorithm parameters. We keep them on a per-algorithm approach, so they
can
- * be tuned individually for each interface.
- */
-struct rc_pid_rateinfo {
-
- /* Map sorted rates to rates in ieee80211_hw_mode. */
- int index;
-
- /* Map rates in ieee80211_hw_mode to sorted rates. */
- int rev_index;
-
- /* Comparison with the lowest rate. */
- int diff;
-};
-
-struct rc_pid_info {
-
- /* The failed frames percentage target. */
- u32 target;
-
- /* P, I and D coefficients. */
- s32 coeff_p;
- s32 coeff_i;
- s32 coeff_d;
-
- /* Rates information. */
- struct rc_pid_rateinfo *rinfo;
-
- /* Index of the last used rate. */
- int oldrate;
-};
-
-/* Shift the adjustment so that we won't switch to a lower rate if it
exhibited
- * a worse failed frames behaviour and we'll choose the highest rate whose
- * failed frames behaviour is not worse than the one of the original rate
- * target. While at it, check that the adjustment is within the ranges.
Then,
- * provide the new rate index. */
-static int rate_control_pid_shift_adjust(struct rc_pid_rateinfo *r,
- int adj, int cur, int l)
-{
- int i, j, k, tmp;
-
- if (cur + adj < 0)
- return 0;
- if (cur + adj >= l)
- return l - 1;
-
- i = r[cur + adj].rev_index;
-
- j = r[cur].rev_index;
-
- if (adj < 0) {
- tmp = i;
- for (k = j; k >= i; k--)
- if (r[k].diff <= r[j].diff)
- tmp = k;
- return r[tmp].index;
- } else if (adj > 0) {
- tmp = i;
- for (k = i + 1; k + i < l; k++)
- if (r[k].diff <= r[i].diff)
- tmp = k;
- return r[tmp].index;
- }
- return cur + adj;
-}
-
-static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
- struct sta_info *sta, int adj,
- struct rc_pid_rateinfo *rinfo)
-{
- struct ieee80211_sub_if_data *sdata;
- struct ieee80211_hw_mode *mode;
- int newidx;
- int maxrate;
- int back = (adj > 0) ? 1 : -1;
-
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
- if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
- /* forced unicast rate - do not change STA rate */
- return;
- }
-
- mode = local->oper_hw_mode;
- maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
-
- newidx = rate_control_pid_shift_adjust(rinfo, adj, sta->txrate,
- mode->num_rates);
-
- while (newidx != sta->txrate) {
- if (rate_supported(sta, mode, newidx) &&
- (maxrate < 0 || newidx <= maxrate)) {
- sta->txrate = newidx;
- break;
- }
-
- newidx += back;
- }
-}
-
-/* Normalize the failed frames per-rate differences. */
-static void rate_control_pid_normalize(struct rc_pid_rateinfo *r, int l)
-{
- int i;
-
- if (r[0].diff > RC_PID_NORM_OFFSET)
- r[0].diff -= RC_PID_NORM_OFFSET;
- else if (r[0].diff < -RC_PID_NORM_OFFSET)
- r[0].diff += RC_PID_NORM_OFFSET;
- for (i = 0; i < l - 1; i++)
- if (r[i + 1].diff > r[i].diff + RC_PID_NORM_OFFSET)
- r[i + 1].diff -= RC_PID_NORM_OFFSET;
- else if (r[i + 1].diff <= r[i].diff)
- r[i + 1].diff += RC_PID_NORM_OFFSET;
-}
-
-static void rate_control_pid_sample(struct rc_pid_info *pinfo,
- struct ieee80211_local *local,
- struct sta_info *sta)
-{
- struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
- struct rc_pid_rateinfo *rinfo = pinfo->rinfo;
- struct ieee80211_hw_mode *mode;
- u32 pf;
- s32 err_avg;
- s32 err_prop;
- s32 err_int;
- s32 err_der;
- int adj, i, j, tmp;
-
- mode = local->oper_hw_mode;
- spinfo = sta->rate_ctrl_priv;
-
- /* In case nothing happened during the previous control interval,
turn
- * the sharpening factor on. */
- if (jiffies - spinfo->last_sample > 2 * RC_PID_INTERVAL)
- spinfo->sharp_cnt = RC_PID_SHARPENING_DURATION;
-
- spinfo->last_sample = jiffies;
-
- /* This should never happen, but in case, we assume the old sample
is
- * still a good measurement and copy it. */
- if (unlikely(spinfo->tx_num_xmit == 0))
- pf = spinfo->last_pf;
- else {
- pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
- pf <<= RC_PID_ARITH_SHIFT;
- }
-
- spinfo->tx_num_xmit = 0;
- spinfo->tx_num_failed = 0;
-
- /* If we just switched rate, update the rate behaviour info. */
- if (pinfo->oldrate != sta->txrate) {
-
- i = rinfo[pinfo->oldrate].rev_index;
- j = rinfo[sta->txrate].rev_index;
-
- tmp = (pf - spinfo->last_pf);
- tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT);
-
- rinfo[j].diff = rinfo[i].diff + tmp;
- pinfo->oldrate = sta->txrate;
- }
- rate_control_pid_normalize(rinfo, mode->num_rates);
-
- /* Compute the proportional, integral and derivative errors. */
- err_prop = RC_PID_TARGET_PF - pf;
-
- err_avg = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
- spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
- err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
-
- err_der = pf - spinfo->last_pf
- * (1 + RC_PID_SHARPENING_FACTOR * spinfo->sharp_cnt);
- spinfo->last_pf = pf;
- if (spinfo->sharp_cnt)
- spinfo->sharp_cnt--;
-
- /* Compute the controller output. */
- adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i
- + err_der * pinfo->coeff_d);
- adj = RC_PID_DO_ARITH_RIGHT_SHIFT(adj, 2 * RC_PID_ARITH_SHIFT);
-
- /* Change rate. */
- if (adj)
- rate_control_pid_adjust_rate(local, sta, adj, rinfo);
-}
-
-static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
- struct sk_buff *skb,
- struct ieee80211_tx_status *status)
-{
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
- struct rc_pid_info *pinfo = priv;
- struct sta_info *sta;
- struct rc_pid_sta_info *spinfo;
-
- sta = sta_info_get(local, hdr->addr1);
-
- if (!sta)
- return;
-
- /* Ignore all frames that were sent with a different rate than the
rate
- * we currently advise mac80211 to use. */
- if (status->control.rate !=
&local->oper_hw_mode->rates[sta->txrate])
- return;
-
- spinfo = sta->rate_ctrl_priv;
- spinfo->tx_num_xmit++;
-
- /* We count frames that totally failed to be transmitted as two bad
- * frames, those that made it out but had some retries as one good
and
- * one bad frame. */
- if (status->excessive_retries) {
- spinfo->tx_num_failed += 2;
- spinfo->tx_num_xmit++;
- } else if (status->retry_count) {
- spinfo->tx_num_failed++;
- spinfo->tx_num_xmit++;
- }
-
- if (status->excessive_retries) {
- sta->tx_retry_failed++;
- sta->tx_num_consecutive_failures++;
- sta->tx_num_mpdu_fail++;
- } else {
- sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
- sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
- sta->last_ack_rssi[2] = status->ack_signal;
- sta->tx_num_consecutive_failures = 0;
- sta->tx_num_mpdu_ok++;
- }
- sta->tx_retry_count += status->retry_count;
- sta->tx_num_mpdu_fail += status->retry_count;
-
- /* Update PID controller state. */
- if (time_after(jiffies, spinfo->last_sample + RC_PID_INTERVAL))
- rate_control_pid_sample(pinfo, local, sta);
-
- sta_info_put(sta);
-}
-
-static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
- struct ieee80211_hw_mode *mode,
- struct sk_buff *skb,
- struct rate_selection *sel)
-{
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
- struct sta_info *sta;
- int rateidx;
-
- sta = sta_info_get(local, hdr->addr1);
-
- if (!sta) {
- sel->rate = rate_lowest(local, mode, NULL);
- sta_info_put(sta);
- return;
- }
-
- rateidx = sta->txrate;
-
- if (rateidx >= mode->num_rates)
- rateidx = mode->num_rates - 1;
-
- sta_info_put(sta);
-
- sel->rate = &mode->rates[rateidx];
-}
-
-static void rate_control_pid_rate_init(void *priv, void *priv_sta,
- struct ieee80211_local *local,
- struct sta_info *sta)
-{
- /* TODO: This routine should consider using RSSI from previous
packets
- * as we need to have IEEE 802.1X auth succeed immediately after
assoc..
- * Until that method is implemented, we will use the lowest
supported
- * rate as a workaround. */
- sta->txrate = rate_lowest_index(local, local->oper_hw_mode, sta);
-}
-
-static void *rate_control_pid_alloc(struct ieee80211_local *local)
-{
- struct rc_pid_info *pinfo;
- struct rc_pid_rateinfo *rinfo;
- struct ieee80211_hw_mode *mode;
- int i, j, tmp;
- bool s;
-
- pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC);
- if (!pinfo)
- return NULL;
-
- /* We can safely assume that oper_hw_mode won't change unless we
get
- * reinitialized. */
- mode = local->oper_hw_mode;
- rinfo = kmalloc(sizeof(*rinfo) * mode->num_rates, GFP_ATOMIC);
- if (!rinfo) {
- kfree(pinfo);
- return NULL;
- }
-
- /* Sort the rates. This is optimized for the most common case (i.e.
- * almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed
- * mapping too. */
- for (i = 0; i < mode->num_rates; i++) {
- rinfo[i].index = i;
- rinfo[i].rev_index = i;
- if (RC_PID_FAST_START)
- rinfo[i].diff = 0;
- else
- rinfo[i].diff = i * RC_PID_NORM_OFFSET;
- }
- for (i = 1; i < mode->num_rates; i++) {
- s = 0;
- for (j = 0; j < mode->num_rates - i; j++)
- if (unlikely(mode->rates[rinfo[j].index].rate >
- mode->rates[rinfo[j +
1].index].rate)) {
- tmp = rinfo[j].index;
- rinfo[j].index = rinfo[j + 1].index;
- rinfo[j + 1].index = tmp;
- rinfo[rinfo[j].index].rev_index = j;
- rinfo[rinfo[j + 1].index].rev_index = j +
1;
- s = 1;
- }
- if (!s)
- break;
- }
-
- pinfo->target = RC_PID_TARGET_PF;
- pinfo->coeff_p = RC_PID_COEFF_P;
- pinfo->coeff_i = RC_PID_COEFF_I;
- pinfo->coeff_d = RC_PID_COEFF_D;
- pinfo->rinfo = rinfo;
- pinfo->oldrate = 0;
-
- return pinfo;
-}
-
-static void rate_control_pid_free(void *priv)
-{
- struct rc_pid_info *pinfo = priv;
- kfree(pinfo->rinfo);
- kfree(pinfo);
-}
-
-static void rate_control_pid_clear(void *priv)
-{
-}
-
-static void *rate_control_pid_alloc_sta(void *priv, gfp_t gfp)
-{
- struct rc_pid_sta_info *spinfo;
-
- spinfo = kzalloc(sizeof(*spinfo), gfp);
-
- return spinfo;
-}
-
-static void rate_control_pid_free_sta(void *priv, void *priv_sta)
-{
- struct rc_pid_sta_info *spinfo = priv_sta;
- kfree(spinfo);
-}
-
-struct rate_control_ops mac80211_rcpid = {
- .name = "pid",
- .tx_status = rate_control_pid_tx_status,
- .get_rate = rate_control_pid_get_rate,
- .rate_init = rate_control_pid_rate_init,
- .clear = rate_control_pid_clear,
- .alloc = rate_control_pid_alloc,
- .free = rate_control_pid_free,
- .alloc_sta = rate_control_pid_alloc_sta,
- .free_sta = rate_control_pid_free_sta,
-};
Index: wireless-2.6/net/mac80211/rc80211_pid_debugfs.c
===================================================================
--- /dev/null
+++ wireless-2.6/net/mac80211/rc80211_pid_debugfs.c
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/spinlock.h>
+#include <linux/poll.h>
+#include <linux/netdevice.h>
+#include <linux/types.h>
+#include <linux/skbuff.h>
+
+#include <net/mac80211.h>
+#include "ieee80211_rate.h"
+
+#include "rc80211_pid.h"
+
+static void rate_control_pid_event(struct rc_pid_event_buffer *buf,
+ enum rc_pid_event_type type,
+ union rc_pid_event_data *data)
+{
+ struct rc_pid_event *ev;
+ unsigned long status;
+
+ spin_lock_irqsave(&buf->lock, status);
+ ev = &(buf->ring[buf->next_entry]);
+ buf->next_entry = (buf->next_entry + 1) % RC_PID_EVENT_RING_SIZE;
+
+ ev->timestamp = jiffies;
+ ev->id = buf->ev_count++;
+ ev->type = type;
+ ev->data = *data;
+
+ spin_unlock_irqrestore(&buf->lock, status);
+
+ wake_up_all(&buf->waitqueue);
+}
+
+void rate_control_pid_event_tx_status(struct rc_pid_event_buffer *buf,
+ struct ieee80211_tx_status
*stat) +{
+ union rc_pid_event_data evd;
+
+ memcpy(&evd.tx_status, stat, sizeof(struct ieee80211_tx_status));
+ rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_STATUS, &evd);
+}
+
+void rate_control_pid_event_rate_change(struct rc_pid_event_buffer *buf,
+ int index, int rate)
+{
+ union rc_pid_event_data evd;
+
+ evd.index = index;
+ evd.rate = rate;
+ rate_control_pid_event(buf, RC_PID_EVENT_TYPE_RATE_CHANGE, &evd);
+}
+
+void rate_control_pid_event_tx_rate(struct rc_pid_event_buffer *buf,
+ int index, int rate)
+{
+ union rc_pid_event_data evd;
+
+ evd.index = index;
+ evd.rate = rate;
+ rate_control_pid_event(buf, RC_PID_EVENT_TYPE_TX_RATE, &evd);
+}
+
+void rate_control_pid_event_pf_sample(struct rc_pid_event_buffer *buf,
+ s32 pf_sample, s32 prop_err,
+ s32 int_err, s32 der_err)
+{
+ union rc_pid_event_data evd;
+
+ evd.pf_sample = pf_sample;
+ evd.prop_err = prop_err;
+ evd.int_err = int_err;
+ evd.der_err = der_err;
+ rate_control_pid_event(buf, RC_PID_EVENT_TYPE_PF_SAMPLE, &evd);
+}
+
+static int rate_control_pid_events_open(struct inode *inode, struct file
*file) +{
+ struct rc_pid_sta_info *sinfo = inode->i_private;
+ struct rc_pid_event_buffer *events = &sinfo->events;
+ struct rc_pid_events_file_info *file_info;
+ unsigned int status;
+
+ /* Allocate a state struct */
+ file_info = kmalloc(sizeof(*file_info), GFP_KERNEL);
+ if (file_info == NULL)
+ return -ENOMEM;
+
+ spin_lock_irqsave(&events->lock, status);
+
+ file_info->next_entry = events->next_entry;
+ file_info->events = events;
+
+ spin_unlock_irqrestore(&events->lock, status);
+
+ file->private_data = file_info;
+
+ return 0;
+}
+
+static int rate_control_pid_events_release(struct inode *inode,
+ struct file *file)
+{
+ struct rc_pid_events_file_info *file_info = file->private_data;
+
+ kfree(file_info);
+
+ return 0;
+}
+
+static unsigned int rate_control_pid_events_poll(struct file *file,
+ poll_table *wait)
+{
+ struct rc_pid_events_file_info *file_info = file->private_data;
+
+ poll_wait(file, &file_info->events->waitqueue, wait);
+
+ return POLLIN | POLLRDNORM;
+}
+
+#define RC_PID_PRINT_BUF_SIZE 64
+
+static ssize_t rate_control_pid_events_read(struct file *file, char __user
*buf,
+ size_t length, loff_t *offset)
+{
+ struct rc_pid_events_file_info *file_info = file->private_data;
+ struct rc_pid_event_buffer *events = file_info->events;
+ struct rc_pid_event *ev;
+ char pb[RC_PID_PRINT_BUF_SIZE];
+ int ret;
+ int p;
+ unsigned int status;
+
+ /* Check if there is something to read. */
+ if (events->next_entry == file_info->next_entry) {
+ if (file->f_flags & O_NONBLOCK)
+ return -EAGAIN;
+
+ /* Wait */
+ ret = wait_event_interruptible(events->waitqueue,
+ events->next_entry !=
file_info->next_entry); +
+ if (ret)
+ return ret;
+ }
+
+ /* Write out one event per call. I don't care whether it's a little
+ * inefficient, this is debugging code anyway. */
+ spin_lock_irqsave(&events->lock, status);
+
+ /* Get an event */
+ ev = &(events->ring[file_info->next_entry]);
+ file_info->next_entry = (file_info->next_entry + 1) %
+ RC_PID_EVENT_RING_SIZE;
+
+ /* Print information about the event. Note that userpace needs to
+ * provide large enough buffers. */
+ length = length < RC_PID_PRINT_BUF_SIZE ?
+ length : RC_PID_PRINT_BUF_SIZE;
+ p = snprintf(pb, length, "%u %lu ", ev->id, ev->timestamp);
+ switch (ev->type) {
+ case RC_PID_EVENT_TYPE_TX_STATUS:
+ p += snprintf(pb + p, length - p, "tx_status %u %u",
+ ev->data.tx_status.excessive_retries,
+ ev->data.tx_status.retry_count);
+ break;
+ case RC_PID_EVENT_TYPE_RATE_CHANGE:
+ p += snprintf(pb + p, length - p, "rate_change %d %d",
+ ev->data.index, ev->data.rate);
+ break;
+ case RC_PID_EVENT_TYPE_TX_RATE:
+ p += snprintf(pb + p, length - p, "tx_rate %d %d",
+ ev->data.index, ev->data.rate);
+ break;
+ case RC_PID_EVENT_TYPE_PF_SAMPLE:
+ p += snprintf(pb + p, length - p,
+ "pf_sample %d %d %d %d",
+ ev->data.pf_sample, ev->data.prop_err,
+ ev->data.int_err, ev->data.der_err);
+ break;
+ }
+ p += snprintf(pb + p, length - p, "\n");
+
+ spin_unlock_irqrestore(&events->lock, status);
+
+ if (copy_to_user(buf, pb, p))
+ return -EFAULT;
+
+ return p;
+}
+
+#undef RC_PID_PRINT_BUF_SIZE
+
+struct file_operations rc_pid_fop_events = {
+ .owner = THIS_MODULE,
+ .read = rate_control_pid_events_read,
+ .poll = rate_control_pid_events_poll,
+ .open = rate_control_pid_events_open,
+ .release = rate_control_pid_events_release,
+};
+
+void rate_control_pid_add_sta_debugfs(void *priv, void *priv_sta,
+ struct dentry *dir)
+{
+ struct rc_pid_sta_info *spinfo = priv_sta;
+
+ spinfo->events_entry = debugfs_create_file("rc_pid_events",
S_IRUGO,
+ dir, spinfo,
+ &rc_pid_fop_events);
+}
+
+void rate_control_pid_remove_sta_debugfs(void *priv, void *priv_sta)
+{
+ struct rc_pid_sta_info *spinfo = priv_sta;
+
+ debugfs_remove(spinfo->events_entry);
+}
Index: wireless-2.6/net/mac80211/rc80211_pid.h
===================================================================
--- /dev/null
+++ wireless-2.6/net/mac80211/rc80211_pid.h
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef RC80211_PID_H
+#define RC80211_PID_H
+
+/* Sampling period for measuring percentage of failed frames. */
+#define RC_PID_INTERVAL (HZ / 8)
+
+/* Exponential averaging smoothness (used for I part of PID controller) */
+#define RC_PID_SMOOTHING_SHIFT 3
+#define RC_PID_SMOOTHING (1 << RC_PID_SMOOTHING_SHIFT)
+
+/* Sharpening factor (used for D part of PID controller) */
+#define RC_PID_SHARPENING_FACTOR 0
+#define RC_PID_SHARPENING_DURATION 0
+
+/* Fixed point arithmetic shifting amount. */
+#define RC_PID_ARITH_SHIFT 8
+
+/* Fixed point arithmetic factor. */
+#define RC_PID_ARITH_FACTOR (1 << RC_PID_ARITH_SHIFT)
+
+/* Proportional PID component coefficient. */
+#define RC_PID_COEFF_P 15
+/* Integral PID component coefficient. */
+#define RC_PID_COEFF_I 9
+/* Derivative PID component coefficient. */
+#define RC_PID_COEFF_D 15
+
+/* Target failed frames rate for the PID controller. NB: This effectively
gives
+ * maximum failed frames percentage we're willing to accept. If the
wireless
+ * link quality is good, the controller will fail to adjust failed frames
+ * percentage to the target. This is intentional.
+ */
+#define RC_PID_TARGET_PF (11 << RC_PID_ARITH_SHIFT)
+
+/* Rate behaviour normalization quantity over time. */
+#define RC_PID_NORM_OFFSET 3
+
+/* Push high rates right after loading. */
+#define RC_PID_FAST_START 0
+
+/* Arithmetic right shift for positive and negative values for ISO C. */
+#define RC_PID_DO_ARITH_RIGHT_SHIFT(x, y) \
+ (x) < 0 ? -((-(x)) >> (y)) : (x) >> (y)
+
+enum rc_pid_event_type {
+ RC_PID_EVENT_TYPE_TX_STATUS,
+ RC_PID_EVENT_TYPE_RATE_CHANGE,
+ RC_PID_EVENT_TYPE_TX_RATE,
+ RC_PID_EVENT_TYPE_PF_SAMPLE,
+};
+
+union rc_pid_event_data {
+ /* RC_PID_EVENT_TX_STATUS */
+ struct {
+ struct ieee80211_tx_status tx_status;
+ };
+ /* RC_PID_EVENT_TYPE_RATE_CHANGE */
+ /* RC_PID_EVENT_TYPE_TX_RATE */
+ struct {
+ int index;
+ int rate;
+ };
+ /* RC_PID_EVENT_TYPE_PF_SAMPLE */
+ struct {
+ s32 pf_sample;
+ s32 prop_err;
+ s32 int_err;
+ s32 der_err;
+ };
+};
+
+struct rc_pid_event {
+ /* The time when the event occured */
+ unsigned long timestamp;
+
+ /* Event ID number */
+ unsigned int id;
+
+ /* Type of event */
+ enum rc_pid_event_type type;
+
+ /* type specific data */
+ union rc_pid_event_data data;
+};
+
+/* Size of the event ring buffer. */
+#define RC_PID_EVENT_RING_SIZE 32
+
+struct rc_pid_event_buffer {
+ /* Counter that generates event IDs */
+ unsigned int ev_count;
+
+ /* Ring buffer of events */
+ struct rc_pid_event ring[RC_PID_EVENT_RING_SIZE];
+
+ /* Index to the entry in events_buf to be reused */
+ unsigned int next_entry;
+
+ /* Lock that guards against concurrent access to this buffer
struct */
+ spinlock_t lock;
+
+ /* Wait queue for poll/select and blocking I/O */
+ wait_queue_head_t waitqueue;
+};
+
+struct rc_pid_events_file_info {
+ /* The event buffer we read */
+ struct rc_pid_event_buffer *events;
+
+ /* The entry we have should read next */
+ unsigned int next_entry;
+};
+
+void rate_control_pid_event_tx_status(struct rc_pid_event_buffer *buf,
+ struct ieee80211_tx_status
*stat); +
+void rate_control_pid_event_rate_change(struct rc_pid_event_buffer *buf,
+ int index, int rate);
+
+void rate_control_pid_event_tx_rate(struct rc_pid_event_buffer *buf,
+ int index, int rate);
+
+void rate_control_pid_event_pf_sample(struct rc_pid_event_buffer *buf,
+ s32 pf_sample, s32 prop_err,
+ s32 int_err, s32 der_err);
+
+void rate_control_pid_add_sta_debugfs(void *priv, void *priv_sta,
+ struct dentry *dir);
+
+void rate_control_pid_remove_sta_debugfs(void *priv, void *priv_sta);
+
+struct rc_pid_sta_info {
+ unsigned long last_change;
+ unsigned long last_sample;
+
+ u32 tx_num_failed;
+ u32 tx_num_xmit;
+
+ /* Average failed frames percentage error (i.e. actual vs. target
+ * percentage), scaled by RC_PID_SMOOTHING. This value is computed
+ * using using an exponential weighted average technique:
+ *
+ * (RC_PID_SMOOTHING - 1) * err_avg_old + err
+ * err_avg = ------------------------------------------
+ * RC_PID_SMOOTHING
+ *
+ * where err_avg is the new approximation, err_avg_old the
previous one
+ * and err is the error w.r.t. to the current failed frames
percentage
+ * sample. Note that the bigger RC_PID_SMOOTHING the more weight is
+ * given to the previous estimate, resulting in smoother behavior
(i.e.
+ * corresponding to a longer integration window).
+ *
+ * For computation, we actually don't use the above formula, but
this
+ * one:
+ *
+ * err_avg_scaled = err_avg_old_scaled - err_avg_old + err
+ *
+ * where:
+ * err_avg_scaled = err * RC_PID_SMOOTHING
+ * err_avg_old_scaled = err_avg_old * RC_PID_SMOOTHING
+ *
+ * This avoids floating point numbers and the per_failed_old value
can
+ * easily be obtained by shifting per_failed_old_scaled right by
+ * RC_PID_SMOOTHING_SHIFT.
+ */
+ s32 err_avg_sc;
+
+ /* Last framed failes percentage sample. */
+ u32 last_pf;
+
+ /* Sharpening needed. */
+ u8 sharp_cnt;
+
+#ifdef CONFIG_MAC80211_DEBUGFS
+ /* Event buffer */
+ struct rc_pid_event_buffer events;
+
+ /* Events debugfs file entry */
+ struct dentry *events_entry;
+#endif
+};
+
+/* Algorithm parameters. We keep them on a per-algorithm approach, so they
can
+ * be tuned individually for each interface.
+ */
+struct rc_pid_rateinfo {
+
+ /* Map sorted rates to rates in ieee80211_hw_mode. */
+ int index;
+
+ /* Map rates in ieee80211_hw_mode to sorted rates. */
+ int rev_index;
+
+ /* Did we do any measurement on this rate? */
+ bool valid;
+
+ /* Comparison with the lowest rate. */
+ int diff;
+};
+
+struct rc_pid_info {
+
+ /* The failed frames percentage target. */
+ unsigned int target;
+
+ /* Rate at which failed frames percentage is sampled in 0.001s. */
+ unsigned int sampling_period;
+
+ /* P, I and D coefficients. */
+ int coeff_p;
+ int coeff_i;
+ int coeff_d;
+
+ /* Exponential averaging shift. */
+ unsigned int smoothing_shift;
+
+ /* Sharpening shift and duration. */
+ unsigned int sharpen_shift;
+ unsigned int sharpen_duration;
+
+ /* Normalization offset. */
+ unsigned int norm_offset;
+
+ /* Fast starst parameter. */
+ unsigned int fast_start;
+
+ /* Rates information. */
+ struct rc_pid_rateinfo *rinfo;
+
+ /* Index of the last used rate. */
+ int oldrate;
+};
+
+#endif /* RC80211_PID_H */
Index: wireless-2.6/net/mac80211/Makefile
===================================================================
--- wireless-2.6.orig/net/mac80211/Makefile
+++ wireless-2.6/net/mac80211/Makefile
@@ -32,3 +33,10 @@ mac80211-objs := \
ifneq ($(CONFIG_MAC80211_RC_PID),y)
mac80211-objs += rc80211_simple.o
endif
+
+
+rc80211_pid-objs-$(CONFIG_MAC80211_DEBUGFS) += rc80211_pid_debugfs.o
+
+rc80211_pid-objs := \
+ rc80211_pid_algo.o \
+ $(rc80211_pid-objs-y)
Index: wireless-2.6/net/mac80211/rc80211_pid_algo.c
===================================================================
--- /dev/null
+++ wireless-2.6/net/mac80211/rc80211_pid_algo.c
@@ -0,0 +1,444 @@
+/*
+ * Copyright 2002-2005, Instant802 Networks, Inc.
+ * Copyright 2005, Devicescape Software, Inc.
+ * Copyright 2007, Mattias Nissler <mattias.nissler@gmx.de>
+ * Copyright 2007, Stefano Brivio <stefano.brivio@polimi.it>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/netdevice.h>
+#include <linux/types.h>
+#include <linux/skbuff.h>
+
+#include <net/mac80211.h>
+#include "ieee80211_rate.h"
+
+#include "rc80211_pid.h"
+
+
+/* This is an implementation of a TX rate control algorithm that uses a PID
+ * controller. Given a target failed frames rate, the controller decides
about
+ * TX rate changes to meet the target failed frames rate.
+ *
+ * The controller basically computes the following:
+ *
+ * adj = CP * err + CI * err_avg + CD * (err - last_err) * (1 + sharpening)
+ *
+ * where
+ * adj adjustment value that is used to switch TX rate (see
below)
+ * err current error: target vs. current failed frames
percentage
+ * last_err last error
+ * err_avg average (i.e. poor man's integral) of recent
errors
+ * sharpening non-zero when fast response is needed (i.e.
right after
+ * association or no frames sent for a long time),
heading
+ * to zero over time
+ * CP Proportional coefficient
+ * CI Integral coefficient
+ * CD Derivative coefficient
+ *
+ * CP, CI, CD are subject to careful tuning.
+ *
+ * The integral component uses a exponential moving average approach
instead of
+ * an actual sliding window. The advantage is that we don't need to keep an
+ * array of the last N error values and computation is easier.
+ *
+ * Once we have the adj value, we map it to a rate by means of a learning
+ * algorithm. This algorithm keeps the state of the percentual failed
frames
+ * difference between rates. The behaviour of the lowest available rate is
kept
+ * as a reference value, and every time we switch between two rates, we
compute
+ * the difference between the failed frames each rate exhibited. By doing
so,
+ * we compare behaviours which different rates exhibited in adjacent
timeslices,
+ * thus the comparison is minimally affected by external conditions. This
+ * difference gets propagated to the whole set of measurements, so that the
+ * reference is always the same. Periodically, we normalize this set so
that
+ * recent events weigh the most. By comparing the adj value with this set,
we
+ * avoid pejorative switches to lower rates and allow for switches to
higher
+ * rates if they behaved well.
+ *
+ * Note that for the computations we use a fixed-point representation to
avoid
+ * floating point arithmetic. Hence, all values are shifted left by
+ * RC_PID_ARITH_SHIFT.
+ */
+
+
+/* Shift the adjustment so that we won't switch to a lower rate if it
exhibited
+ * a worse failed frames behaviour and we'll choose the highest rate whose
+ * failed frames behaviour is not worse than the one of the original rate
+ * target. While at it, check that the adjustment is within the ranges.
Then,
+ * provide the new rate index. */
+static int rate_control_pid_shift_adjust(struct rc_pid_rateinfo *r,
+ int adj, int cur, int l)
+{
+ int i, j, k, tmp;
+
+ if (cur + adj < 0)
+ return 0;
+ if (cur + adj >= l)
+ return l - 1;
+
+ i = r[cur + adj].rev_index;
+
+ j = r[cur].rev_index;
+
+ if (adj < 0) {
+ tmp = i;
+ for (k = j; k >= i; k--)
+ if (r[k].diff <= r[j].diff)
+ tmp = k;
+ return r[tmp].index;
+ } else if (adj > 0) {
+ tmp = i;
+ for (k = i + 1; k + i < l; k++)
+ if (r[k].diff <= r[i].diff)
+ tmp = k;
+ return r[tmp].index;
+ }
+ return cur + adj;
+}
+
+static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
+ struct sta_info *sta, int adj,
+ struct rc_pid_rateinfo *rinfo)
+{
+ struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_hw_mode *mode;
+ int newidx;
+ int maxrate;
+ int back = (adj > 0) ? 1 : -1;
+
+ sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+ if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
+ /* forced unicast rate - do not change STA rate */
+ return;
+ }
+
+ mode = local->oper_hw_mode;
+ maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
+
+ newidx = rate_control_pid_shift_adjust(rinfo, adj, sta->txrate,
+ mode->num_rates);
+
+ while (newidx != sta->txrate) {
+ if (rate_supported(sta, mode, newidx) &&
+ (maxrate < 0 || newidx <= maxrate)) {
+ sta->txrate = newidx;
+ break;
+ }
+
+ newidx += back;
+ }
+
+#ifdef CONFIG_MAC80211_DEBUGFS
+ rate_control_pid_event_rate_change(
+ &((struct rc_pid_sta_info *)sta->rate_ctrl_priv)->events,
+ newidx, mode->rates[newidx].rate);
+#endif
+}
+
+/* Normalize the failed frames per-rate differences. */
+static void rate_control_pid_normalize(struct rc_pid_rateinfo *r, int l)
+{
+ int i;
+
+ if (r[0].diff > RC_PID_NORM_OFFSET)
+ r[0].diff -= RC_PID_NORM_OFFSET;
+ else if (r[0].diff < -RC_PID_NORM_OFFSET)
+ r[0].diff += RC_PID_NORM_OFFSET;
+ for (i = 0; i < l - 1; i++)
+ if (r[i + 1].diff > r[i].diff + RC_PID_NORM_OFFSET)
+ r[i + 1].diff -= RC_PID_NORM_OFFSET;
+ else if (r[i + 1].diff <= r[i].diff)
+ r[i + 1].diff += RC_PID_NORM_OFFSET;
+}
+
+static void rate_control_pid_sample(struct rc_pid_info *pinfo,
+ struct ieee80211_local *local,
+ struct sta_info *sta)
+{
+ struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
+ struct rc_pid_rateinfo *rinfo = pinfo->rinfo;
+ struct ieee80211_hw_mode *mode;
+ u32 pf;
+ s32 err_avg;
+ s32 err_prop;
+ s32 err_int;
+ s32 err_der;
+ int adj, i, j, tmp;
+
+ mode = local->oper_hw_mode;
+ spinfo = sta->rate_ctrl_priv;
+
+ /* In case nothing happened during the previous control interval,
turn
+ * the sharpening factor on. */
+ if (jiffies - spinfo->last_sample > 2 * RC_PID_INTERVAL)
+ spinfo->sharp_cnt = RC_PID_SHARPENING_DURATION;
+
+ spinfo->last_sample = jiffies;
+
+ /* This should never happen, but in case, we assume the old sample
is
+ * still a good measurement and copy it. */
+ if (unlikely(spinfo->tx_num_xmit == 0))
+ pf = spinfo->last_pf;
+ else {
+ pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
+ pf <<= RC_PID_ARITH_SHIFT;
+ }
+
+ spinfo->tx_num_xmit = 0;
+ spinfo->tx_num_failed = 0;
+
+ /* If we just switched rate, update the rate behaviour info. */
+ if (pinfo->oldrate != sta->txrate) {
+
+ i = rinfo[pinfo->oldrate].rev_index;
+ j = rinfo[sta->txrate].rev_index;
+
+ tmp = (pf - spinfo->last_pf);
+ tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT);
+
+ rinfo[j].diff = rinfo[i].diff + tmp;
+ pinfo->oldrate = sta->txrate;
+ }
+ rate_control_pid_normalize(rinfo, mode->num_rates);
+
+ /* Compute the proportional, integral and derivative errors. */
+ err_prop = RC_PID_TARGET_PF - pf;
+
+ err_avg = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
+ spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
+ err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
+
+ err_der = pf - spinfo->last_pf
+ * (1 + RC_PID_SHARPENING_FACTOR * spinfo->sharp_cnt);
+ spinfo->last_pf = pf;
+ if (spinfo->sharp_cnt)
+ spinfo->sharp_cnt--;
+
+#ifdef CONFIG_MAC80211_DEBUGFS
+ rate_control_pid_event_pf_sample(&spinfo->events, pf, err_prop,
err_int,
+ err_der);
+#endif
+
+ /* Compute the controller output. */
+ adj = (err_prop * pinfo->coeff_p + err_int * pinfo->coeff_i
+ + err_der * pinfo->coeff_d);
+ adj = RC_PID_DO_ARITH_RIGHT_SHIFT(adj, 2 * RC_PID_ARITH_SHIFT);
+
+ /* Change rate. */
+ if (adj)
+ rate_control_pid_adjust_rate(local, sta, adj, rinfo);
+}
+
+static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
+ struct sk_buff *skb,
+ struct ieee80211_tx_status *status)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ struct rc_pid_info *pinfo = priv;
+ struct sta_info *sta;
+ struct rc_pid_sta_info *spinfo;
+
+ sta = sta_info_get(local, hdr->addr1);
+
+ if (!sta)
+ return;
+
+ /* Ignore all frames that were sent with a different rate than the
rate
+ * we currently advise mac80211 to use. */
+ if (status->control.rate !=
&local->oper_hw_mode->rates[sta->txrate])
+ return;
+
+ spinfo = sta->rate_ctrl_priv;
+ spinfo->tx_num_xmit++;
+
+#ifdef CONFIG_MAC80211_DEBUGFS
+ rate_control_pid_event_tx_status(&spinfo->events, status);
+#endif
+
+ /* We count frames that totally failed to be transmitted as two bad
+ * frames, those that made it out but had some retries as one good
and
+ * one bad frame. */
+ if (status->excessive_retries) {
+ spinfo->tx_num_failed += 2;
+ spinfo->tx_num_xmit++;
+ } else if (status->retry_count) {
+ spinfo->tx_num_failed++;
+ spinfo->tx_num_xmit++;
+ }
+
+ if (status->excessive_retries) {
+ sta->tx_retry_failed++;
+ sta->tx_num_consecutive_failures++;
+ sta->tx_num_mpdu_fail++;
+ } else {
+ sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
+ sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
+ sta->last_ack_rssi[2] = status->ack_signal;
+ sta->tx_num_consecutive_failures = 0;
+ sta->tx_num_mpdu_ok++;
+ }
+ sta->tx_retry_count += status->retry_count;
+ sta->tx_num_mpdu_fail += status->retry_count;
+
+ /* Update PID controller state. */
+ if (time_after(jiffies, spinfo->last_sample + RC_PID_INTERVAL))
+ rate_control_pid_sample(pinfo, local, sta);
+
+ sta_info_put(sta);
+}
+
+static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
+ struct ieee80211_hw_mode *mode,
+ struct sk_buff *skb,
+ struct rate_selection *sel)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ struct sta_info *sta;
+ int rateidx;
+
+ sta = sta_info_get(local, hdr->addr1);
+
+ if (!sta) {
+ sel->rate = rate_lowest(local, mode, NULL);
+ sta_info_put(sta);
+ return;
+ }
+
+ rateidx = sta->txrate;
+
+ if (rateidx >= mode->num_rates)
+ rateidx = mode->num_rates - 1;
+
+ sta_info_put(sta);
+
+ sel->rate = &mode->rates[rateidx];
+
+#ifdef CONFIG_MAC80211_DEBUGFS
+ rate_control_pid_event_tx_rate(
+ &((struct rc_pid_sta_info *) sta->rate_ctrl_priv)->events,
+ rateidx, mode->rates[rateidx].rate);
+#endif
+}
+
+static void rate_control_pid_rate_init(void *priv, void *priv_sta,
+ struct ieee80211_local *local,
+ struct sta_info *sta)
+{
+ /* TODO: This routine should consider using RSSI from previous
packets
+ * as we need to have IEEE 802.1X auth succeed immediately after
assoc..
+ * Until that method is implemented, we will use the lowest
supported
+ * rate as a workaround. */
+ sta->txrate = rate_lowest_index(local, local->oper_hw_mode, sta);
+}
+
+static void *rate_control_pid_alloc(struct ieee80211_local *local)
+{
+ struct rc_pid_info *pinfo;
+ struct rc_pid_rateinfo *rinfo;
+ struct ieee80211_hw_mode *mode;
+ int i, j, tmp;
+ bool s;
+
+ pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC);
+ if (!pinfo)
+ return NULL;
+
+ /* We can safely assume that oper_hw_mode won't change unless we
get
+ * reinitialized. */
+ mode = local->oper_hw_mode;
+ rinfo = kmalloc(sizeof(*rinfo) * mode->num_rates, GFP_ATOMIC);
+ if (!rinfo) {
+ kfree(pinfo);
+ return NULL;
+ }
+
+ /* Sort the rates. This is optimized for the most common case (i.e.
+ * almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed
+ * mapping too. */
+ for (i = 0; i < mode->num_rates; i++) {
+ rinfo[i].index = i;
+ rinfo[i].rev_index = i;
+ if (RC_PID_FAST_START)
+ rinfo[i].diff = 0;
+ else
+ rinfo[i].diff = i * RC_PID_NORM_OFFSET;
+ }
+ for (i = 1; i < mode->num_rates; i++) {
+ s = 0;
+ for (j = 0; j < mode->num_rates - i; j++)
+ if (unlikely(mode->rates[rinfo[j].index].rate >
+ mode->rates[rinfo[j +
1].index].rate)) {
+ tmp = rinfo[j].index;
+ rinfo[j].index = rinfo[j + 1].index;
+ rinfo[j + 1].index = tmp;
+ rinfo[rinfo[j].index].rev_index = j;
+ rinfo[rinfo[j + 1].index].rev_index = j +
1;
+ s = 1;
+ }
+ if (!s)
+ break;
+ }
+
+ pinfo->target = RC_PID_TARGET_PF;
+ pinfo->coeff_p = RC_PID_COEFF_P;
+ pinfo->coeff_i = RC_PID_COEFF_I;
+ pinfo->coeff_d = RC_PID_COEFF_D;
+ pinfo->rinfo = rinfo;
+ pinfo->oldrate = 0;
+
+ return pinfo;
+}
+
+static void rate_control_pid_free(void *priv)
+{
+ struct rc_pid_info *pinfo = priv;
+ kfree(pinfo->rinfo);
+ kfree(pinfo);
+}
+
+static void rate_control_pid_clear(void *priv)
+{
+}
+
+static void *rate_control_pid_alloc_sta(void *priv, gfp_t gfp)
+{
+ struct rc_pid_sta_info *spinfo;
+
+ spinfo = kzalloc(sizeof(*spinfo), gfp);
+ if (spinfo == NULL)
+ return NULL;
+
+#ifdef CONFIG_MAC80211_DEBUGFS
+ spin_lock_init(&spinfo->events.lock);
+ init_waitqueue_head(&spinfo->events.waitqueue);
+#endif
+
+ return spinfo;
+}
+
+static void rate_control_pid_free_sta(void *priv, void *priv_sta)
+{
+ struct rc_pid_sta_info *spinfo = priv_sta;
+ kfree(spinfo);
+}
+
+struct rate_control_ops mac80211_rcpid = {
+ .name = "pid",
+ .tx_status = rate_control_pid_tx_status,
+ .get_rate = rate_control_pid_get_rate,
+ .rate_init = rate_control_pid_rate_init,
+ .clear = rate_control_pid_clear,
+ .alloc = rate_control_pid_alloc,
+ .free = rate_control_pid_free,
+ .alloc_sta = rate_control_pid_alloc_sta,
+ .free_sta = rate_control_pid_free_sta,
+#ifdef CONFIG_MAC80211_DEBUGFS
+ .add_sta_debugfs = rate_control_pid_add_sta_debugfs,
+ .remove_sta_debugfs = rate_control_pid_remove_sta_debugfs,
+#endif
+};
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 7/8] debugfs: allow access to signed values
[not found] <20071218233749.871878037@polimi.it>
` (5 preceding siblings ...)
2007-12-19 0:04 ` [PATCH v2 6/8] rc80211-pid: add debugging Stefano Brivio
@ 2007-12-19 0:04 ` Stefano Brivio
2007-12-19 0:04 ` [PATCH v2 8/8] rc80211-pid: export tuning parameters through debugfs Stefano Brivio
2007-12-19 0:15 ` [PATCH v2 0/8] rate control rework Stefano Brivio
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:04 UTC (permalink / raw)
To: John W. Linville, Greg Kroah-Hartman
Cc: Johannes Berg, Mattias Nissler, linux-wireless, linux-kernel
Add debugfs_create_s{8,16,32,64}. For these to work properly, we need to
remove a cast in libfs.
Cc: Johannes Berg <johannes@sipsolutions.net>
To: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Stefano Brivio <stefano.brivio@polimi.it>
---
Greg,
here comes an implementation of debugfs_create_s{8,16,32,64} which avoids
code duplication, suggested by Johannes Berg. We would need this to be
merged to 2.6.25, as we need those functions to be available for
rc80211-pid, the new mac80211 rate control algorithm.
---
fs/debugfs/file.c | 166
++++++++++++++++++++++++++++++++++++++++++++++++ fs/libfs.c
| 4 - include/linux/debugfs.h | 30 ++++++++
3 files changed, 197 insertions(+), 3 deletions(-)
Index: wireless-2.6/fs/debugfs/file.c
===================================================================
--- wireless-2.6.orig/fs/debugfs/file.c
+++ wireless-2.6/fs/debugfs/file.c
@@ -221,6 +221,172 @@ struct dentry *debugfs_create_u64(const
}
EXPORT_SYMBOL_GPL(debugfs_create_u64);
+
+static void debugfs_s8_set(void *data, u64 val)
+{
+ *(s8 *)data = val;
+}
+static u64 debugfs_s8_get(void *data)
+{
+ return *(s8 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_s8, debugfs_s8_get, debugfs_s8_set, "%lld\n");
+
+/**
+ * debugfs_create_s8 - create a debugfs file that is used to read and
write a signed 8-bit value
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is %NULL, then the
+ * file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ * from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value. If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds. This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.) If an error occurs, %NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -%ENODEV will be
+ * returned. It is not wise to check for this value, but rather, check for
+ * %NULL or !%NULL instead as to eliminate the need for #ifdef in the
calling
+ * code.
+ */
+struct dentry *debugfs_create_s8(const char *name, mode_t mode,
+ struct dentry *parent, s8 *value)
+{
+ return debugfs_create_file(name, mode, parent, value, &fops_s8);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_s8);
+
+static void debugfs_s16_set(void *data, u64 val)
+{
+ *(s16 *)data = val;
+}
+static u64 debugfs_s16_get(void *data)
+{
+ return *(s16 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_s16, debugfs_s16_get, debugfs_s16_set,
"%lld\n"); +
+/**
+ * debugfs_create_s16 - create a debugfs file that is used to read and
write a signed 16-bit value
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is %NULL, then the
+ * file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ * from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value. If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds. This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.) If an error occurs, %NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -%ENODEV will be
+ * returned. It is not wise to check for this value, but rather, check for
+ * %NULL or !%NULL instead as to eliminate the need for #ifdef in the
calling
+ * code.
+ */
+struct dentry *debugfs_create_s16(const char *name, mode_t mode,
+ struct dentry *parent, s16 *value)
+{
+ return debugfs_create_file(name, mode, parent, value, &fops_s16);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_s16);
+
+static void debugfs_s32_set(void *data, u64 val)
+{
+ *(s32 *)data = val;
+}
+static u64 debugfs_s32_get(void *data)
+{
+ return *(s32 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_s32, debugfs_s32_get, debugfs_s32_set,
"%lld\n"); +
+/**
+ * debugfs_create_s32 - create a debugfs file that is used to read and
write a signed 32-bit value
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is %NULL, then the
+ * file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ * from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value. If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds. This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.) If an error occurs, %NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -%ENODEV will be
+ * returned. It is not wise to check for this value, but rather, check for
+ * %NULL or !%NULL instead as to eliminate the need for #ifdef in the
calling
+ * code.
+ */
+struct dentry *debugfs_create_s32(const char *name, mode_t mode,
+ struct dentry *parent, s32 *value)
+{
+ return debugfs_create_file(name, mode, parent, value, &fops_s32);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_s32);
+
+static void debugfs_s64_set(void *data, u64 val)
+{
+ *(s64 *)data = val;
+}
+
+static u64 debugfs_s64_get(void *data)
+{
+ return *(s64 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_s64, debugfs_s64_get, debugfs_s64_set,
"%lld\n"); +
+/**
+ * debugfs_create_s64 - create a debugfs file that is used to read and
write a signed 64-bit value
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is %NULL, then the
+ * file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ * from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value. If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds. This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.) If an error occurs, %NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -%ENODEV will be
+ * returned. It is not wise to check for this value, but rather, check for
+ * %NULL or !%NULL instead as to eliminate the need for #ifdef in the
calling
+ * code.
+ */
+struct dentry *debugfs_create_s64(const char *name, mode_t mode,
+ struct dentry *parent, u64 *value)
+{
+ return debugfs_create_file(name, mode, parent, value, &fops_s64);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_s64);
+
DEFINE_SIMPLE_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set,
"0x%02llx\n");
DEFINE_SIMPLE_ATTRIBUTE(fops_x16, debugfs_u16_get, debugfs_u16_set,
"0x%04llx\n");
Index: wireless-2.6/fs/libfs.c
===================================================================
--- wireless-2.6.orig/fs/libfs.c
+++ wireless-2.6/fs/libfs.c
@@ -586,7 +586,7 @@ int simple_transaction_release(struct in
/* Simple attribute files */
struct simple_attr {
- u64 (*get)(void *);
+ unsigned long long (*get)(void *);
void (*set)(void *, u64);
char get_buf[24]; /* enough to store a u64 and "\n\0" */
char set_buf[24];
@@ -643,7 +643,7 @@ ssize_t simple_attr_read(struct file *fi
else /* first read */
size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
attr->fmt,
- (unsigned long
long)attr->get(attr->data));
+ attr->get(attr->data));
ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
mutex_unlock(&attr->mutex);
Index: wireless-2.6/include/linux/debugfs.h
===================================================================
--- wireless-2.6.orig/include/linux/debugfs.h
+++ wireless-2.6/include/linux/debugfs.h
@@ -65,7 +65,7 @@ struct dentry *debugfs_create_blob(const
#include <linux/err.h>
-/*
+/*
* We do not return NULL from these functions if CONFIG_DEBUG_FS is not
enabled
* so users have a chance to detect if there was a real error or not. We
don't
* want to duplicate the design decision mistakes of procfs and devfs
again. @@ -128,6 +128,34 @@ static inline struct dentry *debugfs_cre
return ERR_PTR(-ENODEV);
}
+static inline struct dentry *debugfs_create_s8(const char *name, mode_t
mode,
+ struct dentry *parent,
+ u8 *value)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+static inline struct dentry *debugfs_create_s16(const char *name, mode_t
mode,
+ struct dentry *parent,
+ s16 *value)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+static inline struct dentry *debugfs_create_s32(const char *name, mode_t
mode,
+ struct dentry *parent,
+ s32 *value)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+static inline struct dentry *debugfs_create_s64(const char *name, mode_t
mode,
+ struct dentry *parent,
+ s64 *value)
+{
+ return ERR_PTR(-ENODEV);
+}
+
static inline struct dentry *debugfs_create_x8(const char *name, mode_t
mode, struct dentry *parent,
u8 *value)
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 8/8] rc80211-pid: export tuning parameters through debugfs
[not found] <20071218233749.871878037@polimi.it>
` (6 preceding siblings ...)
2007-12-19 0:04 ` [PATCH v2 7/8] debugfs: allow access to signed values Stefano Brivio
@ 2007-12-19 0:04 ` Stefano Brivio
2007-12-19 0:15 ` [PATCH v2 0/8] rate control rework Stefano Brivio
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:04 UTC (permalink / raw)
To: John W. Linville; +Cc: Johannes Berg, Mattias Nissler, linux-wireless
From: Mattias Nissler <mattias.nissler@gmx.de>
This adds all the tunable parameters used by rc80211_pid to debugfs for easy
testing and tuning.
Signed-off-by: Mattias Nissler <mattias.nissler@gmx.de>
---
rc80211_pid.h | 23 ++++++++++-
rc80211_pid_algo.c | 106
+++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 107
insertions(+), 22 deletions(-)
Index: wireless-2.6/net/mac80211/rc80211_pid_algo.c
===================================================================
--- wireless-2.6.orig/net/mac80211/rc80211_pid_algo.c
+++ wireless-2.6/net/mac80211/rc80211_pid_algo.c
@@ -139,19 +139,20 @@ static void rate_control_pid_adjust_rate
}
/* Normalize the failed frames per-rate differences. */
-static void rate_control_pid_normalize(struct rc_pid_rateinfo *r, int l)
+static void rate_control_pid_normalize(struct rc_pid_info *pinfo, int l)
{
- int i;
+ int i, norm_offset = pinfo->norm_offset;
+ struct rc_pid_rateinfo *r = pinfo->rinfo;
- if (r[0].diff > RC_PID_NORM_OFFSET)
- r[0].diff -= RC_PID_NORM_OFFSET;
- else if (r[0].diff < -RC_PID_NORM_OFFSET)
- r[0].diff += RC_PID_NORM_OFFSET;
+ if (r[0].diff > norm_offset)
+ r[0].diff -= norm_offset;
+ else if (r[0].diff < -norm_offset)
+ r[0].diff += norm_offset;
for (i = 0; i < l - 1; i++)
- if (r[i + 1].diff > r[i].diff + RC_PID_NORM_OFFSET)
- r[i + 1].diff -= RC_PID_NORM_OFFSET;
+ if (r[i + 1].diff > r[i].diff + norm_offset)
+ r[i + 1].diff -= norm_offset;
else if (r[i + 1].diff <= r[i].diff)
- r[i + 1].diff += RC_PID_NORM_OFFSET;
+ r[i + 1].diff += norm_offset;
}
static void rate_control_pid_sample(struct rc_pid_info *pinfo,
@@ -167,14 +168,18 @@ static void rate_control_pid_sample(stru
s32 err_int;
s32 err_der;
int adj, i, j, tmp;
+ unsigned long period;
mode = local->oper_hw_mode;
spinfo = sta->rate_ctrl_priv;
/* In case nothing happened during the previous control interval,
turn
* the sharpening factor on. */
- if (jiffies - spinfo->last_sample > 2 * RC_PID_INTERVAL)
- spinfo->sharp_cnt = RC_PID_SHARPENING_DURATION;
+ period = (HZ * pinfo->sampling_period + 500) / 1000;
+ if (!period)
+ period = 1;
+ if (jiffies - spinfo->last_sample > 2 * period)
+ spinfo->sharp_cnt = pinfo->sharpen_duration;
spinfo->last_sample = jiffies;
@@ -202,17 +207,17 @@ static void rate_control_pid_sample(stru
rinfo[j].diff = rinfo[i].diff + tmp;
pinfo->oldrate = sta->txrate;
}
- rate_control_pid_normalize(rinfo, mode->num_rates);
+ rate_control_pid_normalize(pinfo, mode->num_rates);
/* Compute the proportional, integral and derivative errors. */
- err_prop = RC_PID_TARGET_PF - pf;
+ err_prop = pinfo->target - pf;
- err_avg = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
+ err_avg = spinfo->err_avg_sc >> pinfo->smoothing_shift;
spinfo->err_avg_sc = spinfo->err_avg_sc - err_avg + err_prop;
- err_int = spinfo->err_avg_sc >> RC_PID_SMOOTHING_SHIFT;
+ err_int = spinfo->err_avg_sc >> pinfo->smoothing_shift;
- err_der = pf - spinfo->last_pf
- * (1 + RC_PID_SHARPENING_FACTOR * spinfo->sharp_cnt);
+ err_der = (pf - spinfo->last_pf) *
+ (1 + pinfo->sharpen_factor * spinfo->sharp_cnt);
spinfo->last_pf = pf;
if (spinfo->sharp_cnt)
spinfo->sharp_cnt--;
@@ -241,6 +246,7 @@ static void rate_control_pid_tx_status(v
struct rc_pid_info *pinfo = priv;
struct sta_info *sta;
struct rc_pid_sta_info *spinfo;
+ unsigned long period;
sta = sta_info_get(local, hdr->addr1);
@@ -285,7 +291,10 @@ static void rate_control_pid_tx_status(v
sta->tx_num_mpdu_fail += status->retry_count;
/* Update PID controller state. */
- if (time_after(jiffies, spinfo->last_sample + RC_PID_INTERVAL))
+ period = (HZ * pinfo->sampling_period + 500) / 1000;
+ if (!period)
+ period = 1;
+ if (time_after(jiffies, spinfo->last_sample + period))
rate_control_pid_sample(pinfo, local, sta);
sta_info_put(sta);
@@ -343,6 +352,9 @@ static void *rate_control_pid_alloc(stru
struct ieee80211_hw_mode *mode;
int i, j, tmp;
bool s;
+#ifdef CONFIG_MAC80211_DEBUGFS
+ struct rc_pid_debugfs_entries *de;
+#endif
pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC);
if (!pinfo)
@@ -363,10 +375,10 @@ static void *rate_control_pid_alloc(stru
for (i = 0; i < mode->num_rates; i++) {
rinfo[i].index = i;
rinfo[i].rev_index = i;
- if (RC_PID_FAST_START)
+ if (pinfo->fast_start)
rinfo[i].diff = 0;
else
- rinfo[i].diff = i * RC_PID_NORM_OFFSET;
+ rinfo[i].diff = i * pinfo->norm_offset;
}
for (i = 1; i < mode->num_rates; i++) {
s = 0;
@@ -385,18 +397,72 @@ static void *rate_control_pid_alloc(stru
}
pinfo->target = RC_PID_TARGET_PF;
+ pinfo->sampling_period = RC_PID_INTERVAL;
pinfo->coeff_p = RC_PID_COEFF_P;
pinfo->coeff_i = RC_PID_COEFF_I;
pinfo->coeff_d = RC_PID_COEFF_D;
+ pinfo->smoothing_shift = RC_PID_SMOOTHING_SHIFT;
+ pinfo->sharpen_factor = RC_PID_SHARPENING_FACTOR;
+ pinfo->sharpen_duration = RC_PID_SHARPENING_DURATION;
+ pinfo->norm_offset = RC_PID_NORM_OFFSET;
+ pinfo->fast_start = RC_PID_FAST_START;
pinfo->rinfo = rinfo;
pinfo->oldrate = 0;
+#ifdef CONFIG_MAC80211_DEBUGFS
+ de = &pinfo->dentries;
+ de->dir = debugfs_create_dir("rc80211_pid",
+ local->hw.wiphy->debugfsdir);
+ de->target = debugfs_create_u32("target_pf", S_IRUSR | S_IWUSR,
+ de->dir, &pinfo->target);
+ de->sampling_period = debugfs_create_u32("sampling_period",
+ S_IRUSR | S_IWUSR,
de->dir,
+ &pinfo->sampling_period);
+ de->coeff_p = debugfs_create_s32("coeff_p", S_IRUSR | S_IWUSR,
+ de->dir, &pinfo->coeff_p);
+ de->coeff_i = debugfs_create_s32("coeff_i", S_IRUSR | S_IWUSR,
+ de->dir, &pinfo->coeff_i);
+ de->coeff_d = debugfs_create_s32("coeff_d", S_IRUSR | S_IWUSR,
+ de->dir, &pinfo->coeff_d);
+ de->smoothing_shift = debugfs_create_u32("smoothing_shift",
+ S_IRUSR | S_IWUSR,
de->dir,
+ &pinfo->smoothing_shift);
+ de->sharpen_factor = debugfs_create_u32("sharpen_factor",
+ S_IRUSR | S_IWUSR, de->dir,
+ &pinfo->sharpen_factor);
+ de->sharpen_duration = debugfs_create_u32("sharpen_duration",
+ S_IRUSR | S_IWUSR,
de->dir,
+
&pinfo->sharpen_duration);
+ de->norm_offset = debugfs_create_u32("norm_offset",
+ S_IRUSR | S_IWUSR, de->dir,
+ &pinfo->norm_offset);
+ de->fast_start = debugfs_create_bool("fast_start",
+ S_IRUSR | S_IWUSR, de->dir,
+ &pinfo->fast_start);
+#endif
+
return pinfo;
}
static void rate_control_pid_free(void *priv)
{
struct rc_pid_info *pinfo = priv;
+#ifdef CONFIG_MAC80211_DEBUGFS
+ struct rc_pid_debugfs_entries *de = &pinfo->dentries;
+
+ debugfs_remove(de->fast_start);
+ debugfs_remove(de->norm_offset);
+ debugfs_remove(de->sharpen_duration);
+ debugfs_remove(de->sharpen_factor);
+ debugfs_remove(de->smoothing_shift);
+ debugfs_remove(de->coeff_d);
+ debugfs_remove(de->coeff_i);
+ debugfs_remove(de->coeff_p);
+ debugfs_remove(de->sampling_period);
+ debugfs_remove(de->target);
+ debugfs_remove(de->dir);
+#endif
+
kfree(pinfo->rinfo);
kfree(pinfo);
}
Index: wireless-2.6/net/mac80211/rc80211_pid.h
===================================================================
--- wireless-2.6.orig/net/mac80211/rc80211_pid.h
+++ wireless-2.6/net/mac80211/rc80211_pid.h
@@ -119,6 +119,20 @@ struct rc_pid_events_file_info {
unsigned int next_entry;
};
+struct rc_pid_debugfs_entries {
+ struct dentry *dir;
+ struct dentry *target;
+ struct dentry *sampling_period;
+ struct dentry *coeff_p;
+ struct dentry *coeff_i;
+ struct dentry *coeff_d;
+ struct dentry *smoothing_shift;
+ struct dentry *sharpen_factor;
+ struct dentry *sharpen_duration;
+ struct dentry *norm_offset;
+ struct dentry *fast_start;
+};
+
void rate_control_pid_event_tx_status(struct rc_pid_event_buffer *buf,
struct ieee80211_tx_status
*stat);
@@ -222,8 +236,8 @@ struct rc_pid_info {
/* Exponential averaging shift. */
unsigned int smoothing_shift;
- /* Sharpening shift and duration. */
- unsigned int sharpen_shift;
+ /* Sharpening factor and duration. */
+ unsigned int sharpen_factor;
unsigned int sharpen_duration;
/* Normalization offset. */
@@ -237,6 +251,11 @@ struct rc_pid_info {
/* Index of the last used rate. */
int oldrate;
+
+#ifdef CONFIG_MAC80211_DEBUGFS
+ /* Debugfs entries created for the parameters above. */
+ struct rc_pid_debugfs_entries dentries;
+#endif
};
#endif /* RC80211_PID_H */
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/8] rate control rework
[not found] <20071218233749.871878037@polimi.it>
` (7 preceding siblings ...)
2007-12-19 0:04 ` [PATCH v2 8/8] rc80211-pid: export tuning parameters through debugfs Stefano Brivio
@ 2007-12-19 0:15 ` Stefano Brivio
8 siblings, 0 replies; 10+ messages in thread
From: Stefano Brivio @ 2007-12-19 0:15 UTC (permalink / raw)
To: Stefano Brivio
Cc: John W. Linville, Johannes Berg, Mattias Nissler, linux-wireless,
linux-kernel, gregkh
Sorry, people are telling me that this is line wrapped. Which is strange
because claws-mail doesn't show that, will try to fix and resend anyway.
Sorry again for the noise.
--
Ciao
Stefano
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2007-12-19 0:20 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20071218233749.871878037@polimi.it>
2007-12-19 0:02 ` [PATCH v2 1/8] mac80211: clean up rate selection Stefano Brivio
2007-12-19 0:03 ` [PATCH v2 2/8] mac80211: add PID controller based rate control algorithm Stefano Brivio
2007-12-19 0:03 ` [PATCH v2 3/8] mac80211: make PID rate control algorithm the default Stefano Brivio
2007-12-19 0:03 ` [PATCH v2 4/8] rc80211-pid: add rate behaviour learning algorithm Stefano Brivio
2007-12-19 0:04 ` [PATCH v2 5/8] rc80211-pid: add sharpening factor Stefano Brivio
2007-12-19 0:04 ` [PATCH v2 6/8] rc80211-pid: add debugging Stefano Brivio
2007-12-19 0:04 ` [PATCH v2 7/8] debugfs: allow access to signed values Stefano Brivio
2007-12-19 0:04 ` [PATCH v2 8/8] rc80211-pid: export tuning parameters through debugfs Stefano Brivio
2007-12-19 0:15 ` [PATCH v2 0/8] rate control rework Stefano Brivio
2007-12-19 0:02 Stefano Brivio
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).