From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH 2/2] KVM: x86 emulator: Avoid clearing the whole decode_cache Date: Thu, 26 May 2011 11:20:45 +0300 Message-ID: <20110526082045.GD29458@redhat.com> References: <20110525110616.7cd61e29.takuya.yoshikawa@gmail.com> <20110525110938.03bdc229.takuya.yoshikawa@gmail.com> <4DDE0CF7.1030301@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Takuya Yoshikawa , mtosatti@redhat.com, kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:57173 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755355Ab1EZIUv (ORCPT ); Thu, 26 May 2011 04:20:51 -0400 Content-Disposition: inline In-Reply-To: <4DDE0CF7.1030301@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, May 26, 2011 at 11:19:03AM +0300, Avi Kivity wrote: > 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 initialize it in task switch and interrupt injection code too. > 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. > -- Gleb.