[PATCH v3 25/46] perf/x86/intel/cmt: add monr->flags and CMT_MONR_ZOMBIE
From: David Carrillo-Cisneros
Date: Sat Oct 29 2016 - 20:40:33 EST
Add a new enumeration to store monr's internal state information.
This new monr->flags contrasts with monr->uflag that stores user
provided flags.
The first flags is CMT_MONR_ZOMBIE, used to signal that the monr is no
longer valid, yet, must be kept around until its released by its last
user. This is useful when a monr is attached to a cgroup that is destroyed
but there are still events that reference that cgroup.
Signed-off-by: David Carrillo-Cisneros <davidcc@xxxxxxxxxx>
---
arch/x86/events/intel/cmt.c | 17 +++++++++++++++--
arch/x86/events/intel/cmt.h | 9 +++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/intel/cmt.c b/arch/x86/events/intel/cmt.c
index 7545deb..830ce29 100644
--- a/arch/x86/events/intel/cmt.c
+++ b/arch/x86/events/intel/cmt.c
@@ -423,7 +423,12 @@ static void monr_dealloc(struct monr *monr)
{
u16 p, nr_pkgs = topology_max_packages();
- if (WARN_ON_ONCE(monr->nr_has_user) ||
+ /*
+ * Only can dealloc monrs zombie monrs with all pmonrs in Off state
+ * and not attached to the monr hierarchy.
+ */
+ if (WARN_ON_ONCE(!(monr->flags & CMT_MONR_ZOMBIE)) ||
+ WARN_ON_ONCE(monr->nr_has_user) ||
WARN_ON_ONCE(monr->nr_nolazy_rmid) ||
WARN_ON_ONCE(monr->mon_cgrp) ||
WARN_ON_ONCE(monr->mon_events))
@@ -1178,12 +1183,20 @@ static int monr_hrchy_attach_event(struct perf_event *event)
static void monr_destroy(struct monr *monr)
{
+ if (monr->flags & CMT_MONR_ZOMBIE)
+ goto zombie;
+
#ifdef CONFIG_CGROUP_PERF
if (monr->mon_cgrp)
__css_stop_monitoring(&monr->mon_cgrp->css);
#endif
monr_hrchy_remove_leaf(monr);
- monr_dealloc(monr);
+
+ monr->flags = CMT_MONR_ZOMBIE;
+
+zombie:
+ if (!monr_has_user(monr))
+ monr_dealloc(monr);
}
/**
diff --git a/arch/x86/events/intel/cmt.h b/arch/x86/events/intel/cmt.h
index dc52641..1e40e6b 100644
--- a/arch/x86/events/intel/cmt.h
+++ b/arch/x86/events/intel/cmt.h
@@ -240,6 +240,13 @@ struct pkg_data {
};
/**
+ * enum monr_flags - internal monr's flags.
+ */
+enum monr_flags {
+ CMT_MONR_ZOMBIE = BIT(0), /* monr has been terminated. */
+};
+
+/**
* enum cmt_user_flags - user set flags for monr and pmonrs.
*/
enum cmt_user_flags {
@@ -259,6 +266,7 @@ enum cmt_user_flags {
* @parent: Parent in monr hierarchy.
* @children: List of children in monr hierarchy.
* @parent_entry: Entry in parent's children list.
+ * @flags: monr_flags.
* @nr_has_user: nr of CMT_UF_HAS_USER set in events in mon_events.
* @nr_nolazy_user: nr of CMT_UF_NOLAZY_RMID set in events in mon_events.
* @uflags: monr level cmt_user_flags, or'ed with pkg_uflags.
@@ -281,6 +289,7 @@ struct monr {
struct list_head children;
struct list_head parent_entry;
+ enum monr_flags flags;
int nr_has_user;
int nr_nolazy_rmid;
enum cmt_user_flags uflags;
--
2.8.0.rc3.226.g39d4020