home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
cbq2.0g.tar.Z
/
cbq2.0g.tar
/
usr
/
src
/
cmd
/
cbqd
/
cbqd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-07-06
|
5KB
|
218 lines
/*
* Copyright (c) Sun Microsystems, Inc. 1995-1998 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.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the SMCC Technology
* Development Group at Sun Microsystems, Inc.
*
* 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* SUN MICROSYSTEMS MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS
* SOFTWARE FOR ANY PARTICULAR PURPOSE. The software is provided "as is"
* without express or implied warranty of any kind.
*
* These notices must be retained in any copies of any part of this software.
*/
#pragma ident "@(#)cbqd.c 1.30 98/05/11 SMI"
#include <stdio.h>
#include <signal.h>
#include <thread.h>
#include <cbqif.h>
/*
* Local macros.
*/
#define CMD_LINE_OPTS "d:f:c:pi:o"
/*
* Local variables.
*/
static int debug = 0;
static char *config = "cbqd.conf";
static int done = 0;
static char *interface = "ipdptp0";
/*
* Local Functions.
*/
static void *sighandler(void *);
/*
* Global Data.
*/
int count = 0, nclasses = 0;
class_stats_t *clstats = NULL;
class_stats_t *pclstats = NULL;
float *pstats = NULL;
int performance = 0;
int is_offtime = 1;
int
main(int argc, char **argv)
{
extern int optind;
extern char *optarg;
int i, c, sig;
int maxcount = 10000;
sigset_t set;
cbq_ifinfo_t *ifinfo;
thread_t sigthreadid;
int domaxcount = 0;
int inited = 0;
int diff;
float bytes_per_sec, bytes_per_ns;
#ifdef CBQPERF
struct cbq_perf perf, *gp = &perf;
int nperf = 0;
#endif
hrtime_t last, now;
while ((c = getopt(argc, argv, CMD_LINE_OPTS)) != EOF) {
switch (c) {
case 'o':
is_offtime = 0;
break;
case 'p':
performance++;
break;
case 'i':
interface = optarg;
break;
case 'd':
debug = atoi(optarg);
break;
case 'f':
config = optarg;
break;
case 'c':
domaxcount = 1;
maxcount = atoi(optarg);
break;
}
}
if (thr_create((void *)NULL, 0, sighandler, (void *)NULL,
THR_NEW_LWP | THR_BOUND, &sigthreadid)) {
perror("sigthread");
exit(1);
}
if (cbq_init(debug, is_offtime))
goto err_exit;
if ((nclasses = cbq_do_config(config)) == 0)
goto err_exit;
clstats = (class_stats_t *)malloc(sizeof(class_stats_t) * nclasses);
pclstats = (class_stats_t *)malloc(sizeof(class_stats_t) * nclasses);
pstats = (float *)malloc(sizeof (float) * nclasses);
if (!clstats || !pclstats || !pstats)
goto err_exit;
if (cbq_enableall())
goto err_exit;
memset(pstats, 0, sizeof (float) * nclasses);
memset(pclstats, 0, sizeof (class_stats_t) * nclasses);
memset(clstats, 0, sizeof (class_stats_t) * nclasses);
ifinfo = cbq_getifinfo(interface);
bytes_per_sec = (float)ifinfo->bandwidth / 8.0;
bytes_per_ns = bytes_per_sec / 1000000000;
last = gethrtime();
poll(0, 0, 1000);
while (!done) {
if (cbq_getstats(interface, clstats, nclasses))
done++;
else {
now = gethrtime();
diff = (now - last);
last = now;
/*
* nbytes / t = x bytes / sec;
* x bytes/sec / link bytes second = % of link bw;
*/
for (i = 0; i < nclasses; i++) {
pstats[i] = clstats[i].nbytes -
pclstats[i].nbytes;
pstats[i] = ((pstats[i] / diff) * 1000000000.0)
/ bytes_per_sec;
}
cbq_report_stats(interface, clstats, pstats, nclasses);
memcpy((void *)pclstats, (void *)clstats,
sizeof(class_stats_t) * nclasses);
if (domaxcount) {
if (++count >= maxcount)
done++;
}
poll(0, 0, 1000);
}
}
#ifdef CBQPERF
if (performance) {
if (!cbq_getnperf(interface, &nperf)) {
for (i = 0; i < nperf; i++) {
if (!cbq_getperf(interface, i, gp)) {
printf("%s:class.%x, %d, %lld, %lld\n",
interface,
gp->class_id,
i,
gp->schedtime,
gp->departtime);
}
}
} else
fprintf(stderr, "cbq_getnperf failed\n");
}
#endif
err_exit:
cbq_destroyall();
exit(1);
}
static void *
sighandler(void *arg)
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGTERM);
sigaddset(&set, SIGHUP);
switch (sigwait(&set)) {
case SIGINT:
case SIGTERM:
case SIGHUP:
done++;
break;
}
thr_exit(0);
}