From: Dmitry Konishchev <konishchev@gmail.com>
To: Kevin Wolf <kwolf@redhat.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 14:27:07 +0400 [thread overview]
Message-ID: <4DD39EFB.8050400@gmail.com> (raw)
In-Reply-To: <4DD391FC.6070101@redhat.com>
On 18.05.2011 13:31, Kevin Wolf wrote:
> 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;
>> }
OK, fixed.
Signed-off-by: Dmitry Konishchev <konishchev@gmail.com>
---
qemu-img.c | 29 ++++++++++++++++++++++++++---
1 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index e825123..c849c6f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -496,14 +496,37 @@ 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)
+ long d0, d1, d2, d3;
+ const long * const data = (const long *) sector;
+
+ len /= sizeof(long);
+
+ for(i = 0; i < len; i += 4) {
+ d0 = data[i + 0];
+ d1 = data[i + 1];
+ d2 = data[i + 2];
+ d3 = data[i + 3];
+
+ if (d0 || d1 || d2 || d3) {
return 1;
+ }
}
+
return 0;
}
--
1.7.4.1
next prev parent reply other threads:[~2011-05-18 10:27 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
2011-05-18 10:27 ` Dmitry Konishchev [this message]
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=4DD39EFB.8050400@gmail.com \
--to=konishchev@gmail.com \
--cc=kwolf@redhat.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).