diff options
author | Andrew Collins <bsderandrew@gmail.com> | 2012-05-26 00:08:06 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@redhat.com> | 2012-05-29 09:42:48 (GMT) |
commit | 970f5d0221863b1473740455ca4d8cefcb34ff31 (patch) | |
tree | 4d5081a4f375c0949640da790fbdbf357431e7c0 /lib/utils.c | |
parent | 9bb30a5e801fff2333d9b847be42294aa2e34e06 (diff) | |
download | libnl-970f5d0221863b1473740455ca4d8cefcb34ff31.zip libnl-970f5d0221863b1473740455ca4d8cefcb34ff31.tar.gz libnl-970f5d0221863b1473740455ca4d8cefcb34ff31.tar.bz2 |
correct HTB rtable/HZ calculations
The HTB implementation in libnl uses units of microseconds in a number
of places where it seems TC is expecting time in units of ticks, which
causes actual rates much higher than requested. Additionally, libnl
uses USER_HZ for calculating buffer and cbuffer sizes, which can
result in much larger buffers than necessary on systems with high
resolution timers.
Note that the TBF qdisc uses microseconds incorrectly in two spots as
well, I fixed this but did not test.
Diffstat (limited to 'lib/utils.c')
-rw-r--r-- | lib/utils.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/utils.c b/lib/utils.c index 36b6292..efb2cf4 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -359,12 +359,13 @@ long nl_prob2int(const char *str) * @{ */ -#ifdef USER_HZ -static uint32_t user_hz = USER_HZ; -#else -static uint32_t user_hz = 100; +#ifndef USER_HZ +#define USER_HZ 100 #endif +static uint32_t user_hz = USER_HZ; +static uint32_t psched_hz = USER_HZ; + static double ticks_per_usec = 1.0f; /* Retrieves the configured HZ and ticks/us value in the kernel. @@ -394,6 +395,8 @@ static void __init get_psched_settings(void) if (!got_hz) user_hz = sysconf(_SC_CLK_TCK); + psched_hz = user_hz; + if (getenv("TICKS_PER_USEC")) { double t = strtod(getenv("TICKS_PER_USEC"), NULL); ticks_per_usec = t; @@ -408,14 +411,16 @@ static void __init get_psched_settings(void) strncpy(name, "/proc/net/psched", sizeof(name) - 1); if ((fd = fopen(name, "r"))) { - uint32_t ns_per_usec, ns_per_tick; - /* the file contains 4 hexadecimals, but we just use - the first two of them */ - fscanf(fd, "%08x %08x", &ns_per_usec, &ns_per_tick); + uint32_t ns_per_usec, ns_per_tick, nom, denom; + + fscanf(fd, "%08x %08x %08x %08x", + &ns_per_usec, &ns_per_tick, &nom, &denom); ticks_per_usec = (double) ns_per_usec / (double) ns_per_tick; + if (nom == 1000000) + psched_hz = denom; fclose(fd); } @@ -431,6 +436,13 @@ int nl_get_user_hz(void) return user_hz; } +/** + * Return the value of packet scheduler HZ + */ +int nl_get_psched_hz(void) +{ + return psched_hz; +} /** * Convert micro seconds to ticks |