From: David Carrillo-Cisneros <davidcc@google.com>
To: linux-kernel@vger.kernel.org
Cc: "x86@kernel.org" <x86@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Andi Kleen <ak@linux.intel.com>, Kan Liang <kan.liang@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Vegard Nossum <vegard.nossum@gmail.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Nilay Vaish <nilayvaish@gmail.com>, Borislav Petkov <bp@suse.de>,
Vikas Shivappa <vikas.shivappa@linux.intel.com>,
Ravi V Shankar <ravi.v.shankar@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>, Paul Turner <pjt@google.com>,
Stephane Eranian <eranian@google.com>,
David Carrillo-Cisneros <davidcc@google.com>
Subject: [PATCH v3 37/46] perf/x86/intel/cmt: add cont_monitoring to perf cgroup
Date: Sat, 29 Oct 2016 17:38:34 -0700 [thread overview]
Message-ID: <1477787923-61185-38-git-send-email-davidcc@google.com> (raw)
In-Reply-To: <1477787923-61185-1-git-send-email-davidcc@google.com>
Expose the attribute intel_cmt.cont_monitoring to perf cgroups using
the newly introduced hook PERF_CGROUP_ARCH_CGRP_SUBSYS_ATTS.
The format of new attribute is a semi-colon separated list of per-package
hexadecimal flags with missing an empty string assigned to zero.
echo "1;2" > g1/intel_cmt.cont_monitoring
Implies 0x1 for pkg 0 and 0x2 for pkg 1, 0x0 for all other pkgs.
This patch introduces the basic ideas of per-package uflags through
a cgroup attribute. The format can be changed to match Intel CAT's
schemata's file format once that is settled.
Signed-off-by: David Carrillo-Cisneros <davidcc@google.com>
---
arch/x86/events/intel/cmt.c | 173 ++++++++++++++++++++++++++++++++++++++
arch/x86/include/asm/perf_event.h | 10 +++
2 files changed, 183 insertions(+)
diff --git a/arch/x86/events/intel/cmt.c b/arch/x86/events/intel/cmt.c
index 194038b..3ade923 100644
--- a/arch/x86/events/intel/cmt.c
+++ b/arch/x86/events/intel/cmt.c
@@ -2323,4 +2323,177 @@ inline void __intel_cmt_no_event_sched_in(void)
#endif
}
+#ifdef CONFIG_CGROUP_PERF
+
+static int cmt_monitoring_seq_show(struct seq_file *m, void *v)
+{
+ struct perf_cgroup *cgrp = perf_cgroup_from_css(seq_css(m));
+ struct monr *monr = NULL;
+ int p, nr_pkgs = topology_max_packages();
+
+ mutex_lock(&cmt_mutex);
+
+ if (perf_cgroup_mon_started(cgrp))
+ monr = monr_from_perf_cgroup(cgrp);
+
+ for (p = 0; p < nr_pkgs; p++) {
+ seq_printf(m, "%x", monr ? monr->pkg_uflags[p] : 0);
+ if (p + 1 < nr_pkgs)
+ seq_puts(m, ";");
+ }
+
+ seq_puts(m, "\n");
+
+ mutex_unlock(&cmt_mutex);
+ return 0;
+}
+
+/**
+ * Parses uflags string of the form: m1;m2;...;mP where m* are hexadecimal
+ * masks and P is less or equal than topology_max_packages(). Values not
+ * provided in the mask are assumed to be zero.
+ * On success, it allocates and returns an array.
+ */
+static enum cmt_user_flags *parse_pkg_uflags(char *buf, size_t nbytes)
+{
+ enum cmt_user_flags *uflags;
+ char *local_buf, *b, *m;
+ int err = 0, pmask, nr_pkgs = topology_max_packages();
+ u16 p = 0;
+
+ uflags = kcalloc(nr_pkgs, sizeof(*uflags), GFP_KERNEL);
+ if (!uflags)
+ return ERR_PTR(-ENOMEM);
+
+ local_buf = kcalloc(nbytes, sizeof(char), GFP_KERNEL);
+ if (!local_buf) {
+ err = -ENOMEM;
+ goto error;
+ }
+ memcpy(local_buf, buf, nbytes);
+ b = local_buf;
+ while ((m = strsep(&b, ";")) != NULL) {
+ if (p >= nr_pkgs) {
+ err = -EINVAL;
+ goto error;
+ }
+ if (!*m) {
+ uflags[p] = 0;
+ continue;
+ }
+ err = kstrtoint(m, 16, &pmask);
+ if (err)
+ goto error;
+ uflags[p] = pmask;
+ if (uflags[p] > CMT_UF_MAX) {
+ err = -EINVAL;
+ goto error;
+ }
+ /*
+ * Non-zero flags must have CMT_UF_HAS_USER set. Otherwise
+ * there could be that monrs are not used.
+ */
+ if (uflags[p] && (!(uflags[p] & CMT_UF_HAS_USER))) {
+ err = -EINVAL;
+ goto error;
+ }
+ p++;
+ }
+
+ kfree(local_buf);
+
+ return uflags;
+
+error:
+ kfree(local_buf);
+ kfree(uflags);
+
+ return ERR_PTR(err);
+}
+
+static ssize_t cmt_monitoring_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ struct cgroup_subsys_state *css = of_css(of);
+ struct monr *monr;
+ int err = 0;
+ bool is_mon;
+ enum cmt_user_flags *uflags;
+
+ /* root is read-only */
+ if (css == get_root_perf_css())
+ return -EINVAL;
+
+ buf = strstrip(buf);
+
+ mutex_lock(&cmt_mutex);
+ monr_hrchy_acquire_mutexes();
+
+ /* Monitoring active, use new flags. */
+ uflags = parse_pkg_uflags(buf, nbytes);
+ if (IS_ERR(uflags)) {
+ err = PTR_ERR(uflags);
+ goto exit_unlock;
+ }
+
+ is_mon = perf_cgroup_mon_started(perf_cgroup_from_css(css));
+ if (!is_mon) {
+ if (pkg_uflags_has_user(uflags)) {
+ err = __css_start_monitoring(css);
+ if (err)
+ goto exit_free;
+ } else {
+ /*
+ * uflags must be all zero or parse_pkg_uflags
+ * would have failed.
+ */
+ goto exit_free;
+ }
+ }
+
+ /* At this point the monr is guaranteed to be this css's monr. */
+ monr = monr_from_css(css);
+
+ /* Disregard if flags have not changed. */
+ if (!memcmp(uflags, monr->pkg_uflags, pkg_uflags_size))
+ goto exit_free;
+
+ /*
+ * will update monr->pkg_flags. Do not exit on error, continue to
+ * clean up monr if unused.
+ */
+ err = monr_apply_uflags(monr, uflags);
+
+ if (!monr_has_user(monr))
+ monr_destroy(monr);
+
+exit_free:
+ kfree(uflags);
+exit_unlock:
+ monr_hrchy_release_mutexes();
+ mutex_unlock(&cmt_mutex);
+ return err ?: nbytes;
+}
+
+struct cftype perf_event_cgrp_arch_subsys_cftypes[] = {
+ {
+ /*
+ * allows per-package specification of uflags. It takes a
+ * semi-colon separated list of hex uflags values. The hex
+ * value in the i-th position corresponds to the uflags of
+ * the package with logical id == i + 1 . Empty and missing hex
+ * values receive 0.
+ * e.g. "1;2" -> uflag 0x1 for pkg 0, uflag 0x2 for pkg 2,
+ * and 0x0 for all others.
+ */
+ .name = "cmt_monitoring",
+ .seq_show = cmt_monitoring_seq_show,
+ .write = cmt_monitoring_write,
+ },
+
+ {} /* terminate */
+};
+
+#endif
+
device_initcall(intel_cmt_init);
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
index 783bdbb..babee97 100644
--- a/arch/x86/include/asm/perf_event.h
+++ b/arch/x86/include/asm/perf_event.h
@@ -315,6 +315,16 @@ int perf_cgroup_arch_css_online(struct cgroup_subsys_state *css);
perf_cgroup_arch_css_offline
void perf_cgroup_arch_css_offline(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
+
#endif
#endif
--
2.8.0.rc3.226.g39d4020
next prev parent reply other threads:[~2016-10-30 0:43 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-30 0:37 [PATCH v3 00/46] Cache Monitoring Technology (aka CQM) David Carrillo-Cisneros
2016-10-30 0:37 ` [PATCH v3 01/46] perf/x86/intel/cqm: remove previous version of CQM and MBM David Carrillo-Cisneros
2016-10-30 0:37 ` [PATCH v3 02/46] perf/x86/intel: rename CQM cpufeatures to CMT David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 03/46] x86/intel: add CONFIG_INTEL_RDT_M configuration flag David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 04/46] perf/x86/intel/cmt: add device initialization and CPU hotplug support David Carrillo-Cisneros
2016-11-10 15:19 ` Thomas Gleixner
2016-10-30 0:38 ` [PATCH v3 05/46] perf/x86/intel/cmt: add per-package locks David Carrillo-Cisneros
2016-11-10 21:23 ` Thomas Gleixner
2016-11-11 2:22 ` David Carrillo-Cisneros
2016-11-11 7:21 ` Peter Zijlstra
2016-11-11 7:32 ` Ingo Molnar
2016-11-11 9:41 ` Thomas Gleixner
2016-11-11 17:21 ` David Carrillo-Cisneros
2016-11-13 10:58 ` Thomas Gleixner
2016-11-15 4:53 ` David Carrillo-Cisneros
2016-11-16 19:00 ` Thomas Gleixner
2016-10-30 0:38 ` [PATCH v3 06/46] perf/x86/intel/cmt: add intel_cmt pmu David Carrillo-Cisneros
2016-11-10 21:27 ` Thomas Gleixner
2016-10-30 0:38 ` [PATCH v3 07/46] perf/core: add RDT Monitoring attributes to struct hw_perf_event David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 08/46] perf/x86/intel/cmt: add MONitored Resource (monr) initialization David Carrillo-Cisneros
2016-11-10 23:09 ` Thomas Gleixner
2016-10-30 0:38 ` [PATCH v3 09/46] perf/x86/intel/cmt: add basic monr hierarchy David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 10/46] perf/x86/intel/cmt: add Package MONitored Resource (pmonr) initialization David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 11/46] perf/x86/intel/cmt: add cmt_user_flags (uflags) to monr David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 12/46] perf/x86/intel/cmt: add per-package rmid pools David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 13/46] perf/x86/intel/cmt: add pmonr's Off and Unused states David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 14/46] perf/x86/intel/cmt: add Active and Dep_{Idle, Dirty} states David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 15/46] perf/x86/intel: encapsulate rmid and closid updates in pqr cache David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 16/46] perf/x86/intel/cmt: set sched rmid and complete pmu start/stop/add/del David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 17/46] perf/x86/intel/cmt: add uflag CMT_UF_NOLAZY_RMID David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 18/46] perf/core: add arch_info field to struct perf_cgroup David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 19/46] perf/x86/intel/cmt: add support for cgroup events David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 20/46] perf/core: add pmu::event_terminate David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 21/46] perf/x86/intel/cmt: use newly introduced event_terminate David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 22/46] perf/x86/intel/cmt: sync cgroups and intel_cmt device start/stop David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 23/46] perf/core: hooks to add architecture specific features in perf_cgroup David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 24/46] perf/x86/intel/cmt: add perf_cgroup_arch_css_{online,offline} David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 25/46] perf/x86/intel/cmt: add monr->flags and CMT_MONR_ZOMBIE David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 26/46] sched: introduce the finish_arch_pre_lock_switch() scheduler hook David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 27/46] perf/x86/intel: add pqr cache flags and intel_pqr_ctx_switch David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 28/46] perf,perf/x86,perf/powerpc,perf/arm,perf/*: add int error return to pmu::read David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 29/46] perf/x86/intel/cmt: add error handling to intel_cmt_event_read David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 30/46] perf/x86/intel/cmt: add asynchronous read for task events David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 31/46] perf/x86/intel/cmt: add subtree read for cgroup events David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 32/46] perf/core: Add PERF_EV_CAP_READ_ANY_{CPU_,}PKG flags David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 33/46] perf/x86/intel/cmt: use PERF_EV_CAP_READ_{,CPU_}PKG flags in Intel cmt David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 34/46] perf/core: introduce PERF_EV_CAP_CGROUP_NO_RECURSION David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 35/46] perf/x86/intel/cmt: use PERF_EV_CAP_CGROUP_NO_RECURSION in intel_cmt David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 36/46] perf/core: add perf_event cgroup hooks for subsystem attributes David Carrillo-Cisneros
2016-10-30 0:38 ` David Carrillo-Cisneros [this message]
2016-10-30 0:38 ` [PATCH v3 38/46] perf/x86/intel/cmt: introduce read SLOs for rotation David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 39/46] perf/x86/intel/cmt: add max_recycle_threshold sysfs attribute David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 40/46] perf/x86/intel/cmt: add rotation scheduled work David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 41/46] perf/x86/intel/cmt: add rotation minimum progress SLO David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 42/46] perf/x86/intel/cmt: add rmid stealing David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 43/46] perf/x86/intel/cmt: add CMT_UF_NOSTEAL_RMID flag David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 44/46] perf/x86/intel/cmt: add debugfs intel_cmt directory David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 45/46] perf/stat: fix bug in handling events in error state David Carrillo-Cisneros
2016-10-30 0:38 ` [PATCH v3 46/46] perf/stat: revamp read error handling, snapshot and per_pkg events David Carrillo-Cisneros
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1477787923-61185-38-git-send-email-davidcc@google.com \
--to=davidcc@google.com \
--cc=ak@linux.intel.com \
--cc=bp@suse.de \
--cc=eranian@google.com \
--cc=fenghua.yu@intel.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=nilayvaish@gmail.com \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=ravi.v.shankar@intel.com \
--cc=tglx@linutronix.de \
--cc=vegard.nossum@gmail.com \
--cc=vikas.shivappa@linux.intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome