From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: James Bottomley <jbottomley@odin.com>
Cc: "vkuznets\@redhat.com" <vkuznets@redhat.com>,
"ulf.hansson\@linaro.org" <ulf.hansson@linaro.org>,
"andriy.shevchenko\@linux.intel.com"
<andriy.shevchenko@linux.intel.com>,
"keescook\@chromium.org" <keescook@chromium.org>,
"linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"akpm\@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re: [PATCH v3 1/4] lib/string_helpers: change blk_size to u32 for string_get_size() interface
Date: Tue, 03 Nov 2015 21:57:36 +0100 [thread overview]
Message-ID: <87h9l2dcn3.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <1446570148.6440.11.camel@Odin.com> (James Bottomley's message of "Tue, 3 Nov 2015 17:02:29 +0000")
On Tue, Nov 03 2015, James Bottomley <jbottomley@odin.com> wrote:
>
> It was a suggestion when I explained what the missing sources of
> precision were, I don't think it's really a suggestion when it comes
> with an exemplary patch.
ex·em·pla·ry
adjective
1.
serving as a desirable model; representing the best of its kind.
Said exemplary patch produces "1.10 KiB" for size=2047,
blk_size=1. (This is caused by the introduction of rounding, and is
probably fixable.)
James, I do understand the algorithm you're trying to use. What I don't
understand is why you insist on using the approach of reducing size and
blk_size all the way before multiplying them. It seems much simpler to
just reduce them till they're below U32_MAX (not keeping track of any
remainders at that point), multiply them, and then proceed as usual,
This avoids having to deal with weird cross-multiplication terms, gives
more accurate results (yes, I tested that) and avoids the extra 64/32
division you introduce by decrementing i.
Rasmus
To be precise, the body I suggest is
while (blk_size > U32_MAX) {
do_div(blk_size, divisor[units]);
i++;
}
while (size > U32_MAX) {
do_div(size, divisor[units]);
i++;
}
size *= blk_size;
while (size > divisor[units]) {
remainder = do_div(size, divisor[units]);
i++;
}
whether the last one should be > or >= is debatable; I think 1024 KiB is
better than 1.00 MiB.
next prev parent reply other threads:[~2015-11-03 20:57 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-29 16:30 [PATCH v3 0/4] lib/string_helpers: fix precision issues and introduce tests Vitaly Kuznetsov
2015-10-29 16:30 ` [PATCH v3 1/4] lib/string_helpers: change blk_size to u32 for string_get_size() interface Vitaly Kuznetsov
2015-10-29 22:27 ` James Bottomley
2015-10-29 23:19 ` Rasmus Villemoes
2015-10-29 23:24 ` Rasmus Villemoes
2015-10-30 3:33 ` James Bottomley
2015-10-30 10:46 ` Vitaly Kuznetsov
2015-10-31 0:21 ` James Bottomley
2015-11-02 15:58 ` Vitaly Kuznetsov
2015-11-03 3:40 ` James Bottomley
2015-11-03 13:13 ` Vitaly Kuznetsov
2015-11-03 17:02 ` James Bottomley
2015-11-03 20:57 ` Rasmus Villemoes [this message]
2015-11-03 21:19 ` James Bottomley
2015-10-29 16:30 ` [PATCH v3 2/4] lib/string_helpers.c: protect string_get_size() against blk_size=0 Vitaly Kuznetsov
2015-10-29 21:24 ` Andy Shevchenko
2015-10-29 23:00 ` James Bottomley
2015-10-29 23:32 ` Andy Shevchenko
2015-10-30 3:34 ` James Bottomley
2015-10-30 10:41 ` Vitaly Kuznetsov
2015-10-31 0:07 ` James Bottomley
2015-10-29 16:30 ` [PATCH v3 3/4] lib/string_helpers.c: don't lose precision in string_get_size() Vitaly Kuznetsov
2015-10-29 21:22 ` Andy Shevchenko
2015-10-29 16:30 ` [PATCH v3 4/4] lib/test-string_helpers.c: add string_get_size() tests Vitaly Kuznetsov
2015-10-29 21:33 ` Andy Shevchenko
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=87h9l2dcn3.fsf@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=jbottomley@odin.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ulf.hansson@linaro.org \
--cc=vkuznets@redhat.com \
/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
Powered by JetHome