From: Petr Machata <me@pmachata•org>
To: Stephen Hemminger <stephen@networkplumber•org>
Cc: Petr Machata <me@pmachata•org>,
netdev@vger•kernel.org, dsahern@gmail•com, Po.Liu@nxp•com,
toke@toke•dk, dave.taht@gmail•com, edumazet@google•com,
tahiliani@nitk•edu.in, leon@kernel•org
Subject: Re: [PATCH iproute2-next 3/6] lib: Move sprint_size() from tc here, add print_size()
Date: Tue, 01 Dec 2020 23:41:29 +0100 [thread overview]
Message-ID: <87k0u1no8g.fsf@nvidia.com> (raw)
In-Reply-To: <20201130163904.14110c5c@hermes.local>
Stephen Hemminger <stephen@networkplumber•org> writes:
> On Mon, 30 Nov 2020 23:59:39 +0100
> Petr Machata <me@pmachata•org> wrote:
>
>> +char *sprint_size(__u32 sz, char *buf)
>> +{
>> + size_t len = SPRINT_BSIZE - 1;
>> + double tmp = sz;
>> +
>> + if (sz >= 1024*1024 && fabs(1024*1024*rint(tmp/(1024*1024)) - sz) < 1024)
>> + snprintf(buf, len, "%gMb", rint(tmp/(1024*1024)));
>> + else if (sz >= 1024 && fabs(1024*rint(tmp/1024) - sz) < 16)
>> + snprintf(buf, len, "%gKb", rint(tmp/1024));
>> + else
>> + snprintf(buf, len, "%ub", sz);
>> +
>> + return buf;
>> +}
>
> Add some whitespace here and maybe some constants like mb and kb?
Sure.
> Also, instead of magic SPRINT_BSIZE, why not take a len param (and
> name it snprint_size)?
Because keeping the interface like this makes it possible to reuse the
macroized bits in q_cake. I feel like the three current users are
auditable enough that the implied length is not a big deal. And no new
users should pop up, as the comment at the function makes clear.
> Yes when you copy/paste code it is good time to get it back to current
> style standards.
next prev parent reply other threads:[~2020-12-01 22:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-30 22:59 [PATCH iproute2-next 0/6] Move rate and size parsing and output to lib Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 1/6] Move the use_iec declaration to the tools Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 2/6] lib: Move print_rate() from tc here; modernize Petr Machata
2020-12-01 0:35 ` Stephen Hemminger
2020-12-01 22:56 ` Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 3/6] lib: Move sprint_size() from tc here, add print_size() Petr Machata
2020-12-01 0:39 ` Stephen Hemminger
2020-12-01 22:41 ` Petr Machata [this message]
2020-12-02 4:07 ` David Ahern
2020-11-30 22:59 ` [PATCH iproute2-next 4/6] lib: Move get_rate(), get_rate64() from tc here Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 5/6] lib: Move get_size() " Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 6/6] lib: print_rate(): Fix formatting small rates in IEC mode Petr Machata
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=87k0u1no8g.fsf@nvidia.com \
--to=me@pmachata$(echo .)org \
--cc=Po.Liu@nxp$(echo .)com \
--cc=dave.taht@gmail$(echo .)com \
--cc=dsahern@gmail$(echo .)com \
--cc=edumazet@google$(echo .)com \
--cc=leon@kernel$(echo .)org \
--cc=netdev@vger$(echo .)kernel.org \
--cc=stephen@networkplumber$(echo .)org \
--cc=tahiliani@nitk$(echo .)edu.in \
--cc=toke@toke$(echo .)dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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