: Time cleanups
Subsystems (2)
cover : Time cleanups
I'm currently adding support for ktime as clocksource to the qdisc layer and in the course of doing that cleaned up the iproute time handling a bit to make it easier to use a different internal clock resultion and audit for integer overflows.
Increasing iproutes internal clock resolution is necessary for all token bucket based schedulers to take advantage of a higher kernel clock resolution because the kernel only does lookups and additions/subtractions, which can never result in values that have a higher precision that those passed from userspace.
The way I imagine it we have to keep the old clock sources around for userspace compatibility since they can't deal with the higher precision values. iproute is changed to use nsec internally and reads the kernel clock resulution from /proc/net/psched (third value, currently assumed to always be 10^6) to convert it's internal resolution to that of the kernel. With ktime as clocksource the kernel will report a resulution of 10^9. The downside is that distributors can't enable ktime unless they want to break compatibility with old iproute versions. Any better suggestions are welcome of course.
tc/m_estimator.c | 4 ++-- tc/m_police.c | 2 +- tc/q_cbq.c | 15 ++++++++------- tc/q_hfsc.c | 18 +++++++++--------- tc/q_htb.c | 4 ++-- tc/q_netem.c | 12 +++--------- tc/q_tbf.c | 20 ++++++++++---------- tc/tc_cbq.c | 8 ++++---- tc/tc_core.c | 31 +++++++++++++++++++++++-------- tc/tc_core.h | 9 +++++++-- tc/tc_estimator.c | 2 +- tc/tc_red.c | 2 +- tc/tc_util.c | 33 +++++++++++++++++++-------------- tc/tc_util.h | 7 ++++--- 14 files changed, 94 insertions(+), 73 deletions(-)
Patrick McHardy:
[IPROUTE]: Use tc_calc_xmittime where appropriate
[IPROUTE]: Introduce tc_calc_xmitsize and use where appropriate [IPROUTE]: Introduce TIME_UNITS_PER_SEC to represent internal clock resulution [IPROUTE]: Replace "usec" by "time" in function names
[IPROUTE]: Add sprint_ticks() function and use in CBQ
PATCH 1/5 : Use tc_calc_xmittime where appropriate
[IPROUTE]: Use tc_calc_xmittime where appropriate
Replace expressions of the form "1000000 * size/rate" by tc_calc_xmittime(). The CBQ case deserves an extra comment: when called with bnwd=rate tc_cbq_calc_maxidle behaves identical to tc_calc_xmittime, so use it for clarity.
---
commit c25b0a7730d72f266e46fee3cfd53ce9f2a15c2f
tree 39c6fbd3395e8a41170739d6cff8d3a00d31a915
parent 8f8a36487119a3cd1afe86a9649704aca088567b
author Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:02:46 +0200 committer Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:02:46 +0200
tc/q_cbq.c | 2 +- tc/q_tbf.c | 4 ++-- tc/tc_core.c | 2 +- tc/tc_red.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
tc/q_cbq.c +1 -1
@@ -147,7 +147,7 @@ static int cbq_parse_opt(struct qdisc_utif (ewma_log <0 ) ewma_log =TC_CBQ_DEF_EWMA ; lss.ewma_log = ewma_log; - lss.maxidle =tc_cbq_calc_maxidle (r.rate, r.rate, avpkt, lss.ewma_log,0 ); + lss.maxidle =tc_calc_xmittime (r.rate, avpkt); lss.change =TCF_CBQ_LSS_MAXIDLE |TCF_CBQ_LSS_EWMA |TCF_CBQ_LSS_AVPKT ; lss.avpkt = avpkt;
tc/q_tbf.c +2 -2
@@ -245,9 +245,9 @@ static int tbf_print_opt(struct qdisc_utif (show_raw)fprintf (f,"limit %s " ,sprint_size (qopt->limit, b1)); - latency =1000000 *(qopt->limit/(double )qopt->rate.rate) -tc_core_tick2usec (qopt->buffer); + latency =tc_calc_xmittime (qopt->rate.rate, qopt->limit) -tc_core_tick2usec (qopt->buffer);if (qopt->peakrate.rate) { -double lat2 =1000000 *(qopt->limit/(double )qopt->peakrate.rate) -tc_core_tick2usec (qopt->mtu); +double lat2 =tc_calc_xmittime (qopt->peakrate.rate, qopt->limit) -tc_core_tick2usec (qopt->mtu);if (lat2 > latency) latency = lat2; }
tc/tc_core.c +1 -1
@@ -67,7 +67,7 @@ int tc_calc_rtable(unsigned bps, __u32 * sz += overhead;if (sz < mpu) sz = mpu; - rtab[i] =tc_core_usec2tick (1000000 *((double )sz/bps)); + rtab[i] =tc_calc_xmittime (bps, sz); }return cell_log; }
tc/tc_red.c +1 -1
@@ -71,7 +71,7 @@ int tc_red_eval_ewma(unsigned qmin, unsiint tc_red_eval_idle_damping (int Wlog,unsigned avpkt,unsigned bps,__u8 *sbuf) { -double xmit_time =tc_core_usec2tick (1000000 *(double )avpkt/bps); +double xmit_time =tc_calc_xmittime (bps, avpkt);double lW = -log (1.0 -1.0 /(1 <<Wlog))/xmit_time;double maxtime =31 /lW;int clog;
Re: [IPROUTE 01/05]: Use tc_calc_xmittime where appropriate
Quoted 7 lines · Patrick McHardy
[IPROUTE]: Use
tc_calc_xmittimewhere appropriatetc/q_tbf.c +0
-0
tc/q_tbf.c static int tbf_print_opt(struct qdisc_ut · line 251
Quoted 9 lines
tc/q_tbf.c +2
-2@@ -245,9 +245,9 @@ static int tbf_print_opt(struct qdisc_utif (show_raw)fprintf (f,"limit %s " ,sprint_size (qopt->limit, b1)); - latency =1000000 *(qopt->limit/(double )qopt->rate.rate) -tc_core_tick2usec (qopt->buffer); + latency =tc_calc_xmittime (qopt->rate.rate, qopt->limit) -tc_core_tick2usec (qopt->buffer);if (qopt->peakrate.rate) { -double lat2 =1000000 *(qopt->limit/(double )qopt->peakrate.rate) -tc_core_tick2usec (qopt->mtu); +double lat2 =tc_calc_xmittime (qopt->peakrate.rate, qopt->limit) -tc_core_tick2usec (qopt->mtu);if (lat2 > latency)
I think I should start reviewing my own patches in a mail client :) The two cases above are wrong, tc_calc_xmittime does an additional tc_core_usec2tick(). Corrected patch attached.
[IPROUTE]: Use tc_calc_xmittime where appropriate
Replace expressions of the form "1000000 * size/rate" by tc_calc_xmittime(). The CBQ case deserves an extra comment: when called with bnwd=rate tc_cbq_calc_maxidle behaves identical to tc_calc_xmittime, so use it for clarity.
---
commit c25b0a7730d72f266e46fee3cfd53ce9f2a15c2f
tree 39c6fbd3395e8a41170739d6cff8d3a00d31a915
parent 8f8a36487119a3cd1afe86a9649704aca088567b
author Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:02:46 +0200 committer Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:02:46 +0200
tc/q_cbq.c | 2 +- tc/q_tbf.c | 4 ++-- tc/tc_core.c | 2 +- tc/tc_red.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
tc/q_cbq.c +1 -1
@@ -147,7 +147,7 @@ static int cbq_parse_opt(struct qdisc_utif (ewma_log <0 ) ewma_log =TC_CBQ_DEF_EWMA ; lss.ewma_log = ewma_log; - lss.maxidle =tc_cbq_calc_maxidle (r.rate, r.rate, avpkt, lss.ewma_log,0 ); + lss.maxidle =tc_calc_xmittime (r.rate, avpkt); lss.change =TCF_CBQ_LSS_MAXIDLE |TCF_CBQ_LSS_EWMA |TCF_CBQ_LSS_AVPKT ; lss.avpkt = avpkt;
tc/tc_core.c +1 -1
@@ -67,7 +67,7 @@ int tc_calc_rtable(unsigned bps, __u32 * sz += overhead;if (sz < mpu) sz = mpu; - rtab[i] =tc_core_usec2tick (1000000 *((double )sz/bps)); + rtab[i] =tc_calc_xmittime (bps, sz); }return cell_log; }
tc/tc_red.c +1 -1
@@ -71,7 +71,7 @@ int tc_red_eval_ewma(unsigned qmin, unsiint tc_red_eval_idle_damping (int Wlog,unsigned avpkt,unsigned bps,__u8 *sbuf) { -double xmit_time =tc_core_usec2tick (1000000 *(double )avpkt/bps); +double xmit_time =tc_calc_xmittime (bps, avpkt);double lW = -log (1.0 -1.0 /(1 <<Wlog))/xmit_time;double maxtime =31 /lW;int clog;
PATCH 2/5 : Introduce tc_calc_xmitsize and use where appropriate
In reply to Patrick McHardy[IPROUTE]: Introduce tc_calc_xmitsize and use where appropriate
Add tc_calc_xmitsize() as complement to tc_calc_xmittime(), which calculates the size than can be transmitted at a given rate during a given time. Replace all expressions of the form "size = rate*tc_core_tick2usec(time))/1000000" by tc_calc_xmitsize() calls.
---
commit 06a5350c47d028448850788031625ac1961d722b
tree 23eb5f6dbbb4a864e524c048f006842733924c9e
parent c25b0a7730d72f266e46fee3cfd53ce9f2a15c2f
author Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:13:09 +0200 committer Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:13:09 +0200
tc/m_police.c | 2 +- tc/q_htb.c | 4 ++-- tc/q_tbf.c | 4 ++-- tc/tc_core.c | 5 +++++ tc/tc_core.h | 1 + 5 files changed, 11 insertions(+), 5 deletions(-)
tc/m_police.c +1 -1
@@ -334,7 +334,7 @@ #endiffprintf (f," police 0x%x " , p->index);fprintf (f,"rate %s " ,sprint_rate (p->rate.rate, b1)); - buffer = ((double )p->rate.rate*tc_core_tick2usec (p->burst))/1000000 ; + buffer =tc_calc_xmitsize (p->rate.rate, p->burst);fprintf (f,"burst %s " ,sprint_size (buffer, b1));fprintf (f,"mtu %s " ,sprint_size (p->mtu, b1));if (show_raw)
tc/q_htb.c +2 -2
@@ -259,9 +259,9 @@ static int htb_print_opt(struct qdisc_utfprintf (f,"quantum %d " , (int )hopt->quantum); }fprintf (f,"rate %s " ,sprint_rate (hopt->rate.rate, b1)); - buffer = ((double )hopt->rate.rate*tc_core_tick2usec (hopt->buffer))/1000000 ; + buffer =tc_calc_xmitsize (hopt->rate.rate, hopt->buffer);fprintf (f,"ceil %s " ,sprint_rate (hopt->ceil.rate, b1)); - cbuffer = ((double )hopt->ceil.rate*tc_core_tick2usec (hopt->cbuffer))/1000000 ; + cbuffer =tc_calc_xmitsize (hopt->ceil.rate, hopt->cbuffer);if (show_details) { fprintf(f, "burst %s/%u mpu %s overhead %s ", sprint_size(buffer, b1),
tc/q_tbf.c +2 -2
@@ -218,7 +218,7 @@ static int tbf_print_opt(struct qdisc_utif (RTA_PAYLOAD (tb[TCA_TBF_PARMS ]) <sizeof (*qopt))return -1 ;fprintf (f,"rate %s " ,sprint_rate (qopt->rate.rate, b1)); - buffer = ((double )qopt->rate.rate*tc_core_tick2usec (qopt->buffer))/1000000 ; + buffer =tc_calc_xmitsize (qopt->rate.rate, qopt->buffer);if (show_details) {fprintf (f,"burst %s/%u mpu %s " ,sprint_size (buffer, b1),1 <<qopt->rate.cell_log,sprint_size (qopt->rate.mpu, b2));
@@ -230,7 +230,7 @@ static int tbf_print_opt(struct qdisc_utif (qopt->peakrate.rate) {fprintf (f,"peakrate %s " ,sprint_rate (qopt->peakrate.rate, b1));if (qopt->mtu || qopt->peakrate.mpu) { - mtu = ((double )qopt->peakrate.rate*tc_core_tick2usec (qopt->mtu))/1000000 ; + mtu =tc_calc_xmitsize (qopt->peakrate.rate, qopt->mtu);if (show_details) {fprintf (f,"mtu %s/%u mpu %s " ,sprint_size (mtu, b1),1 <<qopt->peakrate.cell_log,sprint_size (qopt->peakrate.mpu, b2));
tc/tc_core.c +5 -0
@@ -42,6 +42,11 @@ unsigned tc_calc_xmittime(unsigned rate,return tc_core_usec2tick (1000000 *((double )size/rate)); } +unsigned tc_calc_xmitsize (unsigned rate,unsigned ticks) +{ +return ((double )rate*tc_core_tick2usec (ticks))/1000000 ; +} +/* rtab[pkt_len>>cell_log] = pkt_xmit_time */
tc/tc_core.h +1 -0
@@ -7,6 +7,7 @@ #include <linux/pkt_sched.h>long tc_core_usec2tick (long usec);long tc_core_tick2usec (long tick);unsigned tc_calc_xmittime (unsigned rate,unsigned size); +unsigned tc_calc_xmitsize (unsigned rate,unsigned ticks);int tc_calc_rtable (unsigned bps,__u32 *rtab,int cell_log,unsigned mtu,unsigned mpu);int tc_setup_estimator (unsigned A ,unsigned time_const,struct tc_estimator *est);
PATCH 3/5 : Introduce TIME_UNITS_PER_SEC to represent internal clock resulution
In reply to Patrick McHardy[IPROUTE]: Introduce TIME_UNITS_PER_SEC to represent internal clock resulution
Introduce TIME_UNITS_PER_SEC and conversion functions between internal resulution and resulution expected by the kernel (currently implemented as NOPs, only needed by HFSC, which currently always uses microseconds).
---
commit 8e2cc14ba6fb8f940de72f307e67eb9040a5d4f7
tree da8e068525029b6571f95e7eeffcbab901f2e1be
parent 06a5350c47d028448850788031625ac1961d722b
author Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:40:34 +0200 committer Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:40:34 +0200
tc/q_hfsc.c | 12 ++++++------ tc/q_tbf.c | 4 ++-- tc/tc_cbq.c | 4 ++-- tc/tc_core.c | 14 ++++++++++++-- tc/tc_core.h | 4 ++++ tc/tc_estimator.c | 2 +- tc/tc_util.c | 14 +++++++------- 7 files changed, 34 insertions(+), 20 deletions(-)
tc/q_hfsc.c +6 -6
@@ -226,7 +226,7 @@ hfsc_print_sc(FILE *f, char *name, strucfprintf (f,"%s " , name);fprintf (f,"m1 %s " ,sprint_rate (sc->m1, b1)); -fprintf (f,"d %s " ,sprint_usecs (sc->d, b1)); +fprintf (f,"d %s " ,sprint_usecs (tc_core_ktime2time (sc->d), b1));fprintf (f,"m2 %s " ,sprint_rate (sc->m2, b1)); }
@@ -320,7 +320,7 @@ hfsc_get_sc1(int *argcp, char ***argvp,return -1 ; sc->m1 = m1; - sc->d = d; + sc->d =tc_core_time2ktime (d); sc->m2 = m2; *argvp = argv;
@@ -367,13 +367,13 @@ hfsc_get_sc2(int *argcp, char ***argvp,return -1 ; } -if (dmax !=0 &&ceil (umax *1000000.0 / dmax) > rate) { +if (dmax !=0 &&ceil (1.0 * umax *TIME_UNITS_PER_SEC / dmax) > rate) {/* * concave curve, slope of first segment is umax/dmax, * intersection is at dmax */ - sc->m1 =ceil (umax *1000000.0 / dmax);/* in bps */ - sc->d = dmax; + sc->m1 =ceil (1.0 * umax *TIME_UNITS_PER_SEC / dmax);/* in bps */ + sc->d =tc_core_time2ktime (dmax); sc->m2 = rate; }else {/*
@@ -381,7 +381,7 @@ hfsc_get_sc2(int *argcp, char ***argvp,* is at dmax - umax / rate */ sc->m1 =0 ; - sc->d =ceil (dmax - umax *1000000.0 / rate);/* in usec */ + sc->d =tc_core_time2ktime (ceil (dmax - umax *TIME_UNITS_PER_SEC / rate)); sc->m2 = rate; }
tc/q_tbf.c +2 -2
@@ -161,9 +161,9 @@ static int tbf_parse_opt(struct qdisc_ut }if (opt.limit ==0 ) { -double lim = opt.rate.rate*(double )latency/1000000 + buffer; +double lim = opt.rate.rate*(double )latency/TIME_UNITS_PER_SEC + buffer;if (opt.peakrate.rate) { -double lim2 = opt.peakrate.rate*(double )latency/1000000 + mtu; +double lim2 = opt.peakrate.rate*(double )latency/TIME_UNITS_PER_SEC + mtu;if (lim2 < lim) lim = lim2; }
tc/tc_cbq.c +2 -2
@@ -38,7 +38,7 @@ unsigned tc_cbq_calc_maxidle(unsigned bnif (vxmt > maxidle) maxidle = vxmt; } -return tc_core_usec2tick (maxidle*(1 <<ewma_log)*1000000 ); +return tc_core_usec2tick (maxidle*(1 <<ewma_log)*TIME_UNITS_PER_SEC ); } unsigned tc_cbq_calc_offtime(unsigned bndw, unsigned rate, unsigned avpkt,
@@ -53,5 +53,5 @@ unsigned tc_cbq_calc_offtime(unsigned bn offtime *=pow (g, -(double )minburst) -1 ; else offtime *= 1 + (pow(g, -(double)(minburst-1)) - 1)/(1-g); -return tc_core_usec2tick (offtime*1000000 ); +return tc_core_usec2tick (offtime*TIME_UNITS_PER_SEC ); }
tc/tc_core.c +12 -2
@@ -37,14 +37,24 @@ long tc_core_tick2usec(long tick)return tick/tick_in_usec; } +long tc_core_time2ktime (long time) +{ +return time; +} + +long tc_core_ktime2time (long ktime) +{ +return ktime; +} +unsigned tc_calc_xmittime (unsigned rate,unsigned size) { -return tc_core_usec2tick (1000000 *((double )size/rate)); +return tc_core_usec2tick (TIME_UNITS_PER_SEC *((double )size/rate)); }unsigned tc_calc_xmitsize (unsigned rate,unsigned ticks) { -return ((double )rate*tc_core_tick2usec (ticks))/1000000 ; +return ((double )rate*tc_core_tick2usec (ticks))/TIME_UNITS_PER_SEC ; }/*
tc/tc_core.h +4 -0
@@ -4,8 +4,12 @@ #define _TC_CORE_H_ 1#include <asm/types.h> #include <linux/pkt_sched.h> +#define TIME_UNITS_PER_SEC 1000000 +long tc_core_usec2tick (long usec);long tc_core_tick2usec (long tick); +long tc_core_time2ktime (long time); +long tc_core_ktime2time (long ktime);unsigned tc_calc_xmittime (unsigned rate,unsigned size);unsigned tc_calc_xmitsize (unsigned rate,unsigned ticks);int tc_calc_rtable (unsigned bps,__u32 *rtab,int cell_log,unsigned mtu,unsigned mpu);
tc/tc_estimator.c +1 -1
@@ -26,7 +26,7 @@ #include "tc_core.h"int tc_setup_estimator (unsigned A ,unsigned time_const,struct tc_estimator *est) {for (est->interval=0 ; est->interval<=5 ; est->interval++) { -if (A <= (1 <<est->interval)*(1000000 /4 )) +if (A <= (1 <<est->interval)*(TIME_UNITS_PER_SEC /4 ))break ; }if (est->interval >5 )
tc/tc_util.c +7 -7
@@ -221,13 +221,13 @@ int get_usecs(unsigned *usecs, const chaif (*p) {if (strcasecmp (p,"s" ) ==0 ||strcasecmp (p,"sec" )==0 ||strcasecmp (p,"secs" )==0 ) - t *=1000000 ; + t *=TIME_UNITS_PER_SEC ;else if (strcasecmp (p,"ms" ) ==0 ||strcasecmp (p,"msec" )==0 ||strcasecmp (p,"msecs" ) ==0 ) - t *=1000 ; + t *=TIME_UNITS_PER_SEC /1000 ;else if (strcasecmp (p,"us" ) ==0 ||strcasecmp (p,"usec" )==0 ||strcasecmp (p,"usecs" ) ==0 ) - t *=1 ; + t *=TIME_UNITS_PER_SEC /1000000 ;else return -1 ; }
@@ -241,10 +241,10 @@ void print_usecs(char *buf, int len, __u {double tmp = usec; -if (tmp >=1000000 ) -snprintf (buf, len,"%.1fs" , tmp/1000000 ); -else if (tmp >=1000 ) -snprintf (buf, len,"%.1fms" , tmp/1000 ); +if (tmp >=TIME_UNITS_PER_SEC ) +snprintf (buf, len,"%.1fs" , tmp/TIME_UNITS_PER_SEC ); +else if (tmp >=TIME_UNITS_PER_SEC /1000 ) +snprintf (buf, len,"%.1fms" , tmp/(TIME_UNITS_PER_SEC /1000 ));else snprintf (buf, len,"%uus" , usec); }
PATCH 4/5 : Replace "usec" by "time" in function names
In reply to Patrick McHardy[IPROUTE]: Replace "usec" by "time" in function names
Rename functions containing "usec" since they don't necessarily return usec units anymore.
---
commit 67edfb2c86323a1c52a60538f677310f6c75efdf
tree 37302dfd036340aac8c7f2070ebcbc570fd634ed
parent 8e2cc14ba6fb8f940de72f307e67eb9040a5d4f7
author Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:47:14 +0200 committer Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:47:14 +0200
tc/m_estimator.c | 4 ++-- tc/q_cbq.c | 6 +++--- tc/q_hfsc.c | 6 +++--- tc/q_netem.c | 6 +++--- tc/q_tbf.c | 8 ++++---- tc/tc_cbq.c | 4 ++-- tc/tc_core.c | 10 +++++----- tc/tc_core.h | 4 ++-- tc/tc_util.c | 14 +++++++------- tc/tc_util.h | 6 +++--- 10 files changed, 34 insertions(+), 34 deletions(-)
tc/m_estimator.c +2 -2
@@ -45,12 +45,12 @@ int parse_estimator(int *p_argc, char **duparg ("estimator" , *argv);if (matches (*argv,"help" ) ==0 )est_help (); -if (get_usecs (&A , *argv)) +if (get_time (&A , *argv))invarg ("estimator" ,"invalid estimator interval" );NEXT_ARG ();if (matches (*argv,"help" ) ==0 )est_help (); -if (get_usecs (&time_const, *argv)) +if (get_time (&time_const, *argv))invarg ("estimator" ,"invalid estimator time constant" );if (tc_setup_estimator (A , time_const, est) <0 ) {fprintf (stderr,"Error: estimator parameters are out of range.\n" );
tc/q_cbq.c +3 -3
@@ -500,17 +500,17 @@ static int cbq_print_opt(struct qdisc_utif (lss && show_details) {fprintf (f,"\nlevel %u ewma %u avpkt %ub " , lss->level, lss->ewma_log, lss->avpkt);if (lss->maxidle) { -fprintf (f,"maxidle %luus " ,tc_core_tick2usec (lss->maxidle>>lss->ewma_log)); +fprintf (f,"maxidle %luus " ,tc_core_tick2time (lss->maxidle>>lss->ewma_log));if (show_raw)fprintf (f,"[%08x] " , lss->maxidle); }if (lss->minidle!=0x7fffffff ) { -fprintf (f,"minidle %luus " ,tc_core_tick2usec (lss->minidle>>lss->ewma_log)); +fprintf (f,"minidle %luus " ,tc_core_tick2time (lss->minidle>>lss->ewma_log));if (show_raw)fprintf (f,"[%08x] " , lss->minidle); }if (lss->offtime) { -fprintf (f,"offtime %luus " ,tc_core_tick2usec (lss->offtime)); +fprintf (f,"offtime %luus " ,tc_core_tick2time (lss->offtime));if (show_raw)fprintf (f,"[%08x] " , lss->offtime); }
tc/q_hfsc.c +3 -3
@@ -226,7 +226,7 @@ hfsc_print_sc(FILE *f, char *name, strucfprintf (f,"%s " , name);fprintf (f,"m1 %s " ,sprint_rate (sc->m1, b1)); -fprintf (f,"d %s " ,sprint_usecs (tc_core_ktime2time (sc->d), b1)); +fprintf (f,"d %s " ,sprint_time (tc_core_ktime2time (sc->d), b1));fprintf (f,"m2 %s " ,sprint_rate (sc->m2, b1)); }
@@ -303,7 +303,7 @@ hfsc_get_sc1(int *argcp, char ***argvp,if (matches (*argv,"d" ) ==0 ) {NEXT_ARG (); -if (get_usecs (&d, *argv) <0 ) { +if (get_time (&d, *argv) <0 ) {explain1 ("d" );return -1 ; }
@@ -346,7 +346,7 @@ hfsc_get_sc2(int *argcp, char ***argvp,if (matches (*argv,"dmax" ) ==0 ) {NEXT_ARG (); -if (get_usecs (&dmax, *argv) <0 ) { +if (get_time (&dmax, *argv) <0 ) {explain1 ("dmax" );return -1 ; }
tc/q_netem.c +3 -3
@@ -108,16 +108,16 @@ static int get_ticks(__u32 *ticks, const {unsigned t; -if (get_usecs (&t, str)) +if (get_time (&t, str))return -1 ; - *ticks =tc_core_usec2tick (t); + *ticks =tc_core_time2tick (t);return 0 ; }static char *sprint_ticks (__u32 ticks,char *buf) { -return sprint_usecs (tc_core_tick2usec (ticks), buf); +return sprint_time (tc_core_tick2time (ticks), buf); }
tc/q_tbf.c +4 -4
@@ -67,7 +67,7 @@ static int tbf_parse_opt(struct qdisc_utfprintf (stderr,"Double \"limit/latency\" spec\n" );return -1 ; } -if (get_usecs (&latency, *argv)) { +if (get_time (&latency, *argv)) {explain1 ("latency" );return -1 ; }
@@ -245,13 +245,13 @@ static int tbf_print_opt(struct qdisc_utif (show_raw)fprintf (f,"limit %s " ,sprint_size (qopt->limit, b1)); - latency =tc_calc_xmittime (qopt->rate.rate, qopt->limit) -tc_core_tick2usec (qopt->buffer); + latency =tc_calc_xmittime (qopt->rate.rate, qopt->limit) -tc_core_tick2time (qopt->buffer);if (qopt->peakrate.rate) { -double lat2 =tc_calc_xmittime (qopt->peakrate.rate, qopt->limit) -tc_core_tick2usec (qopt->mtu); +double lat2 =tc_calc_xmittime (qopt->peakrate.rate, qopt->limit) -tc_core_tick2time (qopt->mtu);if (lat2 > latency) latency = lat2; } -fprintf (f,"lat %s " ,sprint_usecs (tc_core_tick2usec (latency), b1)); +fprintf (f,"lat %s " ,sprint_time (tc_core_tick2time (latency), b1));return 0 ; }
tc/tc_cbq.c +2 -2
@@ -38,7 +38,7 @@ unsigned tc_cbq_calc_maxidle(unsigned bnif (vxmt > maxidle) maxidle = vxmt; } -return tc_core_usec2tick (maxidle*(1 <<ewma_log)*TIME_UNITS_PER_SEC ); +return tc_core_time2tick (maxidle*(1 <<ewma_log)*TIME_UNITS_PER_SEC ); } unsigned tc_cbq_calc_offtime(unsigned bndw, unsigned rate, unsigned avpkt,
@@ -53,5 +53,5 @@ unsigned tc_cbq_calc_offtime(unsigned bn offtime *=pow (g, -(double )minburst) -1 ; else offtime *= 1 + (pow(g, -(double)(minburst-1)) - 1)/(1-g); -return tc_core_usec2tick (offtime*TIME_UNITS_PER_SEC ); +return tc_core_time2tick (offtime*TIME_UNITS_PER_SEC ); }
tc/tc_core.c +5 -5
@@ -27,12 +27,12 @@ static __u32 t2us=1;static __u32 us2t=1 ;static double tick_in_usec =1 ; -long tc_core_usec2tick (long usec) +long tc_core_time2tick (long time) { -return usec*tick_in_usec; +return time*tick_in_usec; } -long tc_core_tick2usec (long tick) +long tc_core_tick2time (long tick) {return tick/tick_in_usec; }
@@ -49,12 +49,12 @@ long tc_core_ktime2time(long ktime)unsigned tc_calc_xmittime (unsigned rate,unsigned size) { -return tc_core_usec2tick (TIME_UNITS_PER_SEC *((double )size/rate)); +return tc_core_time2tick (TIME_UNITS_PER_SEC *((double )size/rate)); }unsigned tc_calc_xmitsize (unsigned rate,unsigned ticks) { -return ((double )rate*tc_core_tick2usec (ticks))/TIME_UNITS_PER_SEC ; +return ((double )rate*tc_core_tick2time (ticks))/TIME_UNITS_PER_SEC ; }/*
tc/tc_core.h +2 -2
@@ -6,8 +6,8 @@ #include <linux/pkt_sched.h>#define TIME_UNITS_PER_SEC 1000000 -long tc_core_usec2tick (long usec); -long tc_core_tick2usec (long tick); +long tc_core_time2tick (long time); +long tc_core_tick2time (long tick);long tc_core_time2ktime (long time);long tc_core_ktime2time (long ktime);unsigned tc_calc_xmittime (unsigned rate,unsigned size);
tc/tc_util.c +7 -7
@@ -209,7 +209,7 @@ char * sprint_rate(__u32 rate, char *bufreturn buf; } -int get_usecs (unsigned *usecs,const char *str) +int get_time (unsigned *time,const char *str) {double t;char *p;
@@ -232,26 +232,26 @@ int get_usecs(unsigned *usecs, const chareturn -1 ; } - *usecs = t; + *time = t;return 0 ; } -void print_usecs (char *buf,int len,__u32 usec) +void print_time (char *buf,int len,__u32 time) { -double tmp = usec; +double tmp = time;if (tmp >=TIME_UNITS_PER_SEC )snprintf (buf, len,"%.1fs" , tmp/TIME_UNITS_PER_SEC );else if (tmp >=TIME_UNITS_PER_SEC /1000 )snprintf (buf, len,"%.1fms" , tmp/(TIME_UNITS_PER_SEC /1000 ));else -snprintf (buf, len,"%uus" , usec); +snprintf (buf, len,"%uus" , time); } -char *sprint_usecs (__u32 usecs,char *buf) +char *sprint_time (__u32 time,char *buf) { -print_usecs (buf,SPRINT_BSIZE -1 , usecs); +print_time (buf,SPRINT_BSIZE -1 , time);return buf; }
tc/tc_util.h +3 -3
@@ -46,17 +46,17 @@ extern int get_rate(unsigned *rate, consextern int get_percent (unsigned *percent,const char *str);extern int get_size (unsigned *size,const char *str);extern int get_size_and_cell (unsigned *size,int *cell_log,char *str); -extern int get_usecs (unsigned *usecs,const char *str); +extern int get_time (unsigned *time,const char *str);extern void print_rate (char *buf,int len,__u32 rate);extern void print_size (char *buf,int len,__u32 size);extern void print_percent (char *buf,int len,__u32 percent);extern void print_qdisc_handle (char *buf,int len,__u32 h); -extern void print_usecs (char *buf,int len,__u32 usecs); +extern void print_time (char *buf,int len,__u32 time);extern char *sprint_rate (__u32 rate,char *buf);extern char *sprint_size (__u32 size,char *buf);extern char *sprint_qdisc_handle (__u32 h,char *buf);extern char *sprint_tc_classid (__u32 h,char *buf); -extern char *sprint_usecs (__u32 usecs,char *buf); +extern char *sprint_time (__u32 time,char *buf);extern char *sprint_percent (__u32 percent,char *buf);extern void print_tcstats_attr (FILE *fp,struct rtattr *tb[],char *prefix,struct rtattr **xstats);
PATCH 5/5 : Add sprint_ticks() function and use in CBQ
In reply to Patrick McHardy[IPROUTE]: Add sprint_ticks() function and use in CBQ
Add helper function to print ticks to avoid assumptions about clock resolution in CBQ.
---
commit 182666ac89f3089a1771564620998fb4f315bd87
tree ce7c3109b7e8ff9a4665e175490a62f8c300ea33
parent 67edfb2c86323a1c52a60538f677310f6c75efdf
author Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:52:11 +0200 committer Patrick McHardy <[email protected]> Fri, 23 Jun 2006 19:52:11 +0200
tc/q_cbq.c | 7 ++++--- tc/q_netem.c | 6 ------ tc/tc_util.c | 5 +++++ tc/tc_util.h | 1 + 4 files changed, 10 insertions(+), 9 deletions(-)
tc/q_cbq.c +4 -3
@@ -418,6 +418,7 @@ static int cbq_print_opt(struct qdisc_utstruct tc_cbq_wrropt *wrr =NULL ;struct tc_cbq_fopt *fopt =NULL ;struct tc_cbq_ovl *ovl =NULL ; +SPRINT_BUF (b1);if (opt ==NULL )return 0 ;
@@ -500,17 +501,17 @@ static int cbq_print_opt(struct qdisc_utif (lss && show_details) {fprintf (f,"\nlevel %u ewma %u avpkt %ub " , lss->level, lss->ewma_log, lss->avpkt);if (lss->maxidle) { -fprintf (f,"maxidle %luus " ,tc_core_tick2time (lss->maxidle>>lss->ewma_log)); +fprintf (f,"maxidle %s " ,sprint_ticks (lss->maxidle>>lss->ewma_log, b1));if (show_raw)fprintf (f,"[%08x] " , lss->maxidle); }if (lss->minidle!=0x7fffffff ) { -fprintf (f,"minidle %luus " ,tc_core_tick2time (lss->minidle>>lss->ewma_log)); +fprintf (f,"minidle %s " ,sprint_ticks (lss->minidle>>lss->ewma_log, b1));if (show_raw)fprintf (f,"[%08x] " , lss->minidle); }if (lss->offtime) { -fprintf (f,"offtime %luus " ,tc_core_tick2time (lss->offtime)); +fprintf (f,"offtime %s " ,sprint_ticks (lss->offtime, b1));if (show_raw)fprintf (f,"[%08x] " , lss->offtime); }
tc/q_netem.c +0 -6
@@ -115,12 +115,6 @@ static int get_ticks(__u32 *ticks, constreturn 0 ; } -static char *sprint_ticks (__u32 ticks,char *buf) -{ -return sprint_time (tc_core_tick2time (ticks), buf); -} - -static int netem_parse_opt (struct qdisc_util *qu,int argc,char **argv,struct nlmsghdr *n) {
tc/tc_util.c +5 -0
@@ -255,6 +255,11 @@ char * sprint_time(__u32 time, char *bufreturn buf; } +char *sprint_ticks (__u32 ticks,char *buf) +{ +return sprint_time (tc_core_tick2time (ticks), buf); +} +int get_size (unsigned *size,const char *str) {double sz;
tc/tc_util.h +1 -0
@@ -57,6 +57,7 @@ extern char * sprint_size(__u32 size, chextern char *sprint_qdisc_handle (__u32 h,char *buf);extern char *sprint_tc_classid (__u32 h,char *buf);extern char *sprint_time (__u32 time,char *buf); +extern char *sprint_ticks (__u32 ticks,char *buf);extern char *sprint_percent (__u32 percent,char *buf);extern void print_tcstats_attr (FILE *fp,struct rtattr *tb[],char *prefix,struct rtattr **xstats);
D'oh, got Stephen's address wrong. Please fix it (add 's' in front) in replies to this thread.
Quoted 42 lines · Patrick McHardy
I'm currently adding support for ktime as clocksource to the qdisc layer and in the course of doing that cleaned up the iproute time handling a bit to make it easier to use a different internal clock resultion and audit for integer overflows.
Increasing iproutes internal clock resolution is necessary for all token bucket based schedulers to take advantage of a higher kernel clock resolution because the kernel only does lookups and additions/subtractions, which can never result in values that have a higher precision that those passed from userspace.
The way I imagine it we have to keep the old clock sources around for userspace compatibility since they can't deal with the higher precision values. iproute is changed to use nsec internally and reads the kernel clock resulution from
/proc/net/psched(third value, currently assumed to always be 10^6) to convert it's internal resolution to that of the kernel. With ktime as clocksource the kernel will report a resulution of 10^9. The downside is that distributors can't enable ktime unless they want to break compatibility with old iproute versions. Any better suggestions are welcome of course.tc/m_estimator.c | 4 ++-- tc/m_police.c | 2 +- tc/q_cbq.c | 15 ++++++++------- tc/q_hfsc.c | 18 +++++++++--------- tc/q_htb.c | 4 ++-- tc/q_netem.c | 12 +++--------- tc/q_tbf.c | 20 ++++++++++---------- tc/tc_cbq.c | 8 ++++---- tc/tc_core.c | 31 +++++++++++++++++++++++-------- tc/tc_core.h | 9 +++++++-- tc/tc_estimator.c | 2 +- tc/tc_red.c | 2 +- tc/tc_util.c | 33 +++++++++++++++++++-------------- tc/tc_util.h | 7 ++++--- 14 files changed, 94 insertions(+), 73 deletions(-)Patrick McHardy:
[IPROUTE]: Usetc_calc_xmittimewhere appropriate
[IPROUTE]: Introducetc_calc_xmitsizeand use where appropriate [IPROUTE]: IntroduceTIME_UNITS_PER_SECto represent internal clock resulution [IPROUTE]: Replace "usec" by "time" in function names
[IPROUTE]: Addsprint_ticks()function and use in CBQ
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Fri, 23 Jun 2006 20:09:18 +0200
Quoted 2 lines
D'oh, got Stephen's address wrong. Please fix it (add 's' in front) in replies to this thread.
Stephen's also on vacation for a week, so it might be a while until this stuff is integrated :)