Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1827207imm; Thu, 20 Sep 2018 03:37:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYJ5WE7BzQn/o+3LsuFHoJtzVFxWQYP2kDeeJ43yadyntE+3AFiQv2mg94D9X6HksDwxQvx X-Received: by 2002:a17:902:bf43:: with SMTP id u3-v6mr38721132pls.88.1537439872327; Thu, 20 Sep 2018 03:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537439872; cv=none; d=google.com; s=arc-20160816; b=xFLPOTBFyNQI0YzmWquH5QCY9d7ECWzv/lnyBqsuAZV8rb85WBNw0PFt5UV+6XzxvN JgGGZ6KRI2dycgjMYSca3uIv8YqY5k17N8xp2PiCrxNX2VL+BjKE4YjU6yeM05pcfW9P 4GPoX6KUJ1+HeY5yQ0ZciCbRzI1KCeh+PxuBkaxleBafVFaEV2zz8t6CDV6fVzGjRGp2 xNoxiG6SaQiErD68rlwWPeXYRqXZOMldxfpS/2CxHB7n5PmyVojwussreOFAFI3mCAwo noVVQa9ccWr5HAA3JhFssyUXK6vVOHGD30qeS0wopsZCgfMIiiJU6MEcug99Vp25o1I1 t5cQ== 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=aT5GMVV53FOBcczYlT5Q6AD0tjRW4DBdgemIxpvGOeU=; b=O3mpyYkCV6jouRGWjPUqqjBnJYcEWr7v2OwGM0cTsDLvuFUB0X0xOSebnSkNkjdVQR RMYeF/wC7sKoCKPIjKjaCeNLrs3vs3LdgWNEJmYkexwHvcN5Yszs2vUktQ8cVrts7gDH NHsftTREn/ada7YGo+DFKVzJ5cGbVZ7Hy77zlNce0h81puykcD9ijjm9hCek+++VChU5 lxr6PzpLZoG8lsLPfSlWuURcJOz48sskQNO1N8Hbx7yq3mlTM+d+sFZWswVukB/pg4gr r83leIt0s0YSe2K7vMtjHPd2O/oCbLQQ+NLKD7tmJZSMaFM3KLB+hECTB17ZIVWvvJvU zr+Q== 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 d10-v6si24044700pla.436.2018.09.20.03.37.36; Thu, 20 Sep 2018 03:37:52 -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 S2387601AbeITQT6 (ORCPT + 99 others); Thu, 20 Sep 2018 12:19:58 -0400 Received: from mga12.intel.com ([192.55.52.136]:59584 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730654AbeITQT5 (ORCPT ); Thu, 20 Sep 2018 12:19:57 -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 fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Sep 2018 03:37:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,398,1531810800"; d="scan'208";a="74796076" Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga008.jf.intel.com with ESMTP; 20 Sep 2018 03:36:33 -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, jannh@google.com, arei.gonglei@huawei.com Subject: [PATCH v3 1/5] perf/x86: add a function to get the lbr stack Date: Thu, 20 Sep 2018 18:05:55 +0800 Message-Id: <1537437959-8751-2-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537437959-8751-1-git-send-email-wei.w.wang@intel.com> References: <1537437959-8751-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 c88ed39..c81f160 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; } + +/** + * 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->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(perf_get_lbr_stack); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index 12f5408..84cc8cb 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 nr; + unsigned long tos; + unsigned long from; + unsigned long to; + unsigned long 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