Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp436369imm; Thu, 6 Sep 2018 05:02:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZJ1w+FRTGPdSkrksEI2WErhEXdzC3yUqzLF1FddSeaZeXPFvoDRmCzdkIjqlVXtmIOrTE1 X-Received: by 2002:a63:2701:: with SMTP id n1-v6mr2384916pgn.146.1536235369847; Thu, 06 Sep 2018 05:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536235369; cv=none; d=google.com; s=arc-20160816; b=cDKLv3yQ/ASAc0YrFzO9H5xJL4kpiJpYMw1VzXFOOnr1gUfeyu8zPh3KulYU9A0okj dr7NUOr5jur0v3RZ0krYcPq5qUuKpyAzL8yIhn8kgOldnoD+Ab29NaIvXwhRPz90jSUE JP7mBXAp4ECFXVioloNSATNElBR2HNr0a93T0AZr0ezcraKRDi+wAmEMsI7pF7pdYTQi k6tyxcxhGdRCJnRmJD1I4Ei4J2r9rtiNGB51p/pWiXpVPXN9wYYedD4dW5MJ7NqTNoBZ Xc2rY/zqcVxk7ZGgLCvhI9/V0DToSiA8xcYsG7OiPL+WQLfndNGJItX/2m8X5dpUjCaW r4Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=kmqPuDcVmPqmB5MDuzEdPdGlee1zHbAekBhlZxEYnog=; b=YCdjHmr0Sx/ajGs7OkRJ/NmRem0oKCW72IM18R2MxB79I/qnZBdAkQ/sgOEHQ2EUzG aeF1ppgRjKyeomek2+IbT4vCLxCVjh/9Cs6nJG7BDXTBwtZMP6/hTHPLFCI3TTwVkoeF zM7d2JDu5IPzHeVm6FLXiHHt6KAGl0+QIhDqPCMcyF1+09KQuA+g0DYxbpE5j27s2aFS opVceKIWInl1OLdvvzYbWJWPHNrV4NlgVd/4P9D5a6UNArS4/7PVmLzwQX0ov1tRze1L u+mdStUtDZHQQu02TlqVkh3iY8sy3K4koxtI1C9VIqAVoQiMERjh1IKLYkf6+zjXb+jj FuMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13-v6si5324441pfj.230.2018.09.06.05.02.33; Thu, 06 Sep 2018 05:02:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728391AbeIFQgV (ORCPT + 99 others); Thu, 6 Sep 2018 12:36:21 -0400 Received: from mga18.intel.com ([134.134.136.126]:62830 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbeIFQgU (ORCPT ); Thu, 6 Sep 2018 12:36:20 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Sep 2018 05:01:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,338,1531810800"; d="scan'208";a="71046970" Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga008.jf.intel.com with ESMTP; 06 Sep 2018 05:01:04 -0700 From: Wei Wang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, ak@linux.intel.com Cc: kan.liang@intel.com, peterz@infradead.org, mingo@redhat.com, rkrcmar@redhat.com, like.xu@intel.com, wei.w.wang@intel.com Subject: [PATCH v2 8/8] perf/x86/intel/lbr: add the guest_lbr boolean to cpuc Date: Thu, 6 Sep 2018 19:30:56 +0800 Message-Id: <1536233456-12173-9-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536233456-12173-1-git-send-email-wei.w.wang@intel.com> References: <1536233456-12173-1-git-send-email-wei.w.wang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu The host creates an lbr perf event for the guest vCPU only for the purpose of saving/restoring the lbr stack on the vCPU context switching. There is no need to enable the lbr functionality for this lbr perf event, because the feature is essentially used in the vCPU. So, we introduce the guest_lbr boolean control to cpuc, to indicate if the lbr perf event is created for the guest. When the perf subsystem handles this event (e.g. enable or read lbr stack on PMI) and finds it is for the guest, it simply returns, because all we need for the perf event is just a context switch support for the lbr stack. Signed-off-by: Like Xu Signed-off-by: Wei Wang Cc: Paolo Bonzini Cc: Andi Kleen --- arch/x86/events/intel/lbr.c | 10 +++++++--- arch/x86/events/perf_event.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index 50921d3..74f6ad9 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -481,6 +481,9 @@ void intel_pmu_lbr_add(struct perf_event *event) if (!x86_pmu.lbr_nr) return; + if (event->attr.exclude_host) + cpuc->guest_lbr = true; + cpuc->br_sel = event->hw.branch_reg.reg; if (branch_user_callstack(cpuc->br_sel) && event->ctx->task_ctx_data) { @@ -528,6 +531,7 @@ void intel_pmu_lbr_del(struct perf_event *event) set_pv_lbr_ctrl_active(false); } + cpuc->guest_lbr = false; cpuc->lbr_users--; WARN_ON_ONCE(cpuc->lbr_users < 0); perf_sched_cb_dec(event->ctx->pmu); @@ -537,7 +541,7 @@ void intel_pmu_lbr_enable_all(bool pmi) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); - if (cpuc->lbr_users) + if (cpuc->lbr_users && !cpuc->guest_lbr) __intel_pmu_lbr_enable(pmi); } @@ -545,7 +549,7 @@ void intel_pmu_lbr_disable_all(void) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); - if (cpuc->lbr_users) + if (cpuc->lbr_users && !cpuc->guest_lbr) __intel_pmu_lbr_disable(); } @@ -679,7 +683,7 @@ void intel_pmu_lbr_read(void) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); - if (!cpuc->lbr_users) + if (!cpuc->lbr_users || cpuc->guest_lbr) return; if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32) diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index 1562863..a91fdef 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -223,6 +223,7 @@ struct cpu_hw_events { */ u64 intel_ctrl_guest_mask; u64 intel_ctrl_host_mask; + bool guest_lbr; struct perf_guest_switch_msr guest_switch_msrs[X86_PMC_IDX_MAX]; /* -- 2.7.4