print_rate: use knowledge in rate_suffix table for human readable rates.
Subsystems (2)
PATCH 1/1 print_rate: use knowledge in rate_suffix table for human readable rates.
Signed-off-by Vimalkumar <[email protected]>
--- tc/tc_util.c | 26 ++++++++++++-------------- 1 files changed, 12 insertions(+), 14 deletions(-)
tc/tc_util.c +12 -14
@@ -139,7 +139,8 @@ static const struct rate_suffix { { "GBps", 8000000000. }, { "TiBps", 8.*1024.*1024.*1024.*1024. }, { "TBps", 8000000000000. }, - { NULL } + { NULL }, + { NULL }, };
@@ -171,21 +172,18 @@ void print_rate(char *buf, int len, __u64 rate) {double tmp = (double )rate*8 ;extern int use_iec; +int start =0 ; +const struct rate_suffix *s;if (use_iec) { -if (tmp >=1000.0 *1024.0 *1024.0 ) -snprintf (buf, len,"%.0fMibit" , tmp/(1024.0 *1024.0 )); -else if (tmp >=1000.0 *1024 ) -snprintf (buf, len,"%.0fKibit" , tmp/1024 ); -else -snprintf (buf, len,"%.0fbit" , tmp); - }else { -if (tmp >=1000.0 *1000000.0 ) -snprintf (buf, len,"%.0fMbit" , tmp/1000000.0 ); -else if (tmp >=1000.0 *1000.0 ) -snprintf (buf, len,"%.0fKbit" , tmp/1000.0 ); -else -snprintf (buf, len,"%.0fbit" , tmp); + start =1 ; + } + +snprintf (buf, len,"%.0fbit" , tmp); +for (s = &suffixes[start]; s->name; s +=2 ) { +if (tmp >= s->scale) { +snprintf (buf, len,"%.3f%s" , tmp / s->scale, s->name); + } } }
Signature · 1 line
1.7.5.3
Quoted 10 lines · Vimalkumar
Signed-off-by Vimalkumar <[email protected]>--- tc/tc_util.c | 26 ++++++++++++-------------- 1 files changed, 12 insertions(+), 14 deletions(-)tc/tc_util.c +0
-0
tc/tc_util.c static const struct rate_suffix { · line 145
Quoted 8 lines
tc/tc_util.c +2
-1@@ -139,7 +139,8 @@ static const struct rate_suffix { { "GBps", 8000000000. }, { "TiBps", 8.*1024.*1024.*1024.*1024. }, { "TBps", 8000000000000. }, - { NULL } + { NULL }, + { NULL }, };
You'll have to explicitly add in the title a way to say its a patch for iproute2.
[PATCH iproute2] tc: use knowledge in rate_suffix table for human readable rates.
To avoid the confusion, as netdev is more likely to review kernel patches.
Quoted 42 lines · On Sat, 9 Mar 2013 19:26:38 -0800 Vimalkumar <[email protected]> wrote:
Signed-off-by Vimalkumar <[email protected]>--- tc/tc_util.c | 26 ++++++++++++-------------- 1 files changed, 12 insertions(+), 14 deletions(-)tc/tc_util.c +5
-14@@ -139,7 +139,8 @@ static const struct rate_suffix { { "GBps", 8000000000. }, { "TiBps", 8.*1024.*1024.*1024.*1024. }, { "TBps", 8000000000000. }, - { NULL } + { NULL }, + { NULL }, };@@ -171,21 +172,18 @@ void print_rate(char *buf, int len, __u64 rate) {double tmp = (double )rate*8 ;extern int use_iec; +int start =0 ; +const struct rate_suffix *s;if (use_iec) { -if (tmp >=1000.0 *1024.0 *1024.0 ) -snprintf (buf, len,"%.0fMibit" , tmp/(1024.0 *1024.0 )); -else if (tmp >=1000.0 *1024 ) -snprintf (buf, len,"%.0fKibit" , tmp/1024 ); -else -snprintf (buf, len,"%.0fbit" , tmp); - }else { -if (tmp >=1000.0 *1000000.0 ) -snprintf (buf, len,"%.0fMbit" , tmp/1000000.0 ); -else if (tmp >=1000.0 *1000.0 ) -snprintf (buf, len,"%.0fKbit" , tmp/1000.0 ); -else -snprintf (buf, len,"%.0fbit" , tmp); + start =1 ;
tc/tc_util.c void print_rate(char *buf, int len, __u64 rate) · line 189
Quoted 10 lines
tc/tc_util.c +7
-0+ } + +snprintf (buf, len,"%.0fbit" , tmp); +for (s = &suffixes[start]; s->name; s +=2 ) { +if (tmp >= s->scale) { +snprintf (buf, len,"%.3f%s" , tmp / s->scale, s->name); + } } }
Sorry, can't accept this because your patch loses functionality. The iec flag was added for those people who
prefer iec (1024 bit) intervals. Your patch gets rid of that.