Skip to contentSkip to conversation

drm/panfrost: Expose HW counters to userspace

PATCH Superseded Boris Brezillon 6 participants 26 messages Apr 4, 2019 – May 13, 2019

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Boris Brezillon

author maintainer
#0 lore raw

cover drm/panfrost: Expose HW counters to userspace

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Let me know if that's an issue and if you think we should approach things differently.

Regards,

Boris

Boris Brezillon (3):
drm/panfrost: Move gpu_{write,read}() macros to panfrost_regs.h drm/panfrost: Expose HW counters to userspace panfrost/drm: Define T860 perf counters

 drivers/gpu/drm/panfrost/Makefile           |   3 +-
 drivers/gpu/drm/panfrost/panfrost_device.c  |   8 +
 drivers/gpu/drm/panfrost/panfrost_device.h  |  11 +
 drivers/gpu/drm/panfrost/panfrost_drv.c     |  22 +-
 drivers/gpu/drm/panfrost/panfrost_gpu.c     |  46 +-
 drivers/gpu/drm/panfrost/panfrost_job.c     |  24 +
 drivers/gpu/drm/panfrost/panfrost_job.h     |   4 +
 drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 954 ++++++++++++++++++++
 drivers/gpu/drm/panfrost/panfrost_perfcnt.h |  59 ++
 drivers/gpu/drm/panfrost/panfrost_regs.h    |  22 +
 include/uapi/drm/panfrost_drm.h             | 122 +++
 11 files changed, 1268 insertions(+), 7 deletions(-)
 create mode 100644 drivers/gpu/drm/panfrost/panfrost_perfcnt.c
 create mode 100644 drivers/gpu/drm/panfrost/panfrost_perfcnt.h
Signature · 6 lines
2.20.1

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

PATCH 1/3 drm/panfrost: Move gpu_{write, read}() macros to panfrost_regs.h

So they can be used from other files.

---
 drivers/gpu/drm/panfrost/panfrost_gpu.c  | 3 ---
 drivers/gpu/drm/panfrost/panfrost_regs.h | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/panfrost/panfrost_gpu.c +0 -3
index 867e2ba3a761..d46d36170e18 100644
@@ -15,9 +15,6 @@
 #include "panfrost_gpu.h"
 #include "panfrost_regs.h"
 
-#define gpu_write(dev, reg, data) writel(data, dev->iomem + reg)
-#define gpu_read(dev, reg) readl(dev->iomem + reg)
-
 static irqreturn_t panfrost_gpu_irq_handler(int irq, void *data)
 {
 	struct panfrost_device *pfdev = data;
drivers/gpu/drm/panfrost/panfrost_regs.h +3 -0
index 578c5fc2188b..42d08860fd76 100644
@@ -295,4 +295,7 @@
 #define AS_FAULTSTATUS_ACCESS_TYPE_READ		(0x2 << 8)
 #define AS_FAULTSTATUS_ACCESS_TYPE_WRITE	(0x3 << 8)
 
+#define gpu_write(dev, reg, data) writel(data, dev->iomem + reg)
+#define gpu_read(dev, reg) readl(dev->iomem + reg)
+
 #endif
Signature · 6 lines
2.20.1

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

PATCH 2/3 drm/panfrost: Expose HW counters to userspace

In reply to Boris Brezillon

Add the necessary infrastructure to expose GPU counters to userspace. This takes the form of 4 new ioctls to:

- query the available counters
- create/destroy a performance monitor
- retrieve its values

The drm_panfrost_submit struct is extended to pass a list of perfmons to attach to a job, which means perfmons will only track changes caused by the jobs they are attached too.

---
 drivers/gpu/drm/panfrost/Makefile           |   3 +-
 drivers/gpu/drm/panfrost/panfrost_device.c  |   8 +
 drivers/gpu/drm/panfrost/panfrost_device.h  |  11 +
 drivers/gpu/drm/panfrost/panfrost_drv.c     |  22 +-
 drivers/gpu/drm/panfrost/panfrost_gpu.c     |  43 +-
 drivers/gpu/drm/panfrost/panfrost_job.c     |  24 +
 drivers/gpu/drm/panfrost/panfrost_job.h     |   4 +
 drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 954 ++++++++++++++++++++
 drivers/gpu/drm/panfrost/panfrost_perfcnt.h |  54 ++
 drivers/gpu/drm/panfrost/panfrost_regs.h    |  19 +
 include/uapi/drm/panfrost_drm.h             | 122 +++
 11 files changed, 1260 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/panfrost/panfrost_perfcnt.c
 create mode 100644 drivers/gpu/drm/panfrost/panfrost_perfcnt.h
drivers/gpu/drm/panfrost/Makefile +2 -1
index d07e0971b687..31cfb9d25682 100644
@@ -6,6 +6,7 @@ panfrost-y := \
 	panfrost_gem.o \
 	panfrost_gpu.o \
 	panfrost_job.o \
-	panfrost_mmu.o
+	panfrost_mmu.o \
+	panfrost_perfcnt.o
 
 obj-$(CONFIG_DRM_PANFROST) += panfrost.o
drivers/gpu/drm/panfrost/panfrost_device.c +8 -0
index 148b5caa2322..f6a87bfa486b 100644
@@ -13,6 +13,7 @@
 #include "panfrost_gpu.h"
 #include "panfrost_job.h"
 #include "panfrost_mmu.h"
+#include "panfrost_perfcnt.h"
 
 static int panfrost_reset_init(struct panfrost_device *pfdev)
 {
@@ -147,7 +148,13 @@ int panfrost_device_init(struct panfrost_device *pfdev)
 	pm_runtime_mark_last_busy(pfdev->dev);
 	pm_runtime_put_autosuspend(pfdev->dev);
 
+	err = panfrost_perfcnt_init(pfdev);
+	if (err)
+		goto err_out5;
+
 	return 0;
+err_out5:
+	panfrost_job_fini(pfdev);
 err_out4:
 	panfrost_mmu_fini(pfdev);
 err_out3:
@@ -163,6 +170,7 @@ int panfrost_device_init(struct panfrost_device *pfdev)
 
 void panfrost_device_fini(struct panfrost_device *pfdev)
 {
+	panfrost_perfcnt_fini(pfdev);
 	panfrost_job_fini(pfdev);
 	panfrost_mmu_fini(pfdev);
 	panfrost_gpu_fini(pfdev);
drivers/gpu/drm/panfrost/panfrost_device.h +11 -0
index a821b50a14c3..f7c4e9e55f1b 100644
@@ -9,11 +9,13 @@
 #include <drm/drm_device.h>
 #include <drm/drm_mm.h>
 #include <drm/gpu_scheduler.h>
+#include <drm/panfrost_drm.h>
 
 struct panfrost_device;
 struct panfrost_mmu;
 struct panfrost_job_slot;
 struct panfrost_job;
+struct panfrost_perfcnt;
 
 #define NUM_JOB_SLOTS 3
 
@@ -45,6 +47,8 @@ struct panfrost_features {
 
 	unsigned long hw_features[64 / BITS_PER_LONG];
 	unsigned long hw_issues[64 / BITS_PER_LONG];
+
+	struct drm_panfrost_block_perfcounters perfcnt_layout[PANFROST_NUM_BLOCKS];
 };
 
 struct panfrost_device {
@@ -70,6 +74,8 @@ struct panfrost_device {
 	struct panfrost_job *jobs[NUM_JOB_SLOTS];
 	struct list_head scheduled_jobs;
 
+	struct panfrost_perfcnt *perfcnt;
+
 	struct mutex sched_lock;
 };
 
@@ -77,6 +83,11 @@ struct panfrost_file_priv {
 	struct panfrost_device *pfdev;
 
 	struct drm_sched_entity sched_entity[NUM_JOB_SLOTS];
+
+	struct {
+		struct idr idr;
+		struct mutex lock;
+	} perfmon;
 };
 
 static inline struct panfrost_device *to_panfrost_device(struct drm_device *ddev)
drivers/gpu/drm/panfrost/panfrost_drv.c +21 -1
index 8cffb70a3548..e5375b31627f 100644
@@ -19,6 +19,7 @@
 #include "panfrost_mmu.h"
 #include "panfrost_job.h"
 #include "panfrost_gpu.h"
+#include "panfrost_perfcnt.h"
 
 static int panfrost_ioctl_get_param(struct drm_device *ddev, void *data, struct drm_file *file)
 {
@@ -219,6 +220,10 @@ static int panfrost_ioctl_submit(struct drm_device *dev, void *data,
 	if (ret)
 		goto fail;
 
+	ret = panfrost_perfcnt_create_job_ctx(job, file, args);
+	if (ret)
+		goto fail;
+
 	ret = panfrost_job_push(job);
 	if (ret)
 		goto fail;
@@ -313,6 +318,7 @@ panfrost_open(struct drm_device *dev, struct drm_file *file)
 {
 	struct panfrost_device *pfdev = dev->dev_private;
 	struct panfrost_file_priv *panfrost_priv;
+	int ret;
 
 	panfrost_priv = kzalloc(sizeof(*panfrost_priv), GFP_KERNEL);
 	if (!panfrost_priv)
@@ -321,7 +327,16 @@ panfrost_open(struct drm_device *dev, struct drm_file *file)
 	panfrost_priv->pfdev = pfdev;
 	file->driver_priv = panfrost_priv;
 
-	return panfrost_job_open(panfrost_priv);
+	ret = panfrost_job_open(panfrost_priv);
+	if (ret)
+		goto err_free_priv;
+
+	panfrost_perfcnt_open(panfrost_priv);
+	return 0;
+
+err_free_priv:
+	kfree(panfrost_priv);
+	return ret;
 }
 
 static void
@@ -329,6 +344,7 @@ panfrost_postclose(struct drm_device *dev, struct drm_file *file)
 {
 	struct panfrost_file_priv *panfrost_priv = file->driver_priv;
 
+	panfrost_perfcnt_close(panfrost_priv);
 	panfrost_job_close(panfrost_priv);
 
 	kfree(panfrost_priv);
@@ -348,6 +364,10 @@ static const struct drm_ioctl_desc panfrost_drm_driver_ioctls[] = {
 	PANFROST_IOCTL(MMAP_BO,		mmap_bo,	DRM_RENDER_ALLOW),
 	PANFROST_IOCTL(GET_PARAM,	get_param,	DRM_RENDER_ALLOW),
 	PANFROST_IOCTL(GET_BO_OFFSET,	get_bo_offset,	DRM_RENDER_ALLOW),
+	PANFROST_IOCTL(GET_PERFCNT_LAYOUT, get_perfcnt_layout, DRM_RENDER_ALLOW),
+	PANFROST_IOCTL(CREATE_PERFMON,	create_perfmon,	DRM_RENDER_ALLOW),
+	PANFROST_IOCTL(DESTROY_PERFMON,	destroy_perfmon, DRM_RENDER_ALLOW),
+	PANFROST_IOCTL(GET_PERFMON_VALUES, get_perfmon_values, DRM_RENDER_ALLOW),
 };
 
 DEFINE_DRM_GEM_SHMEM_FOPS(panfrost_drm_driver_fops);
drivers/gpu/drm/panfrost/panfrost_gpu.c +41 -2

89 lines not on this page · raw message

drivers/gpu/drm/panfrost/panfrost_job.c +24 -0
index 8d570c3f15d0..c2be61a9ebff 100644
@@ -15,6 +15,7 @@
 #include "panfrost_features.h"
 #include "panfrost_issues.h"
 #include "panfrost_gem.h"
+#include "panfrost_perfcnt.h"
 #include "panfrost_regs.h"
 #include "panfrost_gpu.h"
 #include "panfrost_mmu.h"
@@ -153,6 +154,7 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js)
 		goto end;
 
 	spin_lock_irqsave(&pfdev->hwaccess_lock, flags);
+	panfrost_perfcnt_run_job(job);
 
 	job_write(pfdev, JS_HEAD_NEXT_LO(js), jc_head & 0xFFFFFFFF);
 	job_write(pfdev, JS_HEAD_NEXT_HI(js), jc_head >> 32);
@@ -233,6 +235,12 @@ int panfrost_job_push(struct panfrost_job *job)
 		goto unlock;
 	}
 
+	ret = panfrost_perfcnt_push_job(job);
+	if (ret) {
+		mutex_unlock(&pfdev->sched_lock);
+		goto unlock;
+	}
+
 	job->render_done_fence = dma_fence_get(&job->base.s_fence->finished);
 
 	kref_get(&job->refcount); /* put by scheduler job completion */
@@ -272,6 +280,9 @@ static void panfrost_job_cleanup(struct kref *ref)
 
 	for (i = 0; i < job->bo_count; i++)
 		drm_gem_object_put_unlocked(job->bos[i]);
+
+	panfrost_perfcnt_clean_job_ctx(job);
+
 	kvfree(job->bos);
 
 	kfree(job);
@@ -316,6 +327,13 @@ static struct dma_fence *panfrost_job_dependency(struct drm_sched_job *sched_job
 		}
 	}
 
+	/* Return the perfmon wait fence if any. */
+	if (job->perfcnt_fence) {
+		fence = job->perfcnt_fence;
+		job->perfcnt_fence = NULL;
+		return fence;
+	}
+
 	return NULL;
 }
 
@@ -399,6 +417,11 @@ static void panfrost_job_timedout(struct drm_sched_job *sched_job)
 	/* restart scheduler after GPU is usable again */
 	for (i = 0; i < NUM_JOB_SLOTS; i++)
 		drm_sched_start(&pfdev->js->queue[i].sched, true);
+
+	/* For now, just say we're done. No reset and retry. */
+//	job_write(pfdev, JS_COMMAND(js), JS_COMMAND_HARD_STOP);
+	dma_fence_signal(job->done_fence);
+	panfrost_perfcnt_finish_job(job, true);
 }
 
 static const struct drm_sched_backend_ops panfrost_sched_ops = {
@@ -442,6 +465,7 @@ static irqreturn_t panfrost_job_irq_handler(int irq, void *data)
 
 		if (status & JOB_INT_MASK_DONE(j)) {
 			dma_fence_signal(pfdev->jobs[j]->done_fence);
+			panfrost_perfcnt_finish_job(pfdev->jobs[j], false);
 		}
 
 		status &= ~mask;
drivers/gpu/drm/panfrost/panfrost_job.h +4 -0
index 62454128a792..18646cc5eebb 100644
@@ -37,6 +37,10 @@ struct panfrost_job {
 
 	/* Fence to be signaled by drm-sched once its done with the job */
 	struct dma_fence *render_done_fence;
+
+	/* Perfcnt context */
+	struct panfrost_perfcnt_job_ctx *perfcnt_ctx;
+	struct dma_fence *perfcnt_fence;
 };
 
 int panfrost_job_init(struct panfrost_device *pfdev);
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +954 -0

954 lines not on this page · raw message

drivers/gpu/drm/panfrost/panfrost_perfcnt.h new file +54 -0

54 lines not on this page · raw message

drivers/gpu/drm/panfrost/panfrost_regs.h +19 -0
index 42d08860fd76..ea38ac60581c 100644
@@ -44,12 +44,31 @@
 	 GPU_IRQ_MULTIPLE_FAULT)
 #define GPU_CMD				0x30
 #define   GPU_CMD_SOFT_RESET		0x01
+#define   GPU_CMD_PERFCNT_CLEAR		0x03
+#define   GPU_CMD_PERFCNT_SAMPLE	0x04
+#define   GPU_CMD_CLEAN_CACHES		0x07
+#define   GPU_CMD_CLEAN_INV_CACHES	0x08
 #define GPU_STATUS			0x34
+#define   GPU_STATUS_PRFCNT_ACTIVE	BIT(2)
 #define GPU_LATEST_FLUSH_ID		0x38
 #define GPU_FAULT_STATUS		0x3C
 #define GPU_FAULT_ADDRESS_LO		0x40
 #define GPU_FAULT_ADDRESS_HI		0x44
 
+#define GPU_PERFCNT_BASE_LO		0x60
+#define GPU_PERFCNT_BASE_HI		0x64
+#define GPU_PERFCNT_CFG			0x68
+#define   GPU_PERFCNT_CFG_MODE(x)	(x)
+#define   GPU_PERFCNT_CFG_MODE_OFF	0
+#define   GPU_PERFCNT_CFG_MODE_MANUAL	1
+#define   GPU_PERFCNT_CFG_MODE_TILE	2
+#define   GPU_PERFCNT_CFG_AS(x)		((x) << 4)
+#define   GPU_PERFCNT_CFG_SETSEL(x)	((x) << 8)
+#define GPU_PRFCNT_JM_EN		0x6c
+#define GPU_PRFCNT_SHADER_EN		0x70
+#define GPU_PRFCNT_TILER_EN		0x74
+#define GPU_PRFCNT_MMU_L2_EN		0x7c
+
 #define GPU_THREAD_MAX_THREADS		0x0A0	/* (RO) Maximum number of threads per core */
 #define GPU_THREAD_MAX_WORKGROUP_SIZE	0x0A4	/* (RO) Maximum workgroup size */
 #define GPU_THREAD_MAX_BARRIER_SIZE	0x0A8	/* (RO) Maximum threads waiting at a barrier */
include/uapi/drm/panfrost_drm.h +122 -0

146 lines not on this page · raw message

Signature · 6 lines
2.20.1

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

drivers/gpu/drm/panfrost/panfrost_gpu.c static void panfrost_gpu_init_features(struct panfrost_device *pfdev) · line 304

Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_gpu.c +6 -0
+	/*
+	 * In v4 HW we have one tiler per core group, with the number
+	 * of core groups being equal to the number of L2 caches. Other
+	 * HW versions just have one tiler and the number of L2 caches
+	 * can be extracted from the mem_features field.
+	 */

Normalizing layout in kernel sounds like a good idea to me, nice one :) (kbase does not and userspace is messy as a result)

Quoted 12 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +12 -0
+/*
+ * Returns true if the 2 jobs have exactly the same perfcnt context, false
+ * otherwise.
+ */
+static bool panfrost_perfcnt_job_ctx_cmp(struct panfrost_perfcnt_job_ctx *a,
+					 struct panfrost_perfcnt_job_ctx *b)
+{
+	unsigned int i, j;
+
+	if (a->perfmon_count != b->perfmon_count)
+		return false;
+

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 318

Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +10 -0
+	for (i = 0; i < a->perfmon_count; i++) {
+		for (j = 0; j < b->perfmon_count; j++) {
+			if (a->perfmons[i] == b->perfmons[j])
+				break;
+		}
+
+		if (j == b->perfmon_count)
+			return false;
+	}
+

Would using memcmp() be cleaner here?

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 372

Quoted 1 line
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +1 -0
+	if (panfrost_model_cmp(pfdev, 0x1000) >= 0)

What does 0x1000 refer to here? I'm assuming maybe Bifrost, but it's not obvious... probably better to have a #define somewhere and use that (or an enum equivalently).

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 393

Quoted 4 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +4 -0
+	/*
+	 * Due to PRLAM-8186 we need to disable the Tiler before we enable HW
+	 * counters.
+	 */

What on earth is PRLAM-8186? :)

Actually, wait, I can answer that -- old kbase versions had an errata list:

        /* Write of PRFCNT_CONFIG_MODE_MANUAL to PRFCNT_CONFIG causes a instrumentation dump if
           PRFCNT_TILER_EN is enabled */
        BASE_HW_ISSUE_8186,

So that's why. If people want, I'm considering moving these errata descriptions back into the kernel where possible, since otherwise code like this is opaque.

Quoted 7 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +7 -0
+		unsigned int nl2c, ncores;
+
+		/*
+		 * TODO: define a macro to extract the number of l2 caches from
+		 * mem_features.
+		 */
+		nl2c = ((pfdev->features.mem_features >> 8) & GENMASK(3, 0)) + 1;

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 531

Quoted 10 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +10 -0
+
+		/*
+		 * The ARM driver is grouping cores per core group and then
+		 * only using the number of cores in group 0 to calculate the
+		 * size. Not sure why this is done like that, but I guess
+		 * shader_present will only show cores in the first group
+		 * anyway.
+		 */
+		ncores = hweight64(pfdev->features.shader_present);
+

Deja vu. Was this copypaste dmaybe?

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 901

Quoted 1 line
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +1 -0
+		  (panfrost_model_cmp(pfdev, 0x1000) >= 0 ?

THere's that pesky 0x1000 again.

include/uapi/drm/panfrost_drm.h struct drm_panfrost_submit { · line 74

Quoted 13 lines
include/uapi/drm/panfrost_drm.h +9 -0
@@ -55,6 +63,15 @@ struct drm_panfrost_submit {
 
 	/** A combination of PANFROST_JD_REQ_* */
 	__u32 requirements;
+
+	/** Pointer to a u32 array of perfmons that should be attached to the job. */
+	__u64 perfmon_handles;
+
+	/** Number of perfmon handles passed in (size is that times 4). */
+	__u32 perfmon_handle_count;
+
+	/** Unused field, should be set to 0. */
+	__u32 padding;

Bleep blorp. If we're modifying _submit, we'll need to be swift about merging this ahead of the main code to make sure we don't break the UABI. Although I guess if we're just adding fields at the end, that's a nonissue.

Quoted 9 lines
include/uapi/drm/panfrost_drm.h +9 -0
+struct drm_panfrost_block_perfcounters {
+	/*
+	 * For DRM_IOCTL_PANFROST_GET_PERFCNT_LAYOUT, encodes the available
+	 * instances for a specific given block type.
+	 * For DRM_IOCTL_PANFROST_CREATE_PERFMON, encodes the instances the
+	 * user wants to monitor.
+	 * Note: the bitmap might be sparse.
+	 */
+	__u64 instances;

include/uapi/drm/panfrost_drm.h struct drm_panfrost_get_bo_offset { · line 185

Quoted 10 lines
include/uapi/drm/panfrost_drm.h +10 -0
+
+	/*
+	 * For DRM_IOCTL_PANFROST_GET_PERFCNT_LAYOUT, encodes the available
+	 * counters attached to a specific block type.
+	 * For DRM_IOCTL_PANFROST_CREATE_PERFMON, encodes the counters the user
+	 * wants to monitor.
+	 * Note: the bitmap might be sparse.
+	 */
+	__u64 counters;
+};

I don't understand this. Aren't there more than 64 counters?

include/uapi/drm/panfrost_drm.h struct drm_panfrost_get_bo_offset { · line 192

Quoted 3 lines
include/uapi/drm/panfrost_drm.h +3 -0
+struct drm_panfrost_get_perfcnt_layout {
+	struct drm_panfrost_block_perfcounters counters[PANFROST_NUM_BLOCKS];
+};

--Oh. It's per-block. Got it.

Quoted 1 line

+ * Used to create a performance monitor. Each perfmonance monitor is assigned an

Typo.

---

Overall, this looks really great! Thank you! :)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#4 lore raw
Quoted 16 lines · On Thu, 4 Apr 2019 08:41:29 -0700 Alyssa Rosenzweig <[email protected]>…
Quoted 16 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +16 -0
+/*
+ * Returns true if the 2 jobs have exactly the same perfcnt context, false
+ * otherwise.
+ */
+static bool panfrost_perfcnt_job_ctx_cmp(struct panfrost_perfcnt_job_ctx *a,
+					 struct panfrost_perfcnt_job_ctx *b)
+{
+	unsigned int i, j;
+
+	if (a->perfmon_count != b->perfmon_count)
+		return false;
+
+	for (i = 0; i < a->perfmon_count; i++) {
+		for (j = 0; j < b->perfmon_count; j++) {
+			if (a->perfmons[i] == b->perfmons[j])
+				break;
Quoted 8 lines

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 318

Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +6 -0
+		}
+
+		if (j == b->perfmon_count)
+			return false;
+	}
+  

Would using memcmp() be cleaner here?

memcmp() does not account for the case where 2 jobs contain exactly the same perfmons but in a different order. This being said, it's rather unlikely to happen, so maybe we can accept the perf penalty for that case.

Quoted 6 lines

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 372

Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +1 -0
+	if (panfrost_model_cmp(pfdev, 0x1000) >= 0)  

What does 0x1000 refer to here? I'm assuming maybe Bifrost, but it's not obvious... probably better to have a #define somewhere and use that (or an enum equivalently).

Yes, all numbers above 0xfff are bifrost GPUs. I'll add a macro.

Quoted 11 lines

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 393

Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +4 -0
+	/*
+	 * Due to PRLAM-8186 we need to disable the Tiler before we enable HW
+	 * counters.
+	 */  

What on earth is PRLAM-8186? :)

Actually, wait, I can answer that -- old kbase versions had an errata list:

Quoted 7 lines
        /* Write of PRFCNT_CONFIG_MODE_MANUAL to PRFCNT_CONFIG causes a instrumentation dump if
           PRFCNT_TILER_EN is enabled */
        BASE_HW_ISSUE_8186,

So that's why. If people want, I'm considering moving these errata descriptions back into the kernel where possible, since otherwise code like this is opaque.

Will copy the errata.

Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +11 -0
+		unsigned int nl2c, ncores;
+
+		/*
+		 * TODO: define a macro to extract the number of l2 caches from
+		 * mem_features.
+		 */
+		nl2c = ((pfdev->features.mem_features >> 8) & GENMASK(3, 0)) + 1;
+
+		/*
+		 * The ARM driver is grouping cores per core group and then
+		 * only using the number of cores in group 0 to calculate the
Quoted 8 lines

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 531

Quoted 6 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +6 -0
+		 * size. Not sure why this is done like that, but I guess
+		 * shader_present will only show cores in the first group
+		 * anyway.
+		 */
+		ncores = hweight64(pfdev->features.shader_present);
+  

Deja vu. Was this copypaste dmaybe?

Actually, that one is from me, hence the 'not sure why' part :).

Quoted 7 lines

drivers/gpu/drm/panfrost/panfrost_perfcnt.c line 901

Quoted 2 lines
drivers/gpu/drm/panfrost/panfrost_perfcnt.c new file +1 -0
+		  (panfrost_model_cmp(pfdev, 0x1000) >= 0 ?  

THere's that pesky 0x1000 again.

Quoted 2 lines
(quoted diff) +0 -0
@@ -55,6 +63,15 @@ struct drm_panfrost_submit {
 
Quoted 16 lines

include/uapi/drm/panfrost_drm.h struct drm_panfrost_submit { · line 74

Quoted 11 lines
include/uapi/drm/panfrost_drm.h +9 -0
 	/** A combination of PANFROST_JD_REQ_* */
 	__u32 requirements;
+
+	/** Pointer to a u32 array of perfmons that should be attached to the job. */
+	__u64 perfmon_handles;
+
+	/** Number of perfmon handles passed in (size is that times 4). */
+	__u32 perfmon_handle_count;
+
+	/** Unused field, should be set to 0. */
+	__u32 padding;  

Bleep blorp. If we're modifying _submit, we'll need to be swift about merging this ahead of the main code to make sure we don't break the UABI. Although I guess if we're just adding fields at the end, that's a nonissue.

Others are using the same "if data passed is smaller than expected size, unassigned fields are zeroed". That allows us to extend a struct without breaking the ABI as long as zero is a valid value and does not change the behavior compared to when the field was not present.

This is the case here: perfmon_handle_count = 0 means no perfmon attached to the job, so the driver is acting like it previously was.

No need to get that part merged in the initial patch series IMO.

Quoted 29 lines
Quoted 10 lines
include/uapi/drm/panfrost_drm.h +9 -0
+struct drm_panfrost_block_perfcounters {
+	/*
+	 * For DRM_IOCTL_PANFROST_GET_PERFCNT_LAYOUT, encodes the available
+	 * instances for a specific given block type.
+	 * For DRM_IOCTL_PANFROST_CREATE_PERFMON, encodes the instances the
+	 * user wants to monitor.
+	 * Note: the bitmap might be sparse.
+	 */
+	__u64 instances;

include/uapi/drm/panfrost_drm.h struct drm_panfrost_get_bo_offset { · line 185

Quoted 10 lines
include/uapi/drm/panfrost_drm.h +10 -0
+
+	/*
+	 * For DRM_IOCTL_PANFROST_GET_PERFCNT_LAYOUT, encodes the available
+	 * counters attached to a specific block type.
+	 * For DRM_IOCTL_PANFROST_CREATE_PERFMON, encodes the counters the user
+	 * wants to monitor.
+	 * Note: the bitmap might be sparse.
+	 */
+	__u64 counters;
+};  

I don't understand this. Aren't there more than 64 counters?

include/uapi/drm/panfrost_drm.h struct drm_panfrost_get_bo_offset { · line 192

Quoted 3 lines
include/uapi/drm/panfrost_drm.h +3 -0
+struct drm_panfrost_get_perfcnt_layout {
+	struct drm_panfrost_block_perfcounters counters[PANFROST_NUM_BLOCKS];
+};  

--Oh. It's per-block. Got it.

Quoted 3 lines
Quoted 1 line

+ * Used to create a performance monitor. Each perfmonance monitor is assigned an

Typo.

Will fix.

Quoted 4 lines

---

Overall, this looks really great! Thank you! :)

Thanks a lot for your reviews. That was pretty damn fast!
_______________________________________________
dri-devel mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 4 lines

memcmp() does not account for the case where 2 jobs contain exactly the same perfmons but in a different order. This being said, it's rather unlikely to happen, so maybe we can accept the perf penalty for that case.

If you say so!

Quoted 1 line

Yes, all numbers above 0xfff are bifrost GPUs. I'll add a macro.

Thank you.

Quoted 1 line

Will copy the errata.

I was planning to include annotations for the whole file, but that's low prio.

Quoted 1 line

Actually, that one is from me, hence the 'not sure why' part :).

Alright...

Quoted 9 lines

Others are using the same "if data passed is smaller than expected size, unassigned fields are zeroed". That allows us to extend a struct without breaking the ABI as long as zero is a valid value and does not change the behavior compared to when the field was not present.

This is the case here: perfmon_handle_count = 0 means no perfmon attached to the job, so the driver is acting like it previously was.

No need to get that part merged in the initial patch series IMO.

+1

Quoted 1 line

Thanks a lot for your reviews. That was pretty damn fast!

THanks a lot for your code! \ o /
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
In reply to Alyssa Rosenzweig
Quoted 18 lines · Alyssa Rosenzweig

include/uapi/drm/panfrost_drm.h struct drm_panfrost_submit { · line 74

Quoted 13 lines
include/uapi/drm/panfrost_drm.h +9 -0
@@ -55,6 +63,15 @@ struct drm_panfrost_submit {
 
 	/** A combination of PANFROST_JD_REQ_* */
 	__u32 requirements;
+
+	/** Pointer to a u32 array of perfmons that should be attached to the job. */
+	__u64 perfmon_handles;
+
+	/** Number of perfmon handles passed in (size is that times 4). */
+	__u32 perfmon_handle_count;
+
+	/** Unused field, should be set to 0. */
+	__u32 padding;

Bleep blorp. If we're modifying _submit, we'll need to be swift about merging this ahead of the main code to make sure we don't break the UABI. Although I guess if we're just adding fields at the end, that's a nonissue.

You can extend ioctl structs safely. When older userspace passes theirs in, it has the shorter length encoded in the cmd. The kernel allocates the newest version's space, copies in the shorter struct, and zero-extends the rest.

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

author maintainer
#8 lore raw

PATCH 3/3 panfrost/drm: Define T860 perf counters

In reply to Boris Brezillon

So that userspace can now query perfcount values on T860.

---
 drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_perfcnt.h +6 -1
index 7cbfeb072aa1..d1d275a3d750 100644
@@ -18,7 +18,12 @@ struct panfrost_perfcnt_job_ctx;
 #define hw_perfcnt_t760	NO_PERFCNT
 #define hw_perfcnt_t820	NO_PERFCNT
 #define hw_perfcnt_t830	NO_PERFCNT
-#define hw_perfcnt_t860	NO_PERFCNT
+#define hw_perfcnt_t860	PERFCNT(GENMASK_ULL(63, 4),				\
+				GENMASK_ULL(63, 59) | GENMASK_ULL(53, 3),	\
+				GENMASK_ULL(63, 46) | GENMASK_ULL(44, 30) |	\
+				GENMASK_ULL(16, 12) | GENMASK_ULL(9, 4),	\
+				GENMASK_ULL(31, 28) | GENMASK_ULL(26, 20) |	\
+				GENMASK_ULL(18, 12) | GENMASK_ULL(10, 4))
 #define hw_perfcnt_t880	NO_PERFCNT
 #define hw_perfcnt_g76	NO_PERFCNT
 #define hw_perfcnt_g71	NO_PERFCNT
Signature · 6 lines
2.20.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#9 lore raw
In reply to Boris Brezillon
Quoted 5 lines · Boris Brezillon

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

Quoted 7 lines

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

mali_kbase submits overlapping jobs. The jobs on slot 0 and slot 1 can be from different contexts (address spaces), and mali_kbase also fully uses the _NEXT registers. So there can be a job from one context executing on slot 0 and a job from a different context waiting in the _NEXT registers. (And the same for slot 1). This means that there's no (visible) gap between the first job finishing and the second job starting. Early versions of the driver even had a throttle to avoid interrupt storms (see JOB_IRQ_THROTTLE) which would further delay the IRQ - but thankfully that's gone.

The upshot is that it's basically impossible to measure "per-job" counters when running at full speed. Because multiple jobs are running and the driver doesn't actually know when one ends and the next starts.

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

[1]
https://developer.arm.com/tools-and-software/embedded/arm-development-studio/components/streamline-performance-analyzer

Quoted 7 lines

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Let me know if that's an issue and if you think we should approach things differently.

It depends what you expect to do with the counters. Per-job counters are certainly useful sometimes. But serialising all jobs can mess up the thing you are trying to measure the performance of.

Steve

Quoted 9 lines

Regards,

Boris

Boris Brezillon (3):
drm/panfrost: Move gpu_{write,read}() macros to panfrost_regs.h drm/panfrost: Expose HW counters to userspace panfrost/drm: Define T860 perf counters

Quoted 15 lines
 drivers/gpu/drm/panfrost/Makefile           |   3 +-
 drivers/gpu/drm/panfrost/panfrost_device.c  |   8 +
 drivers/gpu/drm/panfrost/panfrost_device.h  |  11 +
 drivers/gpu/drm/panfrost/panfrost_drv.c     |  22 +-
 drivers/gpu/drm/panfrost/panfrost_gpu.c     |  46 +-
 drivers/gpu/drm/panfrost/panfrost_job.c     |  24 +
 drivers/gpu/drm/panfrost/panfrost_job.h     |   4 +
 drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 954 ++++++++++++++++++++
 drivers/gpu/drm/panfrost/panfrost_perfcnt.h |  59 ++
 drivers/gpu/drm/panfrost/panfrost_regs.h    |  22 +
 include/uapi/drm/panfrost_drm.h             | 122 +++
 11 files changed, 1268 insertions(+), 7 deletions(-)
 create mode 100644 drivers/gpu/drm/panfrost/panfrost_perfcnt.c
 create mode 100644 drivers/gpu/drm/panfrost/panfrost_perfcnt.h

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

#10 lore raw
Quoted 5 lines

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

Ah-ha, gotch. I don't know why I didn't put 2 and 2 together, but that definitely makes sense, yeah :) Boris, thoughts?
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#11 lore raw
Quoted 8 lines · On Fri, 5 Apr 2019 09:33:55 -0700 Alyssa Rosenzweig <[email protected]>…
Quoted 5 lines

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

Ah-ha, gotch. I don't know why I didn't put 2 and 2 together, but that definitely makes sense, yeah :) Boris, thoughts?

Nothing to add, except, I had the gut feeling I was doing the wrong choice here, hence the mention to this design decision in my cover letter :-).
I'll rework the implementation to have perfmons apply globally (instead of being attached to jobs) and get rid of the perfcnt fence.

Note that we could support both per-job and global perfmons and avoid the perf penalty when only global perfmons are used, but I don't think it's worth the extra complexity (not to mention that it makes things even more confusing for userspace users).
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#13 lore raw
In reply to Steven Price

+Rob, Eric, Mark and more

Hi,

Quoted 42 lines · On Fri, 5 Apr 2019 16:20:45 +0100 Steven Price <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

Quoted 7 lines

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

mali_kbase submits overlapping jobs. The jobs on slot 0 and slot 1 can be from different contexts (address spaces), and mali_kbase also fully uses the _NEXT registers. So there can be a job from one context executing on slot 0 and a job from a different context waiting in the _NEXT registers. (And the same for slot 1). This means that there's no (visible) gap between the first job finishing and the second job starting. Early versions of the driver even had a throttle to avoid interrupt storms (see JOB_IRQ_THROTTLE) which would further delay the IRQ - but thankfully that's gone.

The upshot is that it's basically impossible to measure "per-job" counters when running at full speed. Because multiple jobs are running and the driver doesn't actually know when one ends and the next starts.

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

[1]
https://developer.arm.com/tools-and-software/embedded/arm-development-studio/components/streamline-performance-analyzer

Quoted 5 lines

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Quoted 6 lines
Quoted 2 lines

Let me know if that's an issue and if you think we should approach things differently.

It depends what you expect to do with the counters. Per-job counters are certainly useful sometimes. But serialising all jobs can mess up the thing you are trying to measure the performance of.

I finally found some time to work on v2 this morning, and it turns out implementing global perf monitors as done in mali_kbase means rewriting almost everything (apart from the perfcnt layout stuff). I'm not against doing that, but I'd like to be sure this is really what we want.

Eric, Rob, any opinion on that? Is it acceptable to expose counters through the pipe_query/AMD_perfmon interface if we don't have this job (or at least draw call) granularity? If not, should we keep the solution I'm proposing here to make sure counters values are accurate, or should we expose perf counters through a non-standard API?

BTW, I'd like to remind you that serialization (waiting on the perfcnt fence) only happens if we have a perfmon context change between 2 consecutive jobs, which only happens when
* 2 applications are running in // and at least one of them is monitored
* or when userspace decides to stop monitoring things and dump counter values

That means that, for the usual case (all perfmons disabled), there's almost zero overhead (just a few more checks in the submit job code). That also means that, if we ever decide to support global perfmon (perf monitors that track things globably) on top of the current approach, and only global perfmons are enabled, things won't be serialized as with the per-job approach, because everyone will share the same perfmon ctx (the same set of perfmons).

I'd appreciate any feedback from people that have used perf counters (or implemented a way to dump them) on their platform.

Thanks,

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

#14 lore raw
Quoted 62 lines · Boris Brezillon

+Rob, Eric, Mark and more

Hi,

Quoted 42 lines · On Fri, 5 Apr 2019 16:20:45 +0100 Steven Price <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

Quoted 7 lines

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

mali_kbase submits overlapping jobs. The jobs on slot 0 and slot 1 can be from different contexts (address spaces), and mali_kbase also fully uses the _NEXT registers. So there can be a job from one context executing on slot 0 and a job from a different context waiting in the _NEXT registers. (And the same for slot 1). This means that there's no (visible) gap between the first job finishing and the second job starting. Early versions of the driver even had a throttle to avoid interrupt storms (see JOB_IRQ_THROTTLE) which would further delay the IRQ - but thankfully that's gone.

The upshot is that it's basically impossible to measure "per-job" counters when running at full speed. Because multiple jobs are running and the driver doesn't actually know when one ends and the next starts.

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

[1]
https://developer.arm.com/tools-and-software/embedded/arm-development-studio/components/streamline-performance-analyzer

Quoted 5 lines

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Quoted 6 lines
Quoted 2 lines

Let me know if that's an issue and if you think we should approach things differently.

It depends what you expect to do with the counters. Per-job counters are certainly useful sometimes. But serialising all jobs can mess up the thing you are trying to measure the performance of.

I finally found some time to work on v2 this morning, and it turns out implementing global perf monitors as done in mali_kbase means rewriting almost everything (apart from the perfcnt layout stuff). I'm not against doing that, but I'd like to be sure this is really what we want.

Quoted 5 lines

Eric, Rob, any opinion on that? Is it acceptable to expose counters through the pipe_query/AMD_perfmon interface if we don't have this job (or at least draw call) granularity? If not, should we keep the solution I'm proposing here to make sure counters values are accurate, or should we expose perf counters through a non-standard API?

I think if you can't do per-draw level granularity, then you should not try to implement AMD_perfmon.. instead the use case is more for a sort of "gpu top" app (as opposed to something like frameretrace which is taking per-draw-call level measurements from within the app. Things that use AMD_perfmon are going to, I think, expect to query values between individual glDraw calls, and you probably don't want to flush tile passes 500 times per frame.

(Although, I suppose if there are multiple GPUs where perfcntrs work this way, it might be an interesting exercise to think about coming up w/ a standardized API (debugfs perhaps?) to monitor the counters.. so you could have a single userspace tool that works across several different drivers.)

BR,
-R

Quoted 17 lines

BTW, I'd like to remind you that serialization (waiting on the perfcnt fence) only happens if we have a perfmon context change between 2 consecutive jobs, which only happens when
* 2 applications are running in // and at least one of them is monitored
* or when userspace decides to stop monitoring things and dump counter values

That means that, for the usual case (all perfmons disabled), there's almost zero overhead (just a few more checks in the submit job code). That also means that, if we ever decide to support global perfmon (perf monitors that track things globably) on top of the current approach, and only global perfmons are enabled, things won't be serialized as with the per-job approach, because everyone will share the same perfmon ctx (the same set of perfmons).

Quoted 6 lines

I'd appreciate any feedback from people that have used perf counters (or implemented a way to dump them) on their platform.

Thanks,

Boris

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

#15 lore raw
Quoted 78 lines · Rob Clark
Quoted 62 lines · Boris Brezillon

+Rob, Eric, Mark and more

Hi,

Quoted 42 lines · On Fri, 5 Apr 2019 16:20:45 +0100 Steven Price <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

Quoted 7 lines

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

mali_kbase submits overlapping jobs. The jobs on slot 0 and slot 1 can be from different contexts (address spaces), and mali_kbase also fully uses the _NEXT registers. So there can be a job from one context executing on slot 0 and a job from a different context waiting in the _NEXT registers. (And the same for slot 1). This means that there's no (visible) gap between the first job finishing and the second job starting. Early versions of the driver even had a throttle to avoid interrupt storms (see JOB_IRQ_THROTTLE) which would further delay the IRQ - but thankfully that's gone.

The upshot is that it's basically impossible to measure "per-job" counters when running at full speed. Because multiple jobs are running and the driver doesn't actually know when one ends and the next starts.

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

[1]
https://developer.arm.com/tools-and-software/embedded/arm-development-studio/components/streamline-performance-analyzer

Quoted 5 lines

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Quoted 6 lines
Quoted 2 lines

Let me know if that's an issue and if you think we should approach things differently.

It depends what you expect to do with the counters. Per-job counters are certainly useful sometimes. But serialising all jobs can mess up the thing you are trying to measure the performance of.

I finally found some time to work on v2 this morning, and it turns out implementing global perf monitors as done in mali_kbase means rewriting almost everything (apart from the perfcnt layout stuff). I'm not against doing that, but I'd like to be sure this is really what we want.

Quoted 5 lines

Eric, Rob, any opinion on that? Is it acceptable to expose counters through the pipe_query/AMD_perfmon interface if we don't have this job (or at least draw call) granularity? If not, should we keep the solution I'm proposing here to make sure counters values are accurate, or should we expose perf counters through a non-standard API?

I think if you can't do per-draw level granularity, then you should not try to implement AMD_perfmon.. instead the use case is more for a sort of "gpu top" app (as opposed to something like frameretrace which is taking per-draw-call level measurements from within the app. Things that use AMD_perfmon are going to, I think, expect to query values between individual glDraw calls, and you probably don't want to flush tile passes 500 times per frame.

Quoted 5 lines

(Although, I suppose if there are multiple GPUs where perfcntrs work this way, it might be an interesting exercise to think about coming up w/ a standardized API (debugfs perhaps?) to monitor the counters.. so you could have a single userspace tool that works across several different drivers.)

I agree. We've been pondering a lot of the same issues for Adreno. I would be greatly interested in seeing if we could come up with a standard solution we can use.

Jordan

Quoted 28 lines
Quoted 18 lines

BTW, I'd like to remind you that serialization (waiting on the perfcnt fence) only happens if we have a perfmon context change between 2 consecutive jobs, which only happens when
* 2 applications are running in // and at least one of them is monitored
* or when userspace decides to stop monitoring things and dump counter values

That means that, for the usual case (all perfmons disabled), there's almost zero overhead (just a few more checks in the submit job code). That also means that, if we ever decide to support global perfmon (perf monitors that track things globably) on top of the current approach, and only global perfmons are enabled, things won't be serialized as with the per-job approach, because everyone will share the same perfmon ctx (the same set of perfmons).

Quoted 6 lines

I'd appreciate any feedback from people that have used perf counters (or implemented a way to dump them) on their platform.

Thanks,

Boris

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

Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#16 lore raw
Quoted 79 lines · On Tue, 30 Apr 2019 09:49:51 -0600 Jordan Crouse <[email protected]> wrote:
Quoted 78 lines · Rob Clark
Quoted 62 lines · Boris Brezillon

+Rob, Eric, Mark and more

Hi,

Quoted 42 lines · On Fri, 5 Apr 2019 16:20:45 +0100 Steven Price <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

Quoted 7 lines

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

mali_kbase submits overlapping jobs. The jobs on slot 0 and slot 1 can be from different contexts (address spaces), and mali_kbase also fully uses the _NEXT registers. So there can be a job from one context executing on slot 0 and a job from a different context waiting in the _NEXT registers. (And the same for slot 1). This means that there's no (visible) gap between the first job finishing and the second job starting. Early versions of the driver even had a throttle to avoid interrupt storms (see JOB_IRQ_THROTTLE) which would further delay the IRQ - but thankfully that's gone.

The upshot is that it's basically impossible to measure "per-job" counters when running at full speed. Because multiple jobs are running and the driver doesn't actually know when one ends and the next starts.

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

[1]
https://developer.arm.com/tools-and-software/embedded/arm-development-studio/components/streamline-performance-analyzer

Quoted 5 lines

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Quoted 6 lines
Quoted 2 lines

Let me know if that's an issue and if you think we should approach things differently.

It depends what you expect to do with the counters. Per-job counters are certainly useful sometimes. But serialising all jobs can mess up the thing you are trying to measure the performance of.

I finally found some time to work on v2 this morning, and it turns out implementing global perf monitors as done in mali_kbase means rewriting almost everything (apart from the perfcnt layout stuff). I'm not against doing that, but I'd like to be sure this is really what we want.

Quoted 5 lines

Eric, Rob, any opinion on that? Is it acceptable to expose counters through the pipe_query/AMD_perfmon interface if we don't have this job (or at least draw call) granularity? If not, should we keep the solution I'm proposing here to make sure counters values are accurate, or should we expose perf counters through a non-standard API?

I think if you can't do per-draw level granularity, then you should not try to implement AMD_perfmon.. instead the use case is more for a sort of "gpu top" app (as opposed to something like frameretrace which is taking per-draw-call level measurements from within the app. Things that use AMD_perfmon are going to, I think, expect to query values between individual glDraw calls, and you probably don't want to flush tile passes 500 times per frame.

Quoted 7 lines
Quoted 5 lines

(Although, I suppose if there are multiple GPUs where perfcntrs work this way, it might be an interesting exercise to think about coming up w/ a standardized API (debugfs perhaps?) to monitor the counters.. so you could have a single userspace tool that works across several different drivers.)

I agree. We've been pondering a lot of the same issues for Adreno.

So, you also have those global perf counters that can't be retrieved through the cmdstream? After the discussion I had with Rob I had the impression freedreno was supporting the AMD_perfmon interface in a proper way.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#17 lore raw
Quoted 88 lines · Boris Brezillon
Quoted 85 lines · On Tue, 30 Apr 2019 09:49:51 -0600 Jordan Crouse <[email protected]> wrote:
Quoted 83 lines · Rob Clark
Quoted 62 lines · Boris Brezillon

+Rob, Eric, Mark and more

Hi,

Quoted 42 lines · On Fri, 5 Apr 2019 16:20:45 +0100 Steven Price <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

Quoted 7 lines

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

mali_kbase submits overlapping jobs. The jobs on slot 0 and slot 1 can be from different contexts (address spaces), and mali_kbase also fully uses the _NEXT registers. So there can be a job from one context executing on slot 0 and a job from a different context waiting in the _NEXT registers. (And the same for slot 1). This means that there's no (visible) gap between the first job finishing and the second job starting. Early versions of the driver even had a throttle to avoid interrupt storms (see JOB_IRQ_THROTTLE) which would further delay the IRQ - but thankfully that's gone.

The upshot is that it's basically impossible to measure "per-job" counters when running at full speed. Because multiple jobs are running and the driver doesn't actually know when one ends and the next starts.

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

[1]
https://developer.arm.com/tools-and-software/embedded/arm-development-studio/components/streamline-performance-analyzer

Quoted 5 lines

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Quoted 6 lines
Quoted 2 lines

Let me know if that's an issue and if you think we should approach things differently.

It depends what you expect to do with the counters. Per-job counters are certainly useful sometimes. But serialising all jobs can mess up the thing you are trying to measure the performance of.

I finally found some time to work on v2 this morning, and it turns out implementing global perf monitors as done in mali_kbase means rewriting almost everything (apart from the perfcnt layout stuff). I'm not against doing that, but I'd like to be sure this is really what we want.

Quoted 5 lines

Eric, Rob, any opinion on that? Is it acceptable to expose counters through the pipe_query/AMD_perfmon interface if we don't have this job (or at least draw call) granularity? If not, should we keep the solution I'm proposing here to make sure counters values are accurate, or should we expose perf counters through a non-standard API?

I think if you can't do per-draw level granularity, then you should not try to implement AMD_perfmon.. instead the use case is more for a sort of "gpu top" app (as opposed to something like frameretrace which is taking per-draw-call level measurements from within the app. Things that use AMD_perfmon are going to, I think, expect to query values between individual glDraw calls, and you probably don't want to flush tile passes 500 times per frame.

(Although, I suppose if there are multiple GPUs where perfcntrs work this way, it might be an interesting exercise to think about coming up w/ a standardized API (debugfs perhaps?) to monitor the counters.. so you could have a single userspace tool that works across several different drivers.)

Quoted 6 lines
Quoted 1 line

I agree. We've been pondering a lot of the same issues for Adreno.

So, you also have those global perf counters that can't be retrieved through the cmdstream? After the discussion I had with Rob I had the impression freedreno was supporting the AMD_perfmon interface in a proper way.

It is true that we can read most of the counters from the cmdstream but we have a limited number of global physical counters that have to be shared across contexts and a metric ton of countables that can be selected. As long as we have just the one process running AMD_perfmon then we are fine, but it breaks down after that.

I am also interested in the 'gpu top' use case which can somewhat emulated through a cmdstream assuming that we stick to a finite set of counters and countables that won't conflict with extensions. This is fine for basic work but anybody doing any serious performance work would run into some limitations quickly.

And finally the kernel uses a few counters for its own purposes and I hate the "gentlemen's agreement" between the user and the kernel as to which physical counters each get ownership of. It would be a lot better to turn it into an explicit dynamic reservation which I feel would be a natural outshoot of a generic interface.

Jordan

Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#18 lore raw
In reply to Boris Brezillon
Quoted 61 lines · Boris Brezillon

+Rob, Eric, Mark and more

Hi,

Quoted 42 lines · On Fri, 5 Apr 2019 16:20:45 +0100 Steven Price <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

Quoted 7 lines

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

mali_kbase submits overlapping jobs. The jobs on slot 0 and slot 1 can be from different contexts (address spaces), and mali_kbase also fully uses the _NEXT registers. So there can be a job from one context executing on slot 0 and a job from a different context waiting in the _NEXT registers. (And the same for slot 1). This means that there's no (visible) gap between the first job finishing and the second job starting. Early versions of the driver even had a throttle to avoid interrupt storms (see JOB_IRQ_THROTTLE) which would further delay the IRQ - but thankfully that's gone.

The upshot is that it's basically impossible to measure "per-job" counters when running at full speed. Because multiple jobs are running and the driver doesn't actually know when one ends and the next starts.

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

[1]
https://developer.arm.com/tools-and-software/embedded/arm-development-studio/components/streamline-performance-analyzer

Quoted 5 lines

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Quoted 6 lines
Quoted 2 lines

Let me know if that's an issue and if you think we should approach things differently.

It depends what you expect to do with the counters. Per-job counters are certainly useful sometimes. But serialising all jobs can mess up the thing you are trying to measure the performance of.

I finally found some time to work on v2 this morning, and it turns out implementing global perf monitors as done in mali_kbase means rewriting almost everything (apart from the perfcnt layout stuff). I'm not against doing that, but I'd like to be sure this is really what we want.

Quoted 5 lines

Eric, Rob, any opinion on that? Is it acceptable to expose counters through the pipe_query/AMD_perfmon interface if we don't have this job (or at least draw call) granularity? If not, should we keep the solution I'm proposing here to make sure counters values are accurate, or should we expose perf counters through a non-standard API?

You should definitely not count perf results from someone else's context against your own! People doing perf analysis will expect slight performance changes (like missing bin/render parallelism between contexts) when doing perf queries, but they will be absolutely lost if their non-texturing job starts showing texturing results from some unrelated context.

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

author maintainer
#19 lore raw
Quoted 63 lines · On Wed, 01 May 2019 10:12:42 -0700 Eric Anholt <[email protected]> wrote:
Quoted 61 lines · Boris Brezillon

+Rob, Eric, Mark and more

Hi,

Quoted 42 lines · On Fri, 5 Apr 2019 16:20:45 +0100 Steven Price <[email protected]> wrote:
Quoted 5 lines · Boris Brezillon

Hello,

This patch adds new ioctls to expose GPU counters to userspace. These will be used by the mesa driver (should be posted soon).

Quoted 7 lines

A few words about the implementation: I followed the VC4/Etnaviv model where perf counters are retrieved on a per-job basis. This allows one to have get accurate results when there are users using the GPU concurrently.
AFAICT, the mali kbase is using a different approach where several users can register a performance monitor but with no way to have fined grained control over what job/GPU-context to track.

mali_kbase submits overlapping jobs. The jobs on slot 0 and slot 1 can be from different contexts (address spaces), and mali_kbase also fully uses the _NEXT registers. So there can be a job from one context executing on slot 0 and a job from a different context waiting in the _NEXT registers. (And the same for slot 1). This means that there's no (visible) gap between the first job finishing and the second job starting. Early versions of the driver even had a throttle to avoid interrupt storms (see JOB_IRQ_THROTTLE) which would further delay the IRQ - but thankfully that's gone.

The upshot is that it's basically impossible to measure "per-job" counters when running at full speed. Because multiple jobs are running and the driver doesn't actually know when one ends and the next starts.

Since one of the primary use cases is to draw pretty graphs of the system load [1], this "per-job" information isn't all that relevant (and minimal performance overhead is important). And if you want to monitor just one application it is usually easiest to ensure that it is the only thing running.

[1]
https://developer.arm.com/tools-and-software/embedded/arm-development-studio/components/streamline-performance-analyzer

Quoted 5 lines

This design choice comes at a cost: every time the perfmon context changes (the perfmon context is the list of currently active perfmons), the driver has to add a fence to prevent new jobs from corrupting counters that will be dumped by previous jobs.

Quoted 6 lines
Quoted 2 lines

Let me know if that's an issue and if you think we should approach things differently.

It depends what you expect to do with the counters. Per-job counters are certainly useful sometimes. But serialising all jobs can mess up the thing you are trying to measure the performance of.

I finally found some time to work on v2 this morning, and it turns out implementing global perf monitors as done in mali_kbase means rewriting almost everything (apart from the perfcnt layout stuff). I'm not against doing that, but I'd like to be sure this is really what we want.

Quoted 8 lines
Quoted 5 lines

Eric, Rob, any opinion on that? Is it acceptable to expose counters through the pipe_query/AMD_perfmon interface if we don't have this job (or at least draw call) granularity? If not, should we keep the solution I'm proposing here to make sure counters values are accurate, or should we expose perf counters through a non-standard API?

You should definitely not count perf results from someone else's context against your own!

Also had the feeling that doing that was a bad idea (which you and Rob confirmed), but I listed it here to clear up my doubts.

Quoted 5 lines

People doing perf analysis will expect slight
performance changes (like missing bin/render parallelism between contexts) when doing perf queries, but they will be absolutely lost if their non-texturing job starts showing texturing results from some unrelated context.

Given the feedback I had so far, it looks like defining a new interface for this type of 'global perfmon' is the way to go if we want to make everyone happy. Also note that the work I've done on VC4 has the same
limitation: a perfmon context between 2 jobs will introduce a serialization point. It seems that you're not as worried as Steven or Rob is about extra cost if this serialization, but I wanted to point that out.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#20 lore raw
In reply to Boris Brezillon

Hi all,

As Steven Price explained, the "GPU top" kbase approach is often more useful and accurate than per-draw timing.

For a 3D game inside a GPU-accelerated desktop, the games' counters *should* include desktop overhead. This external overhead does affect the game's performance, especially if the contexts are competing for resources like memory bandwidth. An isolated sample is easy to achieve running only the app of interest; in ideal conditions (zero-copy fullscreen), desktop interference is negligible.

For driver developers, the system-wide measurements are preferable, painting a complete system picture and avoiding disruptions. There is no risk of confusion, as the driver developers understand how the counters are exposed. Further, benchmarks rendering direct to a GBM surface are available (glmark2-es2-drm), eliminating interference even with poor desktop performance.

For app developers, the confusion of multi-context interference is unfortunate. Nevertheless, if enabling counters were to slow down an app, the confusion could be worse. Consider second-order changes in the app's performance characteristics due to slowdown: if techniques like dynamic resolution scaling are employed, the counters' results can be invalid. Likewise, even if the lower-performance counters are appropriate for purely graphical workloads, complex apps with variable CPU overhead (e.g. from an FPS-dependent physics engine) can further confound counters. Low-overhead system-wide measurements mitigate these concerns.

As Rob Clark suggested, system-wide counters could be exposed via a semi-standardized interface, perhaps within debugfs/sysfs. The interface could not be completely standard, as the list of counters exposed varies substantially by vendor and model. Nevertheless, the mechanics of discovering, enabling, reading, and disabling counters can be standardized, as can a small set of universally meaningful counters like total GPU utilization. This would permit a vendor-independent GPU top app as suggested, as is I believe currently possible with vendor-specific downstream kernels (e.g. via Gator/Streamline for Mali)

It looks like this discussion is dormant. Could we try to get this sorted? For Panfrost, I'm hitting GPU-side bottlenecks that I'm unable to diagnose without access to the counters, so I'm eager for a mainline solution to be implemented.

Thank you,

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

author maintainer
#21 lore raw
Quoted 19 lines · On Sat, 11 May 2019 15:32:20 -0700 Alyssa Rosenzweig <[email protected]>…

Hi all,

As Steven Price explained, the "GPU top" kbase approach is often more useful and accurate than per-draw timing.

For a 3D game inside a GPU-accelerated desktop, the games' counters *should* include desktop overhead. This external overhead does affect the game's performance, especially if the contexts are competing for resources like memory bandwidth. An isolated sample is easy to achieve running only the app of interest; in ideal conditions (zero-copy fullscreen), desktop interference is negligible.

For driver developers, the system-wide measurements are preferable, painting a complete system picture and avoiding disruptions. There is no risk of confusion, as the driver developers understand how the counters are exposed. Further, benchmarks rendering direct to a GBM surface are available (glmark2-es2-drm), eliminating interference even with poor desktop performance.

Quoted 10 lines

For app developers, the confusion of multi-context interference is unfortunate. Nevertheless, if enabling counters were to slow down an app, the confusion could be worse. Consider second-order changes in the app's performance characteristics due to slowdown: if techniques like dynamic resolution scaling are employed, the counters' results can be invalid. Likewise, even if the lower-performance counters are appropriate for purely graphical workloads, complex apps with variable CPU overhead (e.g. from an FPS-dependent physics engine) can further confound counters. Low-overhead system-wide measurements mitigate these concerns.

I'd just like to point out that dumping counters the way mali_kbase/gator does likely has an impact on perfs (at least on some GPUs) because of the clean+invalidate-cache that happens before (or after, I don't remember) each dump. IIUC and this cache is actually global and not a per address space thing (which would be possible if the cache lines contain a tag attaching them to a specific address space), that means all jobs running when the clean+invalidate happens will have extra cache misses after each dump. Of course, that's not as invasive as the full serialization that happens with my solution, but it's not free either.

Quoted 11 lines

As Rob Clark suggested, system-wide counters could be exposed via a semi-standardized interface, perhaps within debugfs/sysfs. The interface could not be completely standard, as the list of counters exposed varies substantially by vendor and model. Nevertheless, the mechanics of discovering, enabling, reading, and disabling counters can be standardized, as can a small set of universally meaningful counters like total GPU utilization. This would permit a vendor-independent GPU top app as suggested, as is I believe currently possible with vendor-specific downstream kernels (e.g. via Gator/Streamline for Mali)

Quoted 4 lines

It looks like this discussion is dormant. Could we try to get this sorted? For Panfrost, I'm hitting GPU-side bottlenecks that I'm unable to diagnose without access to the counters, so I'm eager for a mainline solution to be implemented.

I spent a bit of time thinking about it and looking at different solutions.

debugfs/sysfs might not be the best solution, especially if we think about the multi-user case (several instances of GPU perfmon tool running in parallel), if we want it to work properly we need a way to instantiate several perf monitors and let the driver add values to all active perfmons everytime a dump happens (no matter who triggered the dump). That's exactly what mali_kbase/gator does BTW. That's achievable through debugs if we consider exposing a knob to instantiate such perfmon instances, but that also means risking perfmon leaks if the user does not take care of killing the perfmon it created when it's done with it (or when it crashes). It might also prove hard to expose that to non-root users in a secure way.

I also had a quick look at the perf_event interface to see if we could extend it to support monitoring GPU events. I might be wrong as I didn't spend much time investigating how it works, but it seems that perf counters are saved/dumped/restored at each thread context switch, which is not what we want here (might add extra perfcnt dump points thus impacting GPU perfs more than we expect).

So maybe the best option is a pseudo-generic ioctl-based interface to expose those perf counters.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#22 lore raw
Quoted 33 lines · Boris Brezillon
Quoted 19 lines · On Sat, 11 May 2019 15:32:20 -0700 Alyssa Rosenzweig <[email protected]>…

Hi all,

As Steven Price explained, the "GPU top" kbase approach is often more useful and accurate than per-draw timing.

For a 3D game inside a GPU-accelerated desktop, the games' counters *should* include desktop overhead. This external overhead does affect the game's performance, especially if the contexts are competing for resources like memory bandwidth. An isolated sample is easy to achieve running only the app of interest; in ideal conditions (zero-copy fullscreen), desktop interference is negligible.

For driver developers, the system-wide measurements are preferable, painting a complete system picture and avoiding disruptions. There is no risk of confusion, as the driver developers understand how the counters are exposed. Further, benchmarks rendering direct to a GBM surface are available (glmark2-es2-drm), eliminating interference even with poor desktop performance.

Quoted 10 lines

For app developers, the confusion of multi-context interference is unfortunate. Nevertheless, if enabling counters were to slow down an app, the confusion could be worse. Consider second-order changes in the app's performance characteristics due to slowdown: if techniques like dynamic resolution scaling are employed, the counters' results can be invalid. Likewise, even if the lower-performance counters are appropriate for purely graphical workloads, complex apps with variable CPU overhead (e.g. from an FPS-dependent physics engine) can further confound counters. Low-overhead system-wide measurements mitigate these concerns.

Quoted 4 lines

I'd just like to point out that dumping counters the way mali_kbase/gator does likely has an impact on perfs (at least on some GPUs) because of the clean+invalidate-cache that happens before (or after, I don't remember) each dump. IIUC and this cache is actually

The clean is required after the dump to ensure that the CPU can see the dumped counters (otherwise they could be stuck in the GPU's cache). Note that if you don't immediately need to observe the values the clean can be deferred. E.g. if each dump you target a different memory region then you could perform a flush only after several dumps.

Quoted 6 lines

global and not a per address space thing (which would be possible if the cache lines contain a tag attaching them to a specific address space), that means all jobs running when the clean+invalidate happens will have extra cache misses after each dump. Of course, that's not as invasive as the full serialization that happens with my solution, but it's not free either.

Cache cleans (at the L2 cache level) are global. There are L1 caches (and TLBs) but they are not relevant to counter dumping.

In practice cache cleans are not that expensive most of the time. As you note - mali_kbase doesn't bother to avoid them when doing counter capture.

It should also be unnecessary to "invalidate" - a clean should be sufficient. The invalidate is only required if e.g. MMU page tables have been modified as well. That would reduce the affect on currently running jobs. But I notice that mali_kbase doesn't appear to use the "clean only" (GPU_COMMAND_CLEAN_CACHES) option. I'm not aware of it being broken though.

Quoted 19 lines
Quoted 11 lines

As Rob Clark suggested, system-wide counters could be exposed via a semi-standardized interface, perhaps within debugfs/sysfs. The interface could not be completely standard, as the list of counters exposed varies substantially by vendor and model. Nevertheless, the mechanics of discovering, enabling, reading, and disabling counters can be standardized, as can a small set of universally meaningful counters like total GPU utilization. This would permit a vendor-independent GPU top app as suggested, as is I believe currently possible with vendor-specific downstream kernels (e.g. via Gator/Streamline for Mali)

Quoted 4 lines

It looks like this discussion is dormant. Could we try to get this sorted? For Panfrost, I'm hitting GPU-side bottlenecks that I'm unable to diagnose without access to the counters, so I'm eager for a mainline solution to be implemented.

I spent a bit of time thinking about it and looking at different solutions.

Quoted 11 lines

debugfs/sysfs might not be the best solution, especially if we think about the multi-user case (several instances of GPU perfmon tool running in parallel), if we want it to work properly we need a way to instantiate several perf monitors and let the driver add values to all active perfmons everytime a dump happens (no matter who triggered the dump). That's exactly what mali_kbase/gator does BTW. That's achievable through debugs if we consider exposing a knob to instantiate such perfmon instances, but that also means risking perfmon leaks if the user does not take care of killing the perfmon it created when it's done with it (or when it crashes). It might also prove hard to expose that to non-root users in a secure way.

Note that mali_kbase only has to maintain multiple sets of values because it provides backwards compatibility to an old version of the driver. You could maintain one set of counter values and simply ensure they are big enough not to wrap (or handle wrapping, but that is ugly and unlikely to happen). Very early versions of kbase simply exposed the hardware functionality (dump counters and reset) and therefore faced the issue that there could only ever be one user of counters at a time. This was "fixed" by emulating the existence of multiple interfaces (vinstr - "virtual" instrumentation). If I was redesigning it from scratch then I'd definitely remove the "reset" part of the interface and leave it for the clients to latch the first value (of each counter) and subtract that from subsequent counter reads.

Sadly the hardware doesn't help here and some (most?) GPU revisions will saturate the counters rather than wrapping. Hence the need to frequently poll and reset the counters, even if you only want the 'start'/'end' values.

Having only one set of counters might simplify the potential for "leaks"
- although you still want to ensure that if nobody cares you stop collecting counters...

Steve

Quoted 7 lines

I also had a quick look at the perf_event interface to see if we could extend it to support monitoring GPU events. I might be wrong as I didn't spend much time investigating how it works, but it seems that perf counters are saved/dumped/restored at each thread context switch, which is not what we want here (might add extra perfcnt dump points thus impacting GPU perfs more than we expect).

Quoted 7 lines

So maybe the best option is a pseudo-generic ioctl-based interface to expose those perf counters.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

author maintainer
#23 lore raw
Quoted 34 lines · On Mon, 13 May 2019 13:48:08 +0100 Steven Price <[email protected]> wrote:
Quoted 33 lines · Boris Brezillon
Quoted 29 lines · On Sat, 11 May 2019 15:32:20 -0700 Alyssa Rosenzweig <[email protected]>…

Hi all,

As Steven Price explained, the "GPU top" kbase approach is often more useful and accurate than per-draw timing.

For a 3D game inside a GPU-accelerated desktop, the games' counters *should* include desktop overhead. This external overhead does affect the game's performance, especially if the contexts are competing for resources like memory bandwidth. An isolated sample is easy to achieve running only the app of interest; in ideal conditions (zero-copy fullscreen), desktop interference is negligible.

For driver developers, the system-wide measurements are preferable, painting a complete system picture and avoiding disruptions. There is no risk of confusion, as the driver developers understand how the counters are exposed. Further, benchmarks rendering direct to a GBM surface are available (glmark2-es2-drm), eliminating interference even with poor desktop performance.

For app developers, the confusion of multi-context interference is unfortunate. Nevertheless, if enabling counters were to slow down an app, the confusion could be worse. Consider second-order changes in the app's performance characteristics due to slowdown: if techniques like dynamic resolution scaling are employed, the counters' results can be invalid. Likewise, even if the lower-performance counters are appropriate for purely graphical workloads, complex apps with variable CPU overhead (e.g. from an FPS-dependent physics engine) can further confound counters. Low-overhead system-wide measurements mitigate these concerns.

Quoted 7 lines
Quoted 4 lines

I'd just like to point out that dumping counters the way mali_kbase/gator does likely has an impact on perfs (at least on some GPUs) because of the clean+invalidate-cache that happens before (or after, I don't remember) each dump. IIUC and this cache is actually

The clean is required after the dump to ensure that the CPU can see the dumped counters (otherwise they could be stuck in the GPU's cache).

Just to make it clear, I was not questioning the need for a cache clean here, I was simply pointing out that dumping counters is not free even when we don't add those serialization points. Note that dumping counters also has an impact on the cache-miss counter of future dumps, but there's nothing we can do about that no matter the solution we go for.

Quoted 4 lines

Note
that if you don't immediately need to observe the values the clean can be deferred. E.g. if each dump you target a different memory region then you could perform a flush only after several dumps.

Correct. Having a pool of dump buffers might be an option if we need to minimize the impact of dumps at some point.

Quoted 10 lines
Quoted 7 lines

global and not a per address space thing (which would be possible if the cache lines contain a tag attaching them to a specific address space), that means all jobs running when the clean+invalidate happens will have extra cache misses after each dump. Of course, that's not as invasive as the full serialization that happens with my solution, but it's not free either.

Cache cleans (at the L2 cache level) are global. There are L1 caches (and TLBs) but they are not relevant to counter dumping.

Okay.

Quoted 7 lines

In practice cache cleans are not that expensive most of the time. As you note - mali_kbase doesn't bother to avoid them when doing counter capture.

It should also be unnecessary to "invalidate" - a clean should be sufficient. The invalidate is only required if e.g. MMU page tables have been modified as well.

I already dropped the invalidate in my patch as we only have a global address space right now and the buffer used to store perfcnt values is always the same. We'll have to rework that when support for per-context address space is added.

Quoted 4 lines

That would reduce the affect on currently running
jobs. But I notice that mali_kbase doesn't appear to use the "clean only" (GPU_COMMAND_CLEAN_CACHES) option. I'm not aware of it being broken though.

'clean-only' seems to work fine on T860 at least.

Quoted 32 lines
Quoted 20 lines
Quoted 12 lines

As Rob Clark suggested, system-wide counters could be exposed via a semi-standardized interface, perhaps within debugfs/sysfs. The interface could not be completely standard, as the list of counters exposed varies substantially by vendor and model. Nevertheless, the mechanics of discovering, enabling, reading, and disabling counters can be standardized, as can a small set of universally meaningful counters like total GPU utilization. This would permit a vendor-independent GPU top app as suggested, as is I believe currently possible with vendor-specific downstream kernels (e.g. via Gator/Streamline for Mali)

Quoted 4 lines

It looks like this discussion is dormant. Could we try to get this sorted? For Panfrost, I'm hitting GPU-side bottlenecks that I'm unable to diagnose without access to the counters, so I'm eager for a mainline solution to be implemented.

I spent a bit of time thinking about it and looking at different solutions.

Quoted 11 lines

debugfs/sysfs might not be the best solution, especially if we think about the multi-user case (several instances of GPU perfmon tool running in parallel), if we want it to work properly we need a way to instantiate several perf monitors and let the driver add values to all active perfmons everytime a dump happens (no matter who triggered the dump). That's exactly what mali_kbase/gator does BTW. That's achievable through debugs if we consider exposing a knob to instantiate such perfmon instances, but that also means risking perfmon leaks if the user does not take care of killing the perfmon it created when it's done with it (or when it crashes). It might also prove hard to expose that to non-root users in a secure way.

Quoted 12 lines

Note that mali_kbase only has to maintain multiple sets of values because it provides backwards compatibility to an old version of the driver. You could maintain one set of counter values and simply ensure they are big enough not to wrap (or handle wrapping, but that is ugly and unlikely to happen). Very early versions of kbase simply exposed the hardware functionality (dump counters and reset) and therefore faced the issue that there could only ever be one user of counters at a time. This was "fixed" by emulating the existence of multiple interfaces (vinstr - "virtual" instrumentation). If I was redesigning it from scratch then I'd definitely remove the "reset" part of the interface and leave it for the clients to latch the first value (of each counter) and subtract that from subsequent counter reads.

Noted.

Quoted 4 lines

Sadly the hardware doesn't help here and some (most?) GPU revisions will saturate the counters rather than wrapping. Hence the need to frequently poll and reset the counters, even if you only want the 'start'/'end' values.

Not sure wrapping would be better, as you can't tell how many times you've reached the max val.

BTW, counters are reset every time we do a dump, right? If that's the case, there's no risk to have end_val < start_val and the only risk is to get inaccurate values when counter_val > U32_MAX, but reaching U32_MAX already means that this event occurred a lot during the monitoring period.

Quoted 4 lines

Having only one set of counters might simplify the potential for "leaks"
- although you still want to ensure that if nobody cares you stop collecting counters...

Handling that with a debugfs-based iface implies implementing some heuristic like 'counters haven't been dumped for a long time, let's stop monitoring them', and I'm not a big fan of such things.

This being said, I think I'll go for a simple debugfs-based iface to unblock Alyssa. debugfs is not part of the stable-ABI and I guess we can agree on explicitly marking it as "unstable" so that when we settle on a generic interface to expose such counters we can get rid of the old one.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#24 lore raw
Quoted 45 lines · Boris Brezillon
Quoted 34 lines · On Mon, 13 May 2019 13:48:08 +0100 Steven Price <[email protected]> wrote:
Quoted 33 lines · Boris Brezillon
Quoted 29 lines · On Sat, 11 May 2019 15:32:20 -0700 Alyssa Rosenzweig <[email protected]>…

Hi all,

As Steven Price explained, the "GPU top" kbase approach is often more useful and accurate than per-draw timing.

For a 3D game inside a GPU-accelerated desktop, the games' counters *should* include desktop overhead. This external overhead does affect the game's performance, especially if the contexts are competing for resources like memory bandwidth. An isolated sample is easy to achieve running only the app of interest; in ideal conditions (zero-copy fullscreen), desktop interference is negligible.

For driver developers, the system-wide measurements are preferable, painting a complete system picture and avoiding disruptions. There is no risk of confusion, as the driver developers understand how the counters are exposed. Further, benchmarks rendering direct to a GBM surface are available (glmark2-es2-drm), eliminating interference even with poor desktop performance.

For app developers, the confusion of multi-context interference is unfortunate. Nevertheless, if enabling counters were to slow down an app, the confusion could be worse. Consider second-order changes in the app's performance characteristics due to slowdown: if techniques like dynamic resolution scaling are employed, the counters' results can be invalid. Likewise, even if the lower-performance counters are appropriate for purely graphical workloads, complex apps with variable CPU overhead (e.g. from an FPS-dependent physics engine) can further confound counters. Low-overhead system-wide measurements mitigate these concerns.

Quoted 7 lines
Quoted 4 lines

I'd just like to point out that dumping counters the way mali_kbase/gator does likely has an impact on perfs (at least on some GPUs) because of the clean+invalidate-cache that happens before (or after, I don't remember) each dump. IIUC and this cache is actually

The clean is required after the dump to ensure that the CPU can see the dumped counters (otherwise they could be stuck in the GPU's cache).

Quoted 6 lines

Just to make it clear, I was not questioning the need for a cache clean here, I was simply pointing out that dumping counters is not free even when we don't add those serialization points. Note that dumping counters also has an impact on the cache-miss counter of future dumps, but there's nothing we can do about that no matter the solution we go for.

Indeed, counters go through the caches, so clearly will have an impact on the cache performance. But usually the impact is sufficiently "in the noise" that it doesn't matter. But this is a hardware limitation.

Quoted 6 lines

[..]

Quoted 4 lines

Sadly the hardware doesn't help here and some (most?) GPU revisions will saturate the counters rather than wrapping. Hence the need to frequently poll and reset the counters, even if you only want the 'start'/'end' values.

Quoted 8 lines

Not sure wrapping would be better, as you can't tell how many times you've reached the max val.

BTW, counters are reset every time we do a dump, right? If that's the case, there's no risk to have end_val < start_val and the only risk is to get inaccurate values when counter_val > U32_MAX, but reaching U32_MAX already means that this event occurred a lot during the monitoring period.

Yes the h/w resets the counters when dumping. What I intended to say (and re-reading it didn't do a good job) was that it would be quite helpful if the hardware didn't reset and didn't saturate. That way multiple uses could simply observe the counter values. The combination of saturating and resetting on read means that there has to only be done entity reading the counter values from the hardware and summing up.

I *think* later hardware might have dropped the saturating logic (because it costs gates and is fairly useless for software), but sadly because of backwards compatibility the resetting on read behaviour isn't going to change.

Quoted 8 lines
Quoted 4 lines

Having only one set of counters might simplify the potential for "leaks"
- although you still want to ensure that if nobody cares you stop collecting counters...

Handling that with a debugfs-based iface implies implementing some heuristic like 'counters haven't been dumped for a long time, let's stop monitoring them', and I'm not a big fan of such things.

Agreed, it's fairly ugly. If you expose "native" sized counters (i.e. u32) then there's a reasonable heuristic: if (1^32/GPU clock frequency) has passed then the counters might have overflowed so are unlikely to be useful to anyone still looking at them.

Quoted 5 lines

This being said, I think I'll go for a simple debugfs-based iface to unblock Alyssa. debugfs is not part of the stable-ABI and I guess we can agree on explicitly marking it as "unstable" so that when we settle on a generic interface to expose such counters we can get rid of the old one.

A generic interface would be good, but short-term I can definitely see the value of exporting the counters in debugfs.

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

#25 lore raw
In reply to Boris Brezillon
Quoted 5 lines

This being said, I think I'll go for a simple debugfs-based iface to unblock Alyssa. debugfs is not part of the stable-ABI and I guess we can agree on explicitly marking it as "unstable" so that when we settle on a generic interface to expose such counters we can get rid of the old one.

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