From 0dd0a898171774c94c7d3ea47a9c0dd278a4f488 Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Wed, 23 Mar 2011 18:50:12 -0300 Subject: [PATCH 12/16] Fix performance regression in qemu_get_ram_ptr RH-Author: Alex Williamson Message-id: <20110323184258.18741.61858.stgit@s20.home> Patchwork-id: 20525 O-Subject: [RHEL6.1 qemu-kvm PATCH] Fix performance regression in qemu_get_ram_ptr Bugzilla: 690267 RH-Acked-by: Don Dutile RH-Acked-by: Jes Sorensen RH-Acked-by: Markus Armbruster From: Vincent Palatin Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=690267 Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=3199137 Upstream commit: 7d82af38b78305155553013c6fd709dc50404199 When the commit f471a17e9d869df3c6573f7ec02c4725676d6f3a converted the ram_blocks structure to QLIST, it also removed the conditional check before switching the current block at the beginning of the list. In the common use case where ram_blocks has a few blocks with only one frequently accessed (the main RAM), this has a performance impact as it performs the useless list operations on each call (which are on a really hot path). On my machine emulation (ARM on amd64), this patch reduces the percentage of CPU time spent in qemu_get_ram_ptr from 6.3% to 2.1% in the profiling of a full boot. Signed-off-by: Vincent Palatin Signed-off-by: Anthony Liguori --- exec.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) Signed-off-by: Luiz Capitulino --- exec.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index b992016..22ca4c4 100644 --- a/exec.c +++ b/exec.c @@ -2808,8 +2808,11 @@ void *qemu_get_ram_ptr(ram_addr_t addr) QLIST_FOREACH(block, &ram_list.blocks, next) { if (addr - block->offset < block->length) { - QLIST_REMOVE(block, next); - QLIST_INSERT_HEAD(&ram_list.blocks, block, next); + /* Move this entry to to start of the list. */ + if (block != QLIST_FIRST(&ram_list.blocks)) { + QLIST_REMOVE(block, next); + QLIST_INSERT_HEAD(&ram_list.blocks, block, next); + } return block->host + (addr - block->offset); } } -- 1.7.4.1.230.gae447