From patchwork Thu Mar 10 20:47:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Palatin X-Patchwork-Id: 86335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 49F07B6FB8 for ; Fri, 11 Mar 2011 07:49:00 +1100 (EST) Received: from localhost ([127.0.0.1]:49159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pxmn2-0000lE-La for incoming@patchwork.ozlabs.org; Thu, 10 Mar 2011 15:48:56 -0500 Received: from [140.186.70.92] (port=39632 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxmmM-0000ki-KR for qemu-devel@nongnu.org; Thu, 10 Mar 2011 15:48:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PxmmL-0007DM-3j for qemu-devel@nongnu.org; Thu, 10 Mar 2011 15:48:14 -0500 Received: from smtp-out.google.com ([216.239.44.51]:12985) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PxmmK-0007CV-W9 for qemu-devel@nongnu.org; Thu, 10 Mar 2011 15:48:13 -0500 Received: from wpaz1.hot.corp.google.com (wpaz1.hot.corp.google.com [172.24.198.65]) by smtp-out.google.com with ESMTP id p2AKmATb010651; Thu, 10 Mar 2011 12:48:10 -0800 Received: from vpa.cam.corp.google.com (vpa.cam.corp.google.com [172.31.194.117]) by wpaz1.hot.corp.google.com with ESMTP id p2AKm8KU028172; Thu, 10 Mar 2011 12:48:08 -0800 Received: by vpa.cam.corp.google.com (Postfix, from userid 125455) id 519981608DF; Thu, 10 Mar 2011 15:48:08 -0500 (EST) From: Vincent Palatin To: Qemu devel Date: Thu, 10 Mar 2011 15:47:46 -0500 Message-Id: <1299790066-768-1-git-send-email-vpalatin@chromium.org> X-Mailer: git-send-email 1.7.3.1 X-System-Of-Record: true X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 216.239.44.51 Cc: Chris Wright , Alex Williamson , Vincent Palatin , Anthony Liguori Subject: [Qemu-devel] [PATCH] Fix performance regression in qemu_get_ram_ptr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Acked-by: Alex Williamson Acked-by: Chris Wright --- exec.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index d611100..81f08b7 100644 --- a/exec.c +++ b/exec.c @@ -2957,8 +2957,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); } }