]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/tc_cbq.c
devlink: Add support for resource/dpipe relation
[mirror_iproute2.git] / tc / tc_cbq.c
CommitLineData
aba5acdf
SH
1/*
2 * tc_cbq.c CBQ maintanance routines.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
aba5acdf
SH
16#include <fcntl.h>
17#include <math.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <string.h>
22
23#include "tc_core.h"
24#include "tc_cbq.h"
25
32a121cb
SH
26unsigned int tc_cbq_calc_maxidle(unsigned int bndw, unsigned int rate, unsigned int avpkt,
27 int ewma_log, unsigned int maxburst)
aba5acdf
SH
28{
29 double maxidle;
30 double g = 1.0 - 1.0/(1<<ewma_log);
31 double xmt = (double)avpkt/bndw;
32
33 maxidle = xmt*(1-g);
34 if (bndw != rate && maxburst) {
35 double vxmt = (double)avpkt/rate - xmt;
32a121cb 36
aba5acdf
SH
37 vxmt *= (pow(g, -(double)maxburst) - 1);
38 if (vxmt > maxidle)
39 maxidle = vxmt;
40 }
8f34caaf 41 return tc_core_time2tick(maxidle*(1<<ewma_log)*TIME_UNITS_PER_SEC);
aba5acdf
SH
42}
43
32a121cb
SH
44unsigned int tc_cbq_calc_offtime(unsigned int bndw, unsigned int rate, unsigned int avpkt,
45 int ewma_log, unsigned int minburst)
aba5acdf
SH
46{
47 double g = 1.0 - 1.0/(1<<ewma_log);
48 double offtime = (double)avpkt/rate - (double)avpkt/bndw;
49
50 if (minburst == 0)
51 return 0;
52 if (minburst == 1)
53 offtime *= pow(g, -(double)minburst) - 1;
54 else
55 offtime *= 1 + (pow(g, -(double)(minburst-1)) - 1)/(1-g);
8f34caaf 56 return tc_core_time2tick(offtime*TIME_UNITS_PER_SEC);
aba5acdf 57}