Skip to contentSkip to conversation

Enable i915 perf stream for Haswell OA unit

PATCH Superseded Robert Bragg 7 participants 30 messages Oct 24, 2016 – Oct 27, 2016 1 message not in the archive

Subsystems (4)

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 cover Enable i915 perf stream for Haswell OA unit

Rebased on nightly, including recent review updates (CI wasn't happy picking up the replies updating individual patches).

This also reverts back to pinning the context upfront when opening a stream for a single context, instead of hooking into pinning and updating OACONTROL on the fly.

Chris has repeatedly suggested he'd prefer to have the driver work with an upfront pin, as it used to, instead of with the hook. It was changed last time based on feedback considering some concern with the shrinker. At least from inspection it does /seem/ safe to assume a pinned vma will reliably block the shrinker from freeing ctx pages and the shrinker itself doesn't unpin things. I'm not fully certain of the interaction with the _gem.c _context_lost() code path which aims to unpin last_context. At least the code is a little simpler this way, so maybe if Daniel is happy that his original concern was overly cautious (or no longer an issue with the latest code), then this change is ok.

- Robert

Robert Bragg (11):
drm/i915: Add i915 perf infrastructure
drm/i915: rename OACONTROL GEN7_OACONTROL drm/i915: return EACCES for check_cmd() failures drm/i915: don't whitelist oacontrol in cmd parser drm/i915: Add 'render basic' Haswell OA unit config drm/i915: Enable i915 perf stream for Haswell OA unit drm/i915: advertise available metrics via sysfs drm/i915: Add dev.i915.perf_stream_paranoid sysctl option drm/i915: add oa_event_min_timer_exponent sysctl drm/i915: Add more Haswell OA metric sets drm/i915: Add a kerneldoc summary for i915_perf.c

 drivers/gpu/drm/i915/Makefile          |    4 +
 drivers/gpu/drm/i915/gvt/handlers.c    |    2 +-
 drivers/gpu/drm/i915/i915_cmd_parser.c |   45 +-
 drivers/gpu/drm/i915/i915_drv.c        |    9 +
 drivers/gpu/drm/i915/i915_drv.h        |  155 +++
 drivers/gpu/drm/i915/i915_oa_hsw.c     |  752 ++++++++++++++
 drivers/gpu/drm/i915/i915_oa_hsw.h     |   38 +
 drivers/gpu/drm/i915/i915_perf.c       | 1689 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_reg.h        |  340 ++++++-
 include/uapi/drm/i915_drm.h            |  133 +++
 10 files changed, 3127 insertions(+), 40 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_oa_hsw.c
 create mode 100644 drivers/gpu/drm/i915/i915_oa_hsw.h
 create mode 100644 drivers/gpu/drm/i915/i915_perf.c
Signature · 6 lines
2.10.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v7 1/11 drm/i915: Add i915 perf infrastructure

Adds base i915 perf infrastructure for Gen performance metrics.

This adds a DRM_IOCTL_I915_PERF_OPEN ioctl that takes an array of uint64 properties to configure a stream of metrics and returns a new fd usable with standard VFS system calls including read() to read typed and sized records; ioctl() to enable or disable capture and poll() to wait for data.

A stream is opened something like:

  uint64_t properties[] = {
      /* Single context sampling */
      DRM_I915_PERF_PROP_CTX_HANDLE,        ctx_handle,
      /* Include OA reports in samples */
      DRM_I915_PERF_PROP_SAMPLE_OA,         true,

      /* OA unit configuration */
      DRM_I915_PERF_PROP_OA_METRICS_SET,    metrics_set_id,
      DRM_I915_PERF_PROP_OA_FORMAT,         report_format,
      DRM_I915_PERF_PROP_OA_EXPONENT,       period_exponent,
   };
   struct drm_i915_perf_open_param parm = {
      .flags = I915_PERF_FLAG_FD_CLOEXEC |
               I915_PERF_FLAG_FD_NONBLOCK |
               I915_PERF_FLAG_DISABLED,
      .properties_ptr = (uint64_t)properties,
      .num_properties = sizeof(properties) / 16,

};
int fd = drmIoctl(drm_fd, DRM_IOCTL_I915_PERF_OPEN, &param);

Records read all start with a common { type, size } header with DRM_I915_PERF_RECORD_SAMPLE being of most interest. Sample records contain an extensible number of fields and it's the DRM_I915_PERF_PROP_SAMPLE_xyz properties given when opening that determine what's included in every sample.

No specific streams are supported yet so any attempt to open a stream will return an error.

v4:
s/DRM_IORW/DRM_IOW/ - Emil Velikov
v3:
update read() interface to avoid passing state struct - Chris Wilson fix some rebase fallout, with i915-perf init/deinit
v2:
use i915_gem_context_get() - Chris Wilson

---
 drivers/gpu/drm/i915/Makefile    |   3 +
 drivers/gpu/drm/i915/i915_drv.c  |   4 +
 drivers/gpu/drm/i915/i915_drv.h  |  91 ++++++++
 drivers/gpu/drm/i915/i915_perf.c | 443 +++++++++++++++++++++++++++++++++++++++
 include/uapi/drm/i915_drm.h      |  67 ++++++
 5 files changed, 608 insertions(+)
 create mode 100644 drivers/gpu/drm/i915/i915_perf.c
drivers/gpu/drm/i915/Makefile +3 -0
index 6123400..8d4e25f 100644
@@ -113,6 +113,9 @@ i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
 # virtual gpu code
 i915-y += i915_vgpu.o
 
+# perf code
+i915-y += i915_perf.o
+
 ifeq ($(CONFIG_DRM_I915_GVT),y)
 i915-y += intel_gvt.o
 include $(src)/gvt/Makefile
drivers/gpu/drm/i915/i915_drv.c +4 -0
index 99e4e04..e99d14e 100644
@@ -836,6 +836,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
 
 	intel_detect_preproduction_hw(dev_priv);
 
+	i915_perf_init(dev_priv);
+
 	return 0;
 
 err_workqueues:
@@ -849,6 +851,7 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
  */
 static void i915_driver_cleanup_early(struct drm_i915_private *dev_priv)
 {
+	i915_perf_fini(dev_priv);
 	i915_gem_load_cleanup(&dev_priv->drm);
 	i915_workqueues_cleanup(dev_priv);
 }
@@ -2554,6 +2557,7 @@ static const struct drm_ioctl_desc i915_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(I915_PERF_OPEN, i915_perf_open_ioctl, DRM_RENDER_ALLOW),
 };
 
 static struct drm_driver driver = {
drivers/gpu/drm/i915/i915_drv.h +91 -0

115 lines not on this page · raw message

drivers/gpu/drm/i915/i915_perf.c new file +443 -0

443 lines not on this page · raw message

include/uapi/drm/i915_drm.h +67 -0

85 lines not on this page · raw message

Signature · 6 lines
2.10.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v7 1/11
#2 lore raw

Re: [PATCH v7 01/11] drm/i915: Add i915 perf infrastructure

Quoted 29 lines
drivers/gpu/drm/i915/i915_perf.c new file +29 -0
+
+/* Note we copy the properties from userspace outside of the i915 perf
+ * mutex to avoid an awkward lockdep with mmap_sem.
+ *
+ * Note this function only validates properties in isolation it doesn't
+ * validate that the combination of properties makes sense or that all
+ * properties necessary for a particular kind of stream have been set.
+ */
+static int read_properties_unlocked(struct drm_i915_private *dev_priv,
+                                   u64 __user *uprops,
+                                   u32 n_props,
+                                   struct perf_open_properties *props)
+{
+       u64 __user *uprop = uprops;
+       int i;
+
+       memset(props, 0, sizeof(struct perf_open_properties));
+
+       if (!n_props) {
+               DRM_ERROR("No i915 perf properties given");
+               return -EINVAL;
+       }
+
+       if (n_props > DRM_I915_PERF_PROP_MAX) {
+               DRM_ERROR("More i915 perf properties specified than exist");
+               return -EINVAL;
+       }
+
+       for (i = 0; i < n_props; i++) {

drivers/gpu/drm/i915/i915_perf.c line 372

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c new file +10 -0
+               u64 id, value;
+               int ret;
+
+               ret = get_user(id, (u64 __user *)uprop);
+               if (ret)
+                       return ret;
+
+               ret = get_user(value, (u64 __user *)uprop + 1);
+               if (ret)
+                       return ret;

Do we really need all of these __user casts, they seem redundant, no?

Otherwise looks good so:

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw

PATCH v7 2/11 drm/i915: rename OACONTROL GEN7_OACONTROL

In reply to Robert Bragg

OACONTROL changes quite a bit for gen8, with some bits split out into a per-context OACTXCONTROL register. Rename now before adding more gen7 OA registers

---
 drivers/gpu/drm/i915/gvt/handlers.c    | 2 +-
 drivers/gpu/drm/i915/i915_cmd_parser.c | 4 ++--
 drivers/gpu/drm/i915/i915_reg.h        | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gvt/handlers.c +1 -1
index 3e74fb3..68e07a1 100644
@@ -2159,7 +2159,7 @@ static int init_generic_mmio_info(struct intel_gvt *gvt)
 	MMIO_DFH(0x1217c, D_ALL, F_CMD_ACCESS, NULL, NULL);
 
 	MMIO_F(0x2290, 8, 0, 0, 0, D_HSW_PLUS, NULL, NULL);
-	MMIO_D(OACONTROL, D_HSW);
+	MMIO_D(GEN7_OACONTROL, D_HSW);
 	MMIO_D(0x2b00, D_BDW_PLUS);
 	MMIO_D(0x2360, D_BDW_PLUS);
 	MMIO_F(0x5200, 32, 0, 0, 0, D_ALL, NULL, NULL);
drivers/gpu/drm/i915/i915_cmd_parser.c +2 -2
index f191d7b..fe34470 100644
@@ -450,7 +450,7 @@ static const struct drm_i915_reg_descriptor gen7_render_regs[] = {
 	REG64(PS_INVOCATION_COUNT),
 	REG64(PS_DEPTH_COUNT),
 	REG64_IDX(RING_TIMESTAMP, RENDER_RING_BASE),
-	REG32(OACONTROL), /* Only allowed for LRI and SRM. See below. */
+	REG32(GEN7_OACONTROL), /* Only allowed for LRI and SRM. See below. */
 	REG64(MI_PREDICATE_SRC0),
 	REG64(MI_PREDICATE_SRC1),
 	REG32(GEN7_3DPRIM_END_OFFSET),
@@ -1108,7 +1108,7 @@ static bool check_cmd(const struct intel_engine_cs *engine,
 			 * to the register. Hence, limit OACONTROL writes to
 			 * only MI_LOAD_REGISTER_IMM commands.
 			 */
-			if (reg_addr == i915_mmio_reg_offset(OACONTROL)) {
+			if (reg_addr == i915_mmio_reg_offset(GEN7_OACONTROL)) {
 				if (desc->cmd.value == MI_LOAD_REGISTER_MEM) {
 					DRM_DEBUG_DRIVER("CMD: Rejected LRM to OACONTROL\n");
 					return false;
drivers/gpu/drm/i915/i915_reg.h +1 -1
index a9be3f0..070d3297 100644
@@ -615,7 +615,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)
 #define HSW_CS_GPR(n)                   _MMIO(0x2600 + (n) * 8)
 #define HSW_CS_GPR_UDW(n)               _MMIO(0x2600 + (n) * 8 + 4)
 
-#define OACONTROL _MMIO(0x2360)
+#define GEN7_OACONTROL _MMIO(0x2360)
 
 #define _GEN7_PIPEA_DE_LOAD_SL	0x70068
 #define _GEN7_PIPEB_DE_LOAD_SL	0x71068
Signature · 6 lines
2.10.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH v7 3/11 drm/i915: return EACCES for check_cmd() failures

In reply to Robert Bragg

check_cmd() is checking whether a command adheres to certain restrictions that ensure it's safe to execute within a privileged batch buffer. Returning false implies a privilege problem, not that the command is invalid.

The distinction makes the difference between allowing the buffer to be executed as an unprivileged batch buffer or returning an EINVAL error to userspace without executing anything.

In a case where userspace may want to test whether it can successfully write to a register that needs privileges the distinction may be important and an EINVAL error may be considered fatal.

In particular this is currently true for Mesa, which includes a test for whether OACONTROL can be written too, but Mesa treats any error when flushing a batch buffer as fatal, calling exit(1).

As it is currently Mesa can gracefully handle a failure to write to OACONTROL if the command parser is disabled, but if we were to remove OACONTROL from the parser's whitelist then the returned EINVAL would break Mesa applications as they attempt an OACONTROL write.

This bumps the command parser version from 7 to 8, as the change is visible to userspace.

---
 drivers/gpu/drm/i915/i915_cmd_parser.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +5 -2
index fe34470..c45dd83 100644
@@ -1272,7 +1272,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
 
 		if (!check_cmd(engine, desc, cmd, length, is_master,
 			       &oacontrol_set)) {
-			ret = -EINVAL;
+			ret = -EACCES;
 			break;
 		}
 
@@ -1333,6 +1333,9 @@ int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv)
 	 * 5. GPGPU dispatch compute indirect registers.
 	 * 6. TIMESTAMP register and Haswell CS GPR registers
 	 * 7. Allow MI_LOAD_REGISTER_REG between whitelisted registers.
+	 * 8. Don't report cmd_check() failures as EINVAL errors to userspace;
+	 *    rely on the HW to NOOP disallowed commands as it would without
+	 *    the parser enabled.
 	 */
-	return 7;
+	return 8;
 }
Signature · 6 lines
2.10.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v7 3/11
#5 lore raw

Re: [PATCH v7 03/11] drm/i915: return EACCES for check_cmd() failures

Quoted 22 lines · Robert Bragg

check_cmd() is checking whether a command adheres to certain restrictions that ensure it's safe to execute within a privileged batch buffer. Returning false implies a privilege problem, not that the command is invalid.

The distinction makes the difference between allowing the buffer to be executed as an unprivileged batch buffer or returning an EINVAL error to userspace without executing anything.

In a case where userspace may want to test whether it can successfully write to a register that needs privileges the distinction may be important and an EINVAL error may be considered fatal.

In particular this is currently true for Mesa, which includes a test for whether OACONTROL can be written too, but Mesa treats any error when flushing a batch buffer as fatal, calling exit(1).

As it is currently Mesa can gracefully handle a failure to write to OACONTROL if the command parser is disabled, but if we were to remove OACONTROL from the parser's whitelist then the returned EINVAL would break Mesa applications as they attempt an OACONTROL write.

Quoted 4 lines

This bumps the command parser version from 7 to 8, as the change is visible to userspace.

Seems reasonable.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

PATCH v7 4/11 drm/i915: don't whitelist oacontrol in cmd parser

In reply to Robert Bragg

Being able to program OACONTROL from a non-privileged batch buffer is not sufficient to be able to configure the OA unit. This was originally allowed to help enable Mesa to expose OA counters via the INTEL_performance_query extension, but the current implementation based on programming OACONTROL via a batch buffer isn't able to report useable data without a more complete OA unit configuration. Mesa handles the possibility that writes to OACONTROL may not be allowed and so only advertises the extension after explicitly testing that a write to OACONTROL succeeds. Based on this; removing OACONTROL from the whitelist should be ok for userspace.

Removing this simplifies adding a new kernel api for configuring the OA unit without needing to consider the possibility that userspace might trample on OACONTROL state which we'd like to start managing within the kernel instead. In particular running any Mesa based GL application currently results in clearing OACONTROL when initializing which would disable the capturing of metrics.

---
 drivers/gpu/drm/i915/i915_cmd_parser.c | 38 ++--------------------------------
 1 file changed, 2 insertions(+), 36 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +2 -36
index c45dd83..5152d6f 100644
@@ -450,7 +450,6 @@ static const struct drm_i915_reg_descriptor gen7_render_regs[] = {
 	REG64(PS_INVOCATION_COUNT),
 	REG64(PS_DEPTH_COUNT),
 	REG64_IDX(RING_TIMESTAMP, RENDER_RING_BASE),
-	REG32(GEN7_OACONTROL), /* Only allowed for LRI and SRM. See below. */
 	REG64(MI_PREDICATE_SRC0),
 	REG64(MI_PREDICATE_SRC1),
 	REG32(GEN7_3DPRIM_END_OFFSET),
@@ -1060,8 +1059,7 @@ bool intel_engine_needs_cmd_parser(struct intel_engine_cs *engine)
 static bool check_cmd(const struct intel_engine_cs *engine,
 		      const struct drm_i915_cmd_descriptor *desc,
 		      const u32 *cmd, u32 length,
-		      const bool is_master,
-		      bool *oacontrol_set)
+		      const bool is_master)
 {
 	if (desc->flags & CMD_DESC_SKIP)
 		return true;
@@ -1099,31 +1097,6 @@ static bool check_cmd(const struct intel_engine_cs *engine,
 			}
 
 			/*
-			 * OACONTROL requires some special handling for
-			 * writes. We want to make sure that any batch which
-			 * enables OA also disables it before the end of the
-			 * batch. The goal is to prevent one process from
-			 * snooping on the perf data from another process. To do
-			 * that, we need to check the value that will be written
-			 * to the register. Hence, limit OACONTROL writes to
-			 * only MI_LOAD_REGISTER_IMM commands.
-			 */
-			if (reg_addr == i915_mmio_reg_offset(GEN7_OACONTROL)) {
-				if (desc->cmd.value == MI_LOAD_REGISTER_MEM) {
-					DRM_DEBUG_DRIVER("CMD: Rejected LRM to OACONTROL\n");
-					return false;
-				}
-
-				if (desc->cmd.value == MI_LOAD_REGISTER_REG) {
-					DRM_DEBUG_DRIVER("CMD: Rejected LRR to OACONTROL\n");
-					return false;
-				}
-
-				if (desc->cmd.value == MI_LOAD_REGISTER_IMM(1))
-					*oacontrol_set = (cmd[offset + 1] != 0);
-			}
-
-			/*
 			 * Check the value written to the register against the
 			 * allowed mask/value pair given in the whitelist entry.
 			 */
@@ -1214,7 +1187,6 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
 	u32 *cmd, *batch_end;
 	struct drm_i915_cmd_descriptor default_desc = noop_desc;
 	const struct drm_i915_cmd_descriptor *desc = &default_desc;
-	bool oacontrol_set = false; /* OACONTROL tracking. See check_cmd() */
 	bool needs_clflush_after = false;
 	int ret = 0;
 
@@ -1270,8 +1242,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
 			break;
 		}
 
-		if (!check_cmd(engine, desc, cmd, length, is_master,
-			       &oacontrol_set)) {
+		if (!check_cmd(engine, desc, cmd, length, is_master)) {
 			ret = -EACCES;
 			break;
 		}
@@ -1279,11 +1250,6 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
 		cmd += length;
 	}
 
-	if (oacontrol_set) {
-		DRM_DEBUG_DRIVER("CMD: batch set OACONTROL but did not clear it\n");
-		ret = -EINVAL;
-	}
-
 	if (cmd >= batch_end) {
 		DRM_DEBUG_DRIVER("CMD: Got to the end of the buffer w/o a BBE cmd!\n");
 		ret = -EINVAL;
Signature · 6 lines
2.10.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v7 4/11
#7 lore raw

Re: [PATCH v7 04/11] drm/i915: don't whitelist oacontrol in cmd parser

Quoted 11 lines · Robert Bragg

Being able to program OACONTROL from a non-privileged batch buffer is not sufficient to be able to configure the OA unit. This was originally allowed to help enable Mesa to expose OA counters via the INTEL_performance_query extension, but the current implementation based on programming OACONTROL via a batch buffer isn't able to report useable data without a more complete OA unit configuration. Mesa handles the possibility that writes to OACONTROL may not be allowed and so only advertises the extension after explicitly testing that a write to OACONTROL succeeds. Based on this; removing OACONTROL from the whitelist should be ok for userspace.

Quoted 8 lines

Removing this simplifies adding a new kernel api for configuring the OA unit without needing to consider the possibility that userspace might trample on OACONTROL state which we'd like to start managing within the kernel instead. In particular running any Mesa based GL application currently results in clearing OACONTROL when initializing which would disable the capturing of metrics.

Okay, seems reasonable.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

PATCH v7 5/11 drm/i915: Add 'render basic' Haswell OA unit config

In reply to Robert Bragg

Adds a static OA unit, MUX + B Counter configuration for basic render metrics on Haswell. This is auto generated from an XML description of metric sets, currently maintained in gputop, ref:

https://github.com/rib/gputop

Quoted 2 lines

gputop-data/oa-*.xml
scripts/i915-perf-kernelgen.py

  $ make -C gputop-data -f Makefile.xml SYSFS=0 WHITELIST=RenderBasic
---
 drivers/gpu/drm/i915/Makefile      |   3 +-
 drivers/gpu/drm/i915/i915_drv.h    |  14 ++++
 drivers/gpu/drm/i915/i915_oa_hsw.c | 144 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_oa_hsw.h |  34 +++++++++
 4 files changed, 194 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/i915/i915_oa_hsw.c
 create mode 100644 drivers/gpu/drm/i915/i915_oa_hsw.h
drivers/gpu/drm/i915/Makefile +2 -1
index 8d4e25f..ac0c3ad 100644
@@ -114,7 +114,8 @@ i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
 i915-y += i915_vgpu.o
 
 # perf code
-i915-y += i915_perf.o
+i915-y += i915_perf.o \
+	  i915_oa_hsw.o
 
 ifeq ($(CONFIG_DRM_I915_GVT),y)
 i915-y += intel_gvt.o
drivers/gpu/drm/i915/i915_drv.h +14 -0
index fcc5958..3448d05 100644
@@ -1764,6 +1764,11 @@ struct intel_wm_config {
 	bool sprites_scaled;
 };
 
+struct i915_oa_reg {
+	i915_reg_t addr;
+	u32 value;
+};
+
 struct i915_perf_stream;
 
 struct i915_perf_stream_ops {
@@ -2146,6 +2151,15 @@ struct drm_i915_private {
 		bool initialized;
 		struct mutex lock;
 		struct list_head streams;
+
+		struct {
+			u32 metrics_set;
+
+			const struct i915_oa_reg *mux_regs;
+			int mux_regs_len;
+			const struct i915_oa_reg *b_counter_regs;
+			int b_counter_regs_len;
+		} oa;
 	} perf;
 
 	/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
drivers/gpu/drm/i915/i915_oa_hsw.c new file +144 -0

144 lines not on this page · raw message

drivers/gpu/drm/i915/i915_oa_hsw.h new file +34 -0
new file mode 100644
index 0000000..b618a1f
@@ -0,0 +1,34 @@
+/*
+ * Autogenerated file, DO NOT EDIT manually!
+ *
+ * Copyright (c) 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#ifndef __I915_OA_HSW_H__
+#define __I915_OA_HSW_H__
+
+extern int i915_oa_n_builtin_metric_sets_hsw;
+
+extern int i915_oa_select_metric_set_hsw(struct drm_i915_private *dev_priv);
+
+#endif
Signature · 6 lines
2.10.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

PATCH v7 6/11 drm/i915: Enable i915 perf stream for Haswell OA unit

In reply to Robert Bragg

Gen graphics hardware can be set up to periodically write snapshots of performance counters into a circular buffer via its Observation Architecture and this patch exposes that capability to userspace via the i915 perf interface.

v2:
Make sure to initialize ->specific_ctx_id when opening, without relying on _pin_notify hook, in case ctx already pinned.
v3:
Revert back to pinning ctx upfront when opening stream, removing need to hook in to pinning and to update OACONTROL on the fly.

fix enable hsw

---
 drivers/gpu/drm/i915/i915_drv.h  |   65 ++-
 drivers/gpu/drm/i915/i915_perf.c | 1000 +++++++++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_reg.h  |  338 +++++++++++++
 include/uapi/drm/i915_drm.h      |   70 ++-
 4 files changed, 1444 insertions(+), 29 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +55 -10
index 3448d05..ea24814 100644
@@ -1764,6 +1764,11 @@ struct intel_wm_config {
 	bool sprites_scaled;
 };
 
+struct i915_oa_format {
+	u32 format;
+	int size;
+};
+
 struct i915_oa_reg {
 	i915_reg_t addr;
 	u32 value;
@@ -1784,11 +1789,6 @@ struct i915_perf_stream_ops {
 	 */
 	void (*disable)(struct i915_perf_stream *stream);
 
-	/* Return: true if any i915 perf records are ready to read()
-	 * for this stream.
-	 */
-	bool (*can_read)(struct i915_perf_stream *stream);
-
 	/* Call poll_wait, passing a wait queue that will be woken
 	 * once there is something ready to read() for the stream
 	 */
@@ -1798,9 +1798,7 @@ struct i915_perf_stream_ops {
 
 	/* For handling a blocking read, wait until there is something
 	 * to ready to read() for the stream. E.g. wait on the same
-	 * wait queue that would be passed to poll_wait() until
-	 * ->can_read() returns true (if its safe to call ->can_read()
-	 * without the i915 perf lock held).
+	 * wait queue that would be passed to poll_wait().
 	 */
 	int (*wait_unlocked)(struct i915_perf_stream *stream);
 
@@ -1840,11 +1838,28 @@ struct i915_perf_stream {
 	struct list_head link;
 
 	u32 sample_flags;
+	int sample_size;
 
 	struct i915_gem_context *ctx;
 	bool enabled;
 
-	struct i915_perf_stream_ops *ops;
+	const struct i915_perf_stream_ops *ops;
+};
+
+struct i915_oa_ops {
+	void (*init_oa_buffer)(struct drm_i915_private *dev_priv);
+	int (*enable_metric_set)(struct drm_i915_private *dev_priv);
+	void (*disable_metric_set)(struct drm_i915_private *dev_priv);
+	void (*oa_enable)(struct drm_i915_private *dev_priv);
+	void (*oa_disable)(struct drm_i915_private *dev_priv);
+	void (*update_oacontrol)(struct drm_i915_private *dev_priv);
+	void (*update_hw_ctx_id_locked)(struct drm_i915_private *dev_priv,
+					u32 ctx_id);
+	int (*read)(struct i915_perf_stream *stream,
+		    char __user *buf,
+		    size_t count,
+		    size_t *offset);
+	bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv);
 };
 
 struct drm_i915_private {
@@ -2149,16 +2164,46 @@ struct drm_i915_private {
 
 	struct {
 		bool initialized;
+
 		struct mutex lock;
 		struct list_head streams;
 
+		spinlock_t hook_lock;
+
 		struct {
-			u32 metrics_set;
+			struct i915_perf_stream *exclusive_stream;
+
+			u32 specific_ctx_id;
+
+			struct hrtimer poll_check_timer;
+			wait_queue_head_t poll_wq;
+			atomic_t pollin;
+
+			bool periodic;
+			int period_exponent;
+			int timestamp_frequency;
+
+			int tail_margin;
+
+			int metrics_set;
 
 			const struct i915_oa_reg *mux_regs;
 			int mux_regs_len;
 			const struct i915_oa_reg *b_counter_regs;
 			int b_counter_regs_len;
+
+			struct {
+				struct i915_vma *vma;
+				u8 *vaddr;
+				int format;
+				int format_size;
+			} oa_buffer;
+
+			u32 gen7_latched_oastatus1;
+
+			struct i915_oa_ops ops;
+			const struct i915_oa_format *oa_formats;
+			int n_builtin_sets;
 		} oa;
 	} perf;
 
drivers/gpu/drm/i915/i915_perf.c +983 -17

1,074 lines not on this page · raw message

drivers/gpu/drm/i915/i915_reg.h +338 -0

350 lines not on this page · raw message

include/uapi/drm/i915_drm.h +68 -2

104 lines not on this page · raw message

Signature · 6 lines
2.10.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 12 lines · Robert Bragg

Gen graphics hardware can be set up to periodically write snapshots of performance counters into a circular buffer via its Observation Architecture and this patch exposes that capability to userspace via the i915 perf interface.

v2:
Make sure to initialize ->specific_ctx_id when opening, without relying on _pin_notify hook, in case ctx already pinned.
v3:
Revert back to pinning ctx upfront when opening stream, removing need to hook in to pinning and to update OACONTROL on the fly.

Quoted 5 lines

fix enable hsw

Random bit of cruft ?

Quoted 81 lines
---
 drivers/gpu/drm/i915/i915_drv.h  |   65 ++-
 drivers/gpu/drm/i915/i915_perf.c | 1000 +++++++++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_reg.h  |  338 +++++++++++++
 include/uapi/drm/i915_drm.h      |   70 ++-
 4 files changed, 1444 insertions(+), 29 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +25 -9
index 3448d05..ea24814 100644
@@ -1764,6 +1764,11 @@ struct intel_wm_config {
        bool sprites_scaled;
 };
 
+struct i915_oa_format {
+       u32 format;
+       int size;
+};
+
 struct i915_oa_reg {
        i915_reg_t addr;
        u32 value;
@@ -1784,11 +1789,6 @@ struct i915_perf_stream_ops {
         */
        void (*disable)(struct i915_perf_stream *stream);
 
-       /* Return: true if any i915 perf records are ready to read()
-        * for this stream.
-        */
-       bool (*can_read)(struct i915_perf_stream *stream);
-
        /* Call poll_wait, passing a wait queue that will be woken
         * once there is something ready to read() for the stream
         */
@@ -1798,9 +1798,7 @@ struct i915_perf_stream_ops {
 
        /* For handling a blocking read, wait until there is something
         * to ready to read() for the stream. E.g. wait on the same
-        * wait queue that would be passed to poll_wait() until
-        * ->can_read() returns true (if its safe to call ->can_read()
-        * without the i915 perf lock held).
+        * wait queue that would be passed to poll_wait().
         */
        int (*wait_unlocked)(struct i915_perf_stream *stream);
 
@@ -1840,11 +1838,28 @@ struct i915_perf_stream {
        struct list_head link;
 
        u32 sample_flags;
+       int sample_size;
 
        struct i915_gem_context *ctx;
        bool enabled;
 
-       struct i915_perf_stream_ops *ops;
+       const struct i915_perf_stream_ops *ops;
+};
+
+struct i915_oa_ops {
+       void (*init_oa_buffer)(struct drm_i915_private *dev_priv);
+       int (*enable_metric_set)(struct drm_i915_private *dev_priv);
+       void (*disable_metric_set)(struct drm_i915_private *dev_priv);
+       void (*oa_enable)(struct drm_i915_private *dev_priv);
+       void (*oa_disable)(struct drm_i915_private *dev_priv);
+       void (*update_oacontrol)(struct drm_i915_private *dev_priv);
+       void (*update_hw_ctx_id_locked)(struct drm_i915_private *dev_priv,
+                                       u32 ctx_id);
+       int (*read)(struct i915_perf_stream *stream,
+                   char __user *buf,
+                   size_t count,
+                   size_t *offset);
+       bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv);
 };
 
 struct drm_i915_private {
@@ -2149,16 +2164,46 @@ struct drm_i915_private {
 
        struct {
                bool initialized;
+

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2176

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +5 -1
                struct mutex lock;
                struct list_head streams;
 
+               spinlock_t hook_lock;
+
                struct {
-                       u32 metrics_set;
+                       struct i915_perf_stream *exclusive_stream;
+
+                       u32 specific_ctx_id;

Can we just get rid of this, now that the vma remains pinned we can simply get the ggtt address at the time of configuring the OA_CONTROL register ?

Quoted 81 lines
drivers/gpu/drm/i915/i915_drv.h +25 -0
+
+                       struct hrtimer poll_check_timer;
+                       wait_queue_head_t poll_wq;
+                       atomic_t pollin;
+
+                       bool periodic;
+                       int period_exponent;
+                       int timestamp_frequency;
+
+                       int tail_margin;
+
+                       int metrics_set;
 
                        const struct i915_oa_reg *mux_regs;
                        int mux_regs_len;
                        const struct i915_oa_reg *b_counter_regs;
                        int b_counter_regs_len;
+
+                       struct {
+                               struct i915_vma *vma;
+                               u8 *vaddr;
+                               int format;
+                               int format_size;
+                       } oa_buffer;
+
+                       u32 gen7_latched_oastatus1;
+
+                       struct i915_oa_ops ops;
+                       const struct i915_oa_format *oa_formats;
+                       int n_builtin_sets;
                } oa;
        } perf;
 
drivers/gpu/drm/i915/i915_perf.c +38 -0
index 4d51586..d7a4899 100644
@@ -25,16 +25,867 @@
  */
 
 #include <linux/anon_inodes.h>
+#include <linux/sizes.h>
 
 #include "i915_drv.h"
+#include "i915_oa_hsw.h"
+
+/* HW requires this to be a power of two, between 128k and 16M, though driver
+ * is currently generally designed assuming the largest 16M size is used such
+ * that the overflow cases are unlikely in normal operation.
+ */
+#define OA_BUFFER_SIZE         SZ_16M
+
+#define OA_TAKEN(tail, head)   ((tail - head) & (OA_BUFFER_SIZE - 1))
+
+/* There's a HW race condition between OA unit tail pointer register updates and
+ * writes to memory whereby the tail pointer can sometimes get ahead of what's
+ * been written out to the OA buffer so far.
+ *
+ * Although this can be observed explicitly by checking for a zeroed report-id
+ * field in tail reports, it seems preferable to account for this earlier e.g.
+ * as part of the _oa_buffer_is_empty checks to minimize -EAGAIN polling cycles
+ * in this situation.
+ *
+ * To give time for the most recent reports to land before they may be copied to
+ * userspace, the driver operates as if the tail pointer effectively lags behind
+ * the HW tail pointer by 'tail_margin' bytes. The margin in bytes is calculated
+ * based on this constant in nanoseconds, the current OA sampling exponent
+ * and current report size.
+ *
+ * There is also a fallback check while reading to simply skip over reports with
+ * a zeroed report-id.
+ */
+#define OA_TAIL_MARGIN_NSEC    100000ULL
+
+/* frequency for checking whether the OA unit has written new reports to the
+ * circular OA buffer...
+ */
+#define POLL_FREQUENCY 200
+#define POLL_PERIOD (NSEC_PER_SEC / POLL_FREQUENCY)
+
+/* The maximum exponent the hardware accepts is 63 (essentially it selects one

drivers/gpu/drm/i915/i915_perf.c line 77

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10 -0
+ * of the 64bit timestamp bits to trigger reports from) but there's currently
+ * no known use case for sampling as infrequently as once per 47 thousand years.
+ *
+ * Since the timestamps included in OA reports are only 32bits it seems
+ * reasonable to limit the OA exponent where it's still possible to account for
+ * overflow in OA report timestamps.
+ */
+#define OA_EXPONENT_MAX 31
+
+#define INVALID_CTX_ID 0xffffffff

We shouldn't need this anymore.

Quoted 115 lines
drivers/gpu/drm/i915/i915_perf.c +107 -0
+
+
+/* XXX: beware if future OA HW adds new report formats that the current
+ * code assumes all reports have a power-of-two size and ~(size - 1) can
+ * be used as a mask to align the OA tail pointer.
+ */
+static struct i915_oa_format hsw_oa_formats[I915_OA_FORMAT_MAX] = {
+       [I915_OA_FORMAT_A13]        = { 0, 64 },
+       [I915_OA_FORMAT_A29]        = { 1, 128 },
+       [I915_OA_FORMAT_A13_B8_C8]  = { 2, 128 },
+       /* A29_B8_C8 Disallowed as 192 bytes doesn't factor into buffer size */
+       [I915_OA_FORMAT_B4_C8]      = { 4, 64 },
+       [I915_OA_FORMAT_A45_B8_C8]  = { 5, 256 },
+       [I915_OA_FORMAT_B4_C8_A16]  = { 6, 128 },
+       [I915_OA_FORMAT_C4_B8]      = { 7, 64 },
+};
+
+#define SAMPLE_OA_REPORT      (1<<0)
 
 struct perf_open_properties {
        u32 sample_flags;
 
        u64 single_context:1;
        u64 ctx_handle;
+
+       /* OA sampling state */
+       int metrics_set;
+       int oa_format;
+       bool oa_periodic;
+       int oa_period_exponent;
 };
 
+/* NB: This is either called via fops or the poll check hrtimer (atomic ctx)
+ *
+ * It's safe to read OA config state here unlocked, assuming that this is only
+ * called while the stream is enabled, while the global OA configuration can't
+ * be modified.
+ *
+ * Note: we don't lock around the head/tail reads even though there's the slim
+ * possibility of read() fop errors forcing a re-init of the OA buffer
+ * pointers.  A race here could result in a false positive !empty status which
+ * is acceptable.
+ */
+static bool gen7_oa_buffer_is_empty_fop_unlocked(struct drm_i915_private *dev_priv)
+{
+       int report_size = dev_priv->perf.oa.oa_buffer.format_size;
+       u32 oastatus2 = I915_READ(GEN7_OASTATUS2);
+       u32 oastatus1 = I915_READ(GEN7_OASTATUS1);
+       u32 head = oastatus2 & GEN7_OASTATUS2_HEAD_MASK;
+       u32 tail = oastatus1 & GEN7_OASTATUS1_TAIL_MASK;
+
+       return OA_TAKEN(tail, head) <
+               dev_priv->perf.oa.tail_margin + report_size;
+}
+
+/**
+ * Appends a status record to a userspace read() buffer.
+ */
+static int append_oa_status(struct i915_perf_stream *stream,
+                           char __user *buf,
+                           size_t count,
+                           size_t *offset,
+                           enum drm_i915_perf_record_type type)
+{
+       struct drm_i915_perf_record_header header = { type, 0, sizeof(header) };
+
+       if ((count - *offset) < header.size)
+               return -ENOSPC;
+
+       if (copy_to_user(buf + *offset, &header, sizeof(header)))
+               return -EFAULT;
+
+       (*offset) += header.size;
+
+       return 0;
+}
+
+/**
+ * Copies single OA report into userspace read() buffer.
+ */
+static int append_oa_sample(struct i915_perf_stream *stream,
+                           char __user *buf,
+                           size_t count,
+                           size_t *offset,
+                           const u8 *report)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+       int report_size = dev_priv->perf.oa.oa_buffer.format_size;
+       struct drm_i915_perf_record_header header;
+       u32 sample_flags = stream->sample_flags;
+
+       header.type = DRM_I915_PERF_RECORD_SAMPLE;
+       header.pad = 0;
+       header.size = stream->sample_size;
+
+       if ((count - *offset) < header.size)
+               return -ENOSPC;
+
+       buf += *offset;
+       if (copy_to_user(buf, &header, sizeof(header)))
+               return -EFAULT;
+       buf += sizeof(header);
+
+       if (sample_flags & SAMPLE_OA_REPORT) {
+               if (copy_to_user(buf, report, report_size))
+                       return -EFAULT;
+       }
+
+       (*offset) += header.size;
+
+       return 0;
+}
+
+/**
+ * Copies all buffered OA reports into userspace read() buffer.

drivers/gpu/drm/i915/i915_perf.c line 202

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10 -0
+ * @head_ptr: (inout): the head pointer before and after appending
+ *
+ * Returns 0 on success, negative error code on failure.
+ *
+ * Notably any error condition resulting in a short read (-ENOSPC or
+ * -EFAULT) will be returned even though one or more records may
+ * have been successfully copied. In this case it's up to the caller
+ * to decide if the error should be squashed before returning to
+ * userspace.
+ */

This kernel doc could do with a spring clean.

Quoted 228 lines
drivers/gpu/drm/i915/i915_perf.c +228 -0
+static int gen7_append_oa_reports(struct i915_perf_stream *stream,
+                                 char __user *buf,
+                                 size_t count,
+                                 size_t *offset,
+                                 u32 *head_ptr,
+                                 u32 tail)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+       int report_size = dev_priv->perf.oa.oa_buffer.format_size;
+       u8 *oa_buf_base = dev_priv->perf.oa.oa_buffer.vaddr;
+       int tail_margin = dev_priv->perf.oa.tail_margin;
+       u32 gtt_offset = i915_ggtt_offset(dev_priv->perf.oa.oa_buffer.vma);
+       u32 mask = (OA_BUFFER_SIZE - 1);
+       u32 head;
+       u32 taken;
+       int ret = 0;
+
+       BUG_ON(!stream->enabled);
+
+       head = *head_ptr - gtt_offset;
+       tail -= gtt_offset;
+
+       /* The OA unit is expected to wrap the tail pointer according to the OA
+        * buffer size and since we should never write a misaligned head
+        * pointer we don't expect to read one back either...
+        */
+       if (tail > OA_BUFFER_SIZE || head > OA_BUFFER_SIZE ||
+           head % report_size) {
+               DRM_ERROR("Inconsistent OA buffer pointer (head = %u, tail = %u): force restart",
+                         head, tail);
+               dev_priv->perf.oa.ops.oa_disable(dev_priv);
+               dev_priv->perf.oa.ops.oa_enable(dev_priv);
+               *head_ptr = I915_READ(GEN7_OASTATUS2) &
+                       GEN7_OASTATUS2_HEAD_MASK;
+               return -EIO;
+       }
+
+
+       /* The tail pointer increases in 64 byte increments, not in report_size
+        * steps...
+        */
+       tail &= ~(report_size - 1);
+
+       /* Move the tail pointer back by the current tail_margin to account for
+        * the possibility that the latest reports may not have really landed
+        * in memory yet...
+        */
+
+       if (OA_TAKEN(tail, head) < report_size + tail_margin)
+               return -EAGAIN;
+
+       tail -= tail_margin;
+       tail &= mask;
+
+       for (/* none */;
+            (taken = OA_TAKEN(tail, head));
+            head = (head + report_size) & mask) {
+               u8 *report = oa_buf_base + head;
+               u32 *report32 = (void *)report;
+
+               /* All the report sizes factor neatly into the buffer
+                * size so we never expect to see a report split
+                * between the beginning and end of the buffer.
+                *
+                * Given the initial alignment check a misalignment
+                * here would imply a driver bug that would result
+                * in an overrun.
+                */
+               BUG_ON((OA_BUFFER_SIZE - head) < report_size);
+
+               /* The report-ID field for periodic samples includes
+                * some undocumented flags related to what triggered
+                * the report and is never expected to be zero so we
+                * can check that the report isn't invalid before
+                * copying it to userspace...
+                */
+               if (report32[0] == 0) {
+                       DRM_ERROR("Skipping spurious, invalid OA report\n");
+                       continue;
+               }
+
+               ret = append_oa_sample(stream, buf, count, offset, report);
+               if (ret)
+                       break;
+
+               /* The above report-id field sanity check is based on
+                * the assumption that the OA buffer is initially
+                * zeroed and we reset the field after copying so the
+                * check is still meaningful once old reports start
+                * being overwritten.
+                */
+               report32[0] = 0;
+       }
+
+       *head_ptr = gtt_offset + head;
+
+       return ret;
+}
+
+static int gen7_oa_read(struct i915_perf_stream *stream,
+                       char __user *buf,
+                       size_t count,
+                       size_t *offset)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+       int report_size = dev_priv->perf.oa.oa_buffer.format_size;
+       u32 oastatus2;
+       u32 oastatus1;
+       u32 head;
+       u32 tail;
+       int ret;
+
+       BUG_ON(!dev_priv->perf.oa.oa_buffer.vaddr);
+
+       oastatus2 = I915_READ(GEN7_OASTATUS2);
+       oastatus1 = I915_READ(GEN7_OASTATUS1);
+
+       head = oastatus2 & GEN7_OASTATUS2_HEAD_MASK;
+       tail = oastatus1 & GEN7_OASTATUS1_TAIL_MASK;
+
+       /* XXX: On Haswell we don't have a safe way to clear oastatus1
+        * bits while the OA unit is enabled (while the tail pointer
+        * may be updated asynchronously) so we ignore status bits
+        * that have already been reported to userspace.
+        */
+       oastatus1 &= ~dev_priv->perf.oa.gen7_latched_oastatus1;
+
+       /* We treat OABUFFER_OVERFLOW as a significant error:
+        *
+        * - The status can be interpreted to mean that the buffer is
+        *   currently full (with a higher precedence than OA_TAKEN()
+        *   which will start to report a near-empty buffer after an
+        *   overflow) but it's awkward that we can't clear the status
+        *   on Haswell, so without a reset we won't be able to catch
+        *   the state again.
+        *
+        * - Since it also implies the HW has started overwriting old
+        *   reports it may also affect our sanity checks for invalid
+        *   reports when copying to userspace that assume new reports
+        *   are being written to cleared memory.
+        *
+        * - In the future we may want to introduce a flight recorder
+        *   mode where the driver will automatically maintain a safe
+        *   guard band between head/tail, avoiding this overflow
+        *   condition, but we avoid the added driver complexity for
+        *   now.
+        */
+       if (unlikely(oastatus1 & GEN7_OASTATUS1_OABUFFER_OVERFLOW)) {
+               ret = append_oa_status(stream, buf, count, offset,
+                                      DRM_I915_PERF_RECORD_OA_BUFFER_LOST);
+               if (ret)
+                       return ret;
+
+               DRM_ERROR("OA buffer overflow: force restart");
+
+               dev_priv->perf.oa.ops.oa_disable(dev_priv);
+               dev_priv->perf.oa.ops.oa_enable(dev_priv);
+
+               oastatus2 = I915_READ(GEN7_OASTATUS2);
+               oastatus1 = I915_READ(GEN7_OASTATUS1);
+
+               head = oastatus2 & GEN7_OASTATUS2_HEAD_MASK;
+               tail = oastatus1 & GEN7_OASTATUS1_TAIL_MASK;
+       }
+
+       if (unlikely(oastatus1 & GEN7_OASTATUS1_REPORT_LOST)) {
+               ret = append_oa_status(stream, buf, count, offset,
+                                      DRM_I915_PERF_RECORD_OA_REPORT_LOST);
+               if (ret)
+                       return ret;
+               dev_priv->perf.oa.gen7_latched_oastatus1 |=
+                       GEN7_OASTATUS1_REPORT_LOST;
+       }
+
+       ret = gen7_append_oa_reports(stream, buf, count, offset,
+                                    &head, tail);
+
+       /* All the report sizes are a power of two and the
+        * head should always be incremented by some multiple
+        * of the report size.
+        *
+        * A warning here, but notably if we later read back a
+        * misaligned pointer we will treat that as a bug since
+        * it could lead to a buffer overrun.
+        */
+       WARN_ONCE(head & (report_size - 1),
+                 "i915: Writing misaligned OA head pointer");
+
+       /* Note: we update the head pointer here even if an error
+        * was returned since the error may represent a short read
+        * where some some reports were successfully copied.
+        */
+       I915_WRITE(GEN7_OASTATUS2,
+                  ((head & GEN7_OASTATUS2_HEAD_MASK) |
+                   OA_MEM_SELECT_GGTT));
+
+       return ret;
+}
+
+static int i915_oa_wait_unlocked(struct i915_perf_stream *stream)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+
+       /* We would wait indefinitly if periodic sampling is not enabled */
+       if (!dev_priv->perf.oa.periodic)
+               return -EIO;
+
+       /* Note: the oa_buffer_is_empty() condition is ok to run unlocked as it
+        * just performs mmio reads of the OA buffer head + tail pointers and
+        * it's assumed we're handling some operation that implies the stream
+        * can't be destroyed until completion (such as a read()) that ensures
+        * the device + OA buffer can't disappear
+        */
+       return wait_event_interruptible(dev_priv->perf.oa.poll_wq,
+                                       !dev_priv->perf.oa.ops.oa_buffer_is_empty(dev_priv));
+}
+
+static void i915_oa_poll_wait(struct i915_perf_stream *stream,
+                             struct file *file,
+                             poll_table *wait)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+
+       poll_wait(file, &dev_priv->perf.oa.poll_wq, wait);
+}
+
+static int i915_oa_read(struct i915_perf_stream *stream,
+                       char __user *buf,

drivers/gpu/drm/i915/i915_perf.c line 440

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10 -0
+                       size_t count,
+                       size_t *offset)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+
+       return dev_priv->perf.oa.ops.read(stream, buf, count, offset);
+}
+
+static int claim_specific_ctx(struct i915_perf_stream *stream)
+{

pin_oa_specific_ctx, or something? Also would it not make more sense to operate on the context, not the stream.

Quoted 16 lines
drivers/gpu/drm/i915/i915_perf.c +16 -0
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+       struct i915_vma *vma;
+       int ret;
+
+       ret = i915_mutex_lock_interruptible(&dev_priv->drm);
+       if (ret)
+               return ret;
+
+       /* So that we don't have to worry about updating the context ID
+        * in OACONTOL on the fly we make sure to pin the context
+        * upfront for the lifetime of the stream...
+        */
+       vma = stream->ctx->engine[RCS].state;
+       ret = i915_vma_pin(vma, 0, stream->ctx->ggtt_alignment,
+                          PIN_GLOBAL | PIN_HIGH);
+       if (ret)

drivers/gpu/drm/i915/i915_perf.c line 466

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10 -0
+               return ret;
+
+       dev_priv->perf.oa.specific_ctx_id = i915_ggtt_offset(vma);
+
+       mutex_unlock(&dev_priv->drm.struct_mutex);
+
+       return 0;
+}
+
+static void release_specific_ctx(struct i915_perf_stream *stream)

Likewise here, unpin_oa_specific_ctx. Just a thought though so feel free to ignore.

Quoted 577 lines
drivers/gpu/drm/i915/i915_perf.c +512 -15
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+
+       mutex_lock(&dev_priv->drm.struct_mutex);
+
+       i915_vma_unpin(stream->ctx->engine[RCS].state);
+       dev_priv->perf.oa.specific_ctx_id = INVALID_CTX_ID;
+
+       mutex_unlock(&dev_priv->drm.struct_mutex);
+}
+
+static void
+free_oa_buffer(struct drm_i915_private *i915)
+{
+       mutex_lock(&i915->drm.struct_mutex);
+
+       i915_gem_object_unpin_map(i915->perf.oa.oa_buffer.vma->obj);
+       i915_vma_unpin(i915->perf.oa.oa_buffer.vma);
+       i915_gem_object_put(i915->perf.oa.oa_buffer.vma->obj);
+
+       i915->perf.oa.oa_buffer.vma = NULL;
+       i915->perf.oa.oa_buffer.vaddr = NULL;
+
+       mutex_unlock(&i915->drm.struct_mutex);
+}
+
+static void i915_oa_stream_destroy(struct i915_perf_stream *stream)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+
+       BUG_ON(stream != dev_priv->perf.oa.exclusive_stream);
+
+       dev_priv->perf.oa.ops.disable_metric_set(dev_priv);
+
+       free_oa_buffer(dev_priv);
+
+       intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
+       intel_runtime_pm_put(dev_priv);
+
+       if (stream->ctx)
+               release_specific_ctx(stream);
+
+       dev_priv->perf.oa.exclusive_stream = NULL;
+}
+
+static void gen7_init_oa_buffer(struct drm_i915_private *dev_priv)
+{
+       u32 gtt_offset = i915_ggtt_offset(dev_priv->perf.oa.oa_buffer.vma);
+
+       /* Pre-DevBDW: OABUFFER must be set with counters off,
+        * before OASTATUS1, but after OASTATUS2
+        */
+       I915_WRITE(GEN7_OASTATUS2, gtt_offset | OA_MEM_SELECT_GGTT); /* head */
+       I915_WRITE(GEN7_OABUFFER, gtt_offset);
+       I915_WRITE(GEN7_OASTATUS1, gtt_offset | OABUFFER_SIZE_16M); /* tail */
+
+       /* On Haswell we have to track which OASTATUS1 flags we've
+        * already seen since they can't be cleared while periodic
+        * sampling is enabled.
+        */
+       dev_priv->perf.oa.gen7_latched_oastatus1 = 0;
+
+       /* NB: although the OA buffer will initially be allocated
+        * zeroed via shmfs (and so this memset is redundant when
+        * first allocating), we may re-init the OA buffer, either
+        * when re-enabling a stream or in error/reset paths.
+        *
+        * The reason we clear the buffer for each re-init is for the
+        * sanity check in gen7_append_oa_reports() that looks at the
+        * report-id field to make sure it's non-zero which relies on
+        * the assumption that new reports are being written to zeroed
+        * memory...
+        */
+       memset(dev_priv->perf.oa.oa_buffer.vaddr, 0, OA_BUFFER_SIZE);
+
+       /* Maybe make ->pollin per-stream state if we support multiple
+        * concurrent streams in the future. */
+       atomic_set(&dev_priv->perf.oa.pollin, false);
+}
+
+static int alloc_oa_buffer(struct drm_i915_private *dev_priv)
+{
+       struct drm_i915_gem_object *bo;
+       struct i915_vma *vma;
+       int ret;
+
+       BUG_ON(dev_priv->perf.oa.oa_buffer.vma);
+
+       ret = i915_mutex_lock_interruptible(&dev_priv->drm);
+       if (ret)
+               return ret;
+
+       BUILD_BUG_ON_NOT_POWER_OF_2(OA_BUFFER_SIZE);
+       BUILD_BUG_ON(OA_BUFFER_SIZE < SZ_128K || OA_BUFFER_SIZE > SZ_16M);
+
+       bo = i915_gem_object_create(&dev_priv->drm, OA_BUFFER_SIZE);
+       if (IS_ERR(bo)) {
+               DRM_ERROR("Failed to allocate OA buffer\n");
+               ret = PTR_ERR(bo);
+               goto unlock;
+       }
+
+       ret = i915_gem_object_set_cache_level(bo, I915_CACHE_LLC);
+       if (ret)
+               goto err_unref;
+
+       /* PreHSW required 512K alignment, HSW requires 16M */
+       vma = i915_gem_object_ggtt_pin(bo, NULL, 0, SZ_16M, PIN_MAPPABLE);
+       if (IS_ERR(vma)) {
+               ret = PTR_ERR(vma);
+               goto err_unref;
+       }
+       dev_priv->perf.oa.oa_buffer.vma = vma;
+
+       dev_priv->perf.oa.oa_buffer.vaddr =
+               i915_gem_object_pin_map(bo, I915_MAP_WB);
+       if (IS_ERR(dev_priv->perf.oa.oa_buffer.vaddr)) {
+               ret = PTR_ERR(dev_priv->perf.oa.oa_buffer.vaddr);
+               goto err_unpin;
+       }
+
+       dev_priv->perf.oa.ops.init_oa_buffer(dev_priv);
+
+       DRM_DEBUG_DRIVER("OA Buffer initialized, gtt offset = 0x%x, vaddr = %p",
+                        i915_ggtt_offset(dev_priv->perf.oa.oa_buffer.vma),
+                        dev_priv->perf.oa.oa_buffer.vaddr);
+
+       goto unlock;
+
+err_unpin:
+       __i915_vma_unpin(vma);
+
+err_unref:
+       i915_gem_object_put(bo);
+
+       dev_priv->perf.oa.oa_buffer.vaddr = NULL;
+       dev_priv->perf.oa.oa_buffer.vma = NULL;
+
+unlock:
+       mutex_unlock(&dev_priv->drm.struct_mutex);
+       return ret;
+}
+
+static void config_oa_regs(struct drm_i915_private *dev_priv,
+                          const struct i915_oa_reg *regs,
+                          int n_regs)
+{
+       int i;
+
+       for (i = 0; i < n_regs; i++) {
+               const struct i915_oa_reg *reg = regs + i;
+
+               I915_WRITE(reg->addr, reg->value);
+       }
+}
+
+static int hsw_enable_metric_set(struct drm_i915_private *dev_priv)
+{
+       int ret = i915_oa_select_metric_set_hsw(dev_priv);
+
+       if (ret)
+               return ret;
+
+       I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) |
+                                     GT_NOA_ENABLE));
+
+       /* PRM:
+        *
+        * OA unit is using “crclk” for its functionality. When trunk
+        * level clock gating takes place, OA clock would be gated,
+        * unable to count the events from non-render clock domain.
+        * Render clock gating must be disabled when OA is enabled to
+        * count the events from non-render domain. Unit level clock
+        * gating for RCS should also be disabled.
+        */
+       I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) &
+                                   ~GEN7_DOP_CLOCK_GATE_ENABLE));
+       I915_WRITE(GEN6_UCGCTL1, (I915_READ(GEN6_UCGCTL1) |
+                                 GEN6_CSUNIT_CLOCK_GATE_DISABLE));
+
+       config_oa_regs(dev_priv, dev_priv->perf.oa.mux_regs,
+                      dev_priv->perf.oa.mux_regs_len);
+
+       /* It apparently takes a fairly long time for a new MUX
+        * configuration to be be applied after these register writes.
+        * This delay duration was derived empirically based on the
+        * render_basic config but hopefully it covers the maximum
+        * configuration latency.
+        *
+        * As a fallback, the checks in _append_oa_reports() to skip
+        * invalid OA reports do also seem to work to discard reports
+        * generated before this config has completed - albeit not
+        * silently.
+        *
+        * Unfortunately this is essentially a magic number, since we
+        * don't currently know of a reliable mechanism for predicting
+        * how long the MUX config will take to apply and besides
+        * seeing invalid reports we don't know of a reliable way to
+        * explicitly check that the MUX config has landed.
+        *
+        * It's even possible we've miss characterized the underlying
+        * problem - it just seems like the simplest explanation why
+        * a delay at this location would mitigate any invalid reports.
+        */
+       usleep_range(15000, 20000);
+
+       config_oa_regs(dev_priv, dev_priv->perf.oa.b_counter_regs,
+                      dev_priv->perf.oa.b_counter_regs_len);
+
+       return 0;
+}
+
+static void hsw_disable_metric_set(struct drm_i915_private *dev_priv)
+{
+       I915_WRITE(GEN6_UCGCTL1, (I915_READ(GEN6_UCGCTL1) &
+                                 ~GEN6_CSUNIT_CLOCK_GATE_DISABLE));
+       I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) |
+                                   GEN7_DOP_CLOCK_GATE_ENABLE));
+
+       I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) &
+                                     ~GT_NOA_ENABLE));
+}
+
+static void gen7_update_oacontrol_locked(struct drm_i915_private *dev_priv)
+{
+       assert_spin_locked(&dev_priv->perf.hook_lock);
+
+       if (dev_priv->perf.oa.exclusive_stream->enabled) {
+               struct i915_gem_context *ctx =
+                       dev_priv->perf.oa.exclusive_stream->ctx;
+               u32 ctx_id = dev_priv->perf.oa.specific_ctx_id;
+
+               bool periodic = dev_priv->perf.oa.periodic;
+               u32 period_exponent = dev_priv->perf.oa.period_exponent;
+               u32 report_format = dev_priv->perf.oa.oa_buffer.format;
+
+               I915_WRITE(GEN7_OACONTROL,
+                          (ctx_id & GEN7_OACONTROL_CTX_MASK) |
+                          (period_exponent <<
+                           GEN7_OACONTROL_TIMER_PERIOD_SHIFT) |
+                          (periodic ? GEN7_OACONTROL_TIMER_ENABLE : 0) |
+                          (report_format << GEN7_OACONTROL_FORMAT_SHIFT) |
+                          (ctx ? GEN7_OACONTROL_PER_CTX_ENABLE : 0) |
+                          GEN7_OACONTROL_ENABLE);
+       } else
+               I915_WRITE(GEN7_OACONTROL, 0);
+}
+
+static void gen7_oa_enable(struct drm_i915_private *dev_priv)
+{
+       unsigned long flags;
+
+       /* Reset buf pointers so we don't forward reports from before now.
+        *
+        * Think carefully if considering trying to avoid this, since it
+        * also ensures status flags and the buffer itself are cleared
+        * in error paths, and we have checks for invalid reports based
+        * on the assumption that certain fields are written to zeroed
+        * memory which this helps maintains.
+        */
+       gen7_init_oa_buffer(dev_priv);
+
+       spin_lock_irqsave(&dev_priv->perf.hook_lock, flags);
+       gen7_update_oacontrol_locked(dev_priv);
+       spin_unlock_irqrestore(&dev_priv->perf.hook_lock, flags);
+}
+
+static void i915_oa_stream_enable(struct i915_perf_stream *stream)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+
+       dev_priv->perf.oa.ops.oa_enable(dev_priv);
+
+       if (dev_priv->perf.oa.periodic)
+               hrtimer_start(&dev_priv->perf.oa.poll_check_timer,
+                             ns_to_ktime(POLL_PERIOD),
+                             HRTIMER_MODE_REL_PINNED);
+}
+
+static void gen7_oa_disable(struct drm_i915_private *dev_priv)
+{
+       I915_WRITE(GEN7_OACONTROL, 0);
+}
+
+static void i915_oa_stream_disable(struct i915_perf_stream *stream)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+
+       dev_priv->perf.oa.ops.oa_disable(dev_priv);
+
+       if (dev_priv->perf.oa.periodic)
+               hrtimer_cancel(&dev_priv->perf.oa.poll_check_timer);
+}
+
+static u64 oa_exponent_to_ns(struct drm_i915_private *dev_priv, int exponent)
+{
+       return 1000000000ULL * (2ULL << exponent) /
+               dev_priv->perf.oa.timestamp_frequency;
+}
+
+static const struct i915_perf_stream_ops i915_oa_stream_ops = {
+       .destroy = i915_oa_stream_destroy,
+       .enable = i915_oa_stream_enable,
+       .disable = i915_oa_stream_disable,
+       .wait_unlocked = i915_oa_wait_unlocked,
+       .poll_wait = i915_oa_poll_wait,
+       .read = i915_oa_read,
+};
+
+static int i915_oa_stream_init(struct i915_perf_stream *stream,
+                              struct drm_i915_perf_open_param *param,
+                              struct perf_open_properties *props)
+{
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+       int format_size;
+       int ret;
+
+       if (!(props->sample_flags & SAMPLE_OA_REPORT)) {
+               DRM_ERROR("Only OA report sampling supported\n");
+               return -EINVAL;
+       }
+
+       if (!dev_priv->perf.oa.ops.init_oa_buffer) {
+               DRM_ERROR("OA unit not supported\n");
+               return -ENODEV;
+       }
+
+       /* To avoid the complexity of having to accurately filter
+        * counter reports and marshal to the appropriate client
+        * we currently only allow exclusive access
+        */
+       if (dev_priv->perf.oa.exclusive_stream) {
+               DRM_ERROR("OA unit already in use\n");
+               return -EBUSY;
+       }
+
+       if (!props->metrics_set) {
+               DRM_ERROR("OA metric set not specified\n");
+               return -EINVAL;
+       }
+
+       if (!props->oa_format) {
+               DRM_ERROR("OA report format not specified\n");
+               return -EINVAL;
+       }
+
+       stream->sample_size = sizeof(struct drm_i915_perf_record_header);
+
+       format_size = dev_priv->perf.oa.oa_formats[props->oa_format].size;
+
+       stream->sample_flags |= SAMPLE_OA_REPORT;
+       stream->sample_size += format_size;
+
+       dev_priv->perf.oa.oa_buffer.format_size = format_size;
+       BUG_ON(dev_priv->perf.oa.oa_buffer.format_size == 0);
+
+       dev_priv->perf.oa.oa_buffer.format =
+               dev_priv->perf.oa.oa_formats[props->oa_format].format;
+
+       dev_priv->perf.oa.metrics_set = props->metrics_set;
+
+       dev_priv->perf.oa.periodic = props->oa_periodic;
+       if (dev_priv->perf.oa.periodic) {
+               u64 period_ns = oa_exponent_to_ns(dev_priv,
+                                                 props->oa_period_exponent);
+
+               dev_priv->perf.oa.period_exponent = props->oa_period_exponent;
+
+               /* See comment for OA_TAIL_MARGIN_NSEC for details
+                * about this tail_margin...
+                */
+               dev_priv->perf.oa.tail_margin =
+                       ((OA_TAIL_MARGIN_NSEC / period_ns) + 1) * format_size;
+       }
+
+       if (stream->ctx) {
+               ret = claim_specific_ctx(stream);
+               if (ret)
+                       return ret;
+       }
+
+       ret = alloc_oa_buffer(dev_priv);
+       if (ret)
+               goto err_oa_buf_alloc;
+
+       /* PRM - observability performance counters:
+        *
+        *   OACONTROL, performance counter enable, note:
+        *
+        *   "When this bit is set, in order to have coherent counts,
+        *   RC6 power state and trunk clock gating must be disabled.
+        *   This can be achieved by programming MMIO registers as
+        *   0xA094=0 and 0xA090[31]=1"
+        *
+        *   In our case we are expecting that taking pm + FORCEWAKE
+        *   references will effectively disable RC6.
+        */
+       intel_runtime_pm_get(dev_priv);
+       intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
+
+       ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv);
+       if (ret)
+               goto err_enable;
+
+       stream->ops = &i915_oa_stream_ops;
+
+       dev_priv->perf.oa.exclusive_stream = stream;
+
+       return 0;
+
+err_enable:
+       intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
+       intel_runtime_pm_put(dev_priv);
+       free_oa_buffer(dev_priv);
+
+err_oa_buf_alloc:
+       if (stream->ctx)
+               release_specific_ctx(stream);
+
+       return ret;
+}
+
 static ssize_t i915_perf_read_locked(struct i915_perf_stream *stream,
                                     struct file *file,
                                     char __user *buf,
@@ -78,8 +929,20 @@ static ssize_t i915_perf_read(struct file *file,
        struct drm_i915_private *dev_priv = stream->dev_priv;
        ssize_t ret;
 
+       /* To ensure it's handled consistently we simply treat all reads of a
+        * disabled stream as an error. In particular it might otherwise lead
+        * to a deadlock for blocking file descriptors...
+        */
+       if (!stream->enabled)
+               return -EIO;
+
        if (!(file->f_flags & O_NONBLOCK)) {
-               /* Allow false positives from stream->ops->wait_unlocked.
+               /* There's the small chance of false positives from
+                * stream->ops->wait_unlocked.
+                *
+                * E.g. with single context filtering since we only wait until
+                * oabuffer has >= 1 report we don't immediately know whether
+                * any reports really belong to the current context
                 */
                do {
                        ret = stream->ops->wait_unlocked(stream);
@@ -97,21 +960,50 @@ static ssize_t i915_perf_read(struct file *file,
                mutex_unlock(&dev_priv->perf.lock);
        }
 
+       if (ret >= 0) {
+               /* Maybe make ->pollin per-stream state if we support multiple
+                * concurrent streams in the future. */
+               atomic_set(&dev_priv->perf.oa.pollin, false);
+       }
+
        return ret;
 }
 
-static unsigned int i915_perf_poll_locked(struct i915_perf_stream *stream,
+static enum hrtimer_restart oa_poll_check_timer_cb(struct hrtimer *hrtimer)
+{
+       struct drm_i915_private *dev_priv =
+               container_of(hrtimer, typeof(*dev_priv),
+                            perf.oa.poll_check_timer);
+
+       if (!dev_priv->perf.oa.ops.oa_buffer_is_empty(dev_priv)) {
+               atomic_set(&dev_priv->perf.oa.pollin, true);
+               wake_up(&dev_priv->perf.oa.poll_wq);
+       }
+
+       hrtimer_forward_now(hrtimer, ns_to_ktime(POLL_PERIOD));
+
+       return HRTIMER_RESTART;
+}
+
+static unsigned int i915_perf_poll_locked(struct drm_i915_private *dev_priv,
+                                         struct i915_perf_stream *stream,
                                          struct file *file,
                                          poll_table *wait)
 {
-       unsigned int streams = 0;
+       unsigned int events = 0;
 
        stream->ops->poll_wait(stream, file, wait);
 
-       if (stream->ops->can_read(stream))
-               streams |= POLLIN;
+       /* Note: we don't explicitly check whether there's something to read
+        * here since this path may be very hot depending on what else
+        * userspace is polling, or on the timeout in use. We rely solely on
+        * the hrtimer/oa_poll_check_timer_cb to notify us when there are
+        * samples to read.
+        */
+       if (atomic_read(&dev_priv->perf.oa.pollin))
+               events |= POLLIN;
 
-       return streams;
+       return events;
 }
 
 static unsigned int i915_perf_poll(struct file *file, poll_table *wait)
@@ -121,7 +1013,7 @@ static unsigned int i915_perf_poll(struct file *file, poll_table *wait)
        int ret;
 
        mutex_lock(&dev_priv->perf.lock);
-       ret = i915_perf_poll_locked(stream, file, wait);
+       ret = i915_perf_poll_locked(dev_priv, stream, file, wait);
        mutex_unlock(&dev_priv->perf.lock);
 
        return ret;
@@ -285,18 +1177,18 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,
                goto err_ctx;
        }
 
-       stream->sample_flags = props->sample_flags;
        stream->dev_priv = dev_priv;
        stream->ctx = specific_ctx;
 
-       /*
-        * TODO: support sampling something
-        *
-        * For now this is as far as we can go.
+       ret = i915_oa_stream_init(stream, param, props);
+       if (ret)
+               goto err_alloc;
+
+       /* we avoid simply assigning stream->sample_flags = props->sample_flags
+        * to have _stream_init check the combination of sample flags more
+        * thoroughly, but still this is the expected result at this point.
         */
-       DRM_ERROR("Unsupported i915 perf stream configuration\n");
-       ret = -EINVAL;
-       goto err_alloc;
+       BUG_ON(stream->sample_flags != props->sample_flags);
 
        list_add(&stream->link, &dev_priv->perf.streams);
 
@@ -376,6 +1268,56 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,
                        props->single_context = 1;
                        props->ctx_handle = value;
                        break;
+               case DRM_I915_PERF_PROP_SAMPLE_OA:
+                       props->sample_flags |= SAMPLE_OA_REPORT;
+                       break;
+               case DRM_I915_PERF_PROP_OA_METRICS_SET:
+                       if (value == 0 ||
+                           value > dev_priv->perf.oa.n_builtin_sets) {
+                               DRM_ERROR("Unknown OA metric set ID");
+                               return -EINVAL;
+                       }
+                       props->metrics_set = value;
+                       break;
+               case DRM_I915_PERF_PROP_OA_FORMAT:
+                       if (value == 0 || value >= I915_OA_FORMAT_MAX) {
+                               DRM_ERROR("Invalid OA report format\n");
+                               return -EINVAL;
+                       }
+                       if (!dev_priv->perf.oa.oa_formats[value].size) {
+                               DRM_ERROR("Invalid OA report format\n");
+                               return -EINVAL;
+                       }
+                       props->oa_format = value;
+                       break;
+               case DRM_I915_PERF_PROP_OA_EXPONENT:
+                       if (value > OA_EXPONENT_MAX) {
+                               DRM_ERROR("OA timer exponent too high (> %u)\n",
+                                         OA_EXPONENT_MAX);
+                               return -EINVAL;
+                       }
+
+                       /* NB: The exponent represents a period as follows:
+                        *
+                        *   80ns * 2^(period_exponent + 1)
+                        *
+                        * Theoretically we can program the OA unit to sample

drivers/gpu/drm/i915/i915_perf.c static int read_properties_unlocked(struct drm_i915_private *dev_priv, · line 1314

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10 -0
+                        * every 160ns but don't allow that by default unless
+                        * root.
+                        *
+                        * Referring to perf's
+                        * kernel.perf_event_max_sample_rate for a precedent
+                        * (100000 by default); with an OA exponent of 6 we get
+                        * a period of 10.240 microseconds -just under 100000Hz
+                        */
+                       if (value < 6 && !capable(CAP_SYS_ADMIN)) {
+                               DRM_ERROR("Sampling period too high without root privileges\n");

Print the minimum sampling period here? Could be useful especially when in a later patch we make this configurable.

Quoted 465 lines
drivers/gpu/drm/i915/i915_perf.c +32 -2
+                               return -EACCES;
+                       }
+
+                       props->oa_periodic = true;
+                       props->oa_period_exponent = value;
+                       break;
                default:
                        MISSING_CASE(id);
                        DRM_ERROR("Unknown i915 perf property ID");
@@ -426,8 +1368,33 @@ int i915_perf_open_ioctl(struct drm_device *dev, void *data,
 
 void i915_perf_init(struct drm_i915_private *dev_priv)
 {
+       if (!IS_HASWELL(dev_priv))
+               return;
+
+       hrtimer_init(&dev_priv->perf.oa.poll_check_timer,
+                    CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+       dev_priv->perf.oa.poll_check_timer.function = oa_poll_check_timer_cb;
+       init_waitqueue_head(&dev_priv->perf.oa.poll_wq);
+
        INIT_LIST_HEAD(&dev_priv->perf.streams);
        mutex_init(&dev_priv->perf.lock);
+       spin_lock_init(&dev_priv->perf.hook_lock);
+
+       dev_priv->perf.oa.ops.init_oa_buffer = gen7_init_oa_buffer;
+       dev_priv->perf.oa.ops.enable_metric_set = hsw_enable_metric_set;
+       dev_priv->perf.oa.ops.disable_metric_set = hsw_disable_metric_set;
+       dev_priv->perf.oa.ops.oa_enable = gen7_oa_enable;
+       dev_priv->perf.oa.ops.oa_disable = gen7_oa_disable;
+       dev_priv->perf.oa.ops.read = gen7_oa_read;
+       dev_priv->perf.oa.ops.oa_buffer_is_empty =
+               gen7_oa_buffer_is_empty_fop_unlocked;
+
+       dev_priv->perf.oa.timestamp_frequency = 12500000;
+
+       dev_priv->perf.oa.oa_formats = hsw_oa_formats;
+
+       dev_priv->perf.oa.n_builtin_sets =
+               i915_oa_n_builtin_metric_sets_hsw;
 
        dev_priv->perf.initialized = true;
 }
@@ -437,7 +1404,6 @@ void i915_perf_fini(struct drm_i915_private *dev_priv)
        if (!dev_priv->perf.initialized)
                return;
 
-       /* Currently nothing to clean up */
-
+       memset(&dev_priv->perf.oa.ops, 0, sizeof(dev_priv->perf.oa.ops));
        dev_priv->perf.initialized = false;
 }
drivers/gpu/drm/i915/i915_reg.h +338 -0
index 070d3297..2557b3f 100644
@@ -616,6 +616,343 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)
 #define HSW_CS_GPR_UDW(n)               _MMIO(0x2600 + (n) * 8 + 4)
 
 #define GEN7_OACONTROL _MMIO(0x2360)
+#define  GEN7_OACONTROL_CTX_MASK           0xFFFFF000
+#define  GEN7_OACONTROL_TIMER_PERIOD_MASK   0x3F
+#define  GEN7_OACONTROL_TIMER_PERIOD_SHIFT  6
+#define  GEN7_OACONTROL_TIMER_ENABLE       (1<<5)
+#define  GEN7_OACONTROL_FORMAT_A13         (0<<2)
+#define  GEN7_OACONTROL_FORMAT_A29         (1<<2)
+#define  GEN7_OACONTROL_FORMAT_A13_B8_C8    (2<<2)
+#define  GEN7_OACONTROL_FORMAT_A29_B8_C8    (3<<2)
+#define  GEN7_OACONTROL_FORMAT_B4_C8       (4<<2)
+#define  GEN7_OACONTROL_FORMAT_A45_B8_C8    (5<<2)
+#define  GEN7_OACONTROL_FORMAT_B4_C8_A16    (6<<2)
+#define  GEN7_OACONTROL_FORMAT_C4_B8       (7<<2)
+#define  GEN7_OACONTROL_FORMAT_SHIFT       2
+#define  GEN7_OACONTROL_PER_CTX_ENABLE     (1<<1)
+#define  GEN7_OACONTROL_ENABLE             (1<<0)
+
+#define GEN8_OACTXID _MMIO(0x2364)
+
+#define GEN8_OACONTROL _MMIO(0x2B00)
+#define  GEN8_OA_REPORT_FORMAT_A12         (0<<2)
+#define  GEN8_OA_REPORT_FORMAT_A12_B8_C8    (2<<2)
+#define  GEN8_OA_REPORT_FORMAT_A36_B8_C8    (5<<2)
+#define  GEN8_OA_REPORT_FORMAT_C4_B8       (7<<2)
+#define  GEN8_OA_REPORT_FORMAT_SHIFT       2
+#define  GEN8_OA_SPECIFIC_CONTEXT_ENABLE    (1<<1)
+#define  GEN8_OA_COUNTER_ENABLE             (1<<0)
+
+#define GEN8_OACTXCONTROL _MMIO(0x2360)
+#define  GEN8_OA_TIMER_PERIOD_MASK         0x3F
+#define  GEN8_OA_TIMER_PERIOD_SHIFT        2
+#define  GEN8_OA_TIMER_ENABLE              (1<<1)
+#define  GEN8_OA_COUNTER_RESUME                    (1<<0)
+
+#define GEN7_OABUFFER _MMIO(0x23B0) /* R/W */
+#define  GEN7_OABUFFER_OVERRUN_DISABLE     (1<<3)
+#define  GEN7_OABUFFER_EDGE_TRIGGER        (1<<2)
+#define  GEN7_OABUFFER_STOP_RESUME_ENABLE   (1<<1)
+#define  GEN7_OABUFFER_RESUME              (1<<0)
+
+#define GEN8_OABUFFER _MMIO(0x2b14)
+
+#define GEN7_OASTATUS1 _MMIO(0x2364)
+#define  GEN7_OASTATUS1_TAIL_MASK          0xffffffc0
+#define  GEN7_OASTATUS1_COUNTER_OVERFLOW    (1<<2)
+#define  GEN7_OASTATUS1_OABUFFER_OVERFLOW   (1<<1)
+#define  GEN7_OASTATUS1_REPORT_LOST        (1<<0)
+
+#define GEN7_OASTATUS2 _MMIO(0x2368)
+#define GEN7_OASTATUS2_HEAD_MASK    0xffffffc0
+
+#define GEN8_OASTATUS _MMIO(0x2b08)
+#define  GEN8_OASTATUS_OVERRUN_STATUS      (1<<3)
+#define  GEN8_OASTATUS_COUNTER_OVERFLOW     (1<<2)
+#define  GEN8_OASTATUS_OABUFFER_OVERFLOW    (1<<1)
+#define  GEN8_OASTATUS_REPORT_LOST         (1<<0)
+
+#define GEN8_OAHEADPTR _MMIO(0x2B0C)
+#define GEN8_OATAILPTR _MMIO(0x2B10)
+
+#define OABUFFER_SIZE_128K  (0<<3)
+#define OABUFFER_SIZE_256K  (1<<3)
+#define OABUFFER_SIZE_512K  (2<<3)
+#define OABUFFER_SIZE_1M    (3<<3)
+#define OABUFFER_SIZE_2M    (4<<3)
+#define OABUFFER_SIZE_4M    (5<<3)
+#define OABUFFER_SIZE_8M    (6<<3)
+#define OABUFFER_SIZE_16M   (7<<3)
+
+#define OA_MEM_SELECT_GGTT  (1<<0)
+
+#define EU_PERF_CNTL0      _MMIO(0xe458)
+
+#define GDT_CHICKEN_BITS    _MMIO(0x9840)
+#define GT_NOA_ENABLE      0x00000080
+
+/*
+ * OA Boolean state
+ */
+
+#define OAREPORTTRIG1 _MMIO(0x2740)
+#define OAREPORTTRIG1_THRESHOLD_MASK 0xffff
+#define OAREPORTTRIG1_EDGE_LEVEL_TRIGER_SELECT_MASK 0xffff0000 /* 0=level */
+
+#define OAREPORTTRIG2 _MMIO(0x2744)
+#define OAREPORTTRIG2_INVERT_A_0  (1<<0)
+#define OAREPORTTRIG2_INVERT_A_1  (1<<1)
+#define OAREPORTTRIG2_INVERT_A_2  (1<<2)
+#define OAREPORTTRIG2_INVERT_A_3  (1<<3)
+#define OAREPORTTRIG2_INVERT_A_4  (1<<4)
+#define OAREPORTTRIG2_INVERT_A_5  (1<<5)
+#define OAREPORTTRIG2_INVERT_A_6  (1<<6)
+#define OAREPORTTRIG2_INVERT_A_7  (1<<7)
+#define OAREPORTTRIG2_INVERT_A_8  (1<<8)
+#define OAREPORTTRIG2_INVERT_A_9  (1<<9)
+#define OAREPORTTRIG2_INVERT_A_10 (1<<10)
+#define OAREPORTTRIG2_INVERT_A_11 (1<<11)
+#define OAREPORTTRIG2_INVERT_A_12 (1<<12)
+#define OAREPORTTRIG2_INVERT_A_13 (1<<13)
+#define OAREPORTTRIG2_INVERT_A_14 (1<<14)
+#define OAREPORTTRIG2_INVERT_A_15 (1<<15)
+#define OAREPORTTRIG2_INVERT_B_0  (1<<16)
+#define OAREPORTTRIG2_INVERT_B_1  (1<<17)
+#define OAREPORTTRIG2_INVERT_B_2  (1<<18)
+#define OAREPORTTRIG2_INVERT_B_3  (1<<19)
+#define OAREPORTTRIG2_INVERT_C_0  (1<<20)
+#define OAREPORTTRIG2_INVERT_C_1  (1<<21)
+#define OAREPORTTRIG2_INVERT_D_0  (1<<22)
+#define OAREPORTTRIG2_THRESHOLD_ENABLE     (1<<23)
+#define OAREPORTTRIG2_REPORT_TRIGGER_ENABLE (1<<31)
+
+#define OAREPORTTRIG3 _MMIO(0x2748)
+#define OAREPORTTRIG3_NOA_SELECT_MASK      0xf
+#define OAREPORTTRIG3_NOA_SELECT_8_SHIFT    0
+#define OAREPORTTRIG3_NOA_SELECT_9_SHIFT    4
+#define OAREPORTTRIG3_NOA_SELECT_10_SHIFT   8
+#define OAREPORTTRIG3_NOA_SELECT_11_SHIFT   12
+#define OAREPORTTRIG3_NOA_SELECT_12_SHIFT   16
+#define OAREPORTTRIG3_NOA_SELECT_13_SHIFT   20
+#define OAREPORTTRIG3_NOA_SELECT_14_SHIFT   24
+#define OAREPORTTRIG3_NOA_SELECT_15_SHIFT   28
+
+#define OAREPORTTRIG4 _MMIO(0x274c)
+#define OAREPORTTRIG4_NOA_SELECT_MASK      0xf
+#define OAREPORTTRIG4_NOA_SELECT_0_SHIFT    0
+#define OAREPORTTRIG4_NOA_SELECT_1_SHIFT    4
+#define OAREPORTTRIG4_NOA_SELECT_2_SHIFT    8
+#define OAREPORTTRIG4_NOA_SELECT_3_SHIFT    12
+#define OAREPORTTRIG4_NOA_SELECT_4_SHIFT    16
+#define OAREPORTTRIG4_NOA_SELECT_5_SHIFT    20
+#define OAREPORTTRIG4_NOA_SELECT_6_SHIFT    24
+#define OAREPORTTRIG4_NOA_SELECT_7_SHIFT    28
+
+#define OAREPORTTRIG5 _MMIO(0x2750)
+#define OAREPORTTRIG5_THRESHOLD_MASK 0xffff
+#define OAREPORTTRIG5_EDGE_LEVEL_TRIGER_SELECT_MASK 0xffff0000 /* 0=level */
+
+#define OAREPORTTRIG6 _MMIO(0x2754)
+#define OAREPORTTRIG6_INVERT_A_0  (1<<0)
+#define OAREPORTTRIG6_INVERT_A_1  (1<<1)
+#define OAREPORTTRIG6_INVERT_A_2  (1<<2)
+#define OAREPORTTRIG6_INVERT_A_3  (1<<3)
+#define OAREPORTTRIG6_INVERT_A_4  (1<<4)
+#define OAREPORTTRIG6_INVERT_A_5  (1<<5)
+#define OAREPORTTRIG6_INVERT_A_6  (1<<6)
+#define OAREPORTTRIG6_INVERT_A_7  (1<<7)
+#define OAREPORTTRIG6_INVERT_A_8  (1<<8)
+#define OAREPORTTRIG6_INVERT_A_9  (1<<9)
+#define OAREPORTTRIG6_INVERT_A_10 (1<<10)
+#define OAREPORTTRIG6_INVERT_A_11 (1<<11)
+#define OAREPORTTRIG6_INVERT_A_12 (1<<12)
+#define OAREPORTTRIG6_INVERT_A_13 (1<<13)
+#define OAREPORTTRIG6_INVERT_A_14 (1<<14)
+#define OAREPORTTRIG6_INVERT_A_15 (1<<15)
+#define OAREPORTTRIG6_INVERT_B_0  (1<<16)
+#define OAREPORTTRIG6_INVERT_B_1  (1<<17)
+#define OAREPORTTRIG6_INVERT_B_2  (1<<18)
+#define OAREPORTTRIG6_INVERT_B_3  (1<<19)
+#define OAREPORTTRIG6_INVERT_C_0  (1<<20)
+#define OAREPORTTRIG6_INVERT_C_1  (1<<21)
+#define OAREPORTTRIG6_INVERT_D_0  (1<<22)
+#define OAREPORTTRIG6_THRESHOLD_ENABLE     (1<<23)
+#define OAREPORTTRIG6_REPORT_TRIGGER_ENABLE (1<<31)
+
+#define OAREPORTTRIG7 _MMIO(0x2758)
+#define OAREPORTTRIG7_NOA_SELECT_MASK      0xf
+#define OAREPORTTRIG7_NOA_SELECT_8_SHIFT    0
+#define OAREPORTTRIG7_NOA_SELECT_9_SHIFT    4
+#define OAREPORTTRIG7_NOA_SELECT_10_SHIFT   8
+#define OAREPORTTRIG7_NOA_SELECT_11_SHIFT   12
+#define OAREPORTTRIG7_NOA_SELECT_12_SHIFT   16
+#define OAREPORTTRIG7_NOA_SELECT_13_SHIFT   20
+#define OAREPORTTRIG7_NOA_SELECT_14_SHIFT   24
+#define OAREPORTTRIG7_NOA_SELECT_15_SHIFT   28
+
+#define OAREPORTTRIG8 _MMIO(0x275c)
+#define OAREPORTTRIG8_NOA_SELECT_MASK      0xf
+#define OAREPORTTRIG8_NOA_SELECT_0_SHIFT    0
+#define OAREPORTTRIG8_NOA_SELECT_1_SHIFT    4
+#define OAREPORTTRIG8_NOA_SELECT_2_SHIFT    8
+#define OAREPORTTRIG8_NOA_SELECT_3_SHIFT    12
+#define OAREPORTTRIG8_NOA_SELECT_4_SHIFT    16
+#define OAREPORTTRIG8_NOA_SELECT_5_SHIFT    20
+#define OAREPORTTRIG8_NOA_SELECT_6_SHIFT    24
+#define OAREPORTTRIG8_NOA_SELECT_7_SHIFT    28
+
+#define OASTARTTRIG1 _MMIO(0x2710)
+#define OASTARTTRIG1_THRESHOLD_COUNT_MASK_MBZ 0xffff0000
+#define OASTARTTRIG1_THRESHOLD_MASK          0xffff
+
+#define OASTARTTRIG2 _MMIO(0x2714)
+#define OASTARTTRIG2_INVERT_A_0 (1<<0)
+#define OASTARTTRIG2_INVERT_A_1 (1<<1)
+#define OASTARTTRIG2_INVERT_A_2 (1<<2)
+#define OASTARTTRIG2_INVERT_A_3 (1<<3)
+#define OASTARTTRIG2_INVERT_A_4 (1<<4)
+#define OASTARTTRIG2_INVERT_A_5 (1<<5)
+#define OASTARTTRIG2_INVERT_A_6 (1<<6)
+#define OASTARTTRIG2_INVERT_A_7 (1<<7)
+#define OASTARTTRIG2_INVERT_A_8 (1<<8)
+#define OASTARTTRIG2_INVERT_A_9 (1<<9)
+#define OASTARTTRIG2_INVERT_A_10 (1<<10)
+#define OASTARTTRIG2_INVERT_A_11 (1<<11)
+#define OASTARTTRIG2_INVERT_A_12 (1<<12)
+#define OASTARTTRIG2_INVERT_A_13 (1<<13)
+#define OASTARTTRIG2_INVERT_A_14 (1<<14)
+#define OASTARTTRIG2_INVERT_A_15 (1<<15)
+#define OASTARTTRIG2_INVERT_B_0 (1<<16)
+#define OASTARTTRIG2_INVERT_B_1 (1<<17)
+#define OASTARTTRIG2_INVERT_B_2 (1<<18)
+#define OASTARTTRIG2_INVERT_B_3 (1<<19)
+#define OASTARTTRIG2_INVERT_C_0 (1<<20)
+#define OASTARTTRIG2_INVERT_C_1 (1<<21)
+#define OASTARTTRIG2_INVERT_D_0 (1<<22)
+#define OASTARTTRIG2_THRESHOLD_ENABLE      (1<<23)
+#define OASTARTTRIG2_START_TRIG_FLAG_MBZ    (1<<24)
+#define OASTARTTRIG2_EVENT_SELECT_0  (1<<28)
+#define OASTARTTRIG2_EVENT_SELECT_1  (1<<29)
+#define OASTARTTRIG2_EVENT_SELECT_2  (1<<30)
+#define OASTARTTRIG2_EVENT_SELECT_3  (1<<31)
+
+#define OASTARTTRIG3 _MMIO(0x2718)
+#define OASTARTTRIG3_NOA_SELECT_MASK      0xf
+#define OASTARTTRIG3_NOA_SELECT_8_SHIFT    0
+#define OASTARTTRIG3_NOA_SELECT_9_SHIFT    4
+#define OASTARTTRIG3_NOA_SELECT_10_SHIFT   8
+#define OASTARTTRIG3_NOA_SELECT_11_SHIFT   12
+#define OASTARTTRIG3_NOA_SELECT_12_SHIFT   16
+#define OASTARTTRIG3_NOA_SELECT_13_SHIFT   20
+#define OASTARTTRIG3_NOA_SELECT_14_SHIFT   24
+#define OASTARTTRIG3_NOA_SELECT_15_SHIFT   28
+
+#define OASTARTTRIG4 _MMIO(0x271c)
+#define OASTARTTRIG4_NOA_SELECT_MASK       0xf
+#define OASTARTTRIG4_NOA_SELECT_0_SHIFT    0
+#define OASTARTTRIG4_NOA_SELECT_1_SHIFT    4
+#define OASTARTTRIG4_NOA_SELECT_2_SHIFT    8
+#define OASTARTTRIG4_NOA_SELECT_3_SHIFT    12
+#define OASTARTTRIG4_NOA_SELECT_4_SHIFT    16
+#define OASTARTTRIG4_NOA_SELECT_5_SHIFT    20
+#define OASTARTTRIG4_NOA_SELECT_6_SHIFT    24
+#define OASTARTTRIG4_NOA_SELECT_7_SHIFT    28
+
+#define OASTARTTRIG5 _MMIO(0x2720)
+#define OASTARTTRIG5_THRESHOLD_COUNT_MASK_MBZ 0xffff0000
+#define OASTARTTRIG5_THRESHOLD_MASK          0xffff
+
+#define OASTARTTRIG6 _MMIO(0x2724)
+#define OASTARTTRIG6_INVERT_A_0 (1<<0)
+#define OASTARTTRIG6_INVERT_A_1 (1<<1)
+#define OASTARTTRIG6_INVERT_A_2 (1<<2)
+#define OASTARTTRIG6_INVERT_A_3 (1<<3)
+#define OASTARTTRIG6_INVERT_A_4 (1<<4)
+#define OASTARTTRIG6_INVERT_A_5 (1<<5)
+#define OASTARTTRIG6_INVERT_A_6 (1<<6)
+#define OASTARTTRIG6_INVERT_A_7 (1<<7)
+#define OASTARTTRIG6_INVERT_A_8 (1<<8)
+#define OASTARTTRIG6_INVERT_A_9 (1<<9)
+#define OASTARTTRIG6_INVERT_A_10 (1<<10)
+#define OASTARTTRIG6_INVERT_A_11 (1<<11)
+#define OASTARTTRIG6_INVERT_A_12 (1<<12)
+#define OASTARTTRIG6_INVERT_A_13 (1<<13)
+#define OASTARTTRIG6_INVERT_A_14 (1<<14)
+#define OASTARTTRIG6_INVERT_A_15 (1<<15)
+#define OASTARTTRIG6_INVERT_B_0 (1<<16)
+#define OASTARTTRIG6_INVERT_B_1 (1<<17)
+#define OASTARTTRIG6_INVERT_B_2 (1<<18)
+#define OASTARTTRIG6_INVERT_B_3 (1<<19)
+#define OASTARTTRIG6_INVERT_C_0 (1<<20)
+#define OASTARTTRIG6_INVERT_C_1 (1<<21)
+#define OASTARTTRIG6_INVERT_D_0 (1<<22)
+#define OASTARTTRIG6_THRESHOLD_ENABLE      (1<<23)
+#define OASTARTTRIG6_START_TRIG_FLAG_MBZ    (1<<24)
+#define OASTARTTRIG6_EVENT_SELECT_4  (1<<28)
+#define OASTARTTRIG6_EVENT_SELECT_5  (1<<29)
+#define OASTARTTRIG6_EVENT_SELECT_6  (1<<30)
+#define OASTARTTRIG6_EVENT_SELECT_7  (1<<31)
+
+#define OASTARTTRIG7 _MMIO(0x2728)
+#define OASTARTTRIG7_NOA_SELECT_MASK      0xf
+#define OASTARTTRIG7_NOA_SELECT_8_SHIFT    0
+#define OASTARTTRIG7_NOA_SELECT_9_SHIFT    4
+#define OASTARTTRIG7_NOA_SELECT_10_SHIFT   8
+#define OASTARTTRIG7_NOA_SELECT_11_SHIFT   12
+#define OASTARTTRIG7_NOA_SELECT_12_SHIFT   16
+#define OASTARTTRIG7_NOA_SELECT_13_SHIFT   20
+#define OASTARTTRIG7_NOA_SELECT_14_SHIFT   24
+#define OASTARTTRIG7_NOA_SELECT_15_SHIFT   28
+
+#define OASTARTTRIG8 _MMIO(0x272c)
+#define OASTARTTRIG8_NOA_SELECT_MASK      0xf
+#define OASTARTTRIG8_NOA_SELECT_0_SHIFT    0
+#define OASTARTTRIG8_NOA_SELECT_1_SHIFT    4
+#define OASTARTTRIG8_NOA_SELECT_2_SHIFT    8
+#define OASTARTTRIG8_NOA_SELECT_3_SHIFT    12
+#define OASTARTTRIG8_NOA_SELECT_4_SHIFT    16
+#define OASTARTTRIG8_NOA_SELECT_5_SHIFT    20
+#define OASTARTTRIG8_NOA_SELECT_6_SHIFT    24
+#define OASTARTTRIG8_NOA_SELECT_7_SHIFT    28
+
+/* CECX_0 */
+#define OACEC_COMPARE_LESS_OR_EQUAL    6
+#define OACEC_COMPARE_NOT_EQUAL                5
+#define OACEC_COMPARE_LESS_THAN                4
+#define OACEC_COMPARE_GREATER_OR_EQUAL 3
+#define OACEC_COMPARE_EQUAL            2
+#define OACEC_COMPARE_GREATER_THAN     1
+#define OACEC_COMPARE_ANY_EQUAL                0
+
+#define OACEC_COMPARE_VALUE_MASK    0xffff
+#define OACEC_COMPARE_VALUE_SHIFT   3
+
+#define OACEC_SELECT_NOA       (0<<19)
+#define OACEC_SELECT_PREV      (1<<19)
+#define OACEC_SELECT_BOOLEAN   (2<<19)
+
+/* CECX_1 */
+#define OACEC_MASK_MASK                    0xffff
+#define OACEC_CONSIDERATIONS_MASK   0xffff
+#define OACEC_CONSIDERATIONS_SHIFT  16
+
+#define OACEC0_0 _MMIO(0x2770)
+#define OACEC0_1 _MMIO(0x2774)
+#define OACEC1_0 _MMIO(0x2778)
+#define OACEC1_1 _MMIO(0x277c)
+#define OACEC2_0 _MMIO(0x2780)
+#define OACEC2_1 _MMIO(0x2784)
+#define OACEC3_0 _MMIO(0x2788)
+#define OACEC3_1 _MMIO(0x278c)
+#define OACEC4_0 _MMIO(0x2790)
+#define OACEC4_1 _MMIO(0x2794)
+#define OACEC5_0 _MMIO(0x2798)
+#define OACEC5_1 _MMIO(0x279c)
+#define OACEC6_0 _MMIO(0x27a0)
+#define OACEC6_1 _MMIO(0x27a4)
+#define OACEC7_0 _MMIO(0x27a8)
+#define OACEC7_1 _MMIO(0x27ac)
+
 
 #define _GEN7_PIPEA_DE_LOAD_SL 0x70068
 #define _GEN7_PIPEB_DE_LOAD_SL 0x71068
@@ -6982,6 +7319,7 @@ enum {
 # define GEN6_RCCUNIT_CLOCK_GATE_DISABLE               (1 << 11)
 
 #define GEN6_UCGCTL3                           _MMIO(0x9408)
+# define GEN6_OACSUNIT_CLOCK_GATE_DISABLE              (1 << 20)
 
 #define GEN7_UCGCTL4                           _MMIO(0x940c)
 #define  GEN7_L3BANK2X_CLOCK_GATE_DISABLE      (1<<25)
include/uapi/drm/i915_drm.h +38 -0
index 98cd493..bf3b8e2 100644
@@ -1224,6 +1224,18 @@ struct drm_i915_gem_context_param {
        __u64 value;
 };
 
+enum drm_i915_oa_format {
+       I915_OA_FORMAT_A13 = 1,
+       I915_OA_FORMAT_A29,
+       I915_OA_FORMAT_A13_B8_C8,
+       I915_OA_FORMAT_B4_C8,
+       I915_OA_FORMAT_A45_B8_C8,
+       I915_OA_FORMAT_B4_C8_A16,
+       I915_OA_FORMAT_C4_B8,
+
+       I915_OA_FORMAT_MAX          /* non-ABI */
+};
+
 enum drm_i915_perf_property_id {
        /**
         * Open the stream for a specific context handle (as used with
@@ -1232,6 +1244,32 @@ enum drm_i915_perf_property_id {
         */
        DRM_I915_PERF_PROP_CTX_HANDLE = 1,
 
+       /**
+        * A value of 1 requests the inclusion of raw OA unit reports as
+        * part of stream samples.
+        */
+       DRM_I915_PERF_PROP_SAMPLE_OA,
+
+       /**
+        * The value specifies which set of OA unit metrics should be
+        * be configured, defining the contents of any OA unit reports.
+        */
+       DRM_I915_PERF_PROP_OA_METRICS_SET,
+
+       /**
+        * The value specifies the size and layout of OA unit reports.
+        */
+       DRM_I915_PERF_PROP_OA_FORMAT,
+
+       /**
+        * Specifying this property implicitly requests periodic OA unit
+        * sampling and (at least on Haswell) the sampling frequency is derived
+        * from this exponent as follows:
+        *
+        *   80ns * 2^(period_exponent + 1)
+        */
+       DRM_I915_PERF_PROP_OA_EXPONENT,
+
        DRM_I915_PERF_PROP_MAX /* non-ABI */
 };
 

include/uapi/drm/i915_drm.h struct drm_i915_perf_open_param { · line 1294

Quoted 6 lines
include/uapi/drm/i915_drm.h +3 -0
@@ -1251,7 +1289,22 @@ struct drm_i915_perf_open_param {
        __u64 __user properties_ptr;
 };
 
+/**
+ * Enable data capture for a stream that was either opened in a disabled state
+ * via I915_PERF_FLAG_DIABLED or was later disabled via I915_PERF_IOCTL_DISABLE.

I915_PERF_FLAG_DISABLED

Quoted 50 lines
include/uapi/drm/i915_drm.h +27 -3
+ *
+ * It is intended to be cheaper to disable and enable a stream than it may be
+ * to close and re-open a stream with the same configuration.
+ *
+ * It's undefined whether any pending data for the stream will be lost.
+ */
 #define I915_PERF_IOCTL_ENABLE _IO('i', 0x0)
+
+/**
+ * Disable data capture for a stream.
+ *
+ * It is an error to try and read a stream that is disabled.
+ */
 #define I915_PERF_IOCTL_DISABLE        _IO('i', 0x1)
 
 /**
@@ -1275,17 +1328,30 @@ enum drm_i915_perf_record_type {
         * every sample.
         *
         * The order of these sample properties given by userspace has no
-        * affect on the ordering of data within a sample. The order will be
+        * affect on the ordering of data within a sample. The order is
         * documented here.
         *
         * struct {
         *     struct drm_i915_perf_record_header header;
         *
-        *     TODO: itemize extensible sample data here
+        *     { u32 oa_report[]; } && DRM_I915_PERF_PROP_SAMPLE_OA
         * };
         */
        DRM_I915_PERF_RECORD_SAMPLE = 1,
 
+       /*
+        * Indicates that one or more OA reports were not written by the
+        * hardware. This can happen for example if an MI_REPORT_PERF_COUNT
+        * command collides with periodic sampling - which would be more likely
+        * at higher sampling frequencies.
+        */
+       DRM_I915_PERF_RECORD_OA_REPORT_LOST = 2,
+
+       /**
+        * An error occurred that resulted in all pending OA reports being lost.
+        */
+       DRM_I915_PERF_RECORD_OA_BUFFER_LOST = 3,
+
        DRM_I915_PERF_RECORD_MAX /* non-ABI */
 };
 
--
Quoted 2 lines

2.10.1

Otherwise looks good.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#11 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 22 lines · Matthew Auld

Review

Quoted 1 line · Robert Bragg
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_drv.h

Quoted 15 lines

index 3448d05..ea24814 100644

drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -1764,6 +1764,11 @@ struct intel_wm_config {
 
 
 struct drm_i915_private {
@@ -2149,16 +2164,46 @@ struct drm_i915_private {
 
        struct {
                bool initialized;
+
                struct mutex lock;
                struct list_head streams;
 
Quoted 11 lines

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2176

Quoted 7 lines
drivers/gpu/drm/i915/i915_drv.h +5 -1
+               spinlock_t hook_lock;
+
                struct {
-                       u32 metrics_set;
+                       struct i915_perf_stream *exclusive_stream;
+
+                       u32 specific_ctx_id;

Can we just get rid of this, now that the vma remains pinned we can simply get the ggtt address at the time of configuring the OA_CONTROL register ?

I considered that, but would ideally prefer to keep it considering the gen8+ patches to come. For gen8+ (with execlists) the context ID isn't a gtt offset.

Quoted 18 lines

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private {

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +6 -0
+
+                       struct hrtimer poll_check_timer;
+                       wait_queue_head_t poll_wq;
+                       atomic_t pollin;
+
 
 
 
+/* The maximum exponent the hardware accepts is 63 (essentially it

selects one

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2186

Quoted 1 line
drivers/gpu/drm/i915/i915_drv.h +1 -0
+ * of the 64bit timestamp bits to trigger reports from) but there's

currently

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2187

Quoted 1 line
drivers/gpu/drm/i915/i915_drv.h +1 -0
+ * no known use case for sampling as infrequently as once per 47

thousand years.

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2190

Quoted 3 lines
drivers/gpu/drm/i915/i915_drv.h +3 -0
+ *
+ * Since the timestamps included in OA reports are only 32bits it seems
+ * reasonable to limit the OA exponent where it's still possible to
Quoted 8 lines

account for

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2195

Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
+ * overflow in OA report timestamps.
+ */
+#define OA_EXPONENT_MAX 31
+
+#define INVALID_CTX_ID 0xffffffff

We shouldn't need this anymore.

yeah I removed it and then added it back, just for the sake of explicitly setting the specific_ctx_id to an invalid ID when closing the exclusive stream - though resetting the value isn't strictly necessary.

also maybe your comment is assuming specific_ctx_id can be removed, while I'd prefer to keep it.

Quoted 6 lines

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2198

Quoted 3 lines
drivers/gpu/drm/i915/i915_drv.h +3 -0
+
+static int claim_specific_ctx(struct i915_perf_stream *stream)
+{

pin_oa_specific_ctx, or something? Also would it not make more sense to operate on the context, not the stream.

Yeah, I avoided a name like that mainly because it's also initializing specific_ctx_id, which seemed to me like it would become an unexpected side effect with that more specific name.

The other consideration is that in my gen8+ patches the pinning code is conditional depending on whether execlists are enabled, while the function still initializes specific_ctx_id.

Certainly not attached to the names though.

Chris has some feedback with the code, so maybe that will affect this too.

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/i915/i915_drv.h +16 -0
+       struct drm_i915_private *dev_priv = stream->dev_priv;
+       struct i915_vma *vma;
+       int ret;
+
+       ret = i915_mutex_lock_interruptible(&dev_priv->drm);
+       if (ret)
+               return ret;
+
+       /* So that we don't have to worry about updating the context ID
+        * in OACONTOL on the fly we make sure to pin the context
+        * upfront for the lifetime of the stream...
+        */
+       vma = stream->ctx->engine[RCS].state;
+       ret = i915_vma_pin(vma, 0, stream->ctx->ggtt_alignment,
+                          PIN_GLOBAL | PIN_HIGH);
+       if (ret)
Quoted 9 lines

drivers/gpu/drm/i915/i915_drv.h

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +8 -0
+               return ret;
+
+       dev_priv->perf.oa.specific_ctx_id = i915_ggtt_offset(vma);
+
+       mutex_unlock(&dev_priv->drm.struct_mutex);
+
+       return 0;
+}

I'll also follow up on the other notes; thanks!

- Robert

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 31 lines · Robert Bragg
   On Tue, Oct 25, 2016 at 10:35 PM, Matthew Auld
   <[1][email protected]> wrote:

     On 25 October 2016 at 00:19, Robert Bragg <[2][email protected]>
     wrote:

    

     > diff --git a/drivers/gpu/drm/i915/i915_drv.h
     b/drivers/gpu/drm/i915/i915_drv.h
     > index 3448d05..ea24814 100644
     > --- a/drivers/gpu/drm/i915/i915_drv.h
     > +++ b/drivers/gpu/drm/i915/i915_drv.h
     > @@ -1764,6 +1764,11 @@ struct intel_wm_config {

     >
     >  struct drm_i915_private {
     > @@ -2149,16 +2164,46 @@ struct drm_i915_private {
     >
     >         struct {
     >                 bool initialized;
     > +
     >                 struct mutex lock;
     >                 struct list_head streams;
     >
     > +               spinlock_t hook_lock;
     > +
     >                 struct {
     > -                       u32 metrics_set;
     > +                       struct i915_perf_stream *exclusive_stream;
     > +
Quoted 8 lines
     > +                       u32 specific_ctx_id;
     Can we just get rid of this, now that the vma remains pinned we can
     simply get the ggtt address at the time of configuring the OA_CONTROL
     register ?

   I considered that, but would ideally prefer to keep it considering the
   gen8+ patches to come. For gen8+ (with execlists) the context ID isn't a
   gtt offset.

In terms of symmetry, keeping the vma you pinned and unpinning the same later makes its ownership much clearer. (And I do want the owner of each pin to be clear, for when we start enabling debug to catch the VMA leaks.)
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#13 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 17 lines · Chris Wilson
Quoted 15 lines · Robert Bragg
   On Tue, Oct 25, 2016 at 10:35 PM, Matthew Auld
   <[1][email protected]> wrote:

     On 25 October 2016 at 00:19, Robert Bragg <[2][email protected]>
     wrote:



     > diff --git a/drivers/gpu/drm/i915/i915_drv.h
     b/drivers/gpu/drm/i915/i915_drv.h
     > index 3448d05..ea24814 100644
     > --- a/drivers/gpu/drm/i915/i915_drv.h
     > +++ b/drivers/gpu/drm/i915/i915_drv.h
     > @@ -1764,6 +1764,11 @@ struct intel_wm_config {
Quoted 15 lines
Quoted 7 lines
     >
     >  struct drm_i915_private {
     > @@ -2149,16 +2164,46 @@ struct drm_i915_private {
     >
     >         struct {
     >                 bool initialized;
     > +
Quoted 8 lines
     >                 struct mutex lock;
     >                 struct list_head streams;
     >
     > +               spinlock_t hook_lock;
     > +
     >                 struct {
     > -                       u32 metrics_set;
     > +                       struct i915_perf_stream

*exclusive_stream;

Quoted 4 lines
Quoted 4 lines

> +
> + u32 specific_ctx_id;
Can we just get rid of this, now that the vma remains pinned we can simply get the ggtt address at the time of configuring the

OA_CONTROL

Quoted 3 lines
Quoted 3 lines

register ?

I considered that, but would ideally prefer to keep it considering

the

Quoted 1 line
Quoted 1 line

gen8+ patches to come. For gen8+ (with execlists) the context ID

isn't a

Quoted 6 lines
Quoted 1 line

gtt offset.

In terms of symmetry, keeping the vma you pinned and unpinning the same later makes its ownership much clearer. (And I do want the owner of each pin to be clear, for when we start enabling debug to catch the VMA leaks.)

Keeping our own pointer to the pinned vma could be a clarification.

Considering Matt's comments too, I'm thinking I'll put the pinning and specific_ctx_id initialization together with setting stream->ctx, keeping the state together under the stream. It's going to potentially mean redundantly pinning the ctx for the sake of the ID in the future for streams that don't really need it, but I think it's probably not worth worrying about that.

- Robert

Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#14 lore raw

Re: [Intel-gfx] [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 33 lines · Robert Bragg
Quoted 17 lines · Chris Wilson
Quoted 15 lines · Robert Bragg
   On Tue, Oct 25, 2016 at 10:35 PM, Matthew Auld
   <[1][email protected]> wrote:

     On 25 October 2016 at 00:19, Robert Bragg <[2][email protected]>
     wrote:



     > diff --git a/drivers/gpu/drm/i915/i915_drv.h
     b/drivers/gpu/drm/i915/i915_drv.h
     > index 3448d05..ea24814 100644
     > --- a/drivers/gpu/drm/i915/i915_drv.h
     > +++ b/drivers/gpu/drm/i915/i915_drv.h
     > @@ -1764,6 +1764,11 @@ struct intel_wm_config {
Quoted 15 lines
Quoted 7 lines
     >
     >  struct drm_i915_private {
     > @@ -2149,16 +2164,46 @@ struct drm_i915_private {
     >
     >         struct {
     >                 bool initialized;
     > +
Quoted 8 lines
     >                 struct mutex lock;
     >                 struct list_head streams;
     >
     > +               spinlock_t hook_lock;
     > +
     >                 struct {
     > -                       u32 metrics_set;
     > +                       struct i915_perf_stream
Quoted 1 line

*exclusive_stream;

OT:
What kind of MUA are you using that mangles quoted mails like this? I've not seen it on intel-gfx before. mesa-dev seems rife with it, but as I rarely read that in any great detail I've managed to ignore it there. Anyways, it makes it espesially hard to navigate long mails since mutt's 'S' (skip quoted text) no longer works correctly.

Quoted 38 lines
Quoted 4 lines
Quoted 4 lines

> +
> + u32 specific_ctx_id;
Can we just get rid of this, now that the vma remains pinned we can simply get the ggtt address at the time of configuring the

OA_CONTROL

Quoted 3 lines
Quoted 3 lines

register ?

I considered that, but would ideally prefer to keep it considering

the

Quoted 1 line
Quoted 1 line

gen8+ patches to come. For gen8+ (with execlists) the context ID

isn't a

Quoted 6 lines
Quoted 1 line

gtt offset.

In terms of symmetry, keeping the vma you pinned and unpinning the same later makes its ownership much clearer. (And I do want the owner of each pin to be clear, for when we start enabling debug to catch the VMA leaks.)

Keeping our own pointer to the pinned vma could be a clarification.

Considering Matt's comments too, I'm thinking I'll put the pinning and specific_ctx_id initialization together with setting stream->ctx, keeping the state together under the stream. It's going to potentially mean redundantly pinning the ctx for the sake of the ID in the future for streams that don't really need it, but I think it's probably not worth worrying about that.

- Robert

Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#15 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 36 lines · Ville Syrjälä
Quoted 1 line · Robert Bragg

On 26 Oct 2016 9:54 a.m., "Chris Wilson" <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines · Robert Bragg
Quoted 4 lines

On Tue, Oct 25, 2016 at 10:35 PM, Matthew Auld
<[1][email protected]> wrote:

     On 25 October 2016 at 00:19, Robert Bragg <[2]

[email protected]>

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
     wrote:



     > diff --git a/drivers/gpu/drm/i915/i915_drv.h
     b/drivers/gpu/drm/i915/i915_drv.h
     > index 3448d05..ea24814 100644
     > --- a/drivers/gpu/drm/i915/i915_drv.h
     > +++ b/drivers/gpu/drm/i915/i915_drv.h
     > @@ -1764,6 +1764,11 @@ struct intel_wm_config {

     >
     >  struct drm_i915_private {
     > @@ -2149,16 +2164,46 @@ struct drm_i915_private {
     >
     >         struct {
     >                 bool initialized;
     > +
     >                 struct mutex lock;
     >                 struct list_head streams;
     >
     > +               spinlock_t hook_lock;
     > +
     >                 struct {
     > -                       u32 metrics_set;
     > +                       struct i915_perf_stream
Quoted 9 lines
Quoted 1 line

*exclusive_stream;

OT:
What kind of MUA are you using that mangles quoted mails like this? I've not seen it on intel-gfx before. mesa-dev seems rife with it, but as I rarely read that in any great detail I've managed to ignore it there. Anyways, it makes it espesially hard to navigate long mails since mutt's 'S' (skip quoted text) no longer works correctly.

Not sure I want to say, and get booted out the door :-)

I've heard that gmail has an annoying habit of forcibly wrapping plain text emails like this, and a lot of people have complained that there's no way to disable that 'feature' :-/

I used to use Mutt, but I don't think I could really bare to go back to it any more. Last time I was using it I found myself spending too much time patching it to try and make it work how I'd like, but can't say I got much enjoyment from that process.

I've tried most MUA options available, and can't say any of them make me very happy - I think these days it's just not something developers are very interesting in working on.

I'm a sell out and just use Gmail... sorry. I can't really see myself changing, though I do wish Google weren't so pedantic about forcing wrapping without any option to change that behaviour. I suspect you wouldn't be happy with me sending html emails, which has been Google's default response to this complaint afik.

Maybe it's gmail users causing trouble on the Mesa list too.

- Robert

P.S please don't think lesser of me due to my misguided MUA choices.

Quoted 43 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
     > +
     > +                       u32 specific_ctx_id;
     Can we just get rid of this, now that the vma remains pinned we

can

Quoted 12 lines
Quoted 1 line
Quoted 1 line

simply get the ggtt address at the time of configuring the

OA_CONTROL

Quoted 3 lines
Quoted 3 lines

register ?

I considered that, but would ideally prefer to keep it considering

the

Quoted 1 line
Quoted 1 line

gen8+ patches to come. For gen8+ (with execlists) the context ID

isn't a

Quoted 4 lines
Quoted 1 line

gtt offset.

In terms of symmetry, keeping the vma you pinned and unpinning the same later makes its ownership much clearer. (And I do want the owner of

each

Quoted 16 lines
Quoted 2 lines

pin to be clear, for when we start enabling debug to catch the VMA leaks.)

Keeping our own pointer to the pinned vma could be a clarification.

Considering Matt's comments too, I'm thinking I'll put the pinning and specific_ctx_id initialization together with setting stream->ctx, keeping the state together under the stream. It's going to potentially mean redundantly pinning the ctx for the sake of the ID in the future for streams that don't really need it, but I think it's probably not worth worrying about that.

- Robert

Quoted 2 lines

-Chris

Quoted 7 lines
Quoted 2 lines

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Quoted 4 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 70 lines · Robert Bragg
Quoted 36 lines · Ville Syrjälä
Quoted 1 line · Robert Bragg

On 26 Oct 2016 9:54 a.m., "Chris Wilson" <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines · Robert Bragg
Quoted 4 lines

On Tue, Oct 25, 2016 at 10:35 PM, Matthew Auld
<[1][email protected]> wrote:

     On 25 October 2016 at 00:19, Robert Bragg <[2]

[email protected]>

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
     wrote:



     > diff --git a/drivers/gpu/drm/i915/i915_drv.h
     b/drivers/gpu/drm/i915/i915_drv.h
     > index 3448d05..ea24814 100644
     > --- a/drivers/gpu/drm/i915/i915_drv.h
     > +++ b/drivers/gpu/drm/i915/i915_drv.h
     > @@ -1764,6 +1764,11 @@ struct intel_wm_config {

     >
     >  struct drm_i915_private {
     > @@ -2149,16 +2164,46 @@ struct drm_i915_private {
     >
     >         struct {
     >                 bool initialized;
     > +
     >                 struct mutex lock;
     >                 struct list_head streams;
     >
     > +               spinlock_t hook_lock;
     > +
     >                 struct {
     > -                       u32 metrics_set;
     > +                       struct i915_perf_stream
Quoted 9 lines
Quoted 1 line

*exclusive_stream;

OT:
What kind of MUA are you using that mangles quoted mails like this? I've not seen it on intel-gfx before. mesa-dev seems rife with it, but as I rarely read that in any great detail I've managed to ignore it there. Anyways, it makes it espesially hard to navigate long mails since mutt's 'S' (skip quoted text) no longer works correctly.

Not sure I want to say, and get booted out the door :-)

I've heard that gmail has an annoying habit of forcibly wrapping plain text emails like this, and a lot of people have complained that there's no way to disable that 'feature' :-/

I used to use Mutt, but I don't think I could really bare to go back to it any more. Last time I was using it I found myself spending too much time patching it to try and make it work how I'd like, but can't say I got much enjoyment from that process.

I've tried most MUA options available, and can't say any of them make me very happy - I think these days it's just not something developers are very interesting in working on.

I'm a sell out and just use Gmail... sorry. I can't really see myself changing, though I do wish Google weren't so pedantic about forcing wrapping without any option to change that behaviour. I suspect you wouldn't be happy with me sending html emails, which has been Google's default response to this complaint afik.

Quoted 5 lines

Maybe it's gmail users causing trouble on the Mesa list too.

- Robert

P.S please don't think lesser of me due to my misguided MUA choices.

I use a mix of mutt+gmail web interface, since each has their upsides. Haven't yet seen badly misquoted stuff, I think it mostly seems to work for me. And there's lots of kernel folks who use gmail too afaik. -Daniel

Quoted 55 lines
Quoted 46 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines



     > +
     > +                       u32 specific_ctx_id;
     Can we just get rid of this, now that the vma remains pinned we

can

Quoted 12 lines
Quoted 1 line
Quoted 1 line

simply get the ggtt address at the time of configuring the

OA_CONTROL

Quoted 3 lines
Quoted 3 lines

register ?

I considered that, but would ideally prefer to keep it considering

the

Quoted 1 line
Quoted 1 line

gen8+ patches to come. For gen8+ (with execlists) the context ID

isn't a

Quoted 4 lines
Quoted 1 line

gtt offset.

In terms of symmetry, keeping the vma you pinned and unpinning the same later makes its ownership much clearer. (And I do want the owner of

each

Quoted 16 lines
Quoted 2 lines

pin to be clear, for when we start enabling debug to catch the VMA leaks.)

Keeping our own pointer to the pinned vma could be a clarification.

Considering Matt's comments too, I'm thinking I'll put the pinning and specific_ctx_id initialization together with setting stream->ctx, keeping the state together under the stream. It's going to potentially mean redundantly pinning the ctx for the sake of the ID in the future for streams that don't really need it, but I think it's probably not worth worrying about that.

- Robert

Quoted 2 lines

-Chris

Quoted 7 lines
Quoted 2 lines

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Quoted 4 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw

Re: [Intel-gfx] [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

In reply to Robert Bragg
Quoted 51 lines · Robert Bragg
Quoted 36 lines · Ville Syrjälä
Quoted 1 line · Robert Bragg

On 26 Oct 2016 9:54 a.m., "Chris Wilson" <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines · Robert Bragg
Quoted 4 lines

On Tue, Oct 25, 2016 at 10:35 PM, Matthew Auld
<[1][email protected]> wrote:

     On 25 October 2016 at 00:19, Robert Bragg <[2]

[email protected]>

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
     wrote:



     > diff --git a/drivers/gpu/drm/i915/i915_drv.h
     b/drivers/gpu/drm/i915/i915_drv.h
     > index 3448d05..ea24814 100644
     > --- a/drivers/gpu/drm/i915/i915_drv.h
     > +++ b/drivers/gpu/drm/i915/i915_drv.h
     > @@ -1764,6 +1764,11 @@ struct intel_wm_config {

     >
     >  struct drm_i915_private {
     > @@ -2149,16 +2164,46 @@ struct drm_i915_private {
     >
     >         struct {
     >                 bool initialized;
     > +
     >                 struct mutex lock;
     >                 struct list_head streams;
     >
     > +               spinlock_t hook_lock;
     > +
     >                 struct {
     > -                       u32 metrics_set;
     > +                       struct i915_perf_stream
Quoted 9 lines
Quoted 1 line

*exclusive_stream;

OT:
What kind of MUA are you using that mangles quoted mails like this? I've not seen it on intel-gfx before. mesa-dev seems rife with it, but as I rarely read that in any great detail I've managed to ignore it there. Anyways, it makes it espesially hard to navigate long mails since mutt's 'S' (skip quoted text) no longer works correctly.

Not sure I want to say, and get booted out the door :-)

Quoted 8 lines

I've heard that gmail has an annoying habit of forcibly wrapping plain text emails like this, and a lot of people have complained that there's no way to disable that 'feature' :-/

I used to use Mutt, but I don't think I could really bare to go back to it any more. Last time I was using it I found myself spending too much time patching it to try and make it work how I'd like, but can't say I got much enjoyment from that process.

Isn't gmail just a pile of client side javascript or something? Maybe you'd enjoy patching that one more? ;)

Quoted 11 lines

I've tried most MUA options available, and can't say any of them make me very happy - I think these days it's just not something developers are very interesting in working on.

I'm a sell out and just use Gmail... sorry. I can't really see myself changing, though I do wish Google weren't so pedantic about forcing wrapping without any option to change that behaviour. I suspect you wouldn't be happy with me sending html emails, which has been Google's default response to this complaint afik.

Quoted 5 lines

Maybe it's gmail users causing trouble on the Mesa list too.

- Robert

P.S please don't think lesser of me due to my misguided MUA choices.

I think I'll just reserve the right to ignore any mail with bad quoting.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): CAMou1-2j1FTGSCGh=0nq3BokVNe2U308M4STK-G6iz5-n5Gtfg@mail.gmail.com

#19 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 41 lines · Ville Syrjälä
Quoted 39 lines · Robert Bragg
Quoted 36 lines · Ville Syrjälä
Quoted 1 line · Robert Bragg

On 26 Oct 2016 9:54 a.m., "Chris Wilson" <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines · Robert Bragg
Quoted 4 lines

On Tue, Oct 25, 2016 at 10:35 PM, Matthew Auld
<[1][email protected]> wrote:

     On 25 October 2016 at 00:19, Robert Bragg <[2]

[email protected]>

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
     wrote:



     > diff --git a/drivers/gpu/drm/i915/i915_drv.h
     b/drivers/gpu/drm/i915/i915_drv.h
     > index 3448d05..ea24814 100644
     > --- a/drivers/gpu/drm/i915/i915_drv.h
     > +++ b/drivers/gpu/drm/i915/i915_drv.h
     > @@ -1764,6 +1764,11 @@ struct intel_wm_config {

     >
     >  struct drm_i915_private {
     > @@ -2149,16 +2164,46 @@ struct drm_i915_private {
     >
     >         struct {
     >                 bool initialized;
     > +
     >                 struct mutex lock;
     >                 struct list_head streams;
     >
     > +               spinlock_t hook_lock;
     > +
     >                 struct {
     > -                       u32 metrics_set;
     > +                       struct i915_perf_stream
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

*exclusive_stream;

OT:
What kind of MUA are you using that mangles quoted mails like this?

I've

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

not seen it on intel-gfx before. mesa-dev seems rife with it, but as I rarely read that in any great detail I've managed to ignore it there. Anyways, it makes it espesially hard to navigate long mails since

mutt's

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

'S' (skip quoted text) no longer works correctly.

Not sure I want to say, and get booted out the door :-)

I've heard that gmail has an annoying habit of forcibly wrapping plain

text

Quoted 1 line
Quoted 1 line

emails like this, and a lot of people have complained that there's no

way

Quoted 3 lines
Quoted 3 lines

to disable that 'feature' :-/

I used to use Mutt, but I don't think I could really bare to go back to

it

Quoted 2 lines
Quoted 2 lines

any more. Last time I was using it I found myself spending too much time patching it to try and make it work how I'd like, but can't say I got

much

Quoted 8 lines
Quoted 1 line

enjoyment from that process.

Isn't gmail just a pile of client side javascript or something? Maybe you'd enjoy patching that one more? ;)

Quoted 3 lines

I've tried most MUA options available, and can't say any of them make me very happy - I think these days it's just not something developers are

very

Quoted 8 lines
Quoted 8 lines

interesting in working on.

I'm a sell out and just use Gmail... sorry. I can't really see myself changing, though I do wish Google weren't so pedantic about forcing wrapping without any option to change that behaviour. I suspect you wouldn't be happy with me sending html emails, which has been Google's default response to this complaint afik.

Quoted 7 lines
Quoted 5 lines

Maybe it's gmail users causing trouble on the Mesa list too.

- Robert

P.S please don't think lesser of me due to my misguided MUA choices.

I think I'll just reserve the right to ignore any mail with bad quoting.

Okey, fwiw, at least my patches sent out via git send-email should be fine, so maybe just ignore my replies to feedback - which I promise not to exploit to achieve 'consensus' through silence.

- Robert

--
Sent from Gmail on Android, in a spare moment at a VR for Immersive Theatre meet up.

Quoted 4 lines

--
Ville Syrjälä
Intel OTC

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#20 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

In reply to Robert Bragg
Quoted 71 lines · Robert Bragg
Quoted 23 lines · Matthew Auld
Quoted 17 lines · Robert Bragg
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 3448d05..ea24814 100644
@@ -1764,6 +1764,11 @@ struct intel_wm_config {
 
 
 struct drm_i915_private {
@@ -2149,16 +2164,46 @@ struct drm_i915_private {
 
        struct {
                bool initialized;
+
                struct mutex lock;
                struct list_head streams;
 
Quoted 10 lines

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2176

Quoted 7 lines
drivers/gpu/drm/i915/i915_drv.h +5 -1
+               spinlock_t hook_lock;
+
                struct {
-                       u32 metrics_set;
+                       struct i915_perf_stream *exclusive_stream;
+
+                       u32 specific_ctx_id;

Can we just get rid of this, now that the vma remains pinned we can simply get the ggtt address at the time of configuring the OA_CONTROL register ?

I considered that, but would ideally prefer to keep it considering the gen8+ patches to come. For gen8+ (with execlists) the context ID isn't a gtt offset.

Quoted 10 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
+
+                       struct hrtimer poll_check_timer;
+                       wait_queue_head_t poll_wq;
+                       atomic_t pollin;
+
Quoted 16 lines
Quoted 12 lines
drivers/gpu/drm/i915/i915_drv.h +1 -0
+/* The maximum exponent the hardware accepts is 63 (essentially it

selects one
+ * of the 64bit timestamp bits to trigger reports from) but there's currently
+ * no known use case for sampling as infrequently as once per 47 thousand years.
+ *
+ * Since the timestamps included in OA reports are only 32bits it seems
+ * reasonable to limit the OA exponent where it's still possible to account for
+ * overflow in OA report timestamps.
+ */

drivers/gpu/drm/i915/i915_drv.h

Quoted 3 lines
drivers/gpu/drm/i915/i915_drv.h +3 -0
+#define OA_EXPONENT_MAX 31
+
+#define INVALID_CTX_ID 0xffffffff

We shouldn't need this anymore.

Quoted 3 lines

yeah I removed it and then added it back, just for the sake of explicitly setting the specific_ctx_id to an invalid ID when closing the exclusive stream - though resetting the value isn't strictly necessary.

Can we not make the specific_ctx_id per-stream, the gem context already is, then we don't need to be concerned with resetting it ?
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#21 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 41 lines · Matthew Auld
Quoted 39 lines · Robert Bragg
Quoted 33 lines · Matthew Auld
Quoted 14 lines · Robert Bragg
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 3448d05..ea24814 100644
@@ -1764,6 +1764,11 @@ struct intel_wm_config {
 
 
 struct drm_i915_private {
@@ -2149,16 +2164,46 @@ struct drm_i915_private {
 
        struct {
                bool initialized;
+

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2176

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +5 -1
                struct mutex lock;
                struct list_head streams;
 
+               spinlock_t hook_lock;
+
                struct {
-                       u32 metrics_set;
+                       struct i915_perf_stream *exclusive_stream;
+
+                       u32 specific_ctx_id;

Can we just get rid of this, now that the vma remains pinned we can simply get the ggtt address at the time of configuring the OA_CONTROL register ?

Quoted 1 line
Quoted 1 line

I considered that, but would ideally prefer to keep it considering the

gen8+

Quoted 13 lines
Quoted 13 lines

patches to come. For gen8+ (with execlists) the context ID isn't a gtt offset.

Quoted 10 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
+
+                       struct hrtimer poll_check_timer;
+                       wait_queue_head_t poll_wq;
+                       atomic_t pollin;
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +1 -0
+/* The maximum exponent the hardware accepts is 63 (essentially it

selects one
+ * of the 64bit timestamp bits to trigger reports from) but there's currently
+ * no known use case for sampling as infrequently as once per 47 thousand years.
+ *
+ * Since the timestamps included in OA reports are only 32bits it

seems

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.h

Quoted 7 lines

+ * reasonable to limit the OA exponent where it's still possible to account for
+ * overflow in OA report timestamps.
+ */

drivers/gpu/drm/i915/i915_drv.h +3 -0
+#define OA_EXPONENT_MAX 31
+
+#define INVALID_CTX_ID 0xffffffff

We shouldn't need this anymore.

yeah I removed it and then added it back, just for the sake of

explicitly

Quoted 4 lines
Quoted 2 lines

setting the specific_ctx_id to an invalid ID when closing the exclusive stream - though resetting the value isn't strictly necessary.

Can we not make the specific_ctx_id per-stream, the gem context already is, then we don't need to be concerned with resetting it ?

Hmm, I'm not sure about that, conceptually to me it's global OA unit state.

Currently the driver only supports a single exclusive stream, while Sourab later relaxes that to a per-engine stream and that could be relaxed further with non-oa metric stream types.

With multiple streams we'll still only be able to programmer a single ctx id in oacontol.

Conceptually to me, other stream types could be associated with different contexts (if they don't depend on the OA unit) so to me stream->ctx isn't necessarily OA unit state.

It probably could be played around with, but right now we don't track OA specific state in the stream. For the ID it's just semantics to say it's OA state, and we could consider that it's maybe generally useful to track the ID, even for future non-oa streams. That might mean potentially redundantly pinning state for the sake of tracking the ID for streams that don't end up needing it.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#22 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 98 lines · Robert Bragg
Quoted 8 lines · Matthew Auld
Quoted 6 lines · Robert Bragg
Quoted 2 lines · Matthew Auld

On 25 October 2016 at 00:19, Robert Bragg <[email protected]>

Quoted 33 lines · wrote:
Quoted 33 lines
Quoted 31 lines
Quoted 18 lines
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 3448d05..ea24814 100644
@@ -1764,6 +1764,11 @@ struct intel_wm_config {
 
 
 struct drm_i915_private {
@@ -2149,16 +2164,46 @@ struct drm_i915_private {
 
        struct {
                bool initialized;
+

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 2176

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +5 -1
                struct mutex lock;
                struct list_head streams;
 
+               spinlock_t hook_lock;
+
                struct {
-                       u32 metrics_set;
+                       struct i915_perf_stream *exclusive_stream;
+
+                       u32 specific_ctx_id;

Can we just get rid of this, now that the vma remains pinned we can simply get the ggtt address at the time of configuring the OA_CONTROL register ?

Quoted 1 line
Quoted 1 line

I considered that, but would ideally prefer to keep it considering the

gen8+

Quoted 13 lines
Quoted 13 lines

patches to come. For gen8+ (with execlists) the context ID isn't a gtt offset.

Quoted 10 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_drv.h +5 -0
+
+                       struct hrtimer poll_check_timer;
+                       wait_queue_head_t poll_wq;
+                       atomic_t pollin;
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +1 -0
+/* The maximum exponent the hardware accepts is 63 (essentially it

selects one
+ * of the 64bit timestamp bits to trigger reports from) but there's currently
+ * no known use case for sampling as infrequently as once per 47 thousand years.
+ *
+ * Since the timestamps included in OA reports are only 32bits it

seems

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.h

Quoted 7 lines

+ * reasonable to limit the OA exponent where it's still possible to account for
+ * overflow in OA report timestamps.
+ */

drivers/gpu/drm/i915/i915_drv.h +3 -0
+#define OA_EXPONENT_MAX 31
+
+#define INVALID_CTX_ID 0xffffffff

We shouldn't need this anymore.

yeah I removed it and then added it back, just for the sake of

explicitly

Quoted 4 lines
Quoted 2 lines

setting the specific_ctx_id to an invalid ID when closing the exclusive stream - though resetting the value isn't strictly necessary.

Can we not make the specific_ctx_id per-stream, the gem context already is, then we don't need to be concerned with resetting it ?

Hmm, I'm not sure about that, conceptually to me it's global OA unit state.

Currently the driver only supports a single exclusive stream, while Sourab later relaxes that to a per-engine stream and that could be relaxed further with non-oa metric stream types.

With multiple streams we'll still only be able to programmer a single ctx id in oacontol.

Conceptually to me, other stream types could be associated with different contexts (if they don't depend on the OA unit) so to me stream->ctx isn't necessarily OA unit state.

Quoted 7 lines

It probably could be played around with, but right now we don't track OA specific state in the stream. For the ID it's just semantics to say it's OA state, and we could consider that it's maybe generally useful to track the ID, even for future non-oa streams. That might mean potentially redundantly pinning state for the sake of tracking the ID for streams that don't end up needing it.

I started to try out moving the specific_ctx_id and vma pointer (new) to the stream, and also looked at initializing them together with the stream->ctx reference, but I'm not really happy with how it's looking.

The specific_ctx_id and pinning are only for the render context, since the OA unit is only well integrated with the render engine, which makes me more inclined to consider them OA stream specific, not something we want/need for all streams (considering that Sourab enables multiple streams in his series).

Btw, for reference, my patches for gen8+ can also end up making use of the INVALID_CTX_ID define (when overwriting the undefined ctx_id field in HW reports when the report's ctx-id is flagged as invalid by the OA unit.) so we maybe don't want to worry to much about removing the need for it here.

- Robert

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#23 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

In reply to Robert Bragg

drivers/gpu/drm/i915/i915_perf.c line 445

Quoted 7 lines · Robert Bragg
drivers/gpu/drm/i915/i915_perf.c +7 -0
+static int claim_specific_ctx(struct i915_perf_stream *stream)
+{
+	struct drm_i915_private *dev_priv = stream->dev_priv;
+	struct i915_vma *vma;
+	int ret;
+
+	ret = i915_mutex_lock_interruptible(&dev_priv->drm);

Looking forward to the day these don't need struct_mutex.

drivers/gpu/drm/i915/i915_perf.c line 453

Quoted 8 lines
drivers/gpu/drm/i915/i915_perf.c +8 -0
+	if (ret)
+		return ret;
+
+	/* So that we don't have to worry about updating the context ID
+	 * in OACONTOL on the fly we make sure to pin the context
+	 * upfront for the lifetime of the stream...
+	 */
+	vma = stream->ctx->engine[RCS].state;

There's a caveat here that suggests I had better wrap up this into its own function. (We need to flush dirty cachelines to memory on first binding of the context.)

drivers/gpu/drm/i915/i915_perf.c line 457

Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +4 -0
+	ret = i915_vma_pin(vma, 0, stream->ctx->ggtt_alignment,
+			   PIN_GLOBAL | PIN_HIGH);
+	if (ret)
+		return ret;

Oops.

Quoted 27 lines
drivers/gpu/drm/i915/i915_perf.c +25 -0
+
+	dev_priv->perf.oa.specific_ctx_id = i915_ggtt_offset(vma);
+
+	mutex_unlock(&dev_priv->drm.struct_mutex);
+
+	return 0;
+}
 
 
+static int alloc_oa_buffer(struct drm_i915_private *dev_priv)
+{
+	struct drm_i915_gem_object *bo;
+	struct i915_vma *vma;
+	int ret;
+
+	BUG_ON(dev_priv->perf.oa.oa_buffer.vma);
+
+	ret = i915_mutex_lock_interruptible(&dev_priv->drm);
+	if (ret)
+		return ret;
+
+	BUILD_BUG_ON_NOT_POWER_OF_2(OA_BUFFER_SIZE);
+	BUILD_BUG_ON(OA_BUFFER_SIZE < SZ_128K || OA_BUFFER_SIZE > SZ_16M);
+
+	bo = i915_gem_object_create(&dev_priv->drm, OA_BUFFER_SIZE);
+	if (IS_ERR(bo)) {
+		DRM_ERROR("Failed to allocate OA buffer\n");

drivers/gpu/drm/i915/i915_perf.c line 574

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10 -0
+		ret = PTR_ERR(bo);
+		goto unlock;
+	}
+
+	ret = i915_gem_object_set_cache_level(bo, I915_CACHE_LLC);
+	if (ret)
+		goto err_unref;
+
+	/* PreHSW required 512K alignment, HSW requires 16M */
+	vma = i915_gem_object_ggtt_pin(bo, NULL, 0, SZ_16M, PIN_MAPPABLE);

Does this need mappable aperture space for OA? You aren't accessing it via the aperture, but is the hw limited to it?

Quoted 72 lines
drivers/gpu/drm/i915/i915_perf.c +59 -2
+	if (IS_ERR(vma)) {
+		ret = PTR_ERR(vma);
+		goto err_unref;
+	}
+	dev_priv->perf.oa.oa_buffer.vma = vma;
+
+	dev_priv->perf.oa.oa_buffer.vaddr =
+		i915_gem_object_pin_map(bo, I915_MAP_WB);
+	if (IS_ERR(dev_priv->perf.oa.oa_buffer.vaddr)) {
+		ret = PTR_ERR(dev_priv->perf.oa.oa_buffer.vaddr);
+		goto err_unpin;
+	}
+
+	dev_priv->perf.oa.ops.init_oa_buffer(dev_priv);
+
+	DRM_DEBUG_DRIVER("OA Buffer initialized, gtt offset = 0x%x, vaddr = %p",
+			 i915_ggtt_offset(dev_priv->perf.oa.oa_buffer.vma),
+			 dev_priv->perf.oa.oa_buffer.vaddr);
+
+	goto unlock;
+
+err_unpin:
+	__i915_vma_unpin(vma);
+
+err_unref:
+	i915_gem_object_put(bo);
+
+	dev_priv->perf.oa.oa_buffer.vaddr = NULL;
+	dev_priv->perf.oa.oa_buffer.vma = NULL;
+
+unlock:
+	mutex_unlock(&dev_priv->drm.struct_mutex);
+	return ret;
+}
 
 
+	if (ret >= 0) {
+		/* Maybe make ->pollin per-stream state if we support multiple
+		 * concurrent streams in the future. */
+		atomic_set(&dev_priv->perf.oa.pollin, false);
+	}
+
 	return ret;
 }
 
-static unsigned int i915_perf_poll_locked(struct i915_perf_stream *stream,
+static enum hrtimer_restart oa_poll_check_timer_cb(struct hrtimer *hrtimer)
+{
+	struct drm_i915_private *dev_priv =
+		container_of(hrtimer, typeof(*dev_priv),
+			     perf.oa.poll_check_timer);
+
+	if (!dev_priv->perf.oa.ops.oa_buffer_is_empty(dev_priv)) {
+		atomic_set(&dev_priv->perf.oa.pollin, true);
+		wake_up(&dev_priv->perf.oa.poll_wq);
+	}
+
+	hrtimer_forward_now(hrtimer, ns_to_ktime(POLL_PERIOD));
+
+	return HRTIMER_RESTART;
+}
+
+static unsigned int i915_perf_poll_locked(struct drm_i915_private *dev_priv,
+					  struct i915_perf_stream *stream,
 					  struct file *file,
 					  poll_table *wait)
 {
-	unsigned int streams = 0;
+	unsigned int events = 0;
 
 	stream->ops->poll_wait(stream, file, wait);
 

drivers/gpu/drm/i915/i915_perf.c

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +8 -2
-	if (stream->ops->can_read(stream))
-		streams |= POLLIN;
+	/* Note: we don't explicitly check whether there's something to read
+	 * here since this path may be very hot depending on what else
+	 * userspace is polling, or on the timeout in use. We rely solely on
+	 * the hrtimer/oa_poll_check_timer_cb to notify us when there are
+	 * samples to read.
+	 */
+	if (atomic_read(&dev_priv->perf.oa.pollin))
+		events |= POLLIN;

The atomic_set() and atomic_read() are superfluous, they don't even impose any memory barriers. The required barrier here is from wake_up().

You can just use dev_priv->perf.ao.pollin = true; WRITE_ONCE() / READ_ONCE() if you want to clearly show that it is outside of the lock and barriers are imposed elsewhere.

drivers/gpu/drm/i915/i915_perf.c i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv, · line 1181

Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c +4 -3
@@ -285,18 +1177,18 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,
+	/* we avoid simply assigning stream->sample_flags = props->sample_flags
+	 * to have _stream_init check the combination of sample flags more
+	 * thoroughly, but still this is the expected result at this point.
 	 */
-	DRM_ERROR("Unsupported i915 perf stream configuration\n");
-	ret = -EINVAL;
-	goto err_alloc;
+	BUG_ON(stream->sample_flags != props->sample_flags);
	if (WARN_ON(...)) {
		ret = -ENODEV;
		goto err_alloc;
	}

just to avoid checkpatch complaining.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#24 lore raw

Re: [PATCH v7 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit

Quoted 10 lines · Chris Wilson

drivers/gpu/drm/i915/i915_perf.c line 453

Quoted 5 lines · Robert Bragg
drivers/gpu/drm/i915/i915_perf.c +5 -0
+	/* So that we don't have to worry about updating the context ID
+	 * in OACONTOL on the fly we make sure to pin the context
+	 * upfront for the lifetime of the stream...
+	 */
+	vma = stream->ctx->engine[RCS].state;

There's a caveat here that suggests I had better wrap up this into its own function. (We need to flush dirty cachelines to memory on first binding of the context.)

Not that actually affects hsw.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#25 lore raw

PATCH v7 7/11 drm/i915: advertise available metrics via sysfs

In reply to Robert Bragg

Each metric set is given a sysfs entry like:

/sys/class/drm/card0/metrics/<guid>/id

This allows userspace to enumerate the specific sets that are available for the current system. The 'id' file contains an unsigned integer that can be used to open the associated metric set via DRM_IOCTL_I915_PERF_OPEN. The <guid> is a globally unique ID for a specific OA unit register configuration that can be reliably used by userspace as a key to lookup corresponding counter meta data and normalization equations.

The guid registry is currently maintained as part of gputop along with the XML metric set descriptions and code generation scripts, ref:

https://github.com/rib/gputop

Quoted 4 lines

gputop-data/guids.xml
scripts/update-guids.py
gputop-data/oa-*.xml
scripts/i915-perf-kernelgen.py

 $ make -C gputop-data -f Makefile.xml SYSFS=1 WHITELIST=RenderBasic
---
 drivers/gpu/drm/i915/i915_drv.c    |  5 ++++
 drivers/gpu/drm/i915/i915_drv.h    |  4 +++
 drivers/gpu/drm/i915/i915_oa_hsw.c | 51 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_oa_hsw.h |  4 +++
 drivers/gpu/drm/i915/i915_perf.c   | 52 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 116 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +5 -0
index e99d14e..b887051 100644
@@ -1115,6 +1115,9 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
 	if (drm_dev_register(dev, 0) == 0) {
 		i915_debugfs_register(dev_priv);
 		i915_setup_sysfs(dev_priv);
+
+		/* Depends on sysfs having been initialized */
+		i915_perf_register(dev_priv);
 	} else
 		DRM_ERROR("Failed to register driver for userspace access!\n");
 
@@ -1151,6 +1154,8 @@ static void i915_driver_unregister(struct drm_i915_private *dev_priv)
 	acpi_video_unregister();
 	intel_opregion_unregister(dev_priv);
 
+	i915_perf_unregister(dev_priv);
+
 	i915_teardown_sysfs(dev_priv);
 	i915_debugfs_unregister(dev_priv);
 	drm_dev_unregister(&dev_priv->drm);
drivers/gpu/drm/i915/i915_drv.h +4 -0
index ea24814..a968212 100644
@@ -2165,6 +2165,8 @@ struct drm_i915_private {
 	struct {
 		bool initialized;
 
+		struct kobject *metrics_kobj;
+
 		struct mutex lock;
 		struct list_head streams;
 
@@ -3748,6 +3750,8 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
 /* i915_perf.c */
 extern void i915_perf_init(struct drm_i915_private *dev_priv);
 extern void i915_perf_fini(struct drm_i915_private *dev_priv);
+extern void i915_perf_register(struct drm_i915_private *dev_priv);
+extern void i915_perf_unregister(struct drm_i915_private *dev_priv);
 
 /* i915_suspend.c */
 extern int i915_save_state(struct drm_device *dev);
drivers/gpu/drm/i915/i915_oa_hsw.c +51 -0

60 lines not on this page · raw message

drivers/gpu/drm/i915/i915_oa_hsw.h +4 -0
index b618a1f..429a229 100644
@@ -31,4 +31,8 @@ extern int i915_oa_n_builtin_metric_sets_hsw;
 
 extern int i915_oa_select_metric_set_hsw(struct drm_i915_private *dev_priv);
 
+extern int i915_perf_register_sysfs_hsw(struct drm_i915_private *dev_priv);
+
+extern void i915_perf_unregister_sysfs_hsw(struct drm_i915_private *dev_priv);
+
 #endif
drivers/gpu/drm/i915/i915_perf.c +52 -0

64 lines not on this page · raw message

Signature · 6 lines
2.10.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#26 lore raw

PATCH v7 8/11 drm/i915: Add dev.i915.perf_stream_paranoid sysctl option

In reply to Robert Bragg

Consistent with the kernel.perf_event_paranoid sysctl option that can allow non-root users to access system wide cpu metrics, this can optionally allow non-root users to access system wide OA counter metrics from Gen graphics hardware.

---
 drivers/gpu/drm/i915/i915_drv.h  |  1 +
 drivers/gpu/drm/i915/i915_perf.c | 50 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index a968212..7010c6e 100644
@@ -2166,6 +2166,7 @@ struct drm_i915_private {
 		bool initialized;
 
 		struct kobject *metrics_kobj;
+		struct ctl_table_header *sysctl_header;
 
 		struct mutex lock;
 		struct list_head streams;
drivers/gpu/drm/i915/i915_perf.c +49 -1

80 lines not on this page · raw message

Signature · 6 lines
2.10.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#27 lore raw

PATCH v7 9/11 drm/i915: add oa_event_min_timer_exponent sysctl

In reply to Robert Bragg

The minimal sampling period is now configurable via a dev.i915.oa_min_timer_exponent sysctl parameter.

Following the precedent set by perf, the default is the minimum that won't (on its own) exceed the default kernel.perf_event_max_sample_rate default of 100000 samples/s.

---
 drivers/gpu/drm/i915/i915_perf.c | 41 ++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +29 -12
index ab4c171..e46cd36 100644
@@ -82,6 +82,22 @@ static u32 i915_perf_stream_paranoid = true;
 #define INVALID_CTX_ID 0xffffffff
 
 
+/* for sysctl proc_dointvec_minmax of i915_oa_min_timer_exponent */
+static int oa_exponent_max = OA_EXPONENT_MAX;
+
+/* Theoretically we can program the OA unit to sample every 160ns but don't
+ * allow that by default unless root...
+ *
+ * The period is derived from the exponent as:
+ *
+ *   period = 80ns * 2^(exponent + 1)
+ *
+ * Referring to perf's kernel.perf_event_max_sample_rate for a precedent
+ * (100000 by default); with an OA exponent of 6 we get a period of 10.240
+ * microseconds - just under 100000Hz
+ */
+static u32 i915_oa_min_timer_exponent = 6;
+
 /* XXX: beware if future OA HW adds new report formats that the current
  * code assumes all reports have a power-of-two size and ~(size - 1) can
  * be used as a mask to align the OA tail pointer.
@@ -1317,21 +1333,13 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,
 				return -EINVAL;
 			}
 
-			/* NB: The exponent represents a period as follows:
-			 *
-			 *   80ns * 2^(period_exponent + 1)
-			 *
-			 * Theoretically we can program the OA unit to sample
+			/* Theoretically we can program the OA unit to sample
 			 * every 160ns but don't allow that by default unless
 			 * root.
-			 *
-			 * Referring to perf's
-			 * kernel.perf_event_max_sample_rate for a precedent
-			 * (100000 by default); with an OA exponent of 6 we get
-			 * a period of 10.240 microseconds -just under 100000Hz
 			 */
-			if (value < 6 && !capable(CAP_SYS_ADMIN)) {
-				DRM_ERROR("Sampling period too high without root privileges\n");
+			if (value < i915_oa_min_timer_exponent &&
+			    !capable(CAP_SYS_ADMIN)) {
+				DRM_ERROR("OA timer exponent too low without root privileges\n");
 				return -EACCES;
 			}
 
@@ -1439,6 +1447,15 @@ static struct ctl_table oa_table[] = {
 	 .extra1 = &zero,
 	 .extra2 = &one,
 	 },
+	{
+	 .procname = "oa_min_timer_exponent",
+	 .data = &i915_oa_min_timer_exponent,
+	 .maxlen = sizeof(i915_oa_min_timer_exponent),
+	 .mode = 0644,
+	 .proc_handler = proc_dointvec_minmax,
+	 .extra1 = &zero,
+	 .extra2 = &oa_exponent_max,
+	 },
 	{}
 };
 
Signature · 6 lines
2.10.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#28 lore raw

PATCH v7 10/11 drm/i915: Add more Haswell OA metric sets

In reply to Robert Bragg

This adds 'compute', 'compute extended', 'memory reads', 'memory writes' and 'sampler balance' metric sets for Haswell.

The code is auto generated from an XML description of metric sets, currently maintained in gputop, ref:

https://github.com/rib/gputop

Quoted 2 lines

gputop-data/oa-*.xml
scripts/i915-perf-kernelgen.py

 $ make -C gputop-data -f Makefile.xml
---
 drivers/gpu/drm/i915/i915_oa_hsw.c | 559 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 558 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_oa_hsw.c +558 -1
index 19f272b..cd2a23a 100644
@@ -31,9 +31,14 @@
 
 enum metric_set_id {
 	METRIC_SET_ID_RENDER_BASIC = 1,
+	METRIC_SET_ID_COMPUTE_BASIC,
+	METRIC_SET_ID_COMPUTE_EXTENDED,
+	METRIC_SET_ID_MEMORY_READS,
+	METRIC_SET_ID_MEMORY_WRITES,
+	METRIC_SET_ID_SAMPLER_BALANCE,
 };
 
-int i915_oa_n_builtin_metric_sets_hsw = 1;
+int i915_oa_n_builtin_metric_sets_hsw = 6;
 
 static const struct i915_oa_reg b_counter_config_render_basic[] = {
 	{ _MMIO(0x2724), 0x00800000 },
@@ -112,6 +117,298 @@ get_render_basic_mux_config(struct drm_i915_private *dev_priv,
 	return mux_config_render_basic;
 }
 
+static const struct i915_oa_reg b_counter_config_compute_basic[] = {
+	{ _MMIO(0x2710), 0x00000000 },
+	{ _MMIO(0x2714), 0x00800000 },
+	{ _MMIO(0x2718), 0xaaaaaaaa },
+	{ _MMIO(0x271c), 0xaaaaaaaa },
+	{ _MMIO(0x2720), 0x00000000 },
+	{ _MMIO(0x2724), 0x00800000 },
+	{ _MMIO(0x2728), 0xaaaaaaaa },
+	{ _MMIO(0x272c), 0xaaaaaaaa },
+	{ _MMIO(0x2740), 0x00000000 },
+	{ _MMIO(0x2744), 0x00000000 },
+	{ _MMIO(0x2748), 0x00000000 },
+	{ _MMIO(0x274c), 0x00000000 },
+	{ _MMIO(0x2750), 0x00000000 },
+	{ _MMIO(0x2754), 0x00000000 },
+	{ _MMIO(0x2758), 0x00000000 },
+	{ _MMIO(0x275c), 0x00000000 },
+	{ _MMIO(0x236c), 0x00000000 },
+};
+
+static const struct i915_oa_reg mux_config_compute_basic[] = {
+	{ _MMIO(0x253a4), 0x00000000 },
+	{ _MMIO(0x2681c), 0x01f00800 },
+	{ _MMIO(0x26820), 0x00001000 },
+	{ _MMIO(0x2781c), 0x01f00800 },
+	{ _MMIO(0x26520), 0x00000007 },
+	{ _MMIO(0x265a0), 0x00000007 },
+	{ _MMIO(0x25380), 0x00000010 },
+	{ _MMIO(0x2538c), 0x00300000 },
+	{ _MMIO(0x25384), 0xaa8aaaaa },
+	{ _MMIO(0x25404), 0xffffffff },
+	{ _MMIO(0x26800), 0x00004202 },
+	{ _MMIO(0x26808), 0x00605817 },
+	{ _MMIO(0x2680c), 0x10001005 },
+	{ _MMIO(0x26804), 0x00000000 },
+	{ _MMIO(0x27800), 0x00000102 },
+	{ _MMIO(0x27808), 0x0c0701e0 },
+	{ _MMIO(0x2780c), 0x000200a0 },
+	{ _MMIO(0x27804), 0x00000000 },
+	{ _MMIO(0x26484), 0x44000000 },
+	{ _MMIO(0x26704), 0x44000000 },
+	{ _MMIO(0x26500), 0x00000006 },
+	{ _MMIO(0x26510), 0x00000001 },
+	{ _MMIO(0x26504), 0x88000000 },
+	{ _MMIO(0x26580), 0x00000006 },
+	{ _MMIO(0x26590), 0x00000020 },
+	{ _MMIO(0x26584), 0x00000000 },
+	{ _MMIO(0x26104), 0x55822222 },
+	{ _MMIO(0x26184), 0xaa866666 },
+	{ _MMIO(0x25420), 0x08320c83 },
+	{ _MMIO(0x25424), 0x06820c83 },
+	{ _MMIO(0x2541c), 0x00000000 },
+	{ _MMIO(0x25428), 0x00000c03 },
+};
+
+static const struct i915_oa_reg *
+get_compute_basic_mux_config(struct drm_i915_private *dev_priv,
+			     int *len)
+{
+	*len = ARRAY_SIZE(mux_config_compute_basic);
+	return mux_config_compute_basic;
+}
+
+static const struct i915_oa_reg b_counter_config_compute_extended[] = {
+	{ _MMIO(0x2724), 0xf0800000 },
+	{ _MMIO(0x2720), 0x00000000 },
+	{ _MMIO(0x2714), 0xf0800000 },
+	{ _MMIO(0x2710), 0x00000000 },
+	{ _MMIO(0x2770), 0x0007fe2a },
+	{ _MMIO(0x2774), 0x0000ff00 },
+	{ _MMIO(0x2778), 0x0007fe6a },
+	{ _MMIO(0x277c), 0x0000ff00 },
+	{ _MMIO(0x2780), 0x0007fe92 },
+	{ _MMIO(0x2784), 0x0000ff00 },
+	{ _MMIO(0x2788), 0x0007fea2 },
+	{ _MMIO(0x278c), 0x0000ff00 },
+	{ _MMIO(0x2790), 0x0007fe32 },
+	{ _MMIO(0x2794), 0x0000ff00 },
+	{ _MMIO(0x2798), 0x0007fe9a },
+	{ _MMIO(0x279c), 0x0000ff00 },
+	{ _MMIO(0x27a0), 0x0007ff23 },
+	{ _MMIO(0x27a4), 0x0000ff00 },
+	{ _MMIO(0x27a8), 0x0007fff3 },
+	{ _MMIO(0x27ac), 0x0000fffe },
+};
+
+static const struct i915_oa_reg mux_config_compute_extended[] = {
+	{ _MMIO(0x2681c), 0x3eb00800 },
+	{ _MMIO(0x26820), 0x00900000 },
+	{ _MMIO(0x25384), 0x02aaaaaa },
+	{ _MMIO(0x25404), 0x03ffffff },
+	{ _MMIO(0x26800), 0x00142284 },
+	{ _MMIO(0x26808), 0x0e629062 },
+	{ _MMIO(0x2680c), 0x3f6f55cb },
+	{ _MMIO(0x26810), 0x00000014 },
+	{ _MMIO(0x26804), 0x00000000 },
+	{ _MMIO(0x26104), 0x02aaaaaa },
+	{ _MMIO(0x26184), 0x02aaaaaa },
+	{ _MMIO(0x25420), 0x00000000 },
+	{ _MMIO(0x25424), 0x00000000 },
+	{ _MMIO(0x2541c), 0x00000000 },
+	{ _MMIO(0x25428), 0x00000000 },
+};
+
+static const struct i915_oa_reg *
+get_compute_extended_mux_config(struct drm_i915_private *dev_priv,
+				int *len)
+{
+	*len = ARRAY_SIZE(mux_config_compute_extended);
+	return mux_config_compute_extended;
+}
+
+static const struct i915_oa_reg b_counter_config_memory_reads[] = {
+	{ _MMIO(0x2724), 0xf0800000 },
+	{ _MMIO(0x2720), 0x00000000 },
+	{ _MMIO(0x2714), 0xf0800000 },
+	{ _MMIO(0x2710), 0x00000000 },
+	{ _MMIO(0x274c), 0x76543298 },
+	{ _MMIO(0x2748), 0x98989898 },
+	{ _MMIO(0x2744), 0x000000e4 },
+	{ _MMIO(0x2740), 0x00000000 },
+	{ _MMIO(0x275c), 0x98a98a98 },
+	{ _MMIO(0x2758), 0x88888888 },
+	{ _MMIO(0x2754), 0x000c5500 },
+	{ _MMIO(0x2750), 0x00000000 },
+	{ _MMIO(0x2770), 0x0007f81a },
+	{ _MMIO(0x2774), 0x0000fc00 },
+	{ _MMIO(0x2778), 0x0007f82a },
+	{ _MMIO(0x277c), 0x0000fc00 },
+	{ _MMIO(0x2780), 0x0007f872 },
+	{ _MMIO(0x2784), 0x0000fc00 },
+	{ _MMIO(0x2788), 0x0007f8ba },
+	{ _MMIO(0x278c), 0x0000fc00 },
+	{ _MMIO(0x2790), 0x0007f87a },
+	{ _MMIO(0x2794), 0x0000fc00 },
+	{ _MMIO(0x2798), 0x0007f8ea },
+	{ _MMIO(0x279c), 0x0000fc00 },
+	{ _MMIO(0x27a0), 0x0007f8e2 },
+	{ _MMIO(0x27a4), 0x0000fc00 },
+	{ _MMIO(0x27a8), 0x0007f8f2 },
+	{ _MMIO(0x27ac), 0x0000fc00 },
+};
+
+static const struct i915_oa_reg mux_config_memory_reads[] = {
+	{ _MMIO(0x253a4), 0x34300000 },
+	{ _MMIO(0x25440), 0x2d800000 },
+	{ _MMIO(0x25444), 0x00000008 },
+	{ _MMIO(0x25128), 0x0e600000 },
+	{ _MMIO(0x25380), 0x00000450 },
+	{ _MMIO(0x25390), 0x00052c43 },
+	{ _MMIO(0x25384), 0x00000000 },
+	{ _MMIO(0x25400), 0x00006144 },
+	{ _MMIO(0x25408), 0x0a418820 },
+	{ _MMIO(0x2540c), 0x000820e6 },
+	{ _MMIO(0x25404), 0xff500000 },
+	{ _MMIO(0x25100), 0x000005d6 },
+	{ _MMIO(0x2510c), 0x0ef00000 },
+	{ _MMIO(0x25104), 0x00000000 },
+	{ _MMIO(0x25420), 0x02108421 },
+	{ _MMIO(0x25424), 0x00008421 },
+	{ _MMIO(0x2541c), 0x00000000 },
+	{ _MMIO(0x25428), 0x00000000 },
+};
+
+static const struct i915_oa_reg *
+get_memory_reads_mux_config(struct drm_i915_private *dev_priv,
+			    int *len)
+{
+	*len = ARRAY_SIZE(mux_config_memory_reads);
+	return mux_config_memory_reads;
+}
+
+static const struct i915_oa_reg b_counter_config_memory_writes[] = {
+	{ _MMIO(0x2724), 0xf0800000 },
+	{ _MMIO(0x2720), 0x00000000 },
+	{ _MMIO(0x2714), 0xf0800000 },
+	{ _MMIO(0x2710), 0x00000000 },
+	{ _MMIO(0x274c), 0x76543298 },
+	{ _MMIO(0x2748), 0x98989898 },
+	{ _MMIO(0x2744), 0x000000e4 },
+	{ _MMIO(0x2740), 0x00000000 },
+	{ _MMIO(0x275c), 0xbabababa },
+	{ _MMIO(0x2758), 0x88888888 },
+	{ _MMIO(0x2754), 0x000c5500 },
+	{ _MMIO(0x2750), 0x00000000 },
+	{ _MMIO(0x2770), 0x0007f81a },
+	{ _MMIO(0x2774), 0x0000fc00 },
+	{ _MMIO(0x2778), 0x0007f82a },
+	{ _MMIO(0x277c), 0x0000fc00 },
+	{ _MMIO(0x2780), 0x0007f822 },
+	{ _MMIO(0x2784), 0x0000fc00 },
+	{ _MMIO(0x2788), 0x0007f8ba },
+	{ _MMIO(0x278c), 0x0000fc00 },
+	{ _MMIO(0x2790), 0x0007f87a },
+	{ _MMIO(0x2794), 0x0000fc00 },
+	{ _MMIO(0x2798), 0x0007f8ea },
+	{ _MMIO(0x279c), 0x0000fc00 },
+	{ _MMIO(0x27a0), 0x0007f8e2 },
+	{ _MMIO(0x27a4), 0x0000fc00 },
+	{ _MMIO(0x27a8), 0x0007f8f2 },
+	{ _MMIO(0x27ac), 0x0000fc00 },
+};
+
+static const struct i915_oa_reg mux_config_memory_writes[] = {
+	{ _MMIO(0x253a4), 0x34300000 },
+	{ _MMIO(0x25440), 0x01500000 },
+	{ _MMIO(0x25444), 0x00000120 },
+	{ _MMIO(0x25128), 0x0c200000 },
+	{ _MMIO(0x25380), 0x00000450 },
+	{ _MMIO(0x25390), 0x00052c43 },
+	{ _MMIO(0x25384), 0x00000000 },
+	{ _MMIO(0x25400), 0x00007184 },
+	{ _MMIO(0x25408), 0x0a418820 },
+	{ _MMIO(0x2540c), 0x000820e6 },
+	{ _MMIO(0x25404), 0xff500000 },
+	{ _MMIO(0x25100), 0x000005d6 },
+	{ _MMIO(0x2510c), 0x1e700000 },
+	{ _MMIO(0x25104), 0x00000000 },
+	{ _MMIO(0x25420), 0x02108421 },
+	{ _MMIO(0x25424), 0x00008421 },
+	{ _MMIO(0x2541c), 0x00000000 },
+	{ _MMIO(0x25428), 0x00000000 },
+};
+
+static const struct i915_oa_reg *
+get_memory_writes_mux_config(struct drm_i915_private *dev_priv,
+			     int *len)
+{
+	*len = ARRAY_SIZE(mux_config_memory_writes);
+	return mux_config_memory_writes;
+}
+
+static const struct i915_oa_reg b_counter_config_sampler_balance[] = {
+	{ _MMIO(0x2740), 0x00000000 },
+	{ _MMIO(0x2744), 0x00800000 },
+	{ _MMIO(0x2710), 0x00000000 },
+	{ _MMIO(0x2714), 0x00800000 },
+	{ _MMIO(0x2720), 0x00000000 },
+	{ _MMIO(0x2724), 0x00800000 },
+};
+
+static const struct i915_oa_reg mux_config_sampler_balance[] = {
+	{ _MMIO(0x2eb9c), 0x01906400 },
+	{ _MMIO(0x2fb9c), 0x01906400 },
+	{ _MMIO(0x253a4), 0x00000000 },
+	{ _MMIO(0x26b9c), 0x01906400 },
+	{ _MMIO(0x27b9c), 0x01906400 },
+	{ _MMIO(0x27104), 0x00a00000 },
+	{ _MMIO(0x27184), 0x00a50000 },
+	{ _MMIO(0x2e804), 0x00500000 },
+	{ _MMIO(0x2e984), 0x00500000 },
+	{ _MMIO(0x2eb04), 0x00500000 },
+	{ _MMIO(0x2eb80), 0x00000084 },
+	{ _MMIO(0x2eb8c), 0x14200000 },
+	{ _MMIO(0x2eb84), 0x00000000 },
+	{ _MMIO(0x2f804), 0x00050000 },
+	{ _MMIO(0x2f984), 0x00050000 },
+	{ _MMIO(0x2fb04), 0x00050000 },
+	{ _MMIO(0x2fb80), 0x00000084 },
+	{ _MMIO(0x2fb8c), 0x00050800 },
+	{ _MMIO(0x2fb84), 0x00000000 },
+	{ _MMIO(0x25380), 0x00000010 },
+	{ _MMIO(0x2538c), 0x000000c0 },
+	{ _MMIO(0x25384), 0xaa550000 },
+	{ _MMIO(0x25404), 0xffffc000 },
+	{ _MMIO(0x26804), 0x50000000 },
+	{ _MMIO(0x26984), 0x50000000 },
+	{ _MMIO(0x26b04), 0x50000000 },
+	{ _MMIO(0x26b80), 0x00000084 },
+	{ _MMIO(0x26b90), 0x00050800 },
+	{ _MMIO(0x26b84), 0x00000000 },
+	{ _MMIO(0x27804), 0x05000000 },
+	{ _MMIO(0x27984), 0x05000000 },
+	{ _MMIO(0x27b04), 0x05000000 },
+	{ _MMIO(0x27b80), 0x00000084 },
+	{ _MMIO(0x27b90), 0x00000142 },
+	{ _MMIO(0x27b84), 0x00000000 },
+	{ _MMIO(0x26104), 0xa0000000 },
+	{ _MMIO(0x26184), 0xa5000000 },
+	{ _MMIO(0x25424), 0x00008620 },
+	{ _MMIO(0x2541c), 0x00000000 },
+	{ _MMIO(0x25428), 0x0004a54a },
+};
+
+static const struct i915_oa_reg *
+get_sampler_balance_mux_config(struct drm_i915_private *dev_priv,
+			       int *len)
+{
+	*len = ARRAY_SIZE(mux_config_sampler_balance);
+	return mux_config_sampler_balance;
+}
+
 int i915_oa_select_metric_set_hsw(struct drm_i915_private *dev_priv)
 {
 	dev_priv->perf.oa.mux_regs = NULL;
@@ -140,6 +437,106 @@ int i915_oa_select_metric_set_hsw(struct drm_i915_private *dev_priv)
 			ARRAY_SIZE(b_counter_config_render_basic);
 
 		return 0;
+	case METRIC_SET_ID_COMPUTE_BASIC:
+		dev_priv->perf.oa.mux_regs =
+			get_compute_basic_mux_config(dev_priv,
+						     &dev_priv->perf.oa.mux_regs_len);
+		if (!dev_priv->perf.oa.mux_regs) {
+			DRM_DEBUG_DRIVER("No suitable MUX config for \"COMPUTE_BASIC\" metric set");
+
+			/* EINVAL because *_register_sysfs already checked this
+			 * and so it wouldn't have been advertised so userspace and
+			 * so shouldn't have been requested
+			 */
+			return -EINVAL;
+		}
+
+		dev_priv->perf.oa.b_counter_regs =
+			b_counter_config_compute_basic;
+		dev_priv->perf.oa.b_counter_regs_len =
+			ARRAY_SIZE(b_counter_config_compute_basic);
+
+		return 0;
+	case METRIC_SET_ID_COMPUTE_EXTENDED:
+		dev_priv->perf.oa.mux_regs =
+			get_compute_extended_mux_config(dev_priv,
+							&dev_priv->perf.oa.mux_regs_len);
+		if (!dev_priv->perf.oa.mux_regs) {
+			DRM_DEBUG_DRIVER("No suitable MUX config for \"COMPUTE_EXTENDED\" metric set");
+
+			/* EINVAL because *_register_sysfs already checked this
+			 * and so it wouldn't have been advertised so userspace and
+			 * so shouldn't have been requested
+			 */
+			return -EINVAL;
+		}
+
+		dev_priv->perf.oa.b_counter_regs =
+			b_counter_config_compute_extended;
+		dev_priv->perf.oa.b_counter_regs_len =
+			ARRAY_SIZE(b_counter_config_compute_extended);
+
+		return 0;
+	case METRIC_SET_ID_MEMORY_READS:
+		dev_priv->perf.oa.mux_regs =
+			get_memory_reads_mux_config(dev_priv,
+						    &dev_priv->perf.oa.mux_regs_len);
+		if (!dev_priv->perf.oa.mux_regs) {
+			DRM_DEBUG_DRIVER("No suitable MUX config for \"MEMORY_READS\" metric set");
+
+			/* EINVAL because *_register_sysfs already checked this
+			 * and so it wouldn't have been advertised so userspace and
+			 * so shouldn't have been requested
+			 */
+			return -EINVAL;
+		}
+
+		dev_priv->perf.oa.b_counter_regs =
+			b_counter_config_memory_reads;
+		dev_priv->perf.oa.b_counter_regs_len =
+			ARRAY_SIZE(b_counter_config_memory_reads);
+
+		return 0;
+	case METRIC_SET_ID_MEMORY_WRITES:
+		dev_priv->perf.oa.mux_regs =
+			get_memory_writes_mux_config(dev_priv,
+						     &dev_priv->perf.oa.mux_regs_len);
+		if (!dev_priv->perf.oa.mux_regs) {
+			DRM_DEBUG_DRIVER("No suitable MUX config for \"MEMORY_WRITES\" metric set");
+
+			/* EINVAL because *_register_sysfs already checked this
+			 * and so it wouldn't have been advertised so userspace and
+			 * so shouldn't have been requested
+			 */
+			return -EINVAL;
+		}
+
+		dev_priv->perf.oa.b_counter_regs =
+			b_counter_config_memory_writes;
+		dev_priv->perf.oa.b_counter_regs_len =
+			ARRAY_SIZE(b_counter_config_memory_writes);
+
+		return 0;
+	case METRIC_SET_ID_SAMPLER_BALANCE:
+		dev_priv->perf.oa.mux_regs =
+			get_sampler_balance_mux_config(dev_priv,
+						       &dev_priv->perf.oa.mux_regs_len);
+		if (!dev_priv->perf.oa.mux_regs) {
+			DRM_DEBUG_DRIVER("No suitable MUX config for \"SAMPLER_BALANCE\" metric set");
+
+			/* EINVAL because *_register_sysfs already checked this
+			 * and so it wouldn't have been advertised so userspace and
+			 * so shouldn't have been requested
+			 */
+			return -EINVAL;
+		}
+
+		dev_priv->perf.oa.b_counter_regs =
+			b_counter_config_sampler_balance;
+		dev_priv->perf.oa.b_counter_regs_len =
+			ARRAY_SIZE(b_counter_config_sampler_balance);
+
+		return 0;
 	default:
 		return -ENODEV;
 	}
@@ -167,6 +564,116 @@ static struct attribute_group group_render_basic = {
 	.attrs =  attrs_render_basic,
 };
 
+static ssize_t
+show_compute_basic_id(struct device *kdev, struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", METRIC_SET_ID_COMPUTE_BASIC);
+}
+
+static struct device_attribute dev_attr_compute_basic_id = {
+	.attr = { .name = "id", .mode = S_IRUGO },
+	.show = show_compute_basic_id,
+	.store = NULL,
+};
+
+static struct attribute *attrs_compute_basic[] = {
+	&dev_attr_compute_basic_id.attr,
+	NULL,
+};
+
+static struct attribute_group group_compute_basic = {
+	.name = "39ad14bc-2380-45c4-91eb-fbcb3aa7ae7b",
+	.attrs =  attrs_compute_basic,
+};
+
+static ssize_t
+show_compute_extended_id(struct device *kdev, struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", METRIC_SET_ID_COMPUTE_EXTENDED);
+}
+
+static struct device_attribute dev_attr_compute_extended_id = {
+	.attr = { .name = "id", .mode = S_IRUGO },
+	.show = show_compute_extended_id,
+	.store = NULL,
+};
+
+static struct attribute *attrs_compute_extended[] = {
+	&dev_attr_compute_extended_id.attr,
+	NULL,
+};
+
+static struct attribute_group group_compute_extended = {
+	.name = "3865be28-6982-49fe-9494-e4d1b4795413",
+	.attrs =  attrs_compute_extended,
+};
+
+static ssize_t
+show_memory_reads_id(struct device *kdev, struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", METRIC_SET_ID_MEMORY_READS);
+}
+
+static struct device_attribute dev_attr_memory_reads_id = {
+	.attr = { .name = "id", .mode = S_IRUGO },
+	.show = show_memory_reads_id,
+	.store = NULL,
+};
+
+static struct attribute *attrs_memory_reads[] = {
+	&dev_attr_memory_reads_id.attr,
+	NULL,
+};
+
+static struct attribute_group group_memory_reads = {
+	.name = "bb5ed49b-2497-4095-94f6-26ba294db88a",
+	.attrs =  attrs_memory_reads,
+};
+
+static ssize_t
+show_memory_writes_id(struct device *kdev, struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", METRIC_SET_ID_MEMORY_WRITES);
+}
+
+static struct device_attribute dev_attr_memory_writes_id = {
+	.attr = { .name = "id", .mode = S_IRUGO },
+	.show = show_memory_writes_id,
+	.store = NULL,
+};
+
+static struct attribute *attrs_memory_writes[] = {
+	&dev_attr_memory_writes_id.attr,
+	NULL,
+};
+
+static struct attribute_group group_memory_writes = {
+	.name = "3358d639-9b5f-45ab-976d-9b08cbfc6240",
+	.attrs =  attrs_memory_writes,
+};
+
+static ssize_t
+show_sampler_balance_id(struct device *kdev, struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", METRIC_SET_ID_SAMPLER_BALANCE);
+}
+
+static struct device_attribute dev_attr_sampler_balance_id = {
+	.attr = { .name = "id", .mode = S_IRUGO },
+	.show = show_sampler_balance_id,
+	.store = NULL,
+};
+
+static struct attribute *attrs_sampler_balance[] = {
+	&dev_attr_sampler_balance_id.attr,
+	NULL,
+};
+
+static struct attribute_group group_sampler_balance = {
+	.name = "bc274488-b4b6-40c7-90da-b77d7ad16189",
+	.attrs =  attrs_sampler_balance,
+};
+
 int
 i915_perf_register_sysfs_hsw(struct drm_i915_private *dev_priv)
 {
@@ -178,9 +685,49 @@ i915_perf_register_sysfs_hsw(struct drm_i915_private *dev_priv)
 		if (ret)
 			goto error_render_basic;
 	}
+	if (get_compute_basic_mux_config(dev_priv, &mux_len)) {
+		ret = sysfs_create_group(dev_priv->perf.metrics_kobj, &group_compute_basic);
+		if (ret)
+			goto error_compute_basic;
+	}
+	if (get_compute_extended_mux_config(dev_priv, &mux_len)) {
+		ret = sysfs_create_group(dev_priv->perf.metrics_kobj, &group_compute_extended);
+		if (ret)
+			goto error_compute_extended;
+	}
+	if (get_memory_reads_mux_config(dev_priv, &mux_len)) {
+		ret = sysfs_create_group(dev_priv->perf.metrics_kobj, &group_memory_reads);
+		if (ret)
+			goto error_memory_reads;
+	}
+	if (get_memory_writes_mux_config(dev_priv, &mux_len)) {
+		ret = sysfs_create_group(dev_priv->perf.metrics_kobj, &group_memory_writes);
+		if (ret)
+			goto error_memory_writes;
+	}
+	if (get_sampler_balance_mux_config(dev_priv, &mux_len)) {
+		ret = sysfs_create_group(dev_priv->perf.metrics_kobj, &group_sampler_balance);
+		if (ret)
+			goto error_sampler_balance;
+	}
 
 	return 0;
 
+error_sampler_balance:
+	if (get_sampler_balance_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_memory_writes);
+error_memory_writes:
+	if (get_sampler_balance_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_memory_reads);
+error_memory_reads:
+	if (get_sampler_balance_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_compute_extended);
+error_compute_extended:
+	if (get_sampler_balance_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_compute_basic);
+error_compute_basic:
+	if (get_sampler_balance_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_render_basic);
 error_render_basic:
 	return ret;
 }
@@ -192,4 +739,14 @@ i915_perf_unregister_sysfs_hsw(struct drm_i915_private *dev_priv)
 
 	if (get_render_basic_mux_config(dev_priv, &mux_len))
 		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_render_basic);
+	if (get_compute_basic_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_compute_basic);
+	if (get_compute_extended_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_compute_extended);
+	if (get_memory_reads_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_memory_reads);
+	if (get_memory_writes_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_memory_writes);
+	if (get_sampler_balance_mux_config(dev_priv, &mux_len))
+		sysfs_remove_group(dev_priv->perf.metrics_kobj, &group_sampler_balance);
 }
Signature · 6 lines
2.10.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#29 lore raw

PATCH v7 11/11 drm/i915: Add a kerneldoc summary for i915_perf.c

In reply to Robert Bragg

In particular this tries to capture for posterity some of the early challenges we had with using the core perf infrastructure in case we ever want to revisit adapting perf for device metrics.

---
 drivers/gpu/drm/i915/i915_perf.c | 163 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 163 insertions(+)
drivers/gpu/drm/i915/i915_perf.c +163 -0
index e46cd36..501d20a 100644
@@ -24,6 +24,169 @@
  *   Robert Bragg <[email protected]>
  */
 
+
+/**
+ * DOC: i915 Perf, streaming API for GPU metrics
+ *
+ * Gen graphics supports a large number of performance counters that can help
+ * driver and application developers understand and optimize their use of the
+ * GPU.
+ *
+ * This i915 perf interface enables userspace to configure and open a file
+ * descriptor representing a stream of GPU metrics which can then be read() as
+ * a stream of sample records.
+ *
+ * The interface is particularly suited to exposing buffered metrics that are
+ * captured by DMA from the GPU, unsynchronized with and unrelated to the CPU.
+ *
+ * Streams representing a single context are accessible to applications with a
+ * corresponding drm file descriptor, such that OpenGL can use the interface
+ * without special privileges. Access to system-wide metrics requires root
+ * privileges by default, unless changed via the dev.i915.perf_event_paranoid
+ * sysctl option.
+ *
+ *
+ * The interface was initially inspired by the core Perf infrastructure but
+ * some notable differences are:
+ *
+ * i915 perf file descriptors represent a "stream" instead of an "event"; where
+ * a perf event primarily corresponds to a single 64bit value, while a stream
+ * might sample sets of tightly-coupled counters, depending on the
+ * configuration.  For example the Gen OA unit isn't designed to support
+ * orthogonal configurations of individual counters; it's configured for a set
+ * of related counters. Samples for an i915 perf stream capturing OA metrics
+ * will include a set of counter values packed in a compact HW specific format.
+ * The OA unit supports a number of different packing formats which can be
+ * selected by the user opening the stream. Perf has support for grouping
+ * events, but each event in the group is configured, validated and
+ * authenticated individually with separate system calls.
+ *
+ * i915 perf stream configurations are provided as an array of u64 (key,value)
+ * pairs, instead of a fixed struct with multiple miscellaneous config members,
+ * interleaved with event-type specific members.
+ *
+ * i915 perf doesn't support exposing metrics via an mmap'd circular buffer.
+ * The supported metrics are being written to memory by the GPU unsynchronized
+ * with the CPU, using HW specific packing formats for counter sets. Sometimes
+ * the constraints on HW configuration require reports to be filtered before it
+ * would be acceptable to expose them to unprivileged applications - to hide
+ * the metrics of other processes/contexts. For these use cases a read() based
+ * interface is a good fit, and provides an opportunity to filter data as it
+ * gets copied from the GPU mapped buffers to userspace buffers.
+ *
+ *
+ * Some notes regarding Linux Perf:
+ * --------------------------------
+ *
+ * The first prototype of this driver was based on the core perf
+ * infrastructure, and while we did make that mostly work, with some changes to
+ * perf, we found we were breaking or working around too many assumptions baked
+ * into perf's currently cpu centric design.
+ *
+ * In the end we didn't see a clear benefit to making perf's implementation and
+ * interface more complex by changing design assumptions while we knew we still
+ * wouldn't be able to use any existing perf based userspace tools.
+ *
+ * Also considering the Gen specific nature of the Observability hardware and
+ * how userspace will sometimes need to combine i915 perf OA metrics with
+ * side-band OA data captured via MI_REPORT_PERF_COUNT commands; we're
+ * expecting the interface to be used by a platform specific userspace such as
+ * OpenGL or tools. This is to say; we aren't inherently missing out on having
+ * a standard vendor/architecture agnostic interface by not using perf.
+ *
+ *
+ * For posterity, in case we might re-visit trying to adapt core perf to be
+ * better suited to exposing i915 metrics these were the main pain points we
+ * hit:
+ *
+ * - The perf based OA PMU driver broke some significant design assumptions:
+ *
+ *   Existing perf pmus are used for profiling work on a cpu and we were
+ *   introducing the idea of _IS_DEVICE pmus with different security
+ *   implications, the need to fake cpu-related data (such as user/kernel
+ *   registers) to fit with perf's current design, and adding _DEVICE records
+ *   as a way to forward device-specific status records.
+ *
+ *   The OA unit writes reports of counters into a circular buffer, without
+ *   involvement from the CPU, making our PMU driver the first of a kind.
+ *
+ *   Given the way we were periodically forward data from the GPU-mapped, OA
+ *   buffer to perf's buffer, those bursts of sample writes looked to perf like
+ *   we were sampling too fast and so we had to subvert its throttling checks.
+ *
+ *   Perf supports groups of counters and allows those to be read via
+ *   transactions internally but transactions currently seem designed to be
+ *   explicitly initiated from the cpu (say in response to a userspace read())
+ *   and while we could pull a report out of the OA buffer we can't
+ *   trigger a report from the cpu on demand.
+ *
+ *   Related to being report based; the OA counters are configured in HW as a
+ *   set while perf generally expects counter configurations to be orthogonal.
+ *   Although counters can be associated with a group leader as they are
+ *   opened, there's no clear precedent for being able to provide group-wide
+ *   configuration attributes (for example we want to let userspace choose the
+ *   OA unit report format used to capture all counters in a set, or specify a
+ *   GPU context to filter metrics on). We avoided using perf's grouping
+ *   feature and forwarded OA reports to userspace via perf's 'raw' sample
+ *   field. This suited our userspace well considering how coupled the counters
+ *   are when dealing with normalizing. It would be inconvenient to split
+ *   counters up into separate events, only to require userspace to recombine
+ *   them. For Mesa it's also convenient to be forwarded raw, periodic reports
+ *   for combining with the side-band raw reports it captures using
+ *   MI_REPORT_PERF_COUNT commands.
+ *
+ *   _ As a side note on perf's grouping feature; there was also some concern
+ *     that using PERF_FORMAT_GROUP as a way to pack together counter values
+ *     would quite drastically inflate our sample sizes, which would likely
+ *     lower the effective sampling resolutions we could use when the available
+ *     memory bandwidth is limited.
+ *
+ *     With the OA unit's report formats, counters are packed together as 32
+ *     or 40bit values, with the largest report size being 256 bytes.
+ *
+ *     PERF_FORMAT_GROUP values are 64bit, but there doesn't appear to be a
+ *     documented ordering to the values, implying PERF_FORMAT_ID must also be
+ *     used to add a 64bit ID before each value; giving 16 bytes per counter.
+ *
+ *   Related to counter orthogonality; we can't time share the OA unit, while
+ *   event scheduling is a central design idea within perf for allowing
+ *   userspace to open + enable more events than can be configured in HW at any
+ *   one time.  The OA unit is not designed to allow re-configuration while in
+ *   use. We can't reconfigure the OA unit without losing internal OA unit
+ *   state which we can't access explicitly to save and restore. Reconfiguring
+ *   the OA unit is also relatively slow, involving ~100 register writes. From
+ *   userspace Mesa also depends on a stable OA configuration when emitting
+ *   MI_REPORT_PERF_COUNT commands and importantly the OA unit can't be
+ *   disabled while there are outstanding MI_RPC commands lest we hang the
+ *   command streamer.
+ *
+ *   The contents of sample records aren't extensible by device drivers (i.e.
+ *   the sample_type bits). As an example; Sourab Gupta had been looking to
+ *   attach GPU timestamps to our OA samples. We were shoehorning OA reports
+ *   into sample records by using the 'raw' field, but it's tricky to pack more
+ *   than one thing into this field because events/core.c currently only lets a
+ *   pmu give a single raw data pointer plus len which will be copied into the
+ *   ring buffer. To include more than the OA report we'd have to copy the
+ *   report into an intermediate larger buffer. I'd been considering allowing a
+ *   vector of data+len values to be specified for copying the raw data, but
+ *   it felt like a kludge to being using the raw field for this purpose.
+ *
+ * - It felt like our perf based PMU was making some technical compromises
+ *   just for the sake of using perf:
+ *
+ *   perf_event_open() requires events to either relate to a pid or a specific
+ *   cpu core, while our device pmu related to neither.  Events opened with a
+ *   pid will be automatically enabled/disabled according to the scheduling of
+ *   that process - so not appropriate for us. When an event is related to a
+ *   cpu id, perf ensures pmu methods will be invoked via an inter process
+ *   interrupt on that core. To avoid invasive changes our userspace opened OA
+ *   perf events for a specific cpu. This was workable but it meant the
+ *   majority of the OA driver ran in atomic context, including all OA report
+ *   forwarding, which wasn't really necessary in our case and seems to make
+ *   our locking requirements somewhat complex as we handled the interaction
+ *   with the rest of the i915 driver.
+ */
+
 #include <linux/anon_inodes.h>
 #include <linux/sizes.h>
 
Signature · 6 lines
2.10.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#30 lore raw

✗ Fi.CI.BAT: failure for Enable i915 perf stream for Haswell OA unit

In reply to Robert Bragg
== Series Details ==

== Series Details ==

Series: Enable i915 perf stream for Haswell OA unit
URL : https://patchwork.freedesktop.org/series/14308/
State : failure

== Summary ==

Series 14308v1 Enable i915 perf stream for Haswell OA unit
https://patchwork.freedesktop.org/api/1.0/series/14308/revisions/1/mbox/

Test gem_ctx_switch:

        Subgroup basic-default:
                timeout    -> PASS       (fi-bsw-n3050)
        Subgroup basic-default-heavy:
                incomplete -> PASS       (fi-bsw-n3050)
Test gem_exec_parse:
        Subgroup basic-rejected:
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-hsw-4770)
fi-bdw-5557u     total:246  pass:231  dwarn:0   dfail:0   fail:0   skip:15 
fi-bsw-n3050     total:246  pass:204  dwarn:0   dfail:0   fail:0   skip:42 
fi-bxt-t5700     total:246  pass:216  dwarn:0   dfail:0   fail:0   skip:30 
fi-byt-j1900     total:246  pass:214  dwarn:0   dfail:0   fail:1   skip:31 
fi-byt-n2820     total:246  pass:210  dwarn:0   dfail:0   fail:1   skip:35 
fi-hsw-4770      total:246  pass:223  dwarn:0   dfail:0   fail:1   skip:22 
fi-hsw-4770r     total:246  pass:222  dwarn:0   dfail:0   fail:1   skip:23 
fi-ilk-650       total:246  pass:185  dwarn:0   dfail:0   fail:0   skip:61 
fi-ivb-3520m     total:246  pass:219  dwarn:0   dfail:0   fail:1   skip:26 
fi-ivb-3770      total:246  pass:219  dwarn:0   dfail:0   fail:1   skip:26 
fi-kbl-7200u     total:246  pass:222  dwarn:0   dfail:0   fail:0   skip:24 
fi-skl-6260u     total:246  pass:232  dwarn:0   dfail:0   fail:0   skip:14 
fi-skl-6700hq    total:246  pass:223  dwarn:0   dfail:0   fail:0   skip:23 
fi-skl-6700k     total:246  pass:222  dwarn:1   dfail:0   fail:0   skip:23 
fi-skl-6770hq    total:246  pass:232  dwarn:0   dfail:0   fail:0   skip:14 
fi-snb-2520m     total:246  pass:209  dwarn:0   dfail:0   fail:0   skip:37 
fi-snb-2600      total:246  pass:208  dwarn:0   dfail:0   fail:0   skip:38 

418b28c2fc2812aff227b273f400bf611c4e7dff drm-intel-nightly: 2016y-10m-27d-08h-38m-08s UTC integration manifest 1e863d9 drm/i915: Enable i915 perf stream for Haswell OA unit
1aee0c3 drm/i915: Add 'render basic' Haswell OA unit config
3188df2 drm/i915: don't whitelist oacontrol in cmd parser
0c473d5 drm/i915: return EACCES for check_cmd() failures
ef2ec4d drm/i915: rename OACONTROL GEN7_OACONTROL
a03fa81 drm/i915: Add i915 perf infrastructure

Full results at https://intel-gfx-ci.01.org/CI/Patchwork_2838/

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_2838/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx