Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5511079ybf; Thu, 5 Mar 2020 02:00:54 -0800 (PST) X-Google-Smtp-Source: ADFU+vtmV5EacwWiNbDJtF7X+HqQsiKRIlfAUhjKo9vRpsLbXUxEkjsRx+ubhHEFpxHqKdhePcUG X-Received: by 2002:a05:6830:1351:: with SMTP id r17mr5669423otq.227.1583402454447; Thu, 05 Mar 2020 02:00:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583402454; cv=none; d=google.com; s=arc-20160816; b=vcpMjGfUzNuaO5LIpkNdKNjHOOTPLxIXLUtb1QMI968ua6yjqGTHfNtcq5ilms+lf9 iQDYlz1YMj1acHfeeyTJPMAFkHihIv5ZEONiOc9zDKdlIqXuW8tV3+CZ4kTEXwENiaq8 R3qLGSn+VFTF638O5kbhI7shMsb2G5vzeg4KyZoxFeSTNR07uqmdDzHo8NdN3Sd0qYb3 8fORjk+z/v5AXMlDEGNT/IBM6JmzwXN/IfK2SU8bdhUfwB0ykD/Sf2K/Dp/8JP2eqn7g rW5P4gUChyqLYaNMTpftqMfCNBBTBSjGxSxp/gUVO+KVUcsOPVLUjLtneB6wqIKcvNRq FMBA== 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=lbCcahdHSQZlHrd9Yd7MC9Zc6xdMu7wsoitM6OXoQus=; b=Fcr/LmGvyKppZWWFL4zWUiieOPdteMvGanOXRPO1GBWfygsIm99kgDpt13t4hCzBr9 e4VMTQRjP2ERWp6M0cLGjNLBO81y99tYgzJb1/+SJkctOtIo7Mxv4nqjO2CY0ImYgZPT adzwVhWCDhTeLY6yJ4s1BDwaVq2jYi9bhd0ATqxC6fyffV7LnUS1X5/EYWuQ8nnO5/8U MEGraJmyjeKmtlNY7qhC1k7nkDDxRLzz2Ss5Bpg6pmzzrH57x7QEgR53F2CwJ3HLmadI Kf9GwTxLU+SvQDw4Nd77FHvZz98dau5mWkaOxt0XMVoU5gWOpZr3lGObSdoLLOyPwwVp BXLg== 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 9si2855528oix.239.2020.03.05.02.00.42; Thu, 05 Mar 2020 02:00:54 -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 S1727130AbgCEJ7L (ORCPT + 99 others); Thu, 5 Mar 2020 04:59:11 -0500 Received: from mga03.intel.com ([134.134.136.65]:7415 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727071AbgCEJ7L (ORCPT ); Thu, 5 Mar 2020 04:59:11 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2020 01:59:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,517,1574150400"; d="scan'208";a="234366468" Received: from snr.bj.intel.com ([10.240.193.90]) by orsmga008.jf.intel.com with ESMTP; 05 Mar 2020 01:59:03 -0800 From: Luwei Kang To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, tglx@linutronix.de, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, sean.j.christopherson@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, pawan.kumar.gupta@linux.intel.com, ak@linux.intel.com, thomas.lendacky@amd.com, fenghua.yu@intel.com, kan.liang@linux.intel.com, like.xu@linux.intel.com Subject: [PATCH v1 03/11] perf/x86: Expose a function to disable auto-reload Date: Fri, 6 Mar 2020 01:56:57 +0800 Message-Id: <1583431025-19802-4-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1583431025-19802-1-git-send-email-luwei.kang@intel.com> References: <1583431025-19802-1-git-send-email-luwei.kang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang KVM needs to disable PEBS auto-reload for guest owned event to avoid unnecessory drain_pebs() in host. Expose a function to disable auto-reload mechanism by unset the related flag. The function has to be invoked before event enabling, otherwise there is no effect. Signed-off-by: Kan Liang --- arch/x86/events/intel/core.c | 14 ++++++++++++++ arch/x86/include/asm/perf_event.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index ef95076..cd17601 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3299,6 +3299,20 @@ static int core_pmu_hw_config(struct perf_event *event) return intel_pmu_bts_config(event); } +/* + * Disable PEBS auto-reload mechanism by unset the flag. + * The function has to be invoked before event enabling, + * otherwise there is no effect. + * + * Currently, it's used by KVM to disable PEBS auto-reload + * for guest owned event. + */ +void perf_x86_pmu_unset_auto_reload(struct perf_event *event) +{ + event->hw.flags &= ~PERF_X86_EVENT_AUTO_RELOAD; +} +EXPORT_SYMBOL_GPL(perf_x86_pmu_unset_auto_reload); + static int intel_pmu_hw_config(struct perf_event *event) { int ret = x86_pmu_hw_config(event); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index 29964b0..6179234 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -325,6 +325,7 @@ struct perf_guest_switch_msr { 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); +extern void perf_x86_pmu_unset_auto_reload(struct perf_event *event); #else static inline void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap) { @@ -333,6 +334,7 @@ static inline void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap) static inline void perf_events_lapic_init(void) { } static inline void perf_check_microcode(void) { } +static inline void perf_x86_pmu_unset_auto_reload(struct perf_event *event) { } #endif #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) -- 1.8.3.1