mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-05 14:53:16 +00:00

Patrick McHardy, Cite: 'its better to overestimate than underestimate to stay in control of the queue'. Illustrating the rate table array: Legend description rtab[x] : Array index x of rtab[x] xmit_sz : Transmit size contained in rtab[x] (normally transmit time) maps[a-b] : Packet sizes from a to b, will map into rtab[x] Current/old rate table mapping (cell_log:3): rtab[0]:=xmit_sz:0 maps[0-7] rtab[1]:=xmit_sz:8 maps[8-15] rtab[2]:=xmit_sz:16 maps[16-23] rtab[3]:=xmit_sz:24 maps[24-31] rtab[4]:=xmit_sz:32 maps[32-39] rtab[5]:=xmit_sz:40 maps[40-47] rtab[6]:=xmit_sz:48 maps[48-55] New rate table mapping, with kernel cell_align support. rtab[0]:=xmit_sz:8 maps[0-8] rtab[1]:=xmit_sz:16 maps[9-16] rtab[2]:=xmit_sz:24 maps[17-24] rtab[3]:=xmit_sz:32 maps[25-32] rtab[4]:=xmit_sz:40 maps[33-40] rtab[5]:=xmit_sz:48 maps[41-48] rtab[6]:=xmit_sz:56 maps[49-56] New TC util on a kernel WITHOUT support for cell_align rtab[0]:=xmit_sz:8 maps[0-7] rtab[1]:=xmit_sz:16 maps[8-15] rtab[2]:=xmit_sz:24 maps[16-23] rtab[3]:=xmit_sz:32 maps[24-31] rtab[4]:=xmit_sz:40 maps[32-39] rtab[5]:=xmit_sz:48 maps[40-47] rtab[6]:=xmit_sz:56 maps[48-55] Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk> Signed-off-by: Stephen Hemminger <stephen.hemminger@vyatta.com>
125 lines
2.4 KiB
C
125 lines
2.4 KiB
C
/*
|
|
* tc_core.c TC core library.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*
|
|
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <syslog.h>
|
|
#include <fcntl.h>
|
|
#include <math.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <string.h>
|
|
|
|
#include "tc_core.h"
|
|
|
|
static double tick_in_usec = 1;
|
|
static double clock_factor = 1;
|
|
|
|
int tc_core_time2big(unsigned time)
|
|
{
|
|
__u64 t = time;
|
|
|
|
t *= tick_in_usec;
|
|
return (t >> 32) != 0;
|
|
}
|
|
|
|
|
|
unsigned tc_core_time2tick(unsigned time)
|
|
{
|
|
return time*tick_in_usec;
|
|
}
|
|
|
|
unsigned tc_core_tick2time(unsigned tick)
|
|
{
|
|
return tick/tick_in_usec;
|
|
}
|
|
|
|
unsigned tc_core_time2ktime(unsigned time)
|
|
{
|
|
return time * clock_factor;
|
|
}
|
|
|
|
unsigned tc_core_ktime2time(unsigned ktime)
|
|
{
|
|
return ktime / clock_factor;
|
|
}
|
|
|
|
unsigned tc_calc_xmittime(unsigned rate, unsigned size)
|
|
{
|
|
return tc_core_time2tick(TIME_UNITS_PER_SEC*((double)size/rate));
|
|
}
|
|
|
|
unsigned tc_calc_xmitsize(unsigned rate, unsigned ticks)
|
|
{
|
|
return ((double)rate*tc_core_tick2time(ticks))/TIME_UNITS_PER_SEC;
|
|
}
|
|
|
|
/*
|
|
rtab[pkt_len>>cell_log] = pkt_xmit_time
|
|
*/
|
|
|
|
int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab, int cell_log, unsigned mtu)
|
|
{
|
|
int i;
|
|
unsigned bps = r->rate;
|
|
unsigned mpu = r->mpu;
|
|
|
|
if (mtu == 0)
|
|
mtu = 2047;
|
|
|
|
if (cell_log < 0) {
|
|
cell_log = 0;
|
|
while ((mtu>>cell_log) > 255)
|
|
cell_log++;
|
|
}
|
|
for (i=0; i<256; i++) {
|
|
unsigned sz = ((i+1)<<cell_log);
|
|
if (sz < mpu)
|
|
sz = mpu;
|
|
rtab[i] = tc_calc_xmittime(bps, sz);
|
|
}
|
|
r->cell_align=-1; // Due to the sz calc
|
|
r->cell_log=cell_log;
|
|
return cell_log;
|
|
}
|
|
|
|
int tc_core_init()
|
|
{
|
|
FILE *fp;
|
|
__u32 clock_res;
|
|
__u32 t2us;
|
|
__u32 us2t;
|
|
|
|
fp = fopen("/proc/net/psched", "r");
|
|
if (fp == NULL)
|
|
return -1;
|
|
|
|
if (fscanf(fp, "%08x%08x%08x", &t2us, &us2t, &clock_res) != 3) {
|
|
fclose(fp);
|
|
return -1;
|
|
}
|
|
fclose(fp);
|
|
|
|
/* compatibility hack: for old iproute binaries (ignoring
|
|
* the kernel clock resolution) the kernel advertises a
|
|
* tick multiplier of 1000 in case of nano-second resolution,
|
|
* which really is 1. */
|
|
if (clock_res == 1000000000)
|
|
t2us = us2t;
|
|
|
|
clock_factor = (double)clock_res / TIME_UNITS_PER_SEC;
|
|
tick_in_usec = (double)t2us / us2t * clock_factor;
|
|
return 0;
|
|
}
|