Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp437018imm; Thu, 6 Sep 2018 05:03:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ48jZspUf5DBiTlqADin6bQDDaTA5gjO5QVuZrIDXPhxYPm8PrxlDxNUHUjq344eVQbRZX X-Received: by 2002:a65:66d4:: with SMTP id c20-v6mr2355326pgw.55.1536235399939; Thu, 06 Sep 2018 05:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536235399; cv=none; d=google.com; s=arc-20160816; b=bIpwT98O6giykOd8VG40adzmfojP0ajqCYGWkRlwoSftTJLp5c+sN0cXzgB/Dk9iun qeYK7Zn8CtRWNIdjsIOO24XqRwldkF5Cwd3mDzFL0LOc23xJIdmzUMO6wA6DnZsEbheH glvqVyImbozLO7mTtNFNw2SlWwa/DzSZ/nHXta7vIHmHNllXo2WpahjGgkvcFzjJMb0Z KPnvTE5LfotUsVKmsvZ4ahii4TTNU4+tH/S36oUL9TxBuQuY00PcTGZpruVGvEQrbk3v VuPhBtmxRvTTA1gUg0ca6qqhdsddPNC29bLEEerMWLycJnsZLNPyvYOFLTPTBjPcWPjo TVOg== 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=hexvXzqqg9hKmWh8ktT8WN2H5Y7G92wYkKciz1zeOuo=; b=P2cq+oQOBKXGdULh2OoHiBjIJhwZ6f+Wj9JMeIMlqc0Pz6p3mF733ZFmfl3w8D4FtQ BjYqR69pfeEoXfiFOGHbgUtiY5nr8mTMQ9H8cnkjBPuLxzcFrrGK79hz4Q0OYNfbdA8j YzM02CaCb0FwnzIqNCibnAKK71kLcdAgv66H14mel3NV+mXpZd3NRXOekgSMq1by5fzL bj9P0eYPw0bl19/yOWx5maHaX67ctQZfrJ8MninwoK0is8T7SuLiQ7w0GT+J83EtA9bD 1sYnJ7wevrof4wdZvUgsTsBmFsUSccfot98AzOP3o6dbGloxGdFheEbRJeoXECaz0etS CWew== 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 w25-v6si4821761pfa.359.2018.09.06.05.03.04; Thu, 06 Sep 2018 05:03:19 -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 S1728266AbeIFQgS (ORCPT + 99 others); Thu, 6 Sep 2018 12:36:18 -0400 Received: from mga18.intel.com ([134.134.136.126]:62802 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728002AbeIFQgQ (ORCPT ); Thu, 6 Sep 2018 12:36:16 -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:00:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,338,1531810800"; d="scan'208";a="71046721" Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga008.jf.intel.com with ESMTP; 06 Sep 2018 05:00:49 -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 1/8] perf/x86: add a function to get the lbr stack Date: Thu, 6 Sep 2018 19:30:49 +0800 Message-Id: <1536233456-12173-2-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 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: Like Xu Signed-off-by: Wei Wang Cc: Paolo Bonzini Cc: Andi Kleen --- 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 f3e006b..7c3958e 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -1273,3 +1273,26 @@ void intel_pmu_lbr_init_knl(void) x86_pmu.lbr_sel_mask = LBR_SEL_MASK; x86_pmu.lbr_sel_map = snb_lbr_sel_map; } + +/** + * 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 perf_get_lbr_stack(struct perf_lbr_stack *stack) +{ + stack->lbr_nr = x86_pmu.lbr_nr; + stack->lbr_tos = x86_pmu.lbr_tos; + stack->lbr_from = x86_pmu.lbr_from; + stack->lbr_to = x86_pmu.lbr_to; + + if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_INFO) + stack->lbr_info = MSR_LBR_INFO_0; + else + stack->lbr_info = 0; + + return 0; +} +EXPORT_SYMBOL_GPL(perf_get_lbr_stack); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index 12f5408..f40e80a 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -267,7 +267,16 @@ struct perf_guest_switch_msr { u64 host, guest; }; +struct perf_lbr_stack { + int lbr_nr; + unsigned long lbr_tos; + unsigned long lbr_from; + unsigned long lbr_to; + unsigned long lbr_info; +}; + extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); +extern int perf_get_lbr_stack(struct perf_lbr_stack *stack); extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap); extern void perf_check_microcode(void); #else @@ -277,6 +286,11 @@ static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) return NULL; } +static inline int perf_get_lbr_stack(struct 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