Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1638942imj; Thu, 14 Feb 2019 09:33:09 -0800 (PST) X-Google-Smtp-Source: AHgI3IZts0PU/qGs7VVJWb0B2O1cwLMkgFZuDcgJPTjZyupFEhYM2M7O9DLfd6QVISFVcP6c+yLD X-Received: by 2002:a17:902:ba8e:: with SMTP id k14mr5307671pls.219.1550165589479; Thu, 14 Feb 2019 09:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550165589; cv=none; d=google.com; s=arc-20160816; b=oqsisl7sjd0ZQxiUO10iGstzT/9lqucJRwjfIVmMBUddDkNf8Q1CgpDgewEgxHXMAE PZROW6LuogCEm0klF2qumo+tVhl9U1syeqFdQwSmwiyQL5gr3wYY7lAUA1RpPLXO+UAy D4GXd1f8scYV6LwzGo3AscpQBPtUY0HIaGCtmcA9TmZpwxCDxwLNXI9eNt9ynEOlUA5T o+SST/KyGgksYGS33pXifd6OQf56yuTsQ8zSrP784ONslbh/nlHxJHWf9xmQdOcjBouN oG+h5pYHN/8AM5p5RdM5XhHZsDA8Hc0ex83AHj2Js6Cajl8NkmyE1C3x7smFkKyeJDEU L1Ag== 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=XYakL97sPjYHa2KtPxsKcWUsbYroyuqvM00whrJumDI=; b=cqvP4ZAqTSNU5+dYeVX0QIdIjLHRzgLyc2H25cNCih5PpG70m1DXUNUXyOfiY7Gtwz 9BjV0mPcQQmkgE6mR3d1OKwIdPN4pRi3EG3F24TfXTW7lQwJgzYPAdpb8e9tMQ8TExlr akPvC3Mfd3BFEWOuLlYHKS8Sd5QLABNPcDa65OPeBQsNOjDnWpQedLhMaODcGPK50JOm 5ezz0+0NDfLcWfF6VCCSqphVzaa78wg+ra7GjZrXcDv2a5Za0sTWC3Nh2z51zU1Ka0Zr wUWAf2vBGgtB6jmPOMLkYkxkvo3CnuNSjWw9q8UZ2nr8vnzbx1QE5pBCqQDylDWuPopR rbGA== 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 67si2940124pgc.312.2019.02.14.09.32.53; Thu, 14 Feb 2019 09:33:09 -0800 (PST) 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 S2438051AbfBNJob (ORCPT + 99 others); Thu, 14 Feb 2019 04:44:31 -0500 Received: from mga09.intel.com ([134.134.136.24]:32197 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392986AbfBNJmv (ORCPT ); Thu, 14 Feb 2019 04:42:51 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2019 01:42:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,368,1544515200"; d="scan'208";a="124411702" Received: from devel-ww.sh.intel.com ([10.239.48.128]) by fmsmga008.fm.intel.com with ESMTP; 14 Feb 2019 01:42:48 -0800 From: Wei Wang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, ak@linux.intel.com, peterz@infradead.org Cc: kan.liang@intel.com, mingo@redhat.com, rkrcmar@redhat.com, like.xu@intel.com, wei.w.wang@intel.com, jannh@google.com, arei.gonglei@huawei.com, jmattson@google.com Subject: [PATCH v5 02/12] perf/x86: add a function to get the lbr stack Date: Thu, 14 Feb 2019 17:06:04 +0800 Message-Id: <1550135174-5423-3-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550135174-5423-1-git-send-email-wei.w.wang@intel.com> References: <1550135174-5423-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 The LBR stack MSRs are architecturally specific. The perf subsystem has already assigned the abstracted MSR values based on the CPU architecture. This patch enables a caller outside the perf subsystem to get the LBR stack info. This is useful for hyperviosrs to prepare the lbr feature for the guest. Signed-off-by: Wei Wang Cc: Paolo Bonzini Cc: Andi Kleen Cc: Peter Zijlstra --- arch/x86/events/intel/lbr.c | 23 +++++++++++++++++++++++ arch/x86/include/asm/perf_event.h | 14 ++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index c88ed39..594a91b 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -1277,3 +1277,26 @@ void intel_pmu_lbr_init_knl(void) if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_LIP) x86_pmu.intel_cap.lbr_format = LBR_FORMAT_EIP_FLAGS; } + +/** + * x86_perf_get_lbr_stack - get the lbr stack related MSRs + * + * @stack: the caller's memory to get the lbr stack + * + * Returns: 0 indicates that the lbr stack has been successfully obtained. + */ +int x86_perf_get_lbr_stack(struct x86_perf_lbr_stack *stack) +{ + stack->nr = x86_pmu.lbr_nr; + stack->tos = x86_pmu.lbr_tos; + stack->from = x86_pmu.lbr_from; + stack->to = x86_pmu.lbr_to; + + if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_INFO) + stack->info = MSR_LBR_INFO_0; + else + stack->info = 0; + + return 0; +} +EXPORT_SYMBOL_GPL(x86_perf_get_lbr_stack); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index 8bdf749..2f82795 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -275,7 +275,16 @@ struct perf_guest_switch_msr { u64 host, guest; }; +struct x86_perf_lbr_stack { + unsigned int nr; + unsigned int tos; + unsigned int from; + unsigned int to; + unsigned int info; +}; + extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); +extern int x86_perf_get_lbr_stack(struct x86_perf_lbr_stack *stack); extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap); extern void perf_check_microcode(void); extern int x86_perf_rdpmc_index(struct perf_event *event); @@ -286,6 +295,11 @@ static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) return NULL; } +static inline int x86_perf_get_lbr_stack(struct x86_perf_lbr_stack *stack) +{ + return -1; +} + static inline void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap) { memset(cap, 0, sizeof(*cap)); -- 2.7.4