From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Orit Wasserman 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> Subject: [Qemu-devel] [PATCH v17 3/9] Add cache handling functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 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 -- 1.7.7.6