From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751620AbdFHOlt (ORCPT ); Thu, 8 Jun 2017 10:41:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57297 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751344AbdFHOls (ORCPT ); Thu, 8 Jun 2017 10:41:48 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 23A368FD0D Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=jolsa@kernel.org DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 23A368FD0D From: Jiri Olsa To: Thomas Gleixner Cc: Peter Zijlstra , Peter Zijlstra , Vikas Shivappa , Tony Luck , lkml , Ingo Molnar Subject: [PATCH] perf/x86/intel/cqm: Start MBM timers only for MBM events Date: Thu, 8 Jun 2017 16:41:44 +0200 Message-Id: <20170608144144.19253-1-jolsa@kernel.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 08 Jun 2017 14:41:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently start MBM timers for the first event of any kind, though they are not needed for occupancy event. Adding check to ensure the MBM timers are started only for MBM events. Cc: Peter Zijlstra Cc: Peter Zijlstra Cc: Vikas Shivappa Cc: Tony Luck Signed-off-by: Jiri Olsa --- arch/x86/events/intel/cqm.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/intel/cqm.c b/arch/x86/events/intel/cqm.c index 2521f771f2f5..2f7253358c17 100644 --- a/arch/x86/events/intel/cqm.c +++ b/arch/x86/events/intel/cqm.c @@ -1286,6 +1286,35 @@ static int intel_cqm_event_add(struct perf_event *event, int mode) return 0; } +/* Guarded with cache_mutex. */ +static int mbm_events; + +/* + * Start the mbm overflow timers when the first MBM event is created. + */ +static bool should_start_mbm_timers(struct perf_event *event) +{ + if (mbm_enabled && is_mbm_event(event->attr.config)) { + mbm_events++; + return mbm_events == 1; + } + + return false; +} + +/* + * Stop the mbm overflow timers when the last MBM event is destroyed. + */ +static bool should_stop_mbm_timers(struct perf_event *event) +{ + if (mbm_enabled && is_mbm_event(event->attr.config)) { + mbm_events--; + return mbm_events == 0; + } + + return false; +} + static void intel_cqm_event_destroy(struct perf_event *event) { struct perf_event *group_other = NULL; @@ -1330,10 +1359,7 @@ static void intel_cqm_event_destroy(struct perf_event *event) raw_spin_unlock_irqrestore(&cache_lock, flags); - /* - * Stop the mbm overflow timers when the last event is destroyed. - */ - if (mbm_enabled && list_empty(&cache_groups)) + if (should_stop_mbm_timers(event)) mbm_stop_timers(); mutex_unlock(&cache_mutex); @@ -1373,10 +1399,7 @@ static int intel_cqm_event_init(struct perf_event *event) mutex_lock(&cache_mutex); - /* - * Start the mbm overflow timers when the first event is created. - */ - if (mbm_enabled && list_empty(&cache_groups)) + if (should_start_mbm_timers(event)) mbm_start_timers(); /* Will also set rmid */ -- 2.9.4