amrr.c

来自「Atheros wifi driver source code」· C语言 代码 · 共 592 行 · 第 1/2 页

C
592
字号
		 * the node.  We know the rate is there because the		 * rate set is checked when the station associates.		 */		const struct ieee80211_rateset *rs =			&ic->ic_sup_rates[ic->ic_curmode];		int r = rs->rs_rates[ic->ic_fixed_rate] & IEEE80211_RATE_VAL;		/* NB: the rate set is assumed sorted */		srate = ni->ni_rates.rs_nrates - 1;		for (; srate >= 0 && RATE(srate) != r; srate--)			;		KASSERT(srate >= 0,			("fixed rate %d not in rate set", ic->ic_fixed_rate));	}	ath_rate_update(sc, ni, srate);#undef RATE}static voidath_rate_cb(void *arg, struct ieee80211_node *ni){	ath_rate_update(ni->ni_ic->ic_ifp->if_softc, ni, (int)(uintptr_t) arg);}/* * Reset the rate control state for each 802.11 state transition. */voidath_rate_newstate(struct ath_softc *sc, enum ieee80211_state state){	struct amrr_softc *asc = (struct amrr_softc *) sc->sc_rc;	struct ieee80211com *ic = &sc->sc_ic;	struct ieee80211_node *ni;	if (state == IEEE80211_S_INIT) {		del_timer(&asc->timer);		return;	}	if (ic->ic_opmode == IEEE80211_M_STA) {		/*		 * Reset local xmit state; this is really only		 * meaningful when operating in station mode.		 */		ni = ic->ic_bss;		if (state == IEEE80211_S_RUN) {			ath_rate_ctl_start(sc, ni);		} else {			ath_rate_update(sc, ni, 0);		}	} else {		/*		 * When operating as a station the node table holds		 * the AP's that were discovered during scanning.		 * For any other operating mode we want to reset the		 * tx rate state of each node.		 */		ieee80211_iterate_nodes(&ic->ic_sta, ath_rate_cb, 0);		ath_rate_update(sc, ic->ic_bss, 0);	}	if (ic->ic_fixed_rate == -1 && state == IEEE80211_S_RUN) {		int interval;		/*		 * Start the background rate control thread if we		 * are not configured to use a fixed xmit rate.		 */		interval = ath_rateinterval;		if (ic->ic_opmode == IEEE80211_M_STA)			interval /= 2;		mod_timer(&asc->timer, jiffies + ((HZ * interval) / 1000));	}}EXPORT_SYMBOL(ath_rate_newstate);/*  * Examine and potentially adjust the transmit rate. */static voidath_rate_ctl(void *arg, struct ieee80211_node *ni){	struct ath_softc *sc = arg;	struct amrr_node *amn = ATH_NODE_AMRR(ATH_NODE (ni));	int old_rate;#define is_success(amn) \(amn->amn_tx_try1_cnt  < (amn->amn_tx_try0_cnt/10))#define is_enough(amn) \(amn->amn_tx_try0_cnt > 10)#define is_failure(amn) \(amn->amn_tx_try1_cnt > (amn->amn_tx_try0_cnt/3))#define is_max_rate(ni) \((ni->ni_txrate + 1) >= ni->ni_rates.rs_nrates)#define is_min_rate(ni) \(ni->ni_txrate == 0)	old_rate = ni->ni_txrate;    	DPRINTF (sc, "cnt0: %d cnt1: %d cnt2: %d cnt3: %d -- threshold: %d\n",		 amn->amn_tx_try0_cnt,		 amn->amn_tx_try1_cnt,		 amn->amn_tx_try2_cnt,		 amn->amn_tx_try3_cnt,		 amn->amn_success_threshold);  	if (is_success (amn) && is_enough (amn)) {		amn->amn_success++;		if (amn->amn_success == amn->amn_success_threshold &&  		    !is_max_rate (ni)) {  			amn->amn_recovery = 1;  			amn->amn_success = 0;  			ni->ni_txrate++;			DPRINTF (sc, "increase rate to %d\n", ni->ni_txrate);  		} else {			amn->amn_recovery = 0;		}  	} else if (is_failure (amn)) {  		amn->amn_success = 0;  		if (!is_min_rate (ni)) {  			if (amn->amn_recovery) {  				/* recovery failure. */  				amn->amn_success_threshold *= 2;  				amn->amn_success_threshold = min (amn->amn_success_threshold,								  (u_int)ath_rate_max_success_threshold); 				DPRINTF (sc, "decrease rate recovery thr: %d\n", amn->amn_success_threshold);  			} else {  				/* simple failure. */ 				amn->amn_success_threshold = ath_rate_min_success_threshold; 				DPRINTF (sc, "decrease rate normal thr: %d\n", amn->amn_success_threshold);  			}			amn->amn_recovery = 0;  			ni->ni_txrate--;   		} else {			amn->amn_recovery = 0;		}   	}	if (is_enough (amn) || old_rate != ni->ni_txrate) {		/* reset counters. */		amn->amn_tx_try0_cnt = 0;		amn->amn_tx_try1_cnt = 0;		amn->amn_tx_try2_cnt = 0;		amn->amn_tx_try3_cnt = 0;		amn->amn_tx_failure_cnt = 0;	}	if (old_rate != ni->ni_txrate) {		ath_rate_update(sc, ni, ni->ni_txrate);	}}static voidath_ratectl(unsigned long data){	struct net_device *dev = (struct net_device *)data;	struct ath_softc *sc = dev->priv;	struct amrr_softc *asc = (struct amrr_softc *) sc->sc_rc;	struct ieee80211com *ic = &sc->sc_ic;	int interval;	if (dev->flags & IFF_RUNNING) {		sc->sc_stats.ast_rate_calls++;		if (ic->ic_opmode == IEEE80211_M_STA)			ath_rate_ctl(sc, ic->ic_bss);	/* NB: no reference */		else			ieee80211_iterate_nodes(&ic->ic_sta, ath_rate_ctl, sc);	}	interval = ath_rateinterval;	if (ic->ic_opmode == IEEE80211_M_STA)		interval /= 2;	asc->timer.expires = jiffies + ((HZ * interval) / 1000);	add_timer(&asc->timer);}struct ath_ratectrl *ath_rate_attach(struct ath_softc *sc){	struct amrr_softc *asc;	asc = kmalloc(sizeof(struct amrr_softc), GFP_ATOMIC);	if (asc == NULL)		return NULL;	asc->arc.arc_space = sizeof(struct amrr_node);	init_timer(&asc->timer);	asc->timer.data = (unsigned long) &sc->sc_dev;	asc->timer.function = ath_ratectl;	return &asc->arc;}EXPORT_SYMBOL(ath_rate_attach);voidath_rate_detach(struct ath_ratectrl *arc){	struct amrr_softc *asc = (struct amrr_softc *) arc;	del_timer(&asc->timer);	kfree(asc);}EXPORT_SYMBOL(ath_rate_detach);static	int minrateinterval = 500;		/* 500ms */static	int maxint = 0x7fffffff;		/* 32-bit big */static  int min_threshold = 1;#define	CTL_AUTO	-2	/* cannot be CTL_ANY or CTL_NONE *//* * Static (i.e. global) sysctls. */enum {	DEV_ATH		= 9,			/* XXX known by many */};static ctl_table ath_rate_static_sysctls[] = {	{ .ctl_name	= CTL_AUTO,	  .procname	= "interval",	  .mode		= 0644,	  .data		= &ath_rateinterval,	  .maxlen	= sizeof(ath_rateinterval),	  .extra1	= &minrateinterval,	  .extra2	= &maxint,	  .proc_handler	= proc_dointvec_minmax	},	{ .ctl_name	= CTL_AUTO,	  .procname	= "max_success_threshold",	  .mode		= 0644,	  .data		= &ath_rate_max_success_threshold,	  .maxlen	= sizeof(ath_rate_max_success_threshold),	  .extra1	= &min_threshold,	  .extra2	= &maxint,	  .proc_handler	= proc_dointvec_minmax	},	{ .ctl_name	= CTL_AUTO,	  .procname	= "min_success_threshold",	  .mode		= 0644,	  .data		= &ath_rate_min_success_threshold,	  .maxlen	= sizeof(ath_rate_min_success_threshold),	  .extra1	= &min_threshold,	  .extra2	= &maxint,	  .proc_handler	= proc_dointvec_minmax	},	{ 0 }};static ctl_table ath_rate_table[] = {	{ .ctl_name	= CTL_AUTO,	  .procname	= "rate",	  .mode		= 0555,	  .child	= ath_rate_static_sysctls	}, { 0 }};static ctl_table ath_ath_table[] = {	{ .ctl_name	= DEV_ATH,	  .procname	= "ath",	  .mode		= 0555,	  .child	= ath_rate_table	}, { 0 }};static ctl_table ath_root_table[] = {	{ .ctl_name	= CTL_DEV,	  .procname	= "dev",	  .mode		= 0555,	  .child	= ath_ath_table	}, { 0 }};static struct ctl_table_header *ath_sysctl_header;MODULE_AUTHOR("INRIA, Mathieu Lacage");MODULE_DESCRIPTION("AMRR Rate control algorithm");#ifdef MODULE_LICENSEMODULE_LICENSE("Dual BSD/GPL");#endifstatic char *version = "0.1";static char *dev_info = "ath_rate_amrr";static int __initinit_ath_rate_amrr(void){	printk(KERN_INFO "%s: %s\n", dev_info, version);#ifdef CONFIG_SYSCTL	ath_sysctl_header = register_sysctl_table(ath_root_table, 1);#endif	return (0);}module_init(init_ath_rate_amrr);static void __exitexit_ath_rate_amrr(void){#ifdef CONFIG_SYSCTL	if (ath_sysctl_header != NULL)		unregister_sysctl_table(ath_sysctl_header);#endif	printk(KERN_INFO "%s: unloaded\n", dev_info);}module_exit(exit_ath_rate_amrr);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?