Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1578845ybz; Thu, 23 Apr 2020 01:21:25 -0700 (PDT) X-Google-Smtp-Source: APiQypL9prin7xkVX6+VWjhIsbqZ/oanaZYIe/2PZwCs1+AlU5lNBz+SFyLJavDGx9+H+cvLkunj X-Received: by 2002:a17:906:1584:: with SMTP id k4mr1778187ejd.355.1587630085306; Thu, 23 Apr 2020 01:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587630085; cv=none; d=google.com; s=arc-20160816; b=VUWP4j9Tk3/07T+sPK2/w2vnnS3uXVjk/K3N4v45qeIIxKFdCo3GnXKhuZJ9ULjoQ9 JJ4XKzULDPPhHNswKJlOviEhLx/0zz2H2+zt6CEVmt8psDt4q3A0GZ++spxnJRJ3sA/W aQ8ENV8/fyiHp9W47MJXWzjrD1wdtF4t0P9tge5CCfI243pnNQuPz3dKR8lkxCBgmbk7 XvFtL4aw3HCDxrugsnnxKTpbvdOdD2o/L5F791YEoGCarCTaG9Boe9ws2tpMAKN2wQpo e0shHOltFXXVE4b2CsaHO9Zrh4xtpIlapBzE+urXA44nJGKZwHGVz+H01pIji/mwBDDd oKhQ== 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=qgzZgkKj4Yz8GhrUCwhhcU6zXuQFCQIYRf14tCYcl7M=; b=hXWBtMW/lKc9QTaBpMJxQG84MS8QqMQfwVFfIeBEEVX4NWiw6UY6JEkMw1mXu7boPF bPIEeAB36ziuwnmNVNYHabIAMzehmIJPdszvde66MA0+b6i4h1HULQCHbdpMsqx7CS+g GCmxviyPerIUFABkOHTuJXQ9TIDFt8mqzTfm8GR2d526RzhohbyI6V8N7e2jKU9Q09HX g50Ziq3nk7kdww8mbb2znd6tIqFyfJ7Nhkod6jv37A14s+BPxA1SmkaCu0F6uET0dt2T t3RWyjOBDg+KxdQ1pFjceM1CVarMx9tL1JpKUpOK9bDprsgYeiF80v1JB7ym6awBQTMJ JB2Q== 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 oh24si850216ejb.531.2020.04.23.01.21.01; Thu, 23 Apr 2020 01:21:25 -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 S1726692AbgDWIRs (ORCPT + 99 others); Thu, 23 Apr 2020 04:17:48 -0400 Received: from mga18.intel.com ([134.134.136.126]:57581 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbgDWIRq (ORCPT ); Thu, 23 Apr 2020 04:17:46 -0400 IronPort-SDR: okghvkxQp8tzRBXSR3ygshbaqGuZoD7KO+tXlcxJOCRL4u4CuCN0SGiWM+sjLAbpKXdJymrb3u StQNEgR+sZlw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2020 01:17:45 -0700 IronPort-SDR: wDEGoONwrkp1xCBZwvT5CcViKU1v9vE7wKxDoQwPwu02y4lqV2Jabzfh1lLdINTuAU13GT6TZd vgkL+cKcS3Dg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,306,1583222400"; d="scan'208";a="255910051" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by orsmga003.jf.intel.com with ESMTP; 23 Apr 2020 01:17:42 -0700 From: Like Xu To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, wei.w.wang@intel.com, ak@linux.intel.com, Like Xu , Peter Zijlstra Subject: [PATCH v10 03/11] perf/x86/lbr: Add interface to get basic information about LBR stack Date: Thu, 23 Apr 2020 16:14:04 +0800 Message-Id: <20200423081412.164863-4-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200423081412.164863-1-like.xu@linux.intel.com> References: <20200423081412.164863-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 stack msrs are model specific. The perf subsystem has already obtained the LBR stack base addresses based on the cpu model. Therefore, an interface is added to allow callers outside the perf subsystem to obtain the LBR stack base addresses. It's useful for hypervisors to emulate the LBR feature for guests with less code. Cc: Peter Zijlstra (Intel) 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..6c60dcaaaf69 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 stack information + * + * @stack: the caller's memory to store the LBR stack information + * + * Returns: 0 indicates the LBR stack info has been successfully obtained + */ +int x86_perf_get_lbr(struct x86_pmu_lbr *stack) +{ + int lbr_fmt = x86_pmu.intel_cap.lbr_format; + + stack->nr = x86_pmu.lbr_nr; + stack->from = x86_pmu.lbr_from; + stack->to = x86_pmu.lbr_to; + stack->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..5071515f6b0f 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 *stack); #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 *stack) +{ + return -1; +} #endif #ifdef CONFIG_CPU_SUP_INTEL -- 2.21.1