qdisc_hfsc.c revision 1.6 1 1.6 peter /* $NetBSD: qdisc_hfsc.c,v 1.6 2006/10/28 11:43:02 peter Exp $ */
2 1.5 peter /* $KAME: qdisc_hfsc.c,v 1.8 2003/07/10 12:09:38 kjc Exp $ */
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (C) 1999-2000
5 1.1 thorpej * Sony Computer Science Laboratories, Inc. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej *
16 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 thorpej * SUCH DAMAGE.
27 1.1 thorpej */
28 1.1 thorpej
29 1.1 thorpej #include <sys/param.h>
30 1.1 thorpej #include <sys/ioctl.h>
31 1.1 thorpej #include <sys/time.h>
32 1.1 thorpej #include <sys/socket.h>
33 1.1 thorpej #include <net/if.h>
34 1.1 thorpej #include <netinet/in.h>
35 1.1 thorpej #include <altq/altq.h>
36 1.1 thorpej #include <altq/altq_hfsc.h>
37 1.1 thorpej
38 1.1 thorpej #include <stdio.h>
39 1.1 thorpej #include <stdlib.h>
40 1.1 thorpej #include <unistd.h>
41 1.1 thorpej #include <string.h>
42 1.5 peter #include <signal.h>
43 1.1 thorpej #include <math.h>
44 1.1 thorpej #include <errno.h>
45 1.1 thorpej #include <err.h>
46 1.1 thorpej
47 1.1 thorpej #include "quip_client.h"
48 1.1 thorpej #include "altqstat.h"
49 1.1 thorpej
50 1.1 thorpej #define NCLASSES 64
51 1.1 thorpej
52 1.1 thorpej void
53 1.1 thorpej hfsc_stat_loop(int fd, const char *ifname, int count, int interval)
54 1.1 thorpej {
55 1.5 peter struct hfsc_classstats stats1[NCLASSES], stats2[NCLASSES];
56 1.1 thorpej char clnames[NCLASSES][128];
57 1.1 thorpej struct hfsc_class_stats get_stats;
58 1.5 peter struct hfsc_classstats *sp, *lp, *new, *last, *tmp;
59 1.1 thorpej struct timeval cur_time, last_time;
60 1.1 thorpej int i;
61 1.1 thorpej double sec;
62 1.1 thorpej int cnt = count;
63 1.5 peter sigset_t omask;
64 1.5 peter u_int64_t stattime;
65 1.5 peter u_int32_t machclk_freq;
66 1.1 thorpej
67 1.2 itojun strlcpy(get_stats.iface.hfsc_ifname, ifname,
68 1.2 itojun sizeof(get_stats.iface.hfsc_ifname));
69 1.1 thorpej new = &stats1[0];
70 1.1 thorpej last = &stats2[0];
71 1.1 thorpej
72 1.1 thorpej /* invalidate class ids */
73 1.6 peter for (i = 0; i < NCLASSES; i++) {
74 1.1 thorpej last[i].class_id = 999999; /* XXX */
75 1.6 peter last[i].class_handle = HFSC_NULLCLASS_HANDLE;
76 1.6 peter }
77 1.1 thorpej
78 1.6 peter for (;;) {
79 1.1 thorpej get_stats.nskip = 0;
80 1.1 thorpej get_stats.nclasses = NCLASSES;
81 1.1 thorpej get_stats.stats = new;
82 1.1 thorpej
83 1.1 thorpej if (ioctl(fd, HFSC_GETSTATS, &get_stats) < 0)
84 1.1 thorpej err(1, "ioctl HFSC_GETSTATS");
85 1.1 thorpej
86 1.1 thorpej gettimeofday(&cur_time, NULL);
87 1.1 thorpej sec = calc_interval(&cur_time, &last_time);
88 1.1 thorpej
89 1.5 peter stattime = get_stats.cur_time;
90 1.5 peter machclk_freq = get_stats.machclk_freq;
91 1.1 thorpej printf("\ncur_time:%#llx %u classes %u packets in the tree\n",
92 1.5 peter (ull)stattime,
93 1.5 peter get_stats.hif_classes, get_stats.hif_packets);
94 1.1 thorpej
95 1.1 thorpej for (i=0; i<get_stats.nclasses; i++) {
96 1.1 thorpej sp = &new[i];
97 1.1 thorpej lp = &last[i];
98 1.1 thorpej
99 1.1 thorpej if (sp->class_id != lp->class_id) {
100 1.1 thorpej quip_chandle2name(ifname, sp->class_handle,
101 1.6 peter clnames[i], sizeof(clnames[0]));
102 1.1 thorpej }
103 1.1 thorpej
104 1.5 peter printf("[%2d %s] handle:%#x [rt %s %ums %s][ls %s %ums %s]",
105 1.1 thorpej sp->class_id, clnames[i], sp->class_handle,
106 1.1 thorpej rate2str((double)sp->rsc.m1), sp->rsc.d,
107 1.1 thorpej rate2str((double)sp->rsc.m2),
108 1.1 thorpej rate2str((double)sp->fsc.m1), sp->fsc.d,
109 1.1 thorpej rate2str((double)sp->fsc.m2));
110 1.5 peter if (sp->usc.m1 != 0 || sp->usc.m2 != 0)
111 1.5 peter printf("[ul %s %ums %s]\n",
112 1.5 peter rate2str((double)sp->usc.m1), sp->usc.d,
113 1.5 peter rate2str((double)sp->usc.m2));
114 1.5 peter else
115 1.5 peter printf("\n");
116 1.6 peter if (lp->class_handle != HFSC_NULLCLASS_HANDLE) {
117 1.6 peter printf(" measured: %sbps [rt:%s ls:%s] qlen:%2d period:%u\n",
118 1.6 peter rate2str(calc_rate(sp->total, lp->total, sec)),
119 1.6 peter rate2str(calc_rate(sp->cumul, lp->cumul, sec)),
120 1.6 peter rate2str(calc_rate(sp->total - sp->cumul,
121 1.6 peter lp->total - lp->cumul, sec)),
122 1.6 peter sp->qlength, sp->period);
123 1.6 peter }
124 1.5 peter printf(" packets:%llu (%llu bytes) drops:%llu (%llu bytes) \n",
125 1.1 thorpej (ull)sp->xmit_cnt.packets,
126 1.1 thorpej (ull)sp->xmit_cnt.bytes,
127 1.5 peter (ull)sp->drop_cnt.packets,
128 1.5 peter (ull)sp->drop_cnt.bytes);
129 1.1 thorpej printf(" cumul:%#llx total:%#llx\n",
130 1.1 thorpej (ull)sp->cumul, (ull)sp->total);
131 1.5 peter printf(" e:%.2fus d:%.2fus f:%.2fus vt:%#llx\n",
132 1.5 peter sp->e == 0 ? 0 : ((double)sp->e - (double)stattime)
133 1.5 peter / machclk_freq * 1000000,
134 1.5 peter sp->d == 0 ? 0 : ((double)sp->d - (double)stattime)
135 1.5 peter / machclk_freq * 1000000,
136 1.5 peter sp->f == 0 ? 0 : ((double)sp->f - (double)stattime)
137 1.5 peter / machclk_freq * 1000000,
138 1.5 peter (ull)sp->vt);
139 1.5 peter printf(" vtperiod:%u parentperiod:%u nactive:%d\n",
140 1.5 peter sp->vtperiod, sp->parentperiod, sp->nactive);
141 1.5 peter printf(" initvt:%#llx cvtmax:%#llx vtoff:%#llx\n",
142 1.5 peter (ull)sp->initvt, (ull)sp->cvtmax, (ull)sp->vtoff);
143 1.5 peter
144 1.5 peter printf(" myf:%#llx cfmin:%#llx cvtmin:%#llx",
145 1.5 peter (ull)sp->myf, (ull)sp->cfmin, (ull)sp->cvtmin);
146 1.5 peter printf(" myfadj:%#llx vtadj:%#llx\n",
147 1.5 peter (ull)sp->myfadj, (ull)sp->vtadj);
148 1.1 thorpej if (sp->qtype == Q_RED)
149 1.1 thorpej print_redstats(sp->red);
150 1.1 thorpej else if (sp->qtype == Q_RIO)
151 1.1 thorpej print_riostats(sp->red);
152 1.1 thorpej }
153 1.1 thorpej
154 1.1 thorpej /* swap the buffer pointers */
155 1.1 thorpej tmp = last;
156 1.1 thorpej last = new;
157 1.1 thorpej new = tmp;
158 1.1 thorpej
159 1.1 thorpej last_time = cur_time;
160 1.5 peter
161 1.6 peter if (count != 0 && --cnt == 0)
162 1.6 peter break;
163 1.6 peter
164 1.5 peter /* wait for alarm signal */
165 1.5 peter if (sigprocmask(SIG_BLOCK, NULL, &omask) == 0)
166 1.5 peter sigsuspend(&omask);
167 1.1 thorpej }
168 1.1 thorpej }
169