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>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
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,
53 unsigned overhead = (mpu >> 8) & 0xFF;
61 while ((mtu>>cell_log) > 255)
64 for (i=0; i<256; i++) {
65 unsigned sz = (i<<cell_log);
70 rtab[i] = tc_core_usec2tick(1000000*((double)sz/bps));
77 FILE *fp = fopen("/proc/net/psched", "r");
82 if (fscanf(fp, "%08x%08x", &t2us, &us2t) != 2) {
87 tick_in_usec = (double)t2us/us2t;