Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp193464ybt; Sat, 13 Jun 2020 01:16:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTVh/Acc4Vb4jXgiNdbREhl800mx4xJ+lKm/TXL0GDQTiMHrPEv9ISzEBD2yqFKAlFfGdk X-Received: by 2002:aa7:da46:: with SMTP id w6mr15096217eds.31.1592036193938; Sat, 13 Jun 2020 01:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592036193; cv=none; d=google.com; s=arc-20160816; b=E+9dBVB3NOg9LNsyYXjxGi5t9RZIb2t4LyI43dmAH8HO3zTFlgTfX/63+DUjhxXwQt BAFdeVpB/TuosYWbwt82rK9R01OMQdk7f2vCjzOFffin+++CFurefo00hL+ua7El5o8+ jbWN88527q+zfqaI7MBjduNQNkZO/esdJTlz9ZhYNMZnDYL0Dc9Y5763Ilg29eIjyMPW Sdh29aAB4XcsdiUBGn7266vBKGCMUhGpfwOYgO7H8dTT5tY20O7/yvVRFLwTJt16UC9l JQnb65sTJkHDp4npKZVemZo1NWkoR9ThERbIGRQNb36XZ3OBwQpQWUdhLrYQ5nEojX/P Xctw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=1hCgkzUpG2CCn/sCHfvXnFSOfLPhPMJbUHM5ola3ewM=; b=OzMllTpVmNLtq14TRZiQoljrYgNpsH9YQT2XjvMJsNnbso6LcIPlir3szkpt9nbDlC hserPRS9NgQ9pREXqZNVfS2GnT40AKDvHbNT5m+O339IoabhQcTuC/9RA+lE8OS2odZB 5Qvo44FvDzXl5dF8uizC81+ExNEYjX1aOkLMRYM1qwyUzTwzcRQFZfysar7X6P3noVVM xYHzZODjNRfT4tio71rVkhebtNRNq9TaWNPfeB8JQRfBRmjfQskrGaTC9iLER5RgI9N1 xr3P4XfO6EIaaVd/9SYxRZ0D/uAhCmwNORWD/HcTmk9tKWA8FZQVevErBTEoNpU67gNF GheA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id m10si5184271ejc.104.2020.06.13.01.15.42; Sat, 13 Jun 2020 01:16:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726543AbgFMILc (ORCPT + 99 others); Sat, 13 Jun 2020 04:11:32 -0400 Received: from mga07.intel.com ([134.134.136.100]:64586 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbgFMILZ (ORCPT ); Sat, 13 Jun 2020 04:11:25 -0400 IronPort-SDR: pYzNTe0Xd55z7HhcqY9028+PY5CElDg0l108df3B0PUavyE36pWA9GV1MKm9KBWSlvrk9dYWWj wl+bfclPiWUA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2020 01:11:22 -0700 IronPort-SDR: EPDCaGcVwlryAc7sVuB5xVqbAiL5ymdfmM3YZiQJ55hQ8tNuxa1tJhT4DpoK2axaVgpNlcNM7N ad9aMQ6Hv4yA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,506,1583222400"; d="scan'208";a="474467349" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by fmsmga006.fm.intel.com with ESMTP; 13 Jun 2020 01:11:08 -0700 From: Like Xu To: Paolo Bonzini Cc: Peter Zijlstra , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , ak@linux.intel.com, wei.w.wang@intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Like Xu Subject: [PATCH v12 03/11] perf/x86/lbr: Add interface to get LBR information Date: Sat, 13 Jun 2020 16:09:48 +0800 Message-Id: <20200613080958.132489-4-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200613080958.132489-1-like.xu@linux.intel.com> References: <20200613080958.132489-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The LBR records msrs are model specific. The perf subsystem has already obtained the base addresses of LBR records based on the cpu model. Therefore, an interface is added to allow callers outside the perf subsystem to obtain these LBR information. It's useful for hypervisors to emulate the LBR feature for guests with less code. Co-developed-by: Wei Wang Signed-off-by: Wei Wang Signed-off-by: Like Xu --- arch/x86/events/intel/lbr.c | 20 ++++++++++++++++++++ arch/x86/include/asm/perf_event.h | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index 65113b16804a..2ed3f2a51bdf 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -1343,3 +1343,23 @@ 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 - get the LBR records information + * + * @lbr: the caller's memory to store the LBR records information + * + * Returns: 0 indicates the LBR info has been successfully obtained + */ +int x86_perf_get_lbr(struct x86_pmu_lbr *lbr) +{ + int lbr_fmt = x86_pmu.intel_cap.lbr_format; + + lbr->nr = x86_pmu.lbr_nr; + lbr->from = x86_pmu.lbr_from; + lbr->to = x86_pmu.lbr_to; + lbr->info = (lbr_fmt == LBR_FORMAT_INFO) ? MSR_LBR_INFO_0 : 0; + + return 0; +} +EXPORT_SYMBOL_GPL(x86_perf_get_lbr); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index e855e9cf2c37..5d2c30f0df02 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -333,6 +333,13 @@ struct perf_guest_switch_msr { u64 host, guest; }; +struct x86_pmu_lbr { + unsigned int nr; + unsigned int from; + unsigned int to; + unsigned int info; +}; + 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); @@ -348,12 +355,17 @@ static inline void perf_check_microcode(void) { } #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); +extern int x86_perf_get_lbr(struct x86_pmu_lbr *lbr); #else static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) { *nr = 0; return NULL; } +static inline int x86_perf_get_lbr(struct x86_pmu_lbr *lbr) +{ + return -1; +} #endif #ifdef CONFIG_CPU_SUP_INTEL -- 2.21.3