]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Use tc_calc_xmittime() where appropriate
authorPatrick McHardy <kaber@trash.net>
Sun, 4 Mar 2007 19:14:56 +0000 (20:14 +0100)
committerStephen Hemminger <shemminger@linux-foundation.org>
Tue, 13 Mar 2007 21:42:14 +0000 (14:42 -0700)
[IPROUTE]: Use tc_calc_xmittime() where appropriate

Replace expressions of the form "tc_core_usec2tick(1000000 * size/rate)"
by tc_calc_xmittime().

The CBQ case deserves an extra comment: when called with bnwd=rate,
tc_cbq_calc_maxidle() behaves identical to tc_calc_xmittime():

unsigned tc_cbq_calc_maxidle(...)
{
double g = 1.0 - 1.0/(1<<ewma_log);
double xmt = (double)avpkt/bndw;

maxidle = xmt*(1-g);
if (bndw != rate && maxburst) {
...
}
return tc_core_usec2tick(maxidle*(1<<ewma_log)*1000000);
}

which comes down to:

maxidle = xmt * (1 - g)
= xmt * (1 - (1.0 - 1.0/(1 << ewma_log))
= xmt * (1.0/(1 << ewma_log))

so:

maxidle * (1 << ewma_log) * 1000000
= xmt * (1.0/(1 << ewma_log)) * (1 << ewma_log) * 1000000
= xmt * 1000000
= avpkt/bndw * 1000000

Which means tc_core_usec2tick(maxidle*(1<<ewma_log)*1000000) is identical
to tc_calc_xmittime(bndw, avpkt). Use it directly since its a lot easier
to understand its limits.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
tc/q_cbq.c
tc/tc_core.c
tc/tc_red.c

index bc7e8ba75b8a1848e683d3c20cf8b9fd18a8ec90..0000a563b2f965990e84f1d8d51ef9ff18c7472b 100644 (file)
@@ -147,7 +147,7 @@ static int cbq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nl
        if (ewma_log < 0)
                ewma_log = TC_CBQ_DEF_EWMA;
        lss.ewma_log = ewma_log;
-       lss.maxidle = tc_cbq_calc_maxidle(r.rate, r.rate, avpkt, lss.ewma_log, 0);
+       lss.maxidle = tc_calc_xmittime(r.rate, avpkt);
        lss.change = TCF_CBQ_LSS_MAXIDLE|TCF_CBQ_LSS_EWMA|TCF_CBQ_LSS_AVPKT;
        lss.avpkt = avpkt;
 
index 10c375ef8f852125f170ea586b87e38e48e11b96..90a097d3646f5273b7a82f52a4f2afb4be849a8c 100644 (file)
@@ -76,7 +76,7 @@ int tc_calc_rtable(unsigned bps, __u32 *rtab, int cell_log, unsigned mtu,
                        sz += overhead;
                if (sz < mpu)
                        sz = mpu;
-               rtab[i] = tc_core_usec2tick(1000000*((double)sz/bps));
+               rtab[i] = tc_calc_xmittime(bps, sz);
        }
        return cell_log;
 }
index 385e7af116b399980085cd20b1951b4374551ab2..8f9bde088ed1de694ddfae14a0664c3a85fbb452 100644 (file)
@@ -71,7 +71,7 @@ int tc_red_eval_ewma(unsigned qmin, unsigned burst, unsigned avpkt)
 
 int tc_red_eval_idle_damping(int Wlog, unsigned avpkt, unsigned bps, __u8 *sbuf)
 {
-       double xmit_time = tc_core_usec2tick(1000000*(double)avpkt/bps);
+       double xmit_time = tc_calc_xmittime(bps, avpkt);
        double lW = -log(1.0 - 1.0/(1<<Wlog))/xmit_time;
        double maxtime = 31/lW;
        int clog;