From patchwork Tue Jul 10 09:37:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orit Wasserman X-Patchwork-Id: 170118 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 A045E2C0078 for ; Tue, 10 Jul 2012 20:40:28 +1000 (EST) Received: from localhost ([::1]:54936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoWtt-0000NQ-QF for incoming@patchwork.ozlabs.org; Tue, 10 Jul 2012 05:38:33 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoWtf-00009f-NV for qemu-devel@nongnu.org; Tue, 10 Jul 2012 05:38:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoWtY-00017s-Ov for qemu-devel@nongnu.org; Tue, 10 Jul 2012 05:38:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17445) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoWtY-00017b-Gj for qemu-devel@nongnu.org; Tue, 10 Jul 2012 05:38:12 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6A9ba9K011263 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 10 Jul 2012 05:37:36 -0400 Received: from dhcp-1-120.tlv.redhat.com (dhcp-4-125.tlv.redhat.com [10.35.4.125]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6A9b4QJ000518; Tue, 10 Jul 2012 05:37:27 -0400 From: Orit Wasserman To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2012 12:37:11 +0300 Message-Id: <1341913037-8579-4-git-send-email-owasserm@redhat.com> In-Reply-To: <1341913037-8579-1-git-send-email-owasserm@redhat.com> References: <1341913037-8579-1-git-send-email-owasserm@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, aliguori@us.ibm.com, quintela@redhat.com, Petter Svard , stefanha@gmail.com, mdroth@linux.vnet.ibm.com, Benoit Hudzia , blauwirbel@gmail.com, Orit Wasserman , chegu_vinod@hp.com, avi@redhat.com, Aidan Shribman , pbonzini@redhat.com, eblake@redhat.com Subject: [Qemu-devel] [PATCH v17 3/9] Add cache handling functions 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 Add LRU page cache mechanism. The page are accessed by their address. Signed-off-by: Benoit Hudzia Signed-off-by: Petter Svard Signed-off-by: Aidan Shribman Signed-off-by: Orit Wasserman --- Makefile.objs | 1 + cutils.c | 9 +++++++++ qemu-common.h | 13 +++++++++++++ 3 files changed, 23 insertions(+), 0 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 5ebbcfa..e0fb69b 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -77,6 +77,7 @@ common-obj-y += qemu-char.o #aio.o common-obj-y += block-migration.o iohandler.o common-obj-y += pflib.o common-obj-y += bitmap.o bitops.o +common-obj-y += page_cache.o common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o common-obj-$(CONFIG_WIN32) += version.o diff --git a/cutils.c b/cutils.c index e2bc1b8..b0bdd4b 100644 --- a/cutils.c +++ b/cutils.c @@ -375,3 +375,12 @@ int qemu_parse_fd(const char *param) } return fd; } + +/* round down to the nearest power of 2*/ +int64_t pow2floor(int64_t value) +{ + if (!is_power_of_2(value)) { + value = 0x8000000000000000ULL >> clz64(value); + } + return value; +} diff --git a/qemu-common.h b/qemu-common.h index 09676f5..195bab5 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -1,3 +1,4 @@ + /* Common header file that is included by all of qemu. */ #ifndef QEMU_COMMON_H #define QEMU_COMMON_H @@ -411,6 +412,18 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) /* Round number up to multiple */ #define QEMU_ALIGN_UP(n, m) QEMU_ALIGN_DOWN((n) + (m) - 1, (m)) +static inline bool is_power_of_2(int64_t value) +{ + if (!value) { + return 0; + } + + return !(value & (value - 1)); +} + +/* round down to the nearest power of 2*/ +int64_t pow2floor(int64_t value); + #include "module.h" #endif