From owner-svn-src-all@FreeBSD.ORG Fri Jul 20 01:36:03 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CFECE1065674; Fri, 20 Jul 2012 01:36:03 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B9A898FC14; Fri, 20 Jul 2012 01:36:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q6K1a3k1042549; Fri, 20 Jul 2012 01:36:03 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q6K1a3Yu042544; Fri, 20 Jul 2012 01:36:03 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201207200136.q6K1a3Yu042544@svn.freebsd.org> From: Adrian Chadd Date: Fri, 20 Jul 2012 01:36:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r238633 - in head/sys/dev/ath/ath_rate: amrr onoe sample X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jul 2012 01:36:03 -0000 Author: adrian Date: Fri Jul 20 01:36:02 2012 New Revision: 238633 URL: http://svn.freebsd.org/changeset/base/238633 Log: Add a per-node rate control routine for each rate control module. For now, the only module implement is 'sample', and that's only partially implemented. The main issue here with reusing this structure in userland is that it uses 'rix' everywhere, which requires the userland code to have access to the current HAL rate table. For now, this is a very large work in progress. Specific details: * The rate control information is per-node at the moment and wrapped in a TLV, to ease parsing and backwards compatibility. * .. but so I can be slack for now, the userland statistics are just a copy of the kernel-land sample node state. * However, for now use a temporary copy and change the rix entries to dot11rate entries to make it slightly easier to eyeball. Problems: * The actual rate information table is unfortunately indexed by rix and it doesn't contain a rate code. So the userland side of this currently has no way to extract out a mapping. TODO: * Add a TLV payload to dump out the rate control table mapping so 'rix' can be turned into a dot11 / MCS rate. * .. then remove the temporary copy. Modified: head/sys/dev/ath/ath_rate/amrr/amrr.c head/sys/dev/ath/ath_rate/onoe/onoe.c head/sys/dev/ath/ath_rate/sample/sample.c head/sys/dev/ath/ath_rate/sample/sample.h Modified: head/sys/dev/ath/ath_rate/amrr/amrr.c ============================================================================== --- head/sys/dev/ath/ath_rate/amrr/amrr.c Fri Jul 20 01:27:20 2012 (r238632) +++ head/sys/dev/ath/ath_rate/amrr/amrr.c Fri Jul 20 01:36:02 2012 (r238633) @@ -421,6 +421,14 @@ ath_rate_ctl(void *arg, struct ieee80211 } } +static int +ath_rate_fetch_node_stats(struct ath_softc *sc, struct ath_node *an, + struct ath_rateioctl *re) +{ + + return (EINVAL); +} + static void ath_rate_sysctlattach(struct ath_softc *sc) { Modified: head/sys/dev/ath/ath_rate/onoe/onoe.c ============================================================================== --- head/sys/dev/ath/ath_rate/onoe/onoe.c Fri Jul 20 01:27:20 2012 (r238632) +++ head/sys/dev/ath/ath_rate/onoe/onoe.c Fri Jul 20 01:36:02 2012 (r238633) @@ -407,6 +407,14 @@ ath_rate_sysctlattach(struct ath_softc * "rate control: # good periods before raising rate"); } +static int +ath_rate_fetch_node_stats(struct ath_softc *sc, struct ath_node *an, + struct ath_rateioctl *re) +{ + + return (EINVAL); +} + struct ath_ratectrl * ath_rate_attach(struct ath_softc *sc) { Modified: head/sys/dev/ath/ath_rate/sample/sample.c ============================================================================== --- head/sys/dev/ath/ath_rate/sample/sample.c Fri Jul 20 01:27:20 2012 (r238632) +++ head/sys/dev/ath/ath_rate/sample/sample.c Fri Jul 20 01:36:02 2012 (r238633) @@ -105,8 +105,6 @@ __FBSDID("$FreeBSD$"); 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) { @@ -128,12 +126,6 @@ size_to_bin(int size) return NUM_PACKET_SIZE_BINS-1; } -static __inline int -bin_to_size(int index) -{ - return packet_size_bins[index]; -} - void ath_rate_node_init(struct ath_softc *sc, struct ath_node *an) { @@ -1198,6 +1190,79 @@ ath_rate_ctl_reset(struct ath_softc *sc, #undef DOT11RATE } +/* + * Fetch the statistics for the given node. + * + * The ieee80211 node must be referenced and unlocked, however the ath_node + * must be locked. + * + * The main difference here is that we convert the rate indexes + * to 802.11 rates, or the userland output won't make much sense + * as it has no access to the rix table. + */ +int +ath_rate_fetch_node_stats(struct ath_softc *sc, struct ath_node *an, + struct ath_rateioctl *rs) +{ + struct sample_node *sn = ATH_NODE_SAMPLE(an); + const HAL_RATE_TABLE *rt = sc->sc_currates; + struct ath_rateioctl_tlv av; + struct sample_node *ts; + int y; + + ATH_NODE_LOCK_ASSERT(an); + + /* + * Ensure there's enough space for the statistics. + */ + if (rs->len < + sizeof(struct ath_rateioctl_tlv) + + sizeof(struct sample_node)) + return (EINVAL); + + /* + * Take a temporary copy of the sample node state so we can + * modify it before we copy it. + */ + ts = malloc(sizeof(struct sample_node), M_TEMP, M_WAITOK | M_ZERO); + if (ts == NULL) + return (ENOMEM); + memcpy(ts, sn, sizeof(struct sample_node)); + + /* Convert rix -> 802.11 rate codes */ + ts->static_rix = dot11rate(rt, sn->static_rix); + for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) { + /* + * For non-11n rates, clear the high bit - that + * means "basic rate" and will confuse things. + * + * For 11n rates, set the high bit. + */ + ts->current_rix[y] = dot11rate(rt, sn->current_rix[y]); + ts->current_sample_rix[y] = + dot11rate(rt, sn->current_sample_rix[y]); + ts->last_sample_rix[y] = + dot11rate(rt, sn->last_sample_rix[y]); + } + + /* + * Assemble the TLV. + */ + av.tlv_id = ATH_RATE_TLV_SAMPLENODE; + av.tlv_len = sizeof(struct sample_node); + copyout(&av, rs->buf, sizeof(struct ath_rateioctl_tlv)); + + /* + * Copy the statistics over to the provided buffer. + */ + copyout(ts, rs->buf + sizeof(struct ath_rateioctl_tlv), + sizeof(struct sample_node)); + + free(ts, M_TEMP); + + return (0); +} + static void sample_stats(void *arg, struct ieee80211_node *ni) { Modified: head/sys/dev/ath/ath_rate/sample/sample.h ============================================================================== --- head/sys/dev/ath/ath_rate/sample/sample.h Fri Jul 20 01:27:20 2012 (r238632) +++ head/sys/dev/ath/ath_rate/sample/sample.h Fri Jul 20 01:36:02 2012 (r238633) @@ -79,6 +79,14 @@ struct txschedule { */ #define NUM_PACKET_SIZE_BINS 2 +static const int packet_size_bins[NUM_PACKET_SIZE_BINS] = { 250, 1600 }; + +static inline int +bin_to_size(int index) +{ + return packet_size_bins[index]; +} + /* per-node state */ struct sample_node { int static_rix; /* rate index of fixed tx rate */