From: Christoffer Dall Subject: Re: [PATCH v6 2/4] arm64: KVM: add accessors to track guest/host only counters Date: Mon, 10 Dec 2018 11:26:34 +0100 Message-ID: <20181210102634.GL30263@e113682-lin.lund.arm.com> References: <1544435159-54781-1-git-send-email-andrew.murray@arm.com> <1544435159-54781-3-git-send-email-andrew.murray@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BB0EA4A333 for ; Mon, 10 Dec 2018 05:26:38 -0500 (EST) Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cCwGqGt6hm2M for ; Mon, 10 Dec 2018 05:26:37 -0500 (EST) Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 80F0E4A2BD for ; Mon, 10 Dec 2018 05:26:37 -0500 (EST) Content-Disposition: inline In-Reply-To: <1544435159-54781-3-git-send-email-andrew.murray@arm.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu To: Andrew Murray Cc: Marc Zyngier , Catalin Marinas , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org List-Id: kvmarm@lists.cs.columbia.edu On Mon, Dec 10, 2018 at 09:45:57AM +0000, Andrew Murray wrote: > In order to effeciently enable/disable guest/host only perf counters > at guest entry/exit we add bitfields to kvm_cpu_context for guest and > host events as well as accessors for updating them. > > Signed-off-by: Andrew Murray > --- > arch/arm64/include/asm/kvm_host.h | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index 1550192..800c87b 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -203,6 +203,8 @@ struct kvm_cpu_context { > }; > > struct kvm_vcpu *__hyp_running_vcpu; > + u32 events_host; > + u32 events_guest; This is confusing to me. These values appear only to be used for the host instance, which makes me wonder why we add them to kvm_cpu_context, which is also used for the guest state? Should we not instead consider moving them to their own data structure and add a per-cpu data structure or something more fancy like having a new data structure, kvm_percpu_host_data, which contains the kvm_cpu_context and the events flags? I don't know much about perf, but doesn't this design also imply that you can only set these modifiers at a per-cpu level, and not attach the modifiers to a task/vcpu or vm ? Is that by design? Thanks, Christoffer > }; > > typedef struct kvm_cpu_context kvm_cpu_context_t; > @@ -467,11 +469,33 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu); > void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu); > void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu); > > +#define KVM_PMU_EVENTS_HOST 1 > +#define KVM_PMU_EVENTS_GUEST 2 > + > #ifdef CONFIG_KVM /* Avoid conflicts with core headers if CONFIG_KVM=n */ > static inline int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) > { > return kvm_arch_vcpu_run_map_fp(vcpu); > } > +static inline void kvm_set_pmu_events(u32 set, int flags) > +{ > + kvm_cpu_context_t *ctx = this_cpu_ptr(&kvm_host_cpu_state); > + > + if (flags & KVM_PMU_EVENTS_HOST) > + ctx->events_host |= set; > + if (flags & KVM_PMU_EVENTS_GUEST) > + ctx->events_guest |= set; > +} > +static inline void kvm_clr_pmu_events(u32 clr) > +{ > + kvm_cpu_context_t *ctx = this_cpu_ptr(&kvm_host_cpu_state); > + > + ctx->events_host &= ~clr; > + ctx->events_guest &= ~clr; > +} > +#else > +static inline void kvm_set_pmu_events(u32 set, int flags) {} > +static inline void kvm_clr_pmu_events(u32 clr) {} > #endif > > static inline void kvm_arm_vhe_guest_enter(void) > -- > 2.7.4 >