aboutsummaryrefslogtreecommitdiff
path: root/tools/tools
diff options
context:
space:
mode:
authorAdrian Chadd <adrian@FreeBSD.org>2012-07-20 01:38:03 +0000
committerAdrian Chadd <adrian@FreeBSD.org>2012-07-20 01:38:03 +0000
commit78c166febfa039f0c053841f0cffcdf226eb5eba (patch)
treefe5377dcbdf5766a263ab79c342446ef38835905 /tools/tools
parentb8f2a85349ede74d80523b0af92572888c6bb672 (diff)
downloadsrc-78c166febfa039f0c053841f0cffcdf226eb5eba.tar.gz
src-78c166febfa039f0c053841f0cffcdf226eb5eba.zip
Implement a first cut of the 'sample' rate statistics userland utility.
This outputs almost exactly the same information as the kernel sysctl does, however the rix -> rate mapping isn't yet available as a TLV.
Notes
Notes: svn path=/head/; revision=238635
Diffstat (limited to 'tools/tools')
-rw-r--r--tools/tools/ath/athratestats/Makefile27
-rw-r--r--tools/tools/ath/athratestats/main.c200
2 files changed, 227 insertions, 0 deletions
diff --git a/tools/tools/ath/athratestats/Makefile b/tools/tools/ath/athratestats/Makefile
new file mode 100644
index 000000000000..de6da97d8d44
--- /dev/null
+++ b/tools/tools/ath/athratestats/Makefile
@@ -0,0 +1,27 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/../../../../sys/dev/ath/ath_hal
+.PATH: ${.CURDIR}/../../../../sys/dev/ath/
+
+PROG= athratestats
+
+SRCS= main.c
+
+CLEANFILES+= opt_ah.h
+
+.include <../Makefile.inc>
+
+CFLAGS+=-DATH_SUPPORT_ANI -g -ggdb
+CFLAGS+=-DATH_SUPPORT_TDMA
+
+opt_ah.h:
+ echo "#define AH_DEBUG 1" > opt_ah.h
+ echo "#define AH_DEBUG_COUNTRY 1" >> opt_ah.h
+ echo "#define AH_SUPPORT_AR5416 1" >> opt_ah.h
+
+ah_osdep.h:
+ echo 'typedef void *HAL_SOFTC;' >ah_osdep.h
+ echo 'typedef int HAL_BUS_TAG;' >>ah_osdep.h
+ echo 'typedef void *HAL_BUS_HANDLE;' >>ah_osdep.h
+
+.include <bsd.prog.mk>
diff --git a/tools/tools/ath/athratestats/main.c b/tools/tools/ath/athratestats/main.c
new file mode 100644
index 000000000000..ef62bc208634
--- /dev/null
+++ b/tools/tools/ath/athratestats/main.c
@@ -0,0 +1,200 @@
+/*-
+ * Copyright (c) 2012, Adrian Chadd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer,
+ * without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
+ * redistribution must be conditioned upon including a substantially
+ * similar Disclaimer requirement for further binary redistribution.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * $FreeBSD$
+ */
+
+#include "opt_ah.h"
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/sockio.h>
+#include <sys/socket.h>
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <net/if_media.h>
+#include <net/if_var.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include <err.h>
+
+#include "ah.h"
+#include "ah_desc.h"
+#include "net80211/ieee80211_ioctl.h"
+#include "net80211/ieee80211_radiotap.h"
+#include "if_athioctl.h"
+#include "if_athrate.h"
+
+#include "ath_rate/sample/sample.h"
+
+struct ath_ratestats {
+ int s;
+ struct ath_rateioctl re;
+};
+
+static void
+ath_sample_stats(struct ath_ratestats *r, uint8_t *buf)
+{
+ struct sample_node *sn = (void *) buf;
+ uint32_t mask;
+ int rix, y;
+
+ printf("static_rix (%d) ratemask 0x%x\n",
+ sn->static_rix,
+ sn->ratemask);
+
+ for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {
+ printf("[%4u] cur rix %d since switch: packets %d ticks %u\n",
+ bin_to_size(y),
+ sn->current_rix[y],
+ sn->packets_since_switch[y],
+ sn->ticks_since_switch[y]);
+
+ printf("[%4u] last sample (%d) cur sample (%d) "
+ "packets sent %d\n",
+ bin_to_size(y),
+ sn->last_sample_rix[y],
+ sn->current_sample_rix[y],
+ sn->packets_sent[y]);
+
+ printf("[%4u] packets since sample %d sample tt %u\n",
+ bin_to_size(y),
+ sn->packets_since_sample[y],
+ sn->sample_tt[y]);
+ }
+ 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] %8ju:%-8ju (%3d%%) "
+ "(EWMA %3d.%1d%%) T %8ju F %4d avg %5u last %u\n",
+ rix,
+ bin_to_size(y),
+ (uintmax_t) sn->stats[y][rix].total_packets,
+ (uintmax_t) sn->stats[y][rix].packets_acked,
+ (int) ((sn->stats[y][rix].packets_acked * 100ULL) /
+ sn->stats[y][rix].total_packets),
+ sn->stats[y][rix].ewma_pct / 10,
+ sn->stats[y][rix].ewma_pct % 10,
+ (uintmax_t) sn->stats[y][rix].tries,
+ sn->stats[y][rix].successive_failures,
+ sn->stats[y][rix].average_tx_time,
+ sn->stats[y][rix].last_tx);
+ }
+ }
+}
+
+static void
+ath_setifname(struct ath_ratestats *r, const char *ifname)
+{
+
+ strncpy(r->re.if_name, ifname, sizeof (r->re.if_name));
+}
+
+static void
+ath_setsta(struct ath_ratestats *r, const char *mac)
+{
+
+ memcpy(&r->re.is_u.macaddr, mac, sizeof(r->re.is_u.macaddr));
+}
+
+static void
+ath_rate_ioctl(struct ath_ratestats *r)
+{
+ printf("ether: %x:%x:%x:%x:%x:%x\n",
+ r->re.is_u.macaddr[0],
+ r->re.is_u.macaddr[1],
+ r->re.is_u.macaddr[2],
+ r->re.is_u.macaddr[3],
+ r->re.is_u.macaddr[4],
+ r->re.is_u.macaddr[5]);
+ if (ioctl(r->s, SIOCGATHNODERATESTATS, &r->re) < 0)
+ err(1, "ioctl");
+}
+
+#define STATS_BUF_SIZE 4096
+int
+main(int argc, const char *argv[])
+{
+ struct ath_ratestats r;
+ struct ether_addr *e;
+ uint8_t *buf;
+ struct ath_rateioctl_tlv *av;
+
+ buf = calloc(1, STATS_BUF_SIZE);
+ if (buf == NULL)
+ err(1, "calloc");
+
+ bzero(&r, sizeof(r));
+ r.s = socket(AF_INET, SOCK_DGRAM, 0);
+ if (r.s < 0) {
+ err(1, "socket");
+ }
+ /* XXX error check */
+ ath_setifname(&r, "ath0");
+
+ e = ether_aton(argv[1]);
+
+ /* caddr_t ? */
+ r.re.buf = buf;
+ r.re.len = STATS_BUF_SIZE;
+
+ ath_setsta(&r, e->octet);
+ ath_rate_ioctl(&r);
+
+ /*
+ * Ensure the TLV entry in question is actually the sample
+ * rate TLV.
+ */
+ av = (struct ath_rateioctl_tlv *) buf;
+
+ if (av->tlv_id != ATH_RATE_TLV_SAMPLENODE) {
+ fprintf(stderr, "unexpected rate control TLV (got 0x%x, "
+ "expected 0x%x\n",
+ av->tlv_id,
+ ATH_RATE_TLV_SAMPLENODE);
+ exit(127);
+ }
+ if (av->tlv_len != sizeof(struct sample_node)) {
+ fprintf(stderr, "unexpected TLV len (got %d bytes, "
+ "expected %d bytes\n",
+ av->tlv_len,
+ sizeof(struct sample_node));
+ exit(127);
+ }
+
+ ath_sample_stats(&r, buf + sizeof(struct ath_rateioctl_tlv));
+}
+