Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754531AbaBRGH7 (ORCPT ); Tue, 18 Feb 2014 01:07:59 -0500 Received: from mga11.intel.com ([192.55.52.93]:43042 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754438AbaBRGHz (ORCPT ); Tue, 18 Feb 2014 01:07:55 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,500,1389772800"; d="scan'208";a="483239673" From: "Yan, Zheng" To: linux-kernel@vger.kernel.org Cc: a.p.zijlstra@chello.nl, mingo@kernel.org, acme@infradead.org, eranian@google.com, andi@firstfloor.org, "Yan, Zheng" Subject: [PATCH v3 07/14] perf, x86: track number of events that use LBR callstack Date: Tue, 18 Feb 2014 14:07:34 +0800 Message-Id: <1392703661-15104-8-git-send-email-zheng.z.yan@intel.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1392703661-15104-1-git-send-email-zheng.z.yan@intel.com> References: <1392703661-15104-1-git-send-email-zheng.z.yan@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When enabling/disabling an event, check if the event uses the LBR callstack feature, adjust the LBR callstack usage count accordingly. Later patch will use the usage count to decide if the LBR stack should be saved/restored. Signed-off-by: Yan, Zheng --- arch/x86/kernel/cpu/perf_event_intel_lbr.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c index cfb1fe0..2e80727 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c +++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c @@ -201,15 +201,27 @@ void intel_pmu_lbr_sched_task(struct perf_event_context *ctx, bool sched_in) intel_pmu_lbr_reset(); } +static inline bool branch_user_callstack(unsigned br_sel) +{ + return (br_sel & X86_BR_USER) && (br_sel & X86_BR_CALL_STACK); +} + void intel_pmu_lbr_enable(struct perf_event *event) { struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); + struct x86_perf_task_context *task_ctx; if (!x86_pmu.lbr_nr) return; + cpuc = &__get_cpu_var(cpu_hw_events); + task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL; + cpuc->br_sel = event->hw.branch_reg.reg; + if (branch_user_callstack(cpuc->br_sel)) + task_ctx->lbr_callstack_users++; + cpuc->lbr_users++; if (cpuc->lbr_users == 1) perf_sched_cb_enable(event->ctx->pmu); @@ -217,11 +229,18 @@ void intel_pmu_lbr_enable(struct perf_event *event) void intel_pmu_lbr_disable(struct perf_event *event) { - struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); + struct cpu_hw_events *cpuc; + struct x86_perf_task_context *task_ctx; if (!x86_pmu.lbr_nr) return; + cpuc = &__get_cpu_var(cpu_hw_events); + task_ctx = event->ctx ? event->ctx->task_ctx_data : NULL; + + if (branch_user_callstack(cpuc->br_sel)) + task_ctx->lbr_callstack_users--; + cpuc->lbr_users--; WARN_ON_ONCE(cpuc->lbr_users < 0); -- 1.8.5.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/