From: Patrick McHardy <kaber@trash.net>
To: netdev@vger.kernel.org
Cc: Patrick McHardy <kaber@trash.net>, shemminger@linux-foundation.org
Subject: [RFC IPROUTE 07/08]: Handle different kernel clock resolutions
Date: Sun, 4 Mar 2007 20:15:03 +0100 (MET) [thread overview]
Message-ID: <20070304191412.22838.24161.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20070304191402.22838.91224.sendpatchset@localhost.localdomain>
[IPROUTE]: Handle different kernel clock resolutions
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
commit 0e0db5d408bdac33eadd9d947c0e6904df26ab8f
tree 950a6f47287bec01e5996bec3f1141b60f3f6f6a
parent 5950296ff76ba81593928a2ee89757d69b2acba9
author Patrick McHardy <kaber@trash.net> Sat, 03 Mar 2007 20:30:50 +0100
committer Patrick McHardy <kaber@trash.net> Sat, 03 Mar 2007 20:30:50 +0100
tc/tc_core.c | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/tc/tc_core.c b/tc/tc_core.c
index e27254e..58155fb 100644
--- a/tc/tc_core.c
+++ b/tc/tc_core.c
@@ -23,9 +23,8 @@ #include <string.h>
#include "tc_core.h"
-static __u32 t2us=1;
-static __u32 us2t=1;
static double tick_in_usec = 1;
+static double clock_factor = 1;
int tc_core_time2big(long time)
{
@@ -48,12 +47,12 @@ long tc_core_tick2time(long tick)
long tc_core_time2ktime(long time)
{
- return time;
+ return time * clock_factor;
}
long tc_core_ktime2time(long ktime)
{
- return ktime;
+ return ktime / clock_factor;
}
unsigned tc_calc_xmittime(unsigned rate, unsigned size)
@@ -98,16 +97,29 @@ int tc_calc_rtable(unsigned bps, __u32 *
int tc_core_init()
{
- FILE *fp = fopen("/proc/net/psched", "r");
+ 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", &t2us, &us2t) != 2) {
+ if (fscanf(fp, "%08x%08x%08x", &t2us, &us2t, &clock_res) != 3) {
fclose(fp);
return -1;
}
fclose(fp);
- tick_in_usec = (double)t2us/us2t;
+
+ /* 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;
}
next prev parent reply other threads:[~2007-03-04 19:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-04 19:14 [RFC IPROUTE 00/08]: Time cleanups + nano-second clock resolution support Patrick McHardy
2007-03-04 19:14 ` [RFC IPROUTE 01/08]: tbf: fix latency printing Patrick McHardy
2007-03-04 19:14 ` [RFC IPROUTE 02/08]: Use tc_calc_xmittime() where appropriate Patrick McHardy
2007-03-04 19:14 ` [RFC IPROUTE 03/08]: Introduce tc_calc_xmitsize and use " Patrick McHardy
2007-03-04 19:14 ` [RFC IPROUTE 04/08]: Introduce TIME_UNITS_PER_SEC to represent internal clock resolution Patrick McHardy
2007-03-04 19:15 ` [RFC IPROUTE 05/08]: Replace "usec" by "time" in function names Patrick McHardy
2007-03-04 19:15 ` [RFC IPROUTE 06/08]: Add sprint_ticks() function and use in CBQ Patrick McHardy
2007-03-04 19:15 ` Patrick McHardy [this message]
2007-03-04 19:15 ` [RFC IPROUTE 08/08]: Increase internal clock resolution to nsec Patrick McHardy
2007-03-13 21:42 ` [RFC IPROUTE 00/08]: Time cleanups + nano-second clock resolution support Stephen Hemminger
2007-03-14 8:54 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070304191412.22838.24161.sendpatchset@localhost.localdomain \
--to=kaber@trash.net \
--cc=netdev@vger.kernel.org \
--cc=shemminger@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).