From owner-p4-projects@FreeBSD.ORG Tue Oct 28 03:42:38 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 57CF2106567A; Tue, 28 Oct 2008 03:42:38 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10593106566B for ; Tue, 28 Oct 2008 03:42:38 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id F1CC88FC17 for ; Tue, 28 Oct 2008 03:42:37 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m9S3gbm6030403 for ; Tue, 28 Oct 2008 03:42:37 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m9S3gb6M030401 for perforce@freebsd.org; Tue, 28 Oct 2008 03:42:37 GMT (envelope-from sam@freebsd.org) Date: Tue, 28 Oct 2008 03:42:37 GMT Message-Id: <200810280342.m9S3gb6M030401@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Cc: Subject: PERFORCE change 152072 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Oct 2008 03:42:38 -0000 http://perforce.freebsd.org/chv.cgi?CH=152072 Change 152072 by sam@sam_ebb on 2008/10/28 03:42:21 checkpoint rewrite Affected files ... .. //depot/projects/vap/sys/dev/ath/ath_rate/sample/sample.c#17 edit .. //depot/projects/vap/sys/dev/ath/ath_rate/sample/sample.h#8 edit Differences ... ==== //depot/projects/vap/sys/dev/ath/ath_rate/sample/sample.c#17 (text+ko) ==== @@ -105,33 +105,35 @@ static void ath_rate_ctl_reset(struct ath_softc *, struct ieee80211_node *); +static const int packet_size_bins[NUM_PACKET_SIZE_BINS] = { 250, 1600 }; + static __inline int size_to_bin(int size) { - int x = 0; - for (x = 0; x < NUM_PACKET_SIZE_BINS; x++) { - if (size <= packet_size_bins[x]) { - return x; - } - } +#if NUM_PACKET_SIZE_BINS > 1 + if (size <= packet_size_bins[0]) + return 0; +#endif +#if NUM_PACKET_SIZE_BINS > 2 + if (size <= packet_size_bins[1]) + return 1; +#endif +#if NUM_PACKET_SIZE_BINS > 3 + if (size <= packet_size_bins[2]) + return 2; +#endif +#if NUM_PACKET_SIZE_BINS > 4 +#error "add support for more packet sizes" +#endif return NUM_PACKET_SIZE_BINS-1; } + static __inline int -bin_to_size(int index) { +bin_to_size(int index) +{ return packet_size_bins[index]; } -static __inline int -rate_to_ndx(struct sample_node *sn, int rate) { - int x = 0; - for (x = 0; x < sn->num_rates; x++) { - if (sn->rates[x].rate == rate) { - return x; - } - } - return -1; -} - void ath_rate_node_init(struct ath_softc *sc, struct ath_node *an) { @@ -143,205 +145,202 @@ { } - /* - * returns the ndx with the lowest average_tx_time, + * returns the rix with the lowest average_tx_time, * or -1 if all the average_tx_times are 0. */ -static __inline int best_rate_ndx(struct sample_node *sn, int size_bin, - int require_acked_before) +static __inline int +pick_best_rate(struct sample_node *sn, const HAL_RATE_TABLE *rt, + int size_bin, int require_acked_before) { - int x = 0; - int best_rate_ndx = 0; - int best_rate_tt = 0; - for (x = 0; x < sn->num_rates; x++) { - int tt = sn->stats[size_bin][x].average_tx_time; - if (tt <= 0 || (require_acked_before && - !sn->stats[size_bin][x].packets_acked)) { + int best_rate_rix, best_rate_tt; + uint32_t mask; + int rix, tt; + + best_rate_rix = 0; + best_rate_tt = 0; + for (mask = sn->ratemask, rix = 0; mask != 0; mask >>= 1, rix++) { + if ((mask & 1) == 0) /* not a supported rate */ continue; - } - /* 9 megabits never works better than 12 */ - if (sn->rates[x].rate == 18) + tt = sn->stats[size_bin][rix].average_tx_time; + if (tt <= 0 || + (require_acked_before && + !sn->stats[size_bin][rix].packets_acked)) continue; /* don't use a bit-rate that has been failing */ - if (sn->stats[size_bin][x].successive_failures > 3) + if (sn->stats[size_bin][rix].successive_failures > 3) continue; if (!best_rate_tt || best_rate_tt > tt) { best_rate_tt = tt; - best_rate_ndx = x; + best_rate_rix = rix; } } - return (best_rate_tt) ? best_rate_ndx : -1; + return (best_rate_tt ? best_rate_rix : -1); } /* * pick a good "random" bit-rate to sample other than the current one */ static __inline int -pick_sample_ndx(struct sample_node *sn, int size_bin) +pick_sample_rate(struct sample_node *sn, const HAL_RATE_TABLE *rt, int size_bin) { - int x = 0; - int current_ndx = 0; - unsigned current_tt = 0; +#define RATE(ix) (rt->info[ix].dot11Rate & IEEE80211_RATE_VAL) + int current_rix, rix; + unsigned current_tt; + uint32_t mask; - current_ndx = sn->current_rate[size_bin]; - if (current_ndx < 0) { + current_rix = sn->current_rix[size_bin]; + if (current_rix < 0) { /* no successes yet, send at the lowest bit-rate */ return 0; } - current_tt = sn->stats[size_bin][current_ndx].average_tx_time; + current_tt = sn->stats[size_bin][current_rix].average_tx_time; - for (x = 0; x < sn->num_rates; x++) { - int ndx = (sn->last_sample_ndx[size_bin]+1+x) % sn->num_rates; - - /* don't sample the current bit-rate */ - if (ndx == current_ndx) + rix = sn->last_sample_rix[size_bin]+1; /* next sample rate */ + mask = sn->ratemask >> rix; /* clear all rates below */ + for (; mask != 0; mask >>= 1, rix++) { + if ((mask & 1) == 0) /* not a supported rate */ continue; /* this bit-rate is always worse than the current one */ - if (sn->stats[size_bin][ndx].perfect_tx_time > current_tt) + if (sn->stats[size_bin][rix].perfect_tx_time > current_tt) continue; /* rarely sample bit-rates that fail a lot */ - if (ticks - sn->stats[size_bin][ndx].last_tx < ((hz * STALE_FAILURE_TIMEOUT_MS)/1000) && - sn->stats[size_bin][ndx].successive_failures > 3) + if (ticks - sn->stats[size_bin][rix].last_tx < ((hz * STALE_FAILURE_TIMEOUT_MS)/1000) && + sn->stats[size_bin][rix].successive_failures > 3) continue; /* don't sample more than 2 indexes higher * for rates higher than 11 megabits */ - if (sn->rates[ndx].rate > 22 && ndx > current_ndx + 2) + if (RATE(rix) > 2*11 && rix > current_rix + 2) continue; - /* 9 megabits never works better than 12 */ - if (sn->rates[ndx].rate == 18) + /* if we're using 11 megabits, only sample up to 12 megabits */ + if (RATE(current_rix) == 2*11 && rix > current_rix + 1) continue; - /* if we're using 11 megabits, only sample up to 12 megabits - */ - if (sn->rates[current_ndx].rate == 22 && ndx > current_ndx + 1) - continue; - - sn->last_sample_ndx[size_bin] = ndx; - return ndx; + sn->last_sample_rix[size_bin] = rix; + return rix; } - return current_ndx; + return current_rix; +#undef RATE } void ath_rate_findrate(struct ath_softc *sc, struct ath_node *an, int shortPreamble, size_t frameLen, - u_int8_t *rix, int *try0, u_int8_t *txrate) + u_int8_t *rix0, int *try0, u_int8_t *txrate) { +#define RATE(ix) (rt->info[ix].dot11Rate & IEEE80211_RATE_VAL) struct sample_node *sn = ATH_NODE_SAMPLE(an); struct sample_softc *ssc = ATH_SOFTC_SAMPLE(sc); struct ifnet *ifp = sc->sc_ifp; struct ieee80211com *ic = ifp->if_l2com; - int ndx, size_bin, mrr, best_ndx, change_rates; + const HAL_RATE_TABLE *rt = sc->sc_currates; + const int size_bin = size_to_bin(frameLen); + int rix, mrr, best_rix, change_rates; unsigned average_tx_time; + if (sn->static_rix != -1) { + rix = sn->static_rix; + *try0 = ATH_TXMAXTRY; + goto done; + } + mrr = sc->sc_mrretry && !(ic->ic_flags & IEEE80211_F_USEPROT); - size_bin = size_to_bin(frameLen); - best_ndx = best_rate_ndx(sn, size_bin, !mrr); + *try0 = mrr ? 2 : ATH_TXMAXTRY; - if (best_ndx >= 0) { - average_tx_time = sn->stats[size_bin][best_ndx].average_tx_time; + best_rix = pick_best_rate(sn, rt, size_bin, !mrr); + if (best_rix >= 0) { + average_tx_time = sn->stats[size_bin][best_rix].average_tx_time; } else { average_tx_time = 0; } - - if (sn->static_rate_ndx != -1) { - ndx = sn->static_rate_ndx; - *try0 = ATH_TXMAXTRY; + if (sn->sample_tt[size_bin] < average_tx_time * (sn->packets_since_sample[size_bin]*ssc->ath_sample_rate/100)) { + /* + * we want to limit the time measuring the performance + * of other bit-rates to ath_sample_rate% of the + * total transmission time. + */ + rix = pick_sample_rate(sn, rt, size_bin); + if (rix != sn->current_rix[size_bin]) { + sn->current_sample_rix[size_bin] = rix; + } else { + sn->current_sample_rix[size_bin] = -1; + } + sn->packets_since_sample[size_bin] = 0; + } else { - *try0 = mrr ? 2 : ATH_TXMAXTRY; - - if (sn->sample_tt[size_bin] < average_tx_time * (sn->packets_since_sample[size_bin]*ssc->ath_sample_rate/100)) { - /* - * we want to limit the time measuring the performance - * of other bit-rates to ath_sample_rate% of the - * total transmission time. - */ - ndx = pick_sample_ndx(sn, size_bin); - if (ndx != sn->current_rate[size_bin]) { - sn->current_sample_ndx[size_bin] = ndx; - } else { - sn->current_sample_ndx[size_bin] = -1; - } - sn->packets_since_sample[size_bin] = 0; - - } else { - change_rates = 0; - if (!sn->packets_sent[size_bin] || best_ndx == -1) { - /* no packet has been sent successfully yet */ - for (ndx = sn->num_rates-1; ndx > 0; ndx--) { - /* - * pick the highest rate <= 36 Mbps - * that hasn't failed. - */ - if (sn->rates[ndx].rate <= 72 && - sn->stats[size_bin][ndx].successive_failures == 0) { - break; - } + change_rates = 0; + if (!sn->packets_sent[size_bin] || best_rix == -1) { + /* no packet has been sent successfully yet */ + for (rix = rt->rateCount-1; rix > 0; rix--) { + /* + * pick the highest rate <= 36 Mbps + * that hasn't failed. + */ + if (RATE(rix) <= 72 && + sn->stats[size_bin][rix].successive_failures == 0) { + break; } - change_rates = 1; - best_ndx = ndx; - } else if (sn->packets_sent[size_bin] < 20) { - /* let the bit-rate switch quickly during the first few packets */ - change_rates = 1; - } else if (ticks - ((hz*MIN_SWITCH_MS)/1000) > sn->ticks_since_switch[size_bin]) { - /* 2 seconds have gone by */ - change_rates = 1; - } else if (average_tx_time * 2 < sn->stats[size_bin][sn->current_rate[size_bin]].average_tx_time) { - /* the current bit-rate is twice as slow as the best one */ - change_rates = 1; } + change_rates = 1; + best_rix = rix; + } else if (sn->packets_sent[size_bin] < 20) { + /* let the bit-rate switch quickly during the first few packets */ + change_rates = 1; + } else if (ticks - ((hz*MIN_SWITCH_MS)/1000) > sn->ticks_since_switch[size_bin]) { + /* 2 seconds have gone by */ + change_rates = 1; + } else if (average_tx_time * 2 < sn->stats[size_bin][sn->current_rix[size_bin]].average_tx_time) { + /* the current bit-rate is twice as slow as the best one */ + change_rates = 1; + } - sn->packets_since_sample[size_bin]++; - - if (change_rates) { - if (best_ndx != sn->current_rate[size_bin]) { - IEEE80211_NOTE(an->an_node.ni_vap, - IEEE80211_MSG_RATECTL, - &an->an_node, + sn->packets_since_sample[size_bin]++; + + if (change_rates) { + if (best_rix != sn->current_rix[size_bin]) { + IEEE80211_NOTE(an->an_node.ni_vap, + IEEE80211_MSG_RATECTL, + &an->an_node, "%s: size %d switch rate %d (%d/%d) -> %d (%d/%d) after %d packets mrr %d", - __func__, - packet_size_bins[size_bin], - sn->rates[sn->current_rate[size_bin]].rate, - sn->stats[size_bin][sn->current_rate[size_bin]].average_tx_time, - sn->stats[size_bin][sn->current_rate[size_bin]].perfect_tx_time, - sn->rates[best_ndx].rate, - sn->stats[size_bin][best_ndx].average_tx_time, - sn->stats[size_bin][best_ndx].perfect_tx_time, - sn->packets_since_switch[size_bin], - mrr); - } - sn->packets_since_switch[size_bin] = 0; - sn->current_rate[size_bin] = best_ndx; - sn->ticks_since_switch[size_bin] = ticks; - /* - * Set the visible txrate for this node. - */ - an->an_node.ni_txrate = sn->rates[best_ndx].rate; + __func__, + packet_size_bins[size_bin], + RATE(sn->current_rix[size_bin]), + sn->stats[size_bin][sn->current_rix[size_bin]].average_tx_time, + sn->stats[size_bin][sn->current_rix[size_bin]].perfect_tx_time, + RATE(best_rix), + sn->stats[size_bin][best_rix].average_tx_time, + sn->stats[size_bin][best_rix].perfect_tx_time, + sn->packets_since_switch[size_bin], + mrr); } - ndx = sn->current_rate[size_bin]; - sn->packets_since_switch[size_bin]++; + sn->packets_since_switch[size_bin] = 0; + sn->current_rix[size_bin] = best_rix; + sn->ticks_since_switch[size_bin] = ticks; + /* + * Set the visible txrate for this node. + */ + an->an_node.ni_txrate = RATE(best_rix); } + rix = sn->current_rix[size_bin]; + sn->packets_since_switch[size_bin]++; } +done: + KASSERT(rix >= 0 && rix < rt->rateCount, ("rix is %d", rix)); - KASSERT(ndx >= 0 && ndx < sn->num_rates, ("ndx is %d", ndx)); - - *rix = sn->rates[ndx].rix; - if (shortPreamble) { - *txrate = sn->rates[ndx].shortPreambleRateCode; - } else { - *txrate = sn->rates[ndx].rateCode; - } + *rix0 = rix; + *txrate = rt->info[rix].rateCode + | (shortPreamble ? rt->info[rix].shortPreamble : 0); sn->packets_sent[size_bin]++; +#undef RATE } void @@ -349,26 +348,21 @@ struct ath_desc *ds, int shortPreamble, u_int8_t rix) { struct sample_node *sn = ATH_NODE_SAMPLE(an); - int rateCode = -1; - int frame_size = 0; - int size_bin = 0; - int ndx = 0; + const HAL_RATE_TABLE *rt = sc->sc_currates; + const int size_bin = 0; /*XXX*/ + uint8_t rix1, s1code, rix2, s2code; - size_bin = size_to_bin(frame_size); // TODO: it's correct that frame_size alway 0 ? - ndx = sn->current_rate[size_bin]; /* retry at the current bit-rate */ - - if (!sn->stats[size_bin][ndx].packets_acked) { - ndx = 0; /* use the lowest bit-rate */ - } - - if (shortPreamble) { - rateCode = sn->rates[ndx].shortPreambleRateCode; - } else { - rateCode = sn->rates[ndx].rateCode; - } + rix1 = sn->current_rix[size_bin]; /* retry at the current bit-rate */ + if (!sn->stats[size_bin][rix1].packets_acked) + rix1 = rt->info[rix].controlRate; /* next lowest basic rate */ + s1code = rt->info[rix1].rateCode + | (shortPreamble ? rt->info[rix1].shortPreamble : 0); + rix2 = rt->info[rix1].controlRate; + s2code = rt->info[rix2].rateCode + | (shortPreamble ? rt->info[rix2].shortPreamble : 0); ath_hal_setupxtxdesc(sc->sc_ah, ds - , rateCode, 3 /* series 1 */ - , sn->rates[0].rateCode, 3 /* series 2 */ + , s1code, 3 /* series 1 */ + , s2code, 3 /* series 2 */ , 0, 0 /* series 3 */ ); } @@ -376,44 +370,38 @@ static void update_stats(struct ath_softc *sc, struct ath_node *an, int frame_size, - int ndx0, int tries0, - int ndx1, int tries1, - int ndx2, int tries2, - int ndx3, int tries3, + int rix0, int tries0, + int rix1, int tries1, + int rix2, int tries2, + int rix3, int tries3, int short_tries, int tries, int status) { struct sample_node *sn = ATH_NODE_SAMPLE(an); struct sample_softc *ssc = ATH_SOFTC_SAMPLE(sc); - int tt = 0; - int tries_so_far = 0; - int size_bin = 0; - int size = 0; - int rate = 0; + const int size_bin = size_to_bin(frame_size); + const int size = bin_to_size(size_bin); + int tt, tries_so_far; - size_bin = size_to_bin(frame_size); - size = bin_to_size(size_bin); - - if (!(0 <= ndx0 && ndx0 < sn->num_rates)) + if (!IS_RATE_DEFINED(sn, rix0)) return; - rate = sn->rates[ndx0].rate; - tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx0].rix, + tt = calc_usecs_unicast_packet(sc, size, rix0, short_tries, MIN(tries0, tries) - 1); - tries_so_far += tries0; + tries_so_far = tries0; if (tries1 && tries0 < tries) { - if (!(0 <= ndx1 && ndx1 < sn->num_rates)) + if (!IS_RATE_DEFINED(sn, rix1)) return; - tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx1].rix, + tt += calc_usecs_unicast_packet(sc, size, rix1, short_tries, MIN(tries1 + tries_so_far, tries) - tries_so_far - 1); } tries_so_far += tries1; if (tries2 && tries0 + tries1 < tries) { - if (!(0 <= ndx2 && ndx2 < sn->num_rates)) + if (!IS_RATE_DEFINED(sn, rix2)) return; - tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx2].rix, + tt += calc_usecs_unicast_packet(sc, size, rix2, short_tries, MIN(tries2 + tries_so_far, tries) - tries_so_far - 1); } @@ -421,58 +409,58 @@ tries_so_far += tries2; if (tries3 && tries0 + tries1 + tries2 < tries) { - if (!(0 <= ndx3 && ndx3 < sn->num_rates)) + if (!IS_RATE_DEFINED(sn, rix3)) return; - tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx3].rix, + tt += calc_usecs_unicast_packet(sc, size, rix3, short_tries, MIN(tries3 + tries_so_far, tries) - tries_so_far - 1); } - if (sn->stats[size_bin][ndx0].total_packets < (100 / (100 - ssc->ath_smoothing_rate))) { + if (sn->stats[size_bin][rix0].total_packets < (100 / (100 - ssc->ath_smoothing_rate))) { /* just average the first few packets */ - int avg_tx = sn->stats[size_bin][ndx0].average_tx_time; - int packets = sn->stats[size_bin][ndx0].total_packets; - sn->stats[size_bin][ndx0].average_tx_time = (tt+(avg_tx*packets))/(packets+1); + int avg_tx = sn->stats[size_bin][rix0].average_tx_time; + int packets = sn->stats[size_bin][rix0].total_packets; + sn->stats[size_bin][rix0].average_tx_time = (tt+(avg_tx*packets))/(packets+1); } else { /* use a ewma */ - sn->stats[size_bin][ndx0].average_tx_time = - ((sn->stats[size_bin][ndx0].average_tx_time * ssc->ath_smoothing_rate) + + sn->stats[size_bin][rix0].average_tx_time = + ((sn->stats[size_bin][rix0].average_tx_time * ssc->ath_smoothing_rate) + (tt * (100 - ssc->ath_smoothing_rate))) / 100; } if (status) { int y; - sn->stats[size_bin][ndx0].successive_failures++; + sn->stats[size_bin][rix0].successive_failures++; for (y = size_bin+1; y < NUM_PACKET_SIZE_BINS; y++) { /* also say larger packets failed since we * assume if a small packet fails at a lower * bit-rate then a larger one will also. */ - sn->stats[y][ndx0].successive_failures++; - sn->stats[y][ndx0].last_tx = ticks; - sn->stats[y][ndx0].tries += tries; - sn->stats[y][ndx0].total_packets++; + sn->stats[y][rix0].successive_failures++; + sn->stats[y][rix0].last_tx = ticks; + sn->stats[y][rix0].tries += tries; + sn->stats[y][rix0].total_packets++; } } else { - sn->stats[size_bin][ndx0].packets_acked++; - sn->stats[size_bin][ndx0].successive_failures = 0; + sn->stats[size_bin][rix0].packets_acked++; + sn->stats[size_bin][rix0].successive_failures = 0; } - sn->stats[size_bin][ndx0].tries += tries; - sn->stats[size_bin][ndx0].last_tx = ticks; - sn->stats[size_bin][ndx0].total_packets++; + sn->stats[size_bin][rix0].tries += tries; + sn->stats[size_bin][rix0].last_tx = ticks; + sn->stats[size_bin][rix0].total_packets++; - if (ndx0 == sn->current_sample_ndx[size_bin]) { + if (rix0 == sn->current_sample_rix[size_bin]) { IEEE80211_NOTE(an->an_node.ni_vap, IEEE80211_MSG_RATECTL, &an->an_node, "%s: size %d %s sample rate %d tries (%d/%d) tt %d avg_tt (%d/%d)", __func__, size, status ? "FAIL" : "OK", - rate, short_tries, tries, tt, - sn->stats[size_bin][ndx0].average_tx_time, - sn->stats[size_bin][ndx0].perfect_tx_time); + rix0, short_tries, tries, tt, + sn->stats[size_bin][rix0].average_tx_time, + sn->stats[size_bin][rix0].perfect_tx_time); sn->sample_tt[size_bin] = tt; - sn->current_sample_ndx[size_bin] = -1; + sn->current_sample_rix[size_bin] = -1; } } @@ -492,19 +480,18 @@ struct sample_node *sn = ATH_NODE_SAMPLE(an); const struct ath_tx_status *ts = &bf->bf_status.ds_txstat; const struct ath_desc *ds0 = &bf->bf_desc[0]; - int final_rate, short_tries, long_tries, frame_size; + int final_rix, short_tries, long_tries, frame_size; const HAL_RATE_TABLE *rt = sc->sc_currates; int mrr; - final_rate = sc->sc_hwmap[ - rt->rateCodeToIndex[ts->ts_rate &~ HAL_TXSTAT_ALTRATE]].ieeerate; + final_rix = rt->rateCodeToIndex[ts->ts_rate &~ HAL_TXSTAT_ALTRATE]; short_tries = ts->ts_shortretry; long_tries = ts->ts_longretry + 1; frame_size = ds0->ds_ctl0 & 0x0fff; /* low-order 12 bits of ds_ctl0 */ if (frame_size == 0) /* NB: should not happen */ frame_size = 1500; - if (sn->num_rates <= 0) { + if (sn->ratemask == 0) { IEEE80211_NOTE(an->an_node.ni_vap, IEEE80211_MSG_RATECTL, &an->an_node, "%s: size %d %s rate/try %d/%d no rates yet", @@ -516,9 +503,7 @@ } mrr = sc->sc_mrretry && !(ic->ic_flags & IEEE80211_F_USEPROT); if (!mrr || !(ts->ts_rate & HAL_TXSTAT_ALTRATE)) { - int ndx = rate_to_ndx(sn, final_rate); - - if (ndx < 0) { + if (!IS_RATE_DEFINED(sn, final_rix)) { badrate(ifp, 0, ts->ts_rate, long_tries, ts->ts_status); return; } @@ -530,18 +515,18 @@ __func__, bin_to_size(size_to_bin(frame_size)), ts->ts_status ? "FAIL" : "OK", - final_rate, short_tries, long_tries); + final_rix, short_tries, long_tries); update_stats(sc, an, frame_size, - ndx, long_tries, + final_rix, long_tries, 0, 0, 0, 0, 0, 0, short_tries, long_tries, ts->ts_status); } else { - int hwrate0, rate0, tries0, ndx0; - int hwrate1, rate1, tries1, ndx1; - int hwrate2, rate2, tries2, ndx2; - int hwrate3, rate3, tries3, ndx3; + int hwrate0, rix0, tries0; + int hwrate1, rix1, tries1; + int hwrate2, rix2, tries2; + int hwrate3, rix3, tries3; int finalTSIdx = ts->ts_finaltsi; /* @@ -559,30 +544,17 @@ hwrate3 = MS(ds0->ds_ctl3, AR5416_XmitRate3); } - rate0 = sc->sc_hwmap[rt->rateCodeToIndex[hwrate0]].ieeerate; + rix0 = rt->rateCodeToIndex[hwrate0]; tries0 = MS(ds0->ds_ctl2, AR_XmitDataTries0); - ndx0 = rate_to_ndx(sn, rate0); - rate1 = sc->sc_hwmap[rt->rateCodeToIndex[hwrate1]].ieeerate; + rix1 = rt->rateCodeToIndex[hwrate1]; tries1 = MS(ds0->ds_ctl2, AR_XmitDataTries1); - ndx1 = rate_to_ndx(sn, rate1); - rate2 = sc->sc_hwmap[rt->rateCodeToIndex[hwrate2]].ieeerate; + rix2 = rt->rateCodeToIndex[hwrate2]; tries2 = MS(ds0->ds_ctl2, AR_XmitDataTries2); - ndx2 = rate_to_ndx(sn, rate2); - rate3 = sc->sc_hwmap[rt->rateCodeToIndex[hwrate3]].ieeerate; + rix3 = rt->rateCodeToIndex[hwrate3]; tries3 = MS(ds0->ds_ctl2, AR_XmitDataTries3); - ndx3 = rate_to_ndx(sn, rate3); - - if (tries0 && ndx0 < 0) - badrate(ifp, 0, hwrate0, tries0, ts->ts_status); - if (tries1 && ndx1 < 0) - badrate(ifp, 1, hwrate1, tries1, ts->ts_status); - if (tries2 && ndx2 < 0) - badrate(ifp, 2, hwrate2, tries2, ts->ts_status); - if (tries3 && ndx3 < 0) - badrate(ifp, 3, hwrate3, tries3, ts->ts_status); IEEE80211_NOTE(an->an_node.ni_vap, IEEE80211_MSG_RATECTL, &an->an_node, @@ -592,10 +564,19 @@ finalTSIdx, long_tries, ts->ts_status ? "FAIL" : "OK", - rate0, tries0, - rate1, tries1, - rate2, tries2, - rate3, tries3); + rix0, tries0, + rix1, tries1, + rix2, tries2, + rix3, tries3); + + if (tries0 && !IS_RATE_DEFINED(sn, rix0)) + badrate(ifp, 0, hwrate0, tries0, ts->ts_status); + if (tries1 && !IS_RATE_DEFINED(sn, rix1)) + badrate(ifp, 1, hwrate1, tries1, ts->ts_status); + if (tries2 && !IS_RATE_DEFINED(sn, rix2)) + badrate(ifp, 2, hwrate2, tries2, ts->ts_status); + if (tries3 && !IS_RATE_DEFINED(sn, rix3)) + badrate(ifp, 3, hwrate3, tries3, ts->ts_status); /* * NB: series > 0 are not penalized for failure @@ -606,10 +587,10 @@ */ if (tries0) { update_stats(sc, an, frame_size, - ndx0, tries0, - ndx1, tries1, - ndx2, tries2, - ndx3, tries3, + rix0, tries0, + rix1, tries1, + rix2, tries2, + rix3, tries3, short_tries, long_tries, long_tries > tries0); long_tries -= tries0; @@ -617,9 +598,9 @@ if (tries1 && finalTSIdx > 0) { update_stats(sc, an, frame_size, - ndx1, tries1, - ndx2, tries2, - ndx3, tries3, + rix1, tries1, + rix2, tries2, + rix3, tries3, 0, 0, short_tries, long_tries, ts->ts_status); @@ -628,8 +609,8 @@ if (tries2 && finalTSIdx > 1) { update_stats(sc, an, frame_size, - ndx2, tries2, - ndx3, tries3, + rix2, tries2, + rix3, tries3, 0, 0, 0, 0, short_tries, long_tries, @@ -639,7 +620,7 @@ if (tries3 && finalTSIdx > 2) { update_stats(sc, an, frame_size, - ndx3, tries3, + rix3, tries3, 0, 0, 0, 0, 0, 0, @@ -663,14 +644,16 @@ ath_rate_ctl_reset(struct ath_softc *sc, struct ieee80211_node *ni) { #define RATE(_ix) (ni->ni_rates.rs_rates[(_ix)] & IEEE80211_RATE_VAL) +#define INFORATE(_ix) (rt->info[(_ix)].dot11Rate & IEEE80211_RATE_VAL) struct ath_node *an = ATH_NODE(ni); const struct ieee80211_txparam *tp = ni->ni_txparms; struct sample_node *sn = ATH_NODE_SAMPLE(an); const HAL_RATE_TABLE *rt = sc->sc_currates; - int x, y, srate; + int x, y, srate, rix; + uint32_t mask; KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); - sn->static_rate_ndx = -1; + sn->static_rix = -1; if (tp != NULL && tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { /* * A fixed rate is to be used; ic_fixed_rate is the @@ -689,86 +672,135 @@ * can fail. */ if (srate >= 0) - sn->static_rate_ndx = srate; + sn->static_rix = sc->sc_rixmap[srate]; } - sn->num_rates = ni->ni_rates.rs_nrates; - for (x = 0; x < ni->ni_rates.rs_nrates; x++) { - sn->rates[x].rate = ni->ni_rates.rs_rates[x] & IEEE80211_RATE_VAL; - sn->rates[x].rix = sc->sc_rixmap[sn->rates[x].rate]; - if (sn->rates[x].rix == 0xff) { - IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, - "%s: ignore bogus rix at %d", __func__, x); + /* + * Construct a bitmask of usable rates. This has all + * negotiated rates minus those marked by the hal as + * to be ignored for doing rate control. + */ + sn->ratemask = 0; + for (x = 0; x < ni->ni_rates.rs_nrates; x++) { + rix = sc->sc_rixmap[RATE(x)]; + if (rix == 0xff) + continue; + /* skip rates marked broken by hal */ + if (!rt->info[rix].valid) continue; - } - sn->rates[x].rateCode = rt->info[sn->rates[x].rix].rateCode; - sn->rates[x].shortPreambleRateCode = - rt->info[sn->rates[x].rix].rateCode | - rt->info[sn->rates[x].rix].shortPreamble; + KASSERT(rix < SAMPLE_MAXRATES, + ("rate %u has rix %d", RATE(x), rix)); + sn->ratemask |= 1<ni_vap, IEEE80211_MSG_RATECTL)) { ieee80211_note(ni->ni_vap, "[%6D] %s: size 1600 rate/tt", - __func__, ni->ni_macaddr, ":"); - for (x = 0; x < sn->num_rates; x++) { - if (sn->rates[x].rix == 0xff) + ni->ni_macaddr, ":", __func__); + for (mask = sn->ratemask, rix = 0; mask != 0; mask >>= 1, rix++) { + if ((mask & 1) == 0) continue; - printf(" %d/%d", sn->rates[x].rate, - calc_usecs_unicast_packet(sc, 1600, - sn->rates[x].rix, 0,0)); + printf(" %d/%d", INFORATE(rix), + calc_usecs_unicast_packet(sc, 1600, rix, 0,0)); } printf("\n"); } #endif for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) { int size = bin_to_size(y); - int ndx = 0; + uint32_t mask; + sn->packets_sent[y] = 0; - sn->current_sample_ndx[y] = -1; - sn->last_sample_ndx[y] = 0; + sn->current_sample_rix[y] = -1; + sn->last_sample_rix[y] = 0; + /* XXX start with first valid rate */ + sn->current_rix[y] = ffs(sn->ratemask)-1; - for (x = 0; x < ni->ni_rates.rs_nrates; x++) { - sn->stats[y][x].successive_failures = 0; - sn->stats[y][x].tries = 0; - sn->stats[y][x].total_packets = 0; - sn->stats[y][x].packets_acked = 0; - sn->stats[y][x].last_tx = 0; + /* + * Initialize the statistics buckets; these are + * indexed by the rate code index. + */ + for (rix = 0, mask = sn->ratemask; mask != 0; rix++, mask >>= 1) { + if ((mask & 1) == 0) /* not a valid rate */ + continue; + sn->stats[y][rix].successive_failures = 0; + sn->stats[y][rix].tries = 0; + sn->stats[y][rix].total_packets = 0; + sn->stats[y][rix].packets_acked = 0; + sn->stats[y][rix].last_tx = 0; - sn->stats[y][x].perfect_tx_time = - calc_usecs_unicast_packet(sc, size, - sn->rates[x].rix, - 0, 0); - sn->stats[y][x].average_tx_time = sn->stats[y][x].perfect_tx_time; - } - - /* set the initial rate */ - for (ndx = sn->num_rates-1; ndx > 0; ndx--) { - if (sn->rates[ndx].rate <= 72) { - break; - } + sn->stats[y][rix].perfect_tx_time = + calc_usecs_unicast_packet(sc, size, rix, 0, 0); + sn->stats[y][rix].average_tx_time = + sn->stats[y][rix].perfect_tx_time; } - sn->current_rate[y] = ndx; } - +#if 0 + /* XXX 0, num_rates-1 are wrong */ IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, "%s: %d rates %d%sMbps (%dus)- %d%sMbps (%dus)", __func__, sn->num_rates, - sn->rates[0].rate/2, sn->rates[0].rate % 0x1 ? ".5" : "", + INFORATE(0)/2, INFORATE(0) % 1 ? ".5" : "", sn->stats[1][0].perfect_tx_time, - sn->rates[sn->num_rates-1].rate/2, - sn->rates[sn->num_rates-1].rate % 0x1 ? ".5" : "", + INFORATE(sn->num_rates-1)/2, INFORATE(sn->num_rates-1) % 1 ? ".5" : "", sn->stats[1][sn->num_rates-1].perfect_tx_time ); - +#endif /* set the visible bit-rate */ - if (sn->static_rate_ndx != -1) - ni->ni_txrate = sn->rates[sn->static_rate_ndx].rate; + if (sn->static_rix != -1) + ni->ni_txrate = INFORATE(sn->static_rix); else - ni->ni_txrate = sn->rates[0].rate; + ni->ni_txrate = RATE(0); #undef RATE +#undef INFORATE } static void +sample_stats(void *arg, struct ieee80211_node *ni) +{ + struct ath_softc *sc = arg; + const HAL_RATE_TABLE *rt = sc->sc_currates; + struct sample_node *sn = ATH_NODE_SAMPLE(ATH_NODE(ni)); + uint32_t mask; + int rix, y; + + printf("\n[%s] refcnt %d\n", + ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)); + for (mask = sn->ratemask, rix = 0; mask != 0; mask >>= 1, rix++) { + if ((mask & 1) == 0) + continue; + for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) { + if (sn->stats[y][rix].total_packets == 0) + continue; + printf("[%2u:%4u] %6d:%-6d (%3d%%) T %6d F %2d avg_tx_time %u\n", + (rt->info[rix].dot11Rate & IEEE80211_RATE_VAL)/2, + bin_to_size(y), + sn->stats[y][rix].total_packets, + sn->stats[y][rix].packets_acked, + (100*sn->stats[y][rix].packets_acked)/sn->stats[y][rix].total_packets, + sn->stats[y][rix].tries, + sn->stats[y][rix].successive_failures, + sn->stats[y][rix].average_tx_time); + } + } +} + +static int +ath_rate_sysctl_stats(SYSCTL_HANDLER_ARGS) +{ + struct ath_softc *sc = arg1; + struct ifnet *ifp = sc->sc_ifp; + struct ieee80211com *ic = ifp->if_l2com; + int error, v; + + v = 0; + error = sysctl_handle_int(oidp, &v, 0, req); + if (error || !req->newptr) + return error; + ieee80211_iterate_nodes(&ic->ic_sta, sample_stats, sc); + return 0; +} + +static void ath_rate_sysctlattach(struct ath_softc *sc, struct sample_softc *osc) { struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev); @@ -782,6 +814,9 @@ SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "sample_rate", CTLFLAG_RW, &osc->ath_sample_rate,0, "rate control: # good periods before raising rate"); + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "sample_stats", CTLTYPE_INT | CTLFLAG_RW, sc, 0, + ath_rate_sysctl_stats, "I", "print statistics"); } struct ath_ratectrl * ==== //depot/projects/vap/sys/dev/ath/ath_rate/sample/sample.h#8 (text+ko) ==== @@ -50,14 +50,6 @@ }; #define ATH_SOFTC_SAMPLE(sc) ((struct sample_softc *)sc->sc_rc) -struct rate_info { - int rate; - int rix; - int rateCode; - int shortPreambleRateCode; -}; - - struct rate_stats { unsigned average_tx_time; int successive_failures; @@ -72,30 +64,29 @@ * for now, we track performance for three different packet * size buckets */ -#define NUM_PACKET_SIZE_BINS 3 -static int packet_size_bins[NUM_PACKET_SIZE_BINS] = {250, 1600, 3000}; +#define NUM_PACKET_SIZE_BINS 2 /* per-node state */ struct sample_node { - int static_rate_ndx; - int num_rates; + int static_rix; /* rate index of fixed tx rate */ +#define SAMPLE_MAXRATES 32 /* NB: corresponds to hal info[32] */ + uint32_t ratemask; /* bit mask of valid rate indices */ - struct rate_info rates[IEEE80211_RATE_MAXSIZE]; - - struct rate_stats stats[NUM_PACKET_SIZE_BINS][IEEE80211_RATE_MAXSIZE]; - int last_sample_ndx[NUM_PACKET_SIZE_BINS]; + struct rate_stats stats[NUM_PACKET_SIZE_BINS][SAMPLE_MAXRATES]; + int last_sample_rix[NUM_PACKET_SIZE_BINS]; >>> TRUNCATED FOR MAIL (1000 lines) <<<