From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: RFC: cache_regs in kvm_emulate_pio Date: Sat, 21 Jun 2008 10:04:18 +0300 Message-ID: <485CA7F2.6090406@qumranet.com> References: <20080619233123.GA24183@dmt.cnet> <485C134D.2070905@qumranet.com> <20080620212412.GA16688@dmt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm-devel To: Marcelo Tosatti Return-path: Received: from il.qumranet.com ([212.179.150.194]:42275 "EHLO il.qumranet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750824AbYFUHET (ORCPT ); Sat, 21 Jun 2008 03:04:19 -0400 In-Reply-To: <20080620212412.GA16688@dmt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: Marcelo Tosatti wrote: >> >> ugh, another callback. how about instead >> >> /* in vcpu structure */ >> u16 regs_available; >> u16 regs_dirty; >> >> /* read from cache if possible */ >> if (!test_bit(VCPU_REG_RAX, ®s_available)) >> ->cache_regs(); >> printk("%d\n", regs[VCPU_REGS_RAX]); >> >> /* write to cache, ->vcpu_run() will flush */ >> regs[VCPU_REGS_RAX] = 17; >> __set_bit(VCPU_REGS_RAX, ®s_dirty); >> > > I think that hiding whether registers are cached or not behing wrappers > makes a lot of sense, but having the ->cache_regs interface split can > also result in gains. An index argument to ->cache_regs() would do the > trick. > > Yes and yes. > For example, there's no need to read GUEST_RSP for > skip_emulated_instruction, thats another 50+ cycles. > > Unless there's something obscure that means you need to read RSP/RIP > before accessing the now in-memory guest registers saved with "mov" > in vmx_vcpu_run(). The comment on vcpu_load_rsp_rip seems a little > ambiguous to me: > > /* > * Sync the rsp and rip registers into the vcpu structure. This allows > * registers to be accessed by indexing vcpu->arch.regs. > */ > > But I think it just refers to the interface in general, so that nobody > would try to access RSP or RIP (and RAX in AMD's case) before calling > ->cache_regs(). > It refers to the fact that sometimes you don't know which registers you refer to, e.g. in the emulator. -- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.