Home | History | Annotate | Line # | Download | only in altqstat
qdisc_rio.c revision 1.5
      1 /*	$NetBSD: qdisc_rio.c,v 1.5 2006/10/12 19:59:13 peter Exp $	*/
      2 /*	$KAME: qdisc_rio.c,v 1.7 2004/01/22 09:31:24 kjc Exp $	*/
      3 /*
      4  * Copyright (C) 1999-2000
      5  *	Sony Computer Science Laboratories, Inc.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/param.h>
     30 #include <sys/ioctl.h>
     31 #include <sys/time.h>
     32 #include <sys/socket.h>
     33 #include <net/if.h>
     34 #include <netinet/in.h>
     35 #include <altq/altq.h>
     36 #include <altq/altq_red.h>
     37 #include <altq/altq_rio.h>
     38 
     39 #include <stdio.h>
     40 #include <stdlib.h>
     41 #include <unistd.h>
     42 #include <string.h>
     43 #include <signal.h>
     44 #include <errno.h>
     45 #include <err.h>
     46 
     47 #include "altqstat.h"
     48 
     49 static int avg_scale = 4096;	/* default fixed-point scale */
     50 
     51 void
     52 rio_stat_loop(int fd, const char *ifname, int count, int interval)
     53 {
     54 	struct rio_stats rio_stats;
     55 	struct timeval cur_time, last_time;
     56 	u_int64_t last_bytes[3];
     57 	double sec;
     58 	int cnt = count;
     59 	sigset_t		omask;
     60 
     61 	memset(&last_bytes, 0, sizeof last_bytes);	/* XXX gcc */
     62 	bzero(&rio_stats, sizeof(rio_stats));
     63 	strlcpy(rio_stats.iface.rio_ifname, ifname,
     64 		sizeof(rio_stats.iface.rio_ifname));
     65 
     66 	gettimeofday(&last_time, NULL);
     67 	last_time.tv_sec -= interval;
     68 
     69 	while (count == 0 || cnt-- > 0) {
     70 
     71 		if (ioctl(fd, RIO_GETSTATS, &rio_stats) < 0)
     72 			err(1, "ioctl RIO_GETSTATS");
     73 
     74 		gettimeofday(&cur_time, NULL);
     75 		sec = calc_interval(&cur_time, &last_time);
     76 
     77 		printf("weight:%d q_limit:%d\n",
     78 		       rio_stats.weight, rio_stats.q_limit);
     79 
     80 		printf("\t\t\tLOW DP\t\tMEDIUM DP\t\tHIGH DP\n");
     81 
     82 		printf("thresh (prob):\t\t[%d,%d](1/%d)\t[%d,%d](1/%d)\t\t[%d,%d](1/%d)\n",
     83 		       rio_stats.q_params[0].th_min,
     84 		       rio_stats.q_params[0].th_max,
     85 		       rio_stats.q_params[0].inv_pmax,
     86 		       rio_stats.q_params[1].th_min,
     87 		       rio_stats.q_params[1].th_max,
     88 		       rio_stats.q_params[1].inv_pmax,
     89 		       rio_stats.q_params[2].th_min,
     90 		       rio_stats.q_params[2].th_max,
     91 		       rio_stats.q_params[2].inv_pmax);
     92 		printf("qlen (avg):\t\t%d (%.2f)\t%d (%.2f)\t\t%d (%.2f)\n",
     93 		       rio_stats.q_len[0],
     94 		       ((double)rio_stats.q_stats[0].q_avg)/(double)avg_scale,
     95 		       rio_stats.q_len[1],
     96 		       ((double)rio_stats.q_stats[1].q_avg)/(double)avg_scale,
     97 		       rio_stats.q_len[2],
     98 		       ((double)rio_stats.q_stats[2].q_avg)/(double)avg_scale);
     99 		printf("xmit (drop) pkts:\t%llu (%llu)\t\t%llu (%llu)\t\t\t%llu (%llu)\n",
    100 		       (ull)rio_stats.q_stats[0].xmit_cnt.packets,
    101 		       (ull)rio_stats.q_stats[0].drop_cnt.packets,
    102 		       (ull)rio_stats.q_stats[1].xmit_cnt.packets,
    103 		       (ull)rio_stats.q_stats[1].drop_cnt.packets,
    104 		       (ull)rio_stats.q_stats[2].xmit_cnt.packets,
    105 		       (ull)rio_stats.q_stats[2].drop_cnt.packets);
    106 		printf("(forced:early):\t\t(%u:%u)\t\t(%u:%u)\t\t\t(%u:%u)\n",
    107 		       rio_stats.q_stats[0].drop_forced,
    108 		       rio_stats.q_stats[0].drop_unforced,
    109 		       rio_stats.q_stats[1].drop_forced,
    110 		       rio_stats.q_stats[1].drop_unforced,
    111 		       rio_stats.q_stats[2].drop_forced,
    112 		       rio_stats.q_stats[2].drop_unforced);
    113 		if (rio_stats.q_stats[0].marked_packets != 0
    114 		    || rio_stats.q_stats[1].marked_packets != 0
    115 		    || rio_stats.q_stats[2].marked_packets != 0)
    116 			printf("marked:\t\t\t%u\t\t%u\t\t\t%u\n",
    117 			       rio_stats.q_stats[0].marked_packets,
    118 			       rio_stats.q_stats[1].marked_packets,
    119 			       rio_stats.q_stats[2].marked_packets);
    120 		printf("throughput:\t\t%sbps\t%sbps\t\t%sbps\n\n",
    121 		       rate2str(calc_rate(rio_stats.q_stats[0].xmit_cnt.bytes,
    122 					  last_bytes[0], sec)),
    123 		       rate2str(calc_rate(rio_stats.q_stats[1].xmit_cnt.bytes,
    124 					  last_bytes[1], sec)),
    125 		       rate2str(calc_rate(rio_stats.q_stats[2].xmit_cnt.bytes,
    126 					  last_bytes[2], sec)));
    127 
    128 		last_bytes[0] = rio_stats.q_stats[0].xmit_cnt.bytes;
    129 		last_bytes[1] = rio_stats.q_stats[1].xmit_cnt.bytes;
    130 		last_bytes[2] = rio_stats.q_stats[2].xmit_cnt.bytes;
    131 		last_time = cur_time;
    132 
    133 		/* wait for alarm signal */
    134 		if (sigprocmask(SIG_BLOCK, NULL, &omask) == 0)
    135 			sigsuspend(&omask);
    136 	}
    137 }
    138 
    139 int
    140 print_riostats(struct redstats *rp)
    141 {
    142 	int dp;
    143 
    144 	for (dp = 0; dp < RIO_NDROPPREC; dp++)
    145 		printf("     RIO[%d] q_avg:%.2f xmit:%llu (forced: %u early:%u marked:%u)\n",
    146 		       dp,
    147 		       ((double)rp[dp].q_avg)/(double)avg_scale,
    148 		       (ull)rp[dp].xmit_cnt.packets,
    149 		       rp[dp].drop_forced,
    150 		       rp[dp].drop_unforced,
    151 		       rp[dp].marked_packets);
    152 	return 0;
    153 }
    154