Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/altq altq, cbq: convert ns_per_byte to ps_per_byte
details: https://anonhg.NetBSD.org/src/rev/476ad52b2747
branches: trunk
changeset: 984742:476ad52b2747
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Wed Jul 21 06:33:30 2021 +0000
description:
altq, cbq: convert ns_per_byte to ps_per_byte
Also the type of variables of it is changed to u_long from int.
This change provides fine-grain resolution of bandwidth. For example
750 Mbps was treated as 800 Mbps internally because bandwidth was
represented as nanoseconds per byte. Converting the representation
to picoseconds per byte enables to treat 750 Mbps as-is.
PR kern/56319
diffstat:
sys/altq/altq_cbq.c | 16 +++++++-------
sys/altq/altq_cbq.h | 6 ++--
sys/altq/altq_rmclass.c | 53 ++++++++++++++++++++++++++----------------------
sys/altq/altq_rmclass.h | 13 ++++++-----
4 files changed, 47 insertions(+), 41 deletions(-)
diffs (truncated from 336 to 300 lines):
diff -r 5bad8dcbc5da -r 476ad52b2747 sys/altq/altq_cbq.c
--- a/sys/altq/altq_cbq.c Wed Jul 21 06:18:32 2021 +0000
+++ b/sys/altq/altq_cbq.c Wed Jul 21 06:33:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: altq_cbq.c,v 1.34 2021/07/14 08:31:15 ozaki-r Exp $ */
+/* $NetBSD: altq_cbq.c,v 1.35 2021/07/21 06:33:30 ozaki-r Exp $ */
/* $KAME: altq_cbq.c,v 1.21 2005/04/13 03:44:24 suz Exp $ */
/*
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.34 2021/07/14 08:31:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.35 2021/07/21 06:33:30 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_altq.h"
@@ -226,7 +226,7 @@
statsp->minidle = cl->minidle_;
statsp->offtime = cl->offtime_;
statsp->qmax = qlimit(cl->q_);
- statsp->ns_per_byte = cl->ns_per_byte_;
+ statsp->ps_per_byte = cl->ps_per_byte_;
statsp->wrr_allot = cl->w_allotment_;
statsp->qcnt = qlen(cl->q_);
statsp->avgidle = cl->avgidle_;
@@ -384,7 +384,7 @@
*/
if ((opts->flags & CBQCLF_ROOTCLASS) != 0) {
error = rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp,
- opts->ns_per_byte, cbqrestart, a->qlimit, RM_MAXQUEUED,
+ opts->ps_per_byte, cbqrestart, a->qlimit, RM_MAXQUEUED,
opts->maxidle, opts->minidle, opts->offtime,
opts->flags);
if (error != 0)
@@ -392,7 +392,7 @@
cl = cbqp->ifnp.root_;
} else {
cl = rmc_newclass(a->priority,
- &cbqp->ifnp, opts->ns_per_byte,
+ &cbqp->ifnp, opts->ps_per_byte,
rmc_delay_action, a->qlimit, parent, borrow,
opts->maxidle, opts->minidle, opts->offtime,
opts->pktsize, opts->flags);
@@ -681,7 +681,7 @@
if ((cl = clh_to_clp(cbqp, acp->cbq_class_handle)) == NULL)
return (EINVAL);
- if (rmc_modclass(cl, acp->cbq_class.nano_sec_per_byte,
+ if (rmc_modclass(cl, acp->cbq_class.pico_sec_per_byte,
acp->cbq_class.maxq, acp->cbq_class.maxidle,
acp->cbq_class.minidle, acp->cbq_class.offtime,
acp->cbq_class.pktsize) < 0)
@@ -724,7 +724,7 @@
*/
if ((spec->flags & CBQCLF_ROOTCLASS) != 0) {
error = rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp,
- spec->nano_sec_per_byte, cbqrestart, spec->maxq,
+ spec->pico_sec_per_byte, cbqrestart, spec->maxq,
RM_MAXQUEUED, spec->maxidle, spec->minidle, spec->offtime,
spec->flags);
if (error)
@@ -732,7 +732,7 @@
cl = cbqp->ifnp.root_;
} else {
cl = rmc_newclass(spec->priority,
- &cbqp->ifnp, spec->nano_sec_per_byte,
+ &cbqp->ifnp, spec->pico_sec_per_byte,
rmc_delay_action, spec->maxq, parent, borrow,
spec->maxidle, spec->minidle, spec->offtime,
spec->pktsize, spec->flags);
diff -r 5bad8dcbc5da -r 476ad52b2747 sys/altq/altq_cbq.h
--- a/sys/altq/altq_cbq.h Wed Jul 21 06:18:32 2021 +0000
+++ b/sys/altq/altq_cbq.h Wed Jul 21 06:33:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: altq_cbq.h,v 1.8 2006/10/12 19:59:08 peter Exp $ */
+/* $NetBSD: altq_cbq.h,v 1.9 2021/07/21 06:33:30 ozaki-r Exp $ */
/* $KAME: altq_cbq.h,v 1.12 2003/10/03 05:05:15 kjc Exp $ */
/*
@@ -85,7 +85,7 @@
int minidle;
int offtime;
int qmax;
- int ns_per_byte;
+ u_long ps_per_byte;
int wrr_allot;
int qcnt; /* # packets in queue */
@@ -112,7 +112,7 @@
typedef struct cbq_class_spec {
u_int priority;
- u_int nano_sec_per_byte;
+ u_long pico_sec_per_byte;
u_int maxq;
u_int maxidle;
int minidle;
diff -r 5bad8dcbc5da -r 476ad52b2747 sys/altq/altq_rmclass.c
--- a/sys/altq/altq_rmclass.c Wed Jul 21 06:18:32 2021 +0000
+++ b/sys/altq/altq_rmclass.c Wed Jul 21 06:33:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: altq_rmclass.c,v 1.24 2021/07/13 08:23:39 ozaki-r Exp $ */
+/* $NetBSD: altq_rmclass.c,v 1.25 2021/07/21 06:33:30 ozaki-r Exp $ */
/* $KAME: altq_rmclass.c,v 1.19 2005/04/13 03:44:25 suz Exp $ */
/*
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.24 2021/07/13 08:23:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.25 2021/07/21 06:33:30 ozaki-r Exp $");
/* #ident "@(#)rm_class.c 1.48 97/12/05 SMI" */
@@ -80,6 +80,8 @@
#define reset_cutoff(ifd) { ifd->cutoff_ = RM_MAXDEPTH; }
+#define PSEC_TO_NSEC(t) ((t) / 1000)
+
/*
* Local routines.
*/
@@ -192,7 +194,7 @@
* offtime = offtime * (8.0 / nsecPerByte);
*/
struct rm_class *
-rmc_newclass(int pri, struct rm_ifdat *ifd, u_int nsecPerByte,
+rmc_newclass(int pri, struct rm_ifdat *ifd, u_long psecPerByte,
void (*action)(rm_class_t *, rm_class_t *), int maxq,
struct rm_class *parent, struct rm_class *borrow, u_int maxidle,
int minidle, u_int offtime, int pktsize, int flags)
@@ -240,10 +242,10 @@
cl->leaf_ = 1;
cl->ifdat_ = ifd;
cl->pri_ = pri;
- cl->allotment_ = RM_NS_PER_SEC / nsecPerByte; /* Bytes per sec */
+ cl->allotment_ = (u_int)(RM_PS_PER_SEC / psecPerByte); /* Bytes per sec */
cl->depth_ = 0;
cl->qthresh_ = 0;
- cl->ns_per_byte_ = nsecPerByte;
+ cl->ps_per_byte_ = psecPerByte;
qlimit(cl->q_) = maxq;
qtype(cl->q_) = Q_DROPHEAD;
@@ -251,18 +253,18 @@
cl->flags_ = flags;
#if 1 /* minidle is also scaled in ALTQ */
- cl->minidle_ = (minidle * (int)nsecPerByte) / 8;
+ cl->minidle_ = (minidle * (int)PSEC_TO_NSEC(psecPerByte)) / 8;
if (cl->minidle_ > 0)
cl->minidle_ = 0;
#else
cl->minidle_ = minidle;
#endif
- cl->maxidle_ = (maxidle * nsecPerByte) / 8;
+ cl->maxidle_ = (maxidle * PSEC_TO_NSEC(psecPerByte)) / 8;
if (cl->maxidle_ == 0)
cl->maxidle_ = 1;
#if 1 /* offtime is also scaled in ALTQ */
cl->avgidle_ = cl->maxidle_;
- cl->offtime_ = ((offtime * nsecPerByte) / 8) >> RM_FILTER_GAIN;
+ cl->offtime_ = ((offtime * PSEC_TO_NSEC(psecPerByte)) / 8) >> RM_FILTER_GAIN;
if (cl->offtime_ == 0)
cl->offtime_ = 1;
#else
@@ -345,7 +347,7 @@
}
int
-rmc_modclass(struct rm_class *cl, u_int nsecPerByte, int maxq, u_int maxidle,
+rmc_modclass(struct rm_class *cl, u_long psecPerByte, int maxq, u_int maxidle,
int minidle, u_int offtime, int pktsize)
{
struct rm_ifdat *ifd;
@@ -356,25 +358,25 @@
old_allotment = cl->allotment_;
s = splnet();
- cl->allotment_ = RM_NS_PER_SEC / nsecPerByte; /* Bytes per sec */
+ cl->allotment_ = (u_int)(RM_PS_PER_SEC / psecPerByte); /* Bytes per sec */
cl->qthresh_ = 0;
- cl->ns_per_byte_ = nsecPerByte;
+ cl->ps_per_byte_ = psecPerByte;
qlimit(cl->q_) = maxq;
#if 1 /* minidle is also scaled in ALTQ */
- cl->minidle_ = (minidle * nsecPerByte) / 8;
+ cl->minidle_ = (minidle * PSEC_TO_NSEC(psecPerByte)) / 8;
if (cl->minidle_ > 0)
cl->minidle_ = 0;
#else
cl->minidle_ = minidle;
#endif
- cl->maxidle_ = (maxidle * nsecPerByte) / 8;
+ cl->maxidle_ = (maxidle * PSEC_TO_NSEC(psecPerByte)) / 8;
if (cl->maxidle_ == 0)
cl->maxidle_ = 1;
#if 1 /* offtime is also scaled in ALTQ */
cl->avgidle_ = cl->maxidle_;
- cl->offtime_ = ((offtime * nsecPerByte) / 8) >> RM_FILTER_GAIN;
+ cl->offtime_ = ((offtime * PSEC_TO_NSEC(psecPerByte)) / 8) >> RM_FILTER_GAIN;
if (cl->offtime_ == 0)
cl->offtime_ = 1;
#else
@@ -659,7 +661,7 @@
*/
int
-rmc_init(struct ifaltq *ifq, struct rm_ifdat *ifd, u_int nsecPerByte,
+rmc_init(struct ifaltq *ifq, struct rm_ifdat *ifd, u_long psecPerByte,
void (*restart)(struct ifaltq *), int maxq, int maxqueued, u_int maxidle,
int minidle, u_int offtime, int flags)
{
@@ -681,13 +683,13 @@
ifd->ifq_ = ifq;
ifd->restart = restart;
ifd->maxqueued_ = maxqueued;
- ifd->ns_per_byte_ = nsecPerByte;
+ ifd->ps_per_byte_ = psecPerByte;
ifd->maxpkt_ = mtu;
ifd->wrr_ = (flags & RMCF_WRR) ? 1 : 0;
ifd->efficient_ = (flags & RMCF_EFFICIENT) ? 1 : 0;
#if 1
- ifd->maxiftime_ = mtu * nsecPerByte / 1000 * 16;
- if (mtu * nsecPerByte > 10 * 1000000)
+ ifd->maxiftime_ = mtu * psecPerByte / 1000 / 1000 * 16;
+ if ((long)mtu * psecPerByte > (long)10 * 1000000000)
ifd->maxiftime_ /= 4;
#endif
@@ -720,7 +722,7 @@
* Create the root class of the link-sharing structure.
*/
if ((ifd->root_ = rmc_newclass(0, ifd,
- nsecPerByte,
+ psecPerByte,
rmc_root_overlimit, maxq, 0, 0,
maxidle, minidle, offtime,
0, 0)) == NULL) {
@@ -1246,11 +1248,14 @@
* (on pentium, mul takes 9 cycles but div takes 46!)
*/
#define NSEC_TO_USEC(t) (((t) >> 10) + ((t) >> 16) + ((t) >> 17))
+/* Don't worry. Recent compilers don't use div. */
+#define PSEC_TO_USEC(t) ((t) / 1000 / 1000)
void
rmc_update_class_util(struct rm_ifdat *ifd)
{
int idle, avgidle, pktlen;
- int pkt_time, tidle;
+ u_long pkt_time;
+ int tidle;
rm_class_t *cl, *cl0, *borrowed;
rm_class_t *borrows;
struct timeval *nowp;
@@ -1281,8 +1286,8 @@
nowp = &ifd->now_[ifd->qo_];
/* get pkt_time (for link) in usec */
#if 1 /* use approximation */
- pkt_time = ifd->curlen_[ifd->qo_] * ifd->ns_per_byte_;
- pkt_time = NSEC_TO_USEC(pkt_time);
+ pkt_time = (u_long)ifd->curlen_[ifd->qo_] * ifd->ps_per_byte_;
+ pkt_time = PSEC_TO_USEC(pkt_time);
#else
pkt_time = ifd->curlen_[ifd->qo_] * ifd->ns_per_byte_ / 1000;
#endif
@@ -1324,8 +1329,8 @@
/* get pkt_time (for class) in usec */
#if 1 /* use approximation */
- pkt_time = pktlen * cl->ns_per_byte_;
- pkt_time = NSEC_TO_USEC(pkt_time);
+ pkt_time = (u_long)pktlen * cl->ps_per_byte_;
+ pkt_time = PSEC_TO_USEC(pkt_time);
#else
pkt_time = pktlen * cl->ns_per_byte_ / 1000;
#endif
diff -r 5bad8dcbc5da -r 476ad52b2747 sys/altq/altq_rmclass.h
--- a/sys/altq/altq_rmclass.h Wed Jul 21 06:18:32 2021 +0000
+++ b/sys/altq/altq_rmclass.h Wed Jul 21 06:33:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: altq_rmclass.h,v 1.9 2021/07/13 08:04:31 ozaki-r Exp $ */
+/* $NetBSD: altq_rmclass.h,v 1.10 2021/07/21 06:33:30 ozaki-r Exp $ */
/* $KAME: altq_rmclass.h,v 1.10 2003/08/20 23:30:23 itojun Exp $ */
/*
@@ -120,6 +120,7 @@
#define RM_POWER (1 << RM_FILTER_GAIN)
#define RM_MAXDEPTH 32
#define RM_NS_PER_SEC (1000000000)
+#define RM_PS_PER_SEC (1000000000000)
typedef struct _rm_class_stats_ {
u_int handle;
Home |
Main Index |
Thread Index |
Old Index