Debian Codegraph @

tc/tc_estimator.c

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * tc_core.c TC core library.
4 *
5 * Authors: Alexey Kuznetsov, <[email protected]>
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <math.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
16 #include <string.h>
17
18 #include "utils.h"
19 #include "tc_core.h"
20
21 int tc_setup_estimator(unsigned int A, unsigned int time_const, struct tc_estimator *est)
22 {
23 for (est->interval = 0; est->interval <= 5; est->interval++) {
24 if (A <= (1<<est->interval)*(TIME_UNITS_PER_SEC/4))
25 break;
26 }
27 if (est->interval > 5)
28 return -1;
29 est->interval -= 2;
30 for (est->ewma_log = 1; est->ewma_log < 32; est->ewma_log++) {
31 double w = 1.0 - 1.0/(1<<est->ewma_log);
32
33 if (A/(-log(w)) > time_const)
34 break;
35 }
36 est->ewma_log--;
37 if (est->ewma_log == 0 || est->ewma_log >= 31)
38 return -1;
39 return 0;
40 }