📄 sample.c
字号:
if (sn->num_rates <= 0) { printk(KERN_WARNING "%s: no rates for " MAC_FMT "?\n", dev_info, MAC_ADDR(an->an_node.ni_macaddr)); return; } mrr = sc->sc_mrretry && !(ic->ic_flags & IEEE80211_F_USEPROT) && ENABLE_MRR; size_bin = size_to_bin(frameLen); best_ndx = best_rate_ndx(sn, size_bin, !mrr); if (best_ndx >= 0) average_tx_time = sn->stats[size_bin][best_ndx].average_tx_time; else average_tx_time = 0; if (sn->static_rate_ndx != -1) { ndx = sn->static_rate_ndx; *try0 = ATH_TXMAXTRY; } 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, so * pick an rssi-appropriate bit-rate. We know if * the rssi is very low that the really high * bit rates will not work. */ int initial_rate = 72; if (an->an_avgrssi > 50) { initial_rate = 108; /* 54 mbps */ } else if (an->an_avgrssi > 30) { initial_rate = 72; /* 36 mbps */ } else { initial_rate = 22; /* 11 mbps */ } for (ndx = sn->num_rates-1; ndx > 0; ndx--) { /* * pick the highest rate <= initial_rate/2 Mbps * that hasn't failed. */ if (sn->rates[ndx].rate <= initial_rate && sn->stats[size_bin][ndx].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 (time_after(jiffies, sn->jiffies_since_switch[size_bin] + ((HZ * MIN_SWITCH_MS) / 1000))) { /* 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; } sn->packets_since_sample[size_bin]++; if (change_rates) { if (best_ndx != sn->current_rate[size_bin]) { DPRINTF(sc, ATH_DEBUG_RATE, "%s: " MAC_FMT " size %u switch rate %u (%u/%u) -> %u (%u/%u) after %u packets mrr %u\n", dev_info, MAC_ADDR(an->an_node.ni_macaddr), 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->jiffies_since_switch[size_bin] = jiffies; } ndx = sn->current_rate[size_bin]; sn->packets_since_switch[size_bin]++; if (size_bin == 0) { /* * set the visible txrate for this node * to the rate of small packets */ an->an_node.ni_txrate = ndx; } } } KASSERT(ndx >= 0 && ndx < sn->num_rates, ("%s: bad ndx (%u/%u) for " MAC_FMT "?", dev_info, ndx, sn->num_rates, MAC_ADDR(an->an_node.ni_macaddr))); *rix = sn->rates[ndx].rix; if (shortPreamble) *txrate = sn->rates[ndx].shortPreambleRateCode; else *txrate = sn->rates[ndx].rateCode; sn->packets_sent[size_bin]++;}static voidath_rate_get_mrr(struct ath_softc *sc, struct ath_node *an, int shortPreamble, size_t frame_size, u_int8_t rix, struct ieee80211_mrr *mrr){ struct sample_node *sn = ATH_NODE_SAMPLE(an); unsigned int size_bin; int ndx; size_bin = size_to_bin(frame_size); 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) mrr->rate1 = sn->rates[ndx].shortPreambleRateCode; else mrr->rate1 = sn->rates[ndx].rateCode; mrr->retries1 = 3; mrr->rate2 = sn->rates[0].rateCode; mrr->retries2 = 3; mrr->rate3 = 0; mrr->retries3 = 0;}static voidupdate_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 short_tries, int tries, int status){ const HAL_RATE_TABLE *rt = sc->sc_currates; struct sample_node *sn = ATH_NODE_SAMPLE(an); struct sample_softc *ssc = ATH_SOFTC_SAMPLE(sc); unsigned int tt = 0; unsigned int tries_so_far = 0; unsigned int size_bin; unsigned int size; unsigned int rate; size_bin = size_to_bin(frame_size); size = bin_to_size(size_bin); if (!(0 <= ndx0 && ndx0 < sn->num_rates)) { printk("%s: bogus ndx0 %d, max %u, mode %u\n", __func__, ndx0, sn->num_rates, sc->sc_curmode); return; } rate = sn->rates[ndx0].rate; if (!rt->info[ndx0].rateKbps) { /* * sometimes we get feedback back for packets we didn't send. * just ignore these packets. */ return; } tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx0].rix, short_tries, MIN(tries0, tries) - 1); tries_so_far += tries0; if (tries1 && (tries0 < tries)) { if (!(0 <= ndx1 && ndx1 < sn->num_rates)) { printk("%s: bogus ndx1 %d, max %u, mode %u\n", __func__, ndx1, sn->num_rates, sc->sc_curmode); return; } tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx1].rix, 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)) { printk("%s: bogus ndx2 %d, max %u, mode %u\n", __func__, ndx2, sn->num_rates, sc->sc_curmode); return; } tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx2].rix, short_tries, MIN(tries2 + tries_so_far, tries) - tries_so_far - 1); } tries_so_far += tries2; if (tries3 && ((tries0 + tries1 + tries2) < tries)) { if (!(0 <= ndx3 && ndx3 < sn->num_rates)) { printk("%s: bogus ndx3 %d, max %u, mode %u\n", __func__, ndx3, sn->num_rates, sc->sc_curmode); return; } tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx3].rix, 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))) { /* just average the first few packets */ unsigned int avg_tx = sn->stats[size_bin][ndx0].average_tx_time; unsigned int packets = sn->stats[size_bin][ndx0].total_packets; sn->stats[size_bin][ndx0].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) + (tt * (100 - ssc->ath_smoothing_rate))) / 100; } if (status) { unsigned int y; sn->stats[size_bin][ndx0].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 = jiffies; sn->stats[y][ndx0].tries += tries; sn->stats[y][ndx0].total_packets++; } } else { sn->stats[size_bin][ndx0].packets_acked++; sn->stats[size_bin][ndx0].successive_failures = 0; } sn->stats[size_bin][ndx0].tries += tries; sn->stats[size_bin][ndx0].last_tx = jiffies; sn->stats[size_bin][ndx0].total_packets++; if (ndx0 == sn->current_sample_ndx[size_bin]) { DPRINTF(sc, ATH_DEBUG_RATE, "%s: " MAC_FMT " size %u sample rate %u tries (%u/%u) tt %u avg_tt (%u/%u) status %u\n", dev_info, MAC_ADDR(an->an_node.ni_macaddr), size, rate, short_tries, tries, tt, sn->stats[size_bin][ndx0].average_tx_time, sn->stats[size_bin][ndx0].perfect_tx_time, status); sn->sample_tt[size_bin] = tt; sn->current_sample_ndx[size_bin] = -1; }}static voidath_rate_tx_complete(struct ath_softc *sc, struct ath_node *an, const struct ath_buf *bf){ struct sample_node *sn = ATH_NODE_SAMPLE(an); struct ieee80211com *ic = &sc->sc_ic; const struct ath_tx_status *ts = &bf->bf_dsstatus.ds_txstat; const struct ath_desc *ds = &bf->bf_desc[0]; unsigned int final_rate; unsigned int short_tries; unsigned int long_tries; unsigned int frame_size; unsigned int mrr; final_rate = sc->sc_hwmap[ts->ts_rate &~ HAL_TXSTAT_ALTRATE].ieeerate; short_tries = ts->ts_shortretry + 1; long_tries = ts->ts_longretry + 1; frame_size = ds->ds_ctl0 & 0x0fff; /* low-order 12 bits of ds_ctl0 */ if (frame_size == 0) frame_size = 1500; if (sn->num_rates <= 0) { DPRINTF(sc, ATH_DEBUG_RATE, "%s: " MAC_FMT " %s no rates yet\n", dev_info, MAC_ADDR(an->an_node.ni_macaddr), __func__); return; } mrr = sc->sc_mrretry && !(ic->ic_flags & IEEE80211_F_USEPROT) && ENABLE_MRR; if (sc->sc_mrretry && ts->ts_status) { /* this packet failed */ DPRINTF(sc, ATH_DEBUG_RATE, "%s: " MAC_FMT " size %u rate/try %u/%u %u/%u %u/%u %u/%u status %s retries (%u/%u)\n", dev_info, MAC_ADDR(an->an_node.ni_macaddr), bin_to_size(size_to_bin(frame_size)), sc->sc_hwmap[MS(ds->ds_ctl3, AR_XmitRate0)].ieeerate, MS(ds->ds_ctl2, AR_XmitDataTries0), sc->sc_hwmap[MS(ds->ds_ctl3, AR_XmitRate1)].ieeerate, MS(ds->ds_ctl2, AR_XmitDataTries1), sc->sc_hwmap[MS(ds->ds_ctl3, AR_XmitRate2)].ieeerate, MS(ds->ds_ctl2, AR_XmitDataTries2), sc->sc_hwmap[MS(ds->ds_ctl3, AR_XmitRate3)].ieeerate, MS(ds->ds_ctl2, AR_XmitDataTries3), ts->ts_status ? "FAIL" : "OK", short_tries, long_tries); } mrr = sc->sc_mrretry && !(ic->ic_flags & IEEE80211_F_USEPROT) && ENABLE_MRR; if (!mrr || !(ts->ts_rate & HAL_TXSTAT_ALTRATE)) { /* only one rate was used */ int ndx = rate_to_ndx(sn, final_rate); if ((ndx >= 0) && (ndx < sn->num_rates)) { update_stats(sc, an, frame_size, ndx, long_tries, 0, 0, 0, 0, 0, 0, short_tries, long_tries, ts->ts_status); } } else { unsigned int rate[4], tries[4]; int ndx[4]; int finalTSIdx = ts->ts_finaltsi; /* * Process intermediate rates that failed. */ rate[0] = sc->sc_hwmap[MS(ds->ds_ctl3, AR_XmitRate0)].ieeerate; tries[0] = MS(ds->ds_ctl2, AR_XmitDataTries0); ndx[0] = rate_to_ndx(sn, rate[0]); rate[1] = sc->sc_hwmap[MS(ds->ds_ctl3, AR_XmitRate1)].ieeerate; tries[1] = MS(ds->ds_ctl2, AR_XmitDataTries1); ndx[1] = rate_to_ndx(sn, rate[1]); rate[2] = sc->sc_hwmap[MS(ds->ds_ctl3, AR_XmitRate2)].ieeerate; tries[2] = MS(ds->ds_ctl2, AR_XmitDataTries2); ndx[2] = rate_to_ndx(sn, rate[2]); rate[3] = sc->sc_hwmap[MS(ds->ds_ctl3, AR_XmitRate3)].ieeerate; tries[3] = MS(ds->ds_ctl2, AR_XmitDataTries3); ndx[3] = rate_to_ndx(sn, rate[3]);#if 0 DPRINTF(sc, "%s: " MAC_FMT " size %u finaltsidx %u tries %u status %u rate/try %u/%u %u/%u %u/%u %u/%u\n", dev_info, MAC_ADDR(an->an_node.ni_macaddr), bin_to_size(size_to_bin(frame_size)), finalTSIdx, long_tries, ds->ds_txstat.ts_status, rate[0], tries[0], rate[1], tries[1], rate[2], tries[2], rate[3], tries[3]);#endif /* NB: series > 0 are not penalized for failure * based on the try counts under the assumption * that losses are often bursty and since we * sample higher rates 1 try at a time doing so * may unfairly penalize them. */ if (tries[0] && ndx[0] >= 0) { update_stats(sc, an, frame_size, ndx[0], tries[0], ndx[1], tries[1], ndx[2], tries[2], ndx[3], tries[3], short_tries, long_tries,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -