From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 2/2] KVM: x86 emulator: Avoid clearing the whole decode_cache Date: Thu, 26 May 2011 11:19:03 +0300 Message-ID: <4DDE0CF7.1030301@redhat.com> References: <20110525110616.7cd61e29.takuya.yoshikawa@gmail.com> <20110525110938.03bdc229.takuya.yoshikawa@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: mtosatti@redhat.com, kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp, gleb@redhat.com To: Takuya Yoshikawa Return-path: Received: from mx1.redhat.com ([209.132.183.28]:20163 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752482Ab1EZITK (ORCPT ); Thu, 26 May 2011 04:19:10 -0400 In-Reply-To: <20110525110938.03bdc229.takuya.yoshikawa@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On 05/25/2011 05:09 AM, Takuya Yoshikawa wrote: > From: Takuya Yoshikawa > > During tracing the emulator, we noticed that init_emulate_ctxt() > sometimes took a bit longer time than we expected. > > This patch is for mitigating the problem by some degree. > > By looking into the function, we soon notice that it clears the whole > decode_cache whose size is about 2.5K bytes now. Furthermore, most of > the bytes are taken for the two read_cache arrays, which are used only > by a few instructions. > > Considering the fact that we are not assuming the cache arrays have > been cleared when we store actual data, we do not need to clear the > arrays: 2K bytes elimination. In addition, we can avoid clearing the > fetch_cache and regs arrays. > > This patch changes the initialization not to clear the arrays. > > On our 64-bit host, init_emulate_ctxt() becomes 0.3 to 0.5us faster with > this patch applied. > Thanks, applied. It strikes me that initializing the emulator in x86.c is the wrong thing. We should move the entire thing to x86_decode_insn(). We'll need a few more callbacks for that, though (register, eflags); eventually we can read just registers that are used and write only registers that were updated. -- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.