osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 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> |
| 16 | #include <syslog.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <math.h> |
| 19 | #include <sys/socket.h> |
| 20 | #include <netinet/in.h> |
| 21 | #include <arpa/inet.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include "tc_core.h" |
| 25 | #include "tc_cbq.h" |
| 26 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 27 | unsigned int tc_cbq_calc_maxidle(unsigned int bndw, unsigned int rate, unsigned int avpkt, |
| 28 | int ewma_log, unsigned int maxburst) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 29 | { |
| 30 | double maxidle; |
| 31 | double g = 1.0 - 1.0/(1<<ewma_log); |
| 32 | double xmt = (double)avpkt/bndw; |
| 33 | |
| 34 | maxidle = xmt*(1-g); |
| 35 | if (bndw != rate && maxburst) { |
| 36 | double vxmt = (double)avpkt/rate - xmt; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 37 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 38 | vxmt *= (pow(g, -(double)maxburst) - 1); |
| 39 | if (vxmt > maxidle) |
| 40 | maxidle = vxmt; |
| 41 | } |
Patrick McHardy | 8f34caa | 2007-03-04 20:15:00 +0100 | [diff] [blame] | 42 | return tc_core_time2tick(maxidle*(1<<ewma_log)*TIME_UNITS_PER_SEC); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame] | 45 | unsigned int tc_cbq_calc_offtime(unsigned int bndw, unsigned int rate, unsigned int avpkt, |
| 46 | int ewma_log, unsigned int minburst) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 47 | { |
| 48 | double g = 1.0 - 1.0/(1<<ewma_log); |
| 49 | double offtime = (double)avpkt/rate - (double)avpkt/bndw; |
| 50 | |
| 51 | if (minburst == 0) |
| 52 | return 0; |
| 53 | if (minburst == 1) |
| 54 | offtime *= pow(g, -(double)minburst) - 1; |
| 55 | else |
| 56 | offtime *= 1 + (pow(g, -(double)(minburst-1)) - 1)/(1-g); |
Patrick McHardy | 8f34caa | 2007-03-04 20:15:00 +0100 | [diff] [blame] | 57 | return tc_core_time2tick(offtime*TIME_UNITS_PER_SEC); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 58 | } |