From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756272AbcJ3Akd (ORCPT ); Sat, 29 Oct 2016 20:40:33 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:34359 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755775AbcJ3AkT (ORCPT ); Sat, 29 Oct 2016 20:40:19 -0400 From: David Carrillo-Cisneros To: linux-kernel@vger.kernel.org Cc: "x86@kernel.org" , Ingo Molnar , Thomas Gleixner , Andi Kleen , Kan Liang , Peter Zijlstra , Vegard Nossum , Marcelo Tosatti , Nilay Vaish , Borislav Petkov , Vikas Shivappa , Ravi V Shankar , Fenghua Yu , Paul Turner , Stephane Eranian , David Carrillo-Cisneros Subject: [PATCH v3 24/46] perf/x86/intel/cmt: add perf_cgroup_arch_css_{online,offline} Date: Sat, 29 Oct 2016 17:38:21 -0700 Message-Id: <1477787923-61185-25-git-send-email-davidcc@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1477787923-61185-1-git-send-email-davidcc@google.com> References: <1477787923-61185-1-git-send-email-davidcc@google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use newly introduced architecture specific hooks to update monr hierarchy when a cgroup goes online/offline. Add cmt_initialized_key and use it to avoid using the hooks when the intel_cmt is not active. Signed-off-by: David Carrillo-Cisneros --- arch/x86/events/intel/cmt.c | 36 ++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/perf_event.h | 19 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/arch/x86/events/intel/cmt.c b/arch/x86/events/intel/cmt.c index 5c64d94..7545deb 100644 --- a/arch/x86/events/intel/cmt.c +++ b/arch/x86/events/intel/cmt.c @@ -24,6 +24,7 @@ static struct lock_class_key lock_keys[CMT_MAX_NR_PKGS]; static DEFINE_MUTEX(cmt_mutex); /* List of monrs that are associated with an event. */ static LIST_HEAD(cmt_event_monrs); +DEFINE_STATIC_KEY_FALSE(cmt_initialized_key); static unsigned int cmt_l3_scale; /* cmt hw units to bytes. */ @@ -1468,6 +1469,21 @@ static int __css_go_online(struct cgroup_subsys_state *css) return 0; } +int perf_cgroup_arch_css_online(struct cgroup_subsys_state *css) +{ + int err = 0; + + if (static_branch_unlikely(&cmt_initialized_key)) { + mutex_lock(&cmt_mutex); + monr_hrchy_acquire_mutexes(); + err = __css_go_online(css); + monr_hrchy_release_mutexes(); + mutex_unlock(&cmt_mutex); + } + + return err; +} + static void __css_go_offline(struct cgroup_subsys_state *css) { struct monr *monr; @@ -1487,6 +1503,17 @@ static void __css_go_offline(struct cgroup_subsys_state *css) monr_destroy(monr); } +void perf_cgroup_arch_css_offline(struct cgroup_subsys_state *css) +{ + if (static_branch_unlikely(&cmt_initialized_key)) { + mutex_lock(&cmt_mutex); + monr_hrchy_acquire_mutexes(); + __css_go_offline(css); + monr_hrchy_release_mutexes(); + mutex_unlock(&cmt_mutex); + } +} + #endif static void free_pkg_data(struct pkg_data *pkg_data) @@ -1760,6 +1787,12 @@ static void cmt_dealloc(void) static void cmt_stop(void) { + + static_branch_disable(&cmt_initialized_key); + + /* make sure CMT is turned is off before start tearing it down. */ + barrier(); + cpuhp_remove_state(CPUHP_AP_PERF_X86_CMT_ONLINE); cpuhp_remove_state(CPUHP_PERF_X86_CMT_PREP); @@ -1841,6 +1874,9 @@ static int __init cmt_start(void) if (err) goto rm_online; #endif + /* Make sure everything is ready prior to turn on key. */ + barrier(); + static_branch_enable(&cmt_initialized_key); return 0; diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index f353061..783bdbb 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -299,4 +299,23 @@ static inline void perf_check_microcode(void) { } #define arch_perf_out_copy_user copy_from_user_nmi + +/* + * Hooks for architecture specific features of perf_event cgroup. + * Currently used by Intel's CMT. + */ +#ifdef CONFIG_CGROUP_PERF +#ifdef CONFIG_INTEL_RDT_M + +#define perf_cgroup_arch_css_online \ + perf_cgroup_arch_css_online +int perf_cgroup_arch_css_online(struct cgroup_subsys_state *css); + +#define perf_cgroup_arch_css_offline \ + perf_cgroup_arch_css_offline +void perf_cgroup_arch_css_offline(struct cgroup_subsys_state *css); + +#endif +#endif + #endif /* _ASM_X86_PERF_EVENT_H */ -- 2.8.0.rc3.226.g39d4020