From patchwork Tue Mar 12 07:32:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 226828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 577F52C029A for ; Tue, 12 Mar 2013 18:33:22 +1100 (EST) Received: from localhost ([::1]:35215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFJi4-0001rW-7l for incoming@patchwork.ozlabs.org; Tue, 12 Mar 2013 03:33:20 -0400 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 Received: from localhost (localhost [127.0.0.1]) by ssl.dlh.net (Postfix) with ESMTP id 0429C144957; Tue, 12 Mar 2013 08:32:58 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at ssl.dlh.net Received: from ssl.dlh.net ([127.0.0.1]) by localhost (ssl.dlh.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t3VA4sWfwGdF; Tue, 12 Mar 2013 08:32:57 +0100 (CET) Received: from [172.21.12.60] (unknown [82.141.1.226]) by ssl.dlh.net (Postfix) with ESMTPSA id 7BC01140841; Tue, 12 Mar 2013 08:32:57 +0100 (CET) Message-ID: <513EDA2B.5040608@dlhnet.de> Date: Tue, 12 Mar 2013 08:32:59 +0100 From: Peter Lieven User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" 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> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 91.198.192.8 Cc: peter.maydell@linaro.org, Paolo Bonzini , Corentin Chary , ronnie sahlberg , Orit Wasserman Subject: [Qemu-devel] [PATCH] bitops: unroll while loop in find_next_bit(). X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }