• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/iproute2/tc/

Lines Matching defs:*

2  * tc_core.c		TC core library.
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.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
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>
24 #include "tc_core.h"
26 static __u32 t2us=1;
27 static __u32 us2t=1;
28 static double tick_in_usec = 1;
30 long tc_core_usec2tick(long usec)
32 return usec*tick_in_usec;
35 long tc_core_tick2usec(long tick)
37 return tick/tick_in_usec;
40 unsigned tc_calc_xmittime(unsigned rate, unsigned size)
42 return tc_core_usec2tick(1000000*((double)size/rate));
46 rtab[pkt_len>>cell_log] = pkt_xmit_time
49 int tc_calc_rtable(unsigned bps, __u32 *rtab, int cell_log, unsigned mtu,
50 unsigned mpu)
52 int i;
53 unsigned overhead = (mpu >> 8) & 0xFF;
54 mpu = mpu & 0xFF;
56 if (mtu == 0)
57 mtu = 2047;
59 if (cell_log < 0) {
60 cell_log = 0;
61 while ((mtu>>cell_log) > 255)
62 cell_log++;
64 for (i=0; i<256; i++) {
65 unsigned sz = (i<<cell_log);
66 if (overhead)
67 sz += overhead;
68 if (sz < mpu)
69 sz = mpu;
70 rtab[i] = tc_core_usec2tick(1000000*((double)sz/bps));
72 return cell_log;
75 int tc_core_init()
77 FILE *fp = fopen("/proc/net/psched", "r");
79 if (fp == NULL)
80 return -1;
82 if (fscanf(fp, "%08x%08x", &t2us, &us2t) != 2) {
83 fclose(fp);
84 return -1;
86 fclose(fp);
87 tick_in_usec = (double)t2us/us2t;
88 return 0;