From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFJho-0001rQ-5z for qemu-devel@nongnu.org; Tue, 12 Mar 2013 03:33:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFJhj-000552-9a for qemu-devel@nongnu.org; Tue, 12 Mar 2013 03:33:04 -0400 Received: from ssl.dlhnet.de ([91.198.192.8]:41956 helo=ssl.dlh.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFJhj-00054h-3W for qemu-devel@nongnu.org; Tue, 12 Mar 2013 03:32:59 -0400 Message-ID: <513EDA2B.5040608@dlhnet.de> Date: Tue, 12 Mar 2013 08:32:59 +0100 From: Peter Lieven MIME-Version: 1.0 References: <513DDFA3.1020308@dlhnet.de> <513DE6D6.9000105@redhat.com> <513DEBCF.9050407@redhat.com> <513DF854.80003@redhat.com> <32589117-17AC-4A82-820F-364CA5EEC23E@dlhnet.de> <513DFF33.5080400@redhat.com> <513E0F4C.8080202@redhat.com> In-Reply-To: <513E0F4C.8080202@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] bitops: unroll while loop in find_next_bit(). List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "qemu-devel@nongnu.org" Cc: peter.maydell@linaro.org, Paolo Bonzini , Corentin Chary , ronnie sahlberg , Orit Wasserman this patch adopts the loop unrolling idea of bitmap_is_zero() to speed up the skipping of large areas with zeros in find_next_bit(). this routine is extensively used to find dirty pages in live migration. testing only the find_next_bit performance on a zeroed bitfield the loop onrolling decreased executing time by approx. 50% on x86_64. Signed-off-by: Peter Lieven --- util/bitops.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/util/bitops.c b/util/bitops.c index e72237a..227c38b 100644 --- a/util/bitops.c +++ b/util/bitops.c @@ -42,7 +42,23 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, size -= BITS_PER_LONG; result += BITS_PER_LONG; } - while (size & ~(BITS_PER_LONG-1)) { + while (size >= 4*BITS_PER_LONG) { + unsigned long d1, d2, d3; + tmp = *p; + d1 = *(p+1); + d2 = *(p+2); + d3 = *(p+3); + if (tmp) { + goto found_middle; + } + if (d1 | d2 | d3) { + break; + } + p += 4; + result += 4*BITS_PER_LONG; + size -= 4*BITS_PER_LONG; + } + while (size >= BITS_PER_LONG) { if ((tmp = *(p++))) { goto found_middle; } -- 1.7.9.5