Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753283AbcD2EsR (ORCPT ); Fri, 29 Apr 2016 00:48:17 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:36205 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753089AbcD2Eqr (ORCPT ); Fri, 29 Apr 2016 00:46:47 -0400 From: David Carrillo-Cisneros To: Peter Zijlstra , Alexander Shishkin , Arnaldo Carvalho de Melo , Ingo Molnar Cc: Vikas Shivappa , Matt Fleming , Tony Luck , Stephane Eranian , Paul Turner , David Carrillo-Cisneros , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 28/32] perf/x86/intel/cqm: add CQM attributes to perf_event cgroup Date: Thu, 28 Apr 2016 21:43:34 -0700 Message-Id: <1461905018-86355-29-git-send-email-davidcc@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1461905018-86355-1-git-send-email-davidcc@google.com> References: <1461905018-86355-1-git-send-email-davidcc@google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3438 Lines: 123 Expose the boolean attribute intel_cqm.cont_monitoring . When set, the associated group will be monitored even if no perf cgroup event is attached to it. The occupancy of a cgroup must be read using a perf_event, regardless of the value of intel_cqm.cont_monitoring . Reviewed-by: Stephane Eranian Signed-off-by: David Carrillo-Cisneros --- arch/x86/events/intel/cqm.c | 81 +++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/perf_event.h | 6 +++ 2 files changed, 87 insertions(+) diff --git a/arch/x86/events/intel/cqm.c b/arch/x86/events/intel/cqm.c index 4ece0a4..33691c1 100644 --- a/arch/x86/events/intel/cqm.c +++ b/arch/x86/events/intel/cqm.c @@ -3194,4 +3194,85 @@ no_rmid: #endif } +#ifdef CONFIG_CGROUP_PERF + +/* kernfs guarantees that css doesn't need to be pinned. */ +static u64 cqm_cont_monitoring_read_u64(struct cgroup_subsys_state *css, + struct cftype *cft) +{ + int ret = -1; + struct perf_cgroup *perf_cgrp = css_to_perf_cgroup(css); + struct monr *monr; + + mutex_lock(&cqm_init_mutex); + if (!static_branch_likely(&cqm_initialized_key)) + goto out; + + mutex_lock(&cqm_mutex); + + ret = css_to_cqm_info(css)->cont_monitoring; + monr = monr_from_perf_cgroup(perf_cgrp); + WARN_ON(!monr->mon_event_group && + (ret != perf_cgroup_is_monitored(perf_cgrp))); + + mutex_unlock(&cqm_mutex); +out: + mutex_unlock(&cqm_init_mutex); + return ret; +} + +/* kernfs guarantees that css doesn't need to be pinned. */ +static int cqm_cont_monitoring_write_u64(struct cgroup_subsys_state *css, + struct cftype *cft, u64 value) +{ + int ret = 0; + struct perf_cgroup *perf_cgrp = css_to_perf_cgroup(css); + struct monr *monr; + + if (value > 1) + return -1; + + mutex_lock(&cqm_init_mutex); + if (!static_branch_likely(&cqm_initialized_key)) { + ret = -1; + goto out; + } + + /* Root cgroup cannot stop being monitored. */ + if (css == get_root_perf_css()) + goto out; + + mutex_lock(&cqm_mutex); + + monr = monr_from_perf_cgroup(perf_cgrp); + + if (value && !perf_cgroup_is_monitored(perf_cgrp)) + ret = __css_start_monitoring(css); + else if (!value && + !monr->mon_event_group && perf_cgroup_is_monitored(perf_cgrp)) + ret = __css_stop_monitoring(css); + + WARN_ON(!monr->mon_event_group && + (value != perf_cgroup_is_monitored(perf_cgrp))); + + css_to_cqm_info(css)->cont_monitoring = value; + + mutex_unlock(&cqm_mutex); +out: + mutex_unlock(&cqm_init_mutex); + return ret; +} + +struct cftype perf_event_cgrp_arch_subsys_cftypes[] = { + { + .name = "cqm_cont_monitoring", + .read_u64 = cqm_cont_monitoring_read_u64, + .write_u64 = cqm_cont_monitoring_write_u64, + }, + + {} /* terminate */ +}; + +#endif + device_initcall(intel_cqm_init); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index c22d9e0..99fc206 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -326,6 +326,12 @@ inline void perf_cgroup_arch_css_released(struct cgroup_subsys_state *css); perf_cgroup_arch_css_free inline void perf_cgroup_arch_css_free(struct cgroup_subsys_state *css); +extern struct cftype perf_event_cgrp_arch_subsys_cftypes[]; + +#define PERF_CGROUP_ARCH_CGRP_SUBSYS_ATTS \ + .dfl_cftypes = perf_event_cgrp_arch_subsys_cftypes, \ + .legacy_cftypes = perf_event_cgrp_arch_subsys_cftypes, + #else #define PERF_CGROUP_ARCH_CGRP_SUBSYS_ATTS -- 2.8.0.rc3.226.g39d4020