All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Konishchev <konishchev@gmail.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	stanislav.ievlev@gmail.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] [qemu-img] CPU consuming optimization
Date: Wed, 18 May 2011 13:18:59 +0400	[thread overview]
Message-ID: <4DD38F03.7020209@gmail.com> (raw)
In-Reply-To: <BANLkTinbceD4PVaHabCzYxyT7EtFnTNKtg@mail.gmail.com>

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;
+
+    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];
+
+        if (d0 || d1 || d2 || d3)
              return 1;
      }
+
      return 0;
  }

-- 
1.7.4.1

  parent reply	other threads:[~2011-05-18  9:19 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 [this message]
2011-05-18  9:31         ` Kevin Wolf
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=4DD38F03.7020209@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.