From: Kevin Wolf <kwolf@redhat.com>
To: Dmitry Konishchev <konishchev@gmail.com>
Cc: Stefan Hajnoczi <stefanha@gmail.com>,
qemu-devel@nongnu.org, stanislav.ievlev@gmail.com
Subject: Re: [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization
Date: Wed, 18 May 2011 11:31:40 +0200 [thread overview]
Message-ID: <4DD391FC.6070101@redhat.com> (raw)
In-Reply-To: <4DD38F03.7020209@gmail.com>
Am 18.05.2011 11:18, schrieb Dmitry Konishchev:
> On 18.05.2011 11:57, Stefan Hajnoczi wrote:
>> Yes, optimizing is_not_zero() is good. The only additional thing I
>> suggest is adding a comment before the function to document the length
>> constraint.
>
> OK, fixed.
>
>
> On 18.05.2011 12:05, Kevin Wolf wrote:
>> A future bdrv_is_allocated() patch must make sure that the conversion
>> falls back to a simple is_not_zero() when a backing file is used.
>
> Thanks, I'll take this into account.
>
>
> Signed-off-by: Dmitry Konishchev <konishchev@gmail.com>
> ---
> qemu-img.c | 30 +++++++++++++++++++++++++++---
> 1 files changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index e825123..7665c2f 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -496,14 +496,38 @@ static int img_commit(int argc, char **argv)
> return 0;
> }
>
> +/*
> + * Checks whether the sector is not a zero sector.
> + *
> + * Attention! The len must be a multiple of 4 * sizeof(long) due to
> + * restriction of optimizations in this function.
> + */
> static int is_not_zero(const uint8_t *sector, int len)
> {
> + /*
> + * Use long as the biggest available internal data type that fits
> into the
> + * CPU register and unroll the loop to smooth out the effect of memory
> + * latency.
> + */
> +
> int i;
> - len >>= 2;
> - for(i = 0;i < len; i++) {
> - if (((uint32_t *)sector)[i] != 0)
> + len /= sizeof(long);
> +
> + long d0;
> + long d1;
> + long d2;
> + long d3;
Please move the declarations to the start of the function.
I also would use a single line like "long d0, d1, d2, d3;", but that's
up to you.
> +
> + for(i = 0; i < len; i += 4) {
> + d0 = ((const long*) sector)[i + 0];
> + d1 = ((const long*) sector)[i + 1];
> + d2 = ((const long*) sector)[i + 2];
> + d3 = ((const long*) sector)[i + 3];
I would suggest to declare a const long* variable so that you don't have
to cast each time you use, but that's probably a matter of taste.
> +
> + if (d0 || d1 || d2 || d3)
> return 1;
Coding style requires braces here.
> }
> +
> return 0;
> }
Please make sure that your patch isn't line-wrapped when you send it for
inclusion. git send-email will do the right thing.
Kevin
next prev parent reply other threads:[~2011-05-18 9:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-17 14:33 [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization Dmitry Konishchev
2011-05-17 15:35 ` Stefan Hajnoczi
2011-05-18 6:55 ` Dmitry Konishchev
2011-05-18 7:57 ` Stefan Hajnoczi
2011-05-18 8:05 ` Kevin Wolf
2011-05-18 9:18 ` Dmitry Konishchev
2011-05-18 9:31 ` Kevin Wolf [this message]
2011-05-18 10:27 ` Dmitry Konishchev
2011-05-18 11:03 ` [Qemu-devel] [PATCH] is_not_zero() optimization in qemu-img Dmitry Konishchev
2011-05-18 12:14 ` Kevin Wolf
2011-05-18 9:40 ` [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization Peter Maydell
2011-05-18 9:40 ` Peter Maydell
2011-05-18 10:27 ` Dmitry Konishchev
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=4DD391FC.6070101@redhat.com \
--to=kwolf@redhat.com \
--cc=konishchev@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=stanislav.ievlev@gmail.com \
--cc=stefanha@gmail.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;
as well as URLs for NNTP newsgroup(s).