lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 28 Apr 2016 21:43:34 -0700
From:	David Carrillo-Cisneros <davidcc@...gle.com>
To:	Peter Zijlstra <peterz@...radead.org>,
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
	Arnaldo Carvalho de Melo <acme@...nel.org>,
	Ingo Molnar <mingo@...hat.com>
Cc:	Vikas Shivappa <vikas.shivappa@...ux.intel.com>,
	Matt Fleming <matt.fleming@...el.com>,
	Tony Luck <tony.luck@...el.com>,
	Stephane Eranian <eranian@...gle.com>,
	Paul Turner <pjt@...gle.com>,
	David Carrillo-Cisneros <davidcc@...gle.com>, x86@...nel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH 28/32] perf/x86/intel/cqm: add CQM attributes to perf_event cgroup

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 <eranian@...gle.com>
Signed-off-by: David Carrillo-Cisneros <davidcc@...gle.com>
---
 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ