Skip to contentSkip to conversation

Host1x/TegraDRM UAPI

RFC PATCH Superseded Mikko Perttunen 3 participants 64 messages Sep 5, 2020 – Sep 17, 2020

Subsystems (4)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Mikko Perttunen

author maintainer
#0 lore raw

v2 cover Host1x/TegraDRM UAPI

Hi all,

here's a second revision of the Host1x/TegraDRM UAPI proposal, hopefully with most issues from v1 resolved, and also with an implementation. There are still open issues with the implementation:

* Relocs are now handled on TegraDRM side instead of Host1x, so the firewall is not aware of them, causing submission failure where the firewall is enabled. Proposed solution is to move the firewall to TegraDRM side, but this hasn't been done yet.
* For the new UAPI, syncpoint recovery on job timeout is disabled. What this means is that upon job timeout, all further jobs using that syncpoint are cancelled, and the syncpoint is marked unusable until it is freed. However, there is currently a race between the timeout handler and job submission, where submission can observe the syncpoint in non-locked state and yet the job cancellations won't cancel the new job.
* Waiting for DMA reservation fences is not implemented yet.
* I have only tested on Tegra186.

The series consists of three parts:

* The first part contains some fixes and improvements to the Host1x driver of more general nature,
* The second part adds the Host1x side UAPI, as well as Host1x-side changes needed for the new TegraDRM UAPI,
* The third part adds the new TegraDRM UAPI.

I have written some tests to test the new interface, see https://github.com/cyndis/uapi-test. Porting of proper userspace (e.g. opentegra, vdpau-tegra) will come once there is some degree of conclusion on the UAPI definition.

The series can be also found in
https://github.com/cyndis/linux/commits/work/host1x-uapi.

Older versions:
v1: https://www.spinics.net/lists/linux-tegra/msg51000.html

Thank you,
Mikko

Mikko Perttunen (17):
gpu: host1x: Use different lock classes for each client
gpu: host1x: Allow syncpoints without associated client
gpu: host1x: Show number of pending waiters in debugfs
gpu: host1x: Remove cancelled waiters immediately
gpu: host1x: Use HW-equivalent syncpoint expiration check
gpu: host1x: Cleanup and refcounting for syncpoints
gpu: host1x: Introduce UAPI header
gpu: host1x: Implement /dev/host1x device node
gpu: host1x: DMA fences and userspace fence creation
WIP: gpu: host1x: Add no-recovery mode
gpu: host1x: Add job release callback
gpu: host1x: Add support for syncpoint waits in CDMA pushbuffer
gpu: host1x: Reset max value when freeing a syncpoint drm/tegra: Add new UAPI to header
drm/tegra: Add power_on/power_off engine callbacks drm/tegra: Allocate per-engine channel in core code
WIP: drm/tegra: Implement new UAPI

 drivers/gpu/drm/tegra/Makefile      |   2 +
 drivers/gpu/drm/tegra/dc.c          |   4 +-
 drivers/gpu/drm/tegra/drm.c         |  75 ++-
 drivers/gpu/drm/tegra/drm.h         |  20 +-
 drivers/gpu/drm/tegra/gr2d.c        |   4 +-
 drivers/gpu/drm/tegra/gr3d.c        |   4 +-
 drivers/gpu/drm/tegra/uapi.h        |  59 +++
 drivers/gpu/drm/tegra/uapi/submit.c | 687 ++++++++++++++++++++++++++++
 drivers/gpu/drm/tegra/uapi/uapi.c   | 328 +++++++++++++
 drivers/gpu/drm/tegra/vic.c         | 131 +++---
 drivers/gpu/host1x/Makefile         |   2 +
 drivers/gpu/host1x/bus.c            |   7 +-
 drivers/gpu/host1x/cdma.c           |  53 ++-
 drivers/gpu/host1x/debug.c          |  14 +-
 drivers/gpu/host1x/dev.c            |   9 +
 drivers/gpu/host1x/dev.h            |  10 +-
 drivers/gpu/host1x/fence.c          | 207 +++++++++
 drivers/gpu/host1x/fence.h          |  15 +
 drivers/gpu/host1x/hw/cdma_hw.c     |   2 +-
 drivers/gpu/host1x/hw/channel_hw.c  |  67 ++-
 drivers/gpu/host1x/hw/debug_hw.c    |  11 +-
 drivers/gpu/host1x/intr.c           |  23 +-
 drivers/gpu/host1x/intr.h           |   2 +
 drivers/gpu/host1x/job.c            |  79 +++-
 drivers/gpu/host1x/job.h            |  14 +
 drivers/gpu/host1x/syncpt.c         | 137 +++---
 drivers/gpu/host1x/syncpt.h         |  21 +-
 drivers/gpu/host1x/uapi.c           | 381 +++++++++++++++
 drivers/gpu/host1x/uapi.h           |  22 +
 include/linux/host1x.h              |  40 +-
 include/uapi/drm/tegra_drm.h        | 431 +++++++++++++++--
 include/uapi/linux/host1x.h         | 134 ++++++
 32 files changed, 2718 insertions(+), 277 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/uapi.h
 create mode 100644 drivers/gpu/drm/tegra/uapi/submit.c
 create mode 100644 drivers/gpu/drm/tegra/uapi/uapi.c
 create mode 100644 drivers/gpu/host1x/fence.c
 create mode 100644 drivers/gpu/host1x/fence.h
 create mode 100644 drivers/gpu/host1x/uapi.c
 create mode 100644 drivers/gpu/host1x/uapi.h
 create mode 100644 include/uapi/linux/host1x.h
Signature · 1 line
2.28.0
author maintainer
#1 lore raw

RFC PATCH v2 1/17 gpu: host1x: Use different lock classes for each client

To avoid false lockdep warnings, give each client lock a different lock class, passed from the initialization site by macro.

---
 drivers/gpu/host1x/bus.c | 7 ++++---
 include/linux/host1x.h   | 9 ++++++++-
 2 files changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/host1x/bus.c +4 -3
index e201f62d62c0..4101f64bd545 100644
@@ -714,13 +714,14 @@ EXPORT_SYMBOL(host1x_driver_unregister);
  * device and call host1x_device_init(), which will in turn call each client's
  * &host1x_client_ops.init implementation.
  */
-int host1x_client_register(struct host1x_client *client)
+int __host1x_client_register(struct host1x_client *client,
+			   struct lock_class_key *key)
 {
 	struct host1x *host1x;
 	int err;
 
 	INIT_LIST_HEAD(&client->list);
-	mutex_init(&client->lock);
+	__mutex_init(&client->lock, "host1x client lock", key);
 	client->usecount = 0;
 
 	mutex_lock(&devices_lock);
@@ -741,7 +742,7 @@ int host1x_client_register(struct host1x_client *client)
 
 	return 0;
 }
-EXPORT_SYMBOL(host1x_client_register);
+EXPORT_SYMBOL(__host1x_client_register);
 
 /**
  * host1x_client_unregister() - unregister a host1x client
include/linux/host1x.h +8 -1
index 20c885d0bddc..f711fc0154f4 100644
@@ -320,7 +320,14 @@ static inline struct host1x_device *to_host1x_device(struct device *dev)
 int host1x_device_init(struct host1x_device *device);
 int host1x_device_exit(struct host1x_device *device);
 
-int host1x_client_register(struct host1x_client *client);
+int __host1x_client_register(struct host1x_client *client,
+			     struct lock_class_key *key);
+#define host1x_client_register(class) \
+	({ \
+		static struct lock_class_key __key; \
+		__host1x_client_register(class, &__key); \
+	})
+
 int host1x_client_unregister(struct host1x_client *client);
 
 int host1x_client_suspend(struct host1x_client *client);
Signature · 1 line
2.28.0
author maintainer
#2 lore raw

RFC PATCH v2 2/17 gpu: host1x: Allow syncpoints without associated client

In reply to Mikko Perttunen

Syncpoints don't need to be associated with any client, so remove the property, and expose host1x_syncpt_alloc. This will allow allocating syncpoints without prior knowledge of the engine that it will be used with.

---
 drivers/gpu/host1x/syncpt.c | 8 +++-----
 drivers/gpu/host1x/syncpt.h | 6 +++++-
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/host1x/syncpt.c +3 -5
index fce7892d5137..7cb80d4768b1 100644
@@ -42,9 +42,9 @@ static void host1x_syncpt_base_free(struct host1x_syncpt_base *base)
 		base->requested = false;
 }
 
-static struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
-						 struct host1x_client *client,
-						 unsigned long flags)
+struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
+					  struct host1x_client *client,
+					  unsigned long flags)
 {
 	struct host1x_syncpt *sp = host->syncpt;
 	unsigned int i;
@@ -69,7 +69,6 @@ static struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
 	if (!name)
 		goto free_base;
 
-	sp->client = client;
 	sp->name = name;
 
 	if (flags & HOST1X_SYNCPT_CLIENT_MANAGED)
@@ -447,7 +446,6 @@ void host1x_syncpt_free(struct host1x_syncpt *sp)
 	host1x_syncpt_base_free(sp->base);
 	kfree(sp->name);
 	sp->base = NULL;
-	sp->client = NULL;
 	sp->name = NULL;
 	sp->client_managed = false;
 
drivers/gpu/host1x/syncpt.h +5 -1
index 8e1d04dacaa0..77e7206cc316 100644
@@ -33,7 +33,6 @@ struct host1x_syncpt {
 	const char *name;
 	bool client_managed;
 	struct host1x *host;
-	struct host1x_client *client;
 	struct host1x_syncpt_base *base;
 
 	/* interrupt data */
@@ -113,4 +112,9 @@ static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp)
 	return sp->id < host1x_syncpt_nb_pts(sp->host);
 }
 
+/* Allocate a syncpoint. */
+struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
+					  struct host1x_client *client,
+					  unsigned long flags);
+
 #endif
Signature · 6 lines
2.28.0

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

RFC PATCH v2 3/17 gpu: host1x: Show number of pending waiters in debugfs

In reply to Mikko Perttunen

Show the number of pending waiters in the debugfs status file. This is useful for testing to verify that waiters do not leak or accumulate incorrectly.

---
 drivers/gpu/host1x/debug.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/gpu/host1x/debug.c +11 -3
index 3eee4318b158..2d06a7406b3b 100644
@@ -69,6 +69,7 @@ static int show_channel(struct host1x_channel *ch, void *data, bool show_fifo)
 
 static void show_syncpts(struct host1x *m, struct output *o)
 {
+	struct list_head *pos;
 	unsigned int i;
 
 	host1x_debug_output(o, "---- syncpts ----\n");
@@ -76,12 +77,19 @@ static void show_syncpts(struct host1x *m, struct output *o)
 	for (i = 0; i < host1x_syncpt_nb_pts(m); i++) {
 		u32 max = host1x_syncpt_read_max(m->syncpt + i);
 		u32 min = host1x_syncpt_load(m->syncpt + i);
+		unsigned int waiters = 0;
 
-		if (!min && !max)
+		spin_lock(&m->syncpt[i].intr.lock);
+		list_for_each(pos, &m->syncpt[i].intr.wait_head)
+			waiters++;
+		spin_unlock(&m->syncpt[i].intr.lock);
+
+		if (!min && !max && !waiters)
 			continue;
 
-		host1x_debug_output(o, "id %u (%s) min %d max %d\n",
-				    i, m->syncpt[i].name, min, max);
+		host1x_debug_output(o,
+				    "id %u (%s) min %d max %d (%d waiters)\n",
+				    i, m->syncpt[i].name, min, max, waiters);
 	}
 
 	for (i = 0; i < host1x_syncpt_nb_bases(m); i++) {
Signature · 1 line
2.28.0
author maintainer
#4 lore raw

RFC PATCH v2 4/17 gpu: host1x: Remove cancelled waiters immediately

In reply to Mikko Perttunen

Before this patch, cancelled waiters would only be cleaned up once their threshold value was reached. Make host1x_intr_put_ref process the cancellation immediately to fix this.

---
 drivers/gpu/host1x/intr.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/gpu/host1x/intr.c +9 -5
index 9245add23b5d..5d328d20ce6d 100644
@@ -247,13 +247,17 @@ void host1x_intr_put_ref(struct host1x *host, unsigned int id, void *ref)
 	struct host1x_waitlist *waiter = ref;
 	struct host1x_syncpt *syncpt;
 
-	while (atomic_cmpxchg(&waiter->state, WLS_PENDING, WLS_CANCELLED) ==
-	       WLS_REMOVED)
-		schedule();
+	atomic_cmpxchg(&waiter->state, WLS_PENDING, WLS_CANCELLED);
 
 	syncpt = host->syncpt + id;
-	(void)process_wait_list(host, syncpt,
-				host1x_syncpt_load(host->syncpt + id));
+
+	spin_lock(&syncpt->intr.lock);
+	if (atomic_cmpxchg(&waiter->state, WLS_CANCELLED, WLS_HANDLED) ==
+	    WLS_CANCELLED) {
+		list_del(&waiter->list);
+		kref_put(&waiter->refcount, waiter_release);
+	}
+	spin_unlock(&syncpt->intr.lock);
 
 	kref_put(&waiter->refcount, waiter_release);
 }
Signature · 1 line
2.28.0
author maintainer
#5 lore raw

RFC PATCH v2 5/17 gpu: host1x: Use HW-equivalent syncpoint expiration check

In reply to Mikko Perttunen

Make syncpoint expiration checks always use the same logic used by the hardware. This ensures that there are no race conditions that could occur because of the hardware triggering a syncpoint interrupt and then the driver disagreeing.

One situation where this could occur is if a job incremented a syncpoint too many times -- then the hardware would trigger an interrupt, but the driver would assume that a syncpoint value greater than the syncpoint's max value is in the future, and not clean up the job.

---
 drivers/gpu/host1x/syncpt.c | 51 ++-----------------------------------
 1 file changed, 2 insertions(+), 49 deletions(-)
drivers/gpu/host1x/syncpt.c +2 -49
index 7cb80d4768b1..5329a0886d29 100644
@@ -306,59 +306,12 @@ EXPORT_SYMBOL(host1x_syncpt_wait);
 bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh)
 {
 	u32 current_val;
-	u32 future_val;
 
 	smp_rmb();
 
 	current_val = (u32)atomic_read(&sp->min_val);
-	future_val = (u32)atomic_read(&sp->max_val);
-
-	/* Note the use of unsigned arithmetic here (mod 1<<32).
-	 *
-	 * c = current_val = min_val	= the current value of the syncpoint.
-	 * t = thresh			= the value we are checking
-	 * f = future_val  = max_val	= the value c will reach when all
-	 *				  outstanding increments have completed.
-	 *
-	 * Note that c always chases f until it reaches f.
-	 *
-	 * Dtf = (f - t)
-	 * Dtc = (c - t)
-	 *
-	 *  Consider all cases:
-	 *
-	 *	A) .....c..t..f.....	Dtf < Dtc	need to wait
-	 *	B) .....c.....f..t..	Dtf > Dtc	expired
-	 *	C) ..t..c.....f.....	Dtf > Dtc	expired	   (Dct very large)
-	 *
-	 *  Any case where f==c: always expired (for any t).	Dtf == Dcf
-	 *  Any case where t==c: always expired (for any f).	Dtf >= Dtc (because Dtc==0)
-	 *  Any case where t==f!=c: always wait.		Dtf <  Dtc (because Dtf==0,
-	 *							Dtc!=0)
-	 *
-	 *  Other cases:
-	 *
-	 *	A) .....t..f..c.....	Dtf < Dtc	need to wait
-	 *	A) .....f..c..t.....	Dtf < Dtc	need to wait
-	 *	A) .....f..t..c.....	Dtf > Dtc	expired
-	 *
-	 *   So:
-	 *	   Dtf >= Dtc implies EXPIRED	(return true)
-	 *	   Dtf <  Dtc implies WAIT	(return false)
-	 *
-	 * Note: If t is expired then we *cannot* wait on it. We would wait
-	 * forever (hang the system).
-	 *
-	 * Note: do NOT get clever and remove the -thresh from both sides. It
-	 * is NOT the same.
-	 *
-	 * If future valueis zero, we have a client managed sync point. In that
-	 * case we do a direct comparison.
-	 */
-	if (!host1x_syncpt_client_managed(sp))
-		return future_val - thresh >= current_val - thresh;
-	else
-		return (s32)(current_val - thresh) >= 0;
+
+	return ((current_val - thresh) & 0x80000000U) == 0U;
 }
 
 int host1x_syncpt_init(struct host1x *host)
Signature · 6 lines
2.28.0

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

RFC PATCH v2 6/17 gpu: host1x: Cleanup and refcounting for syncpoints

In reply to Mikko Perttunen

Add reference counting for allocated syncpoints to allow keeping them allocated while jobs are referencing them. Additionally, clean up various places using syncpoint IDs to use host1x_syncpt pointers instead.

---
 drivers/gpu/drm/tegra/dc.c         |  4 +-
 drivers/gpu/drm/tegra/drm.c        | 17 ++++---
 drivers/gpu/drm/tegra/gr2d.c       |  4 +-
 drivers/gpu/drm/tegra/gr3d.c       |  4 +-
 drivers/gpu/drm/tegra/vic.c        |  4 +-
 drivers/gpu/host1x/cdma.c          | 11 ++---
 drivers/gpu/host1x/dev.h           |  7 ++-
 drivers/gpu/host1x/hw/cdma_hw.c    |  2 +-
 drivers/gpu/host1x/hw/channel_hw.c | 10 ++--
 drivers/gpu/host1x/hw/debug_hw.c   |  2 +-
 drivers/gpu/host1x/job.c           |  5 +-
 drivers/gpu/host1x/syncpt.c        | 75 +++++++++++++++++++++++-------
 drivers/gpu/host1x/syncpt.h        |  3 ++
 include/linux/host1x.h             |  8 ++--
 14 files changed, 99 insertions(+), 57 deletions(-)
drivers/gpu/drm/tegra/dc.c +2 -2
index 9a0b3240bc58..efb41c10dad4 100644
@@ -2127,7 +2127,7 @@ static int tegra_dc_init(struct host1x_client *client)
 		drm_plane_cleanup(primary);
 
 	host1x_client_iommu_detach(client);
-	host1x_syncpt_free(dc->syncpt);
+	host1x_syncpt_put(dc->syncpt);
 
 	return err;
 }
@@ -2152,7 +2152,7 @@ static int tegra_dc_exit(struct host1x_client *client)
 	}
 
 	host1x_client_iommu_detach(client);
-	host1x_syncpt_free(dc->syncpt);
+	host1x_syncpt_put(dc->syncpt);
 
 	return 0;
 }
drivers/gpu/drm/tegra/drm.c +10 -7
index ba9d1c3e7cac..ceea9db341f0 100644
@@ -171,7 +171,7 @@ int tegra_drm_submit(struct tegra_drm_context *context,
 	struct drm_tegra_syncpt syncpt;
 	struct host1x *host1x = dev_get_drvdata(drm->dev->parent);
 	struct drm_gem_object **refs;
-	struct host1x_syncpt *sp;
+	struct host1x_syncpt *sp = NULL;
 	struct host1x_job *job;
 	unsigned int num_refs;
 	int err;
@@ -298,8 +298,8 @@ int tegra_drm_submit(struct tegra_drm_context *context,
 		goto fail;
 	}
 
-	/* check whether syncpoint ID is valid */
-	sp = host1x_syncpt_get(host1x, syncpt.id);
+	/* Syncpoint ref will be dropped on job release. */
+	sp = host1x_syncpt_get_by_id(host1x, syncpt.id);
 	if (!sp) {
 		err = -ENOENT;
 		goto fail;
@@ -308,7 +308,7 @@ int tegra_drm_submit(struct tegra_drm_context *context,
 	job->is_addr_reg = context->client->ops->is_addr_reg;
 	job->is_valid_class = context->client->ops->is_valid_class;
 	job->syncpt_incrs = syncpt.incrs;
-	job->syncpt_id = syncpt.id;
+	job->syncpt = sp;
 	job->timeout = 10000;
 
 	if (args->timeout && args->timeout < 10000)
@@ -327,6 +327,9 @@ int tegra_drm_submit(struct tegra_drm_context *context,
 	args->fence = job->syncpt_end;
 
 fail:
+	if (sp)
+		host1x_syncpt_put(sp);
+
 	while (num_refs--)
 		drm_gem_object_put(refs[num_refs]);
 
@@ -380,7 +383,7 @@ static int tegra_syncpt_read(struct drm_device *drm, void *data,
 	struct drm_tegra_syncpt_read *args = data;
 	struct host1x_syncpt *sp;
 
-	sp = host1x_syncpt_get(host, args->id);
+	sp = host1x_syncpt_get_by_id_noref(host, args->id);
 	if (!sp)
 		return -EINVAL;
 
@@ -395,7 +398,7 @@ static int tegra_syncpt_incr(struct drm_device *drm, void *data,
 	struct drm_tegra_syncpt_incr *args = data;
 	struct host1x_syncpt *sp;
 
-	sp = host1x_syncpt_get(host1x, args->id);
+	sp = host1x_syncpt_get_by_id_noref(host1x, args->id);
 	if (!sp)
 		return -EINVAL;
 
@@ -409,7 +412,7 @@ static int tegra_syncpt_wait(struct drm_device *drm, void *data,
 	struct drm_tegra_syncpt_wait *args = data;
 	struct host1x_syncpt *sp;
 
-	sp = host1x_syncpt_get(host1x, args->id);
+	sp = host1x_syncpt_get_by_id_noref(host1x, args->id);
 	if (!sp)
 		return -EINVAL;
 
drivers/gpu/drm/tegra/gr2d.c +2 -2
index 1a0d3ba6e525..d857a99b21a7 100644
@@ -67,7 +67,7 @@ static int gr2d_init(struct host1x_client *client)
 detach:
 	host1x_client_iommu_detach(client);
 free:
-	host1x_syncpt_free(client->syncpts[0]);
+	host1x_syncpt_put(client->syncpts[0]);
 put:
 	host1x_channel_put(gr2d->channel);
 	return err;
@@ -86,7 +86,7 @@ static int gr2d_exit(struct host1x_client *client)
 		return err;
 
 	host1x_client_iommu_detach(client);
-	host1x_syncpt_free(client->syncpts[0]);
+	host1x_syncpt_put(client->syncpts[0]);
 	host1x_channel_put(gr2d->channel);
 
 	return 0;
drivers/gpu/drm/tegra/gr3d.c +2 -2
index b0b8154e8104..24442ade0da3 100644
@@ -76,7 +76,7 @@ static int gr3d_init(struct host1x_client *client)
 detach:
 	host1x_client_iommu_detach(client);
 free:
-	host1x_syncpt_free(client->syncpts[0]);
+	host1x_syncpt_put(client->syncpts[0]);
 put:
 	host1x_channel_put(gr3d->channel);
 	return err;
@@ -94,7 +94,7 @@ static int gr3d_exit(struct host1x_client *client)
 		return err;
 
 	host1x_client_iommu_detach(client);
-	host1x_syncpt_free(client->syncpts[0]);
+	host1x_syncpt_put(client->syncpts[0]);
 	host1x_channel_put(gr3d->channel);
 
 	return 0;
drivers/gpu/drm/tegra/vic.c +2 -2
index ade56b860cf9..cb476da59adc 100644
@@ -197,7 +197,7 @@ static int vic_init(struct host1x_client *client)
 	return 0;
 
 free_syncpt:
-	host1x_syncpt_free(client->syncpts[0]);
+	host1x_syncpt_put(client->syncpts[0]);
 free_channel:
 	host1x_channel_put(vic->channel);
 detach:
@@ -221,7 +221,7 @@ static int vic_exit(struct host1x_client *client)
 	if (err < 0)
 		return err;
 
-	host1x_syncpt_free(client->syncpts[0]);
+	host1x_syncpt_put(client->syncpts[0]);
 	host1x_channel_put(vic->channel);
 	host1x_client_iommu_detach(client);
 
drivers/gpu/host1x/cdma.c +3 -8
index e8d3fda91d8a..6e6ca774f68d 100644
@@ -273,15 +273,13 @@ static int host1x_cdma_wait_pushbuffer_space(struct host1x *host1x,
 static void cdma_start_timer_locked(struct host1x_cdma *cdma,
 				    struct host1x_job *job)
 {
-	struct host1x *host = cdma_to_host1x(cdma);
-
 	if (cdma->timeout.client) {
 		/* timer already started */
 		return;
 	}
 
 	cdma->timeout.client = job->client;
-	cdma->timeout.syncpt = host1x_syncpt_get(host, job->syncpt_id);
+	cdma->timeout.syncpt = job->syncpt;
 	cdma->timeout.syncpt_val = job->syncpt_end;
 	cdma->timeout.start_ktime = ktime_get();
 
@@ -312,7 +310,6 @@ static void stop_cdma_timer_locked(struct host1x_cdma *cdma)
 static void update_cdma_locked(struct host1x_cdma *cdma)
 {
 	bool signal = false;
-	struct host1x *host1x = cdma_to_host1x(cdma);
 	struct host1x_job *job, *n;
 
 	/* If CDMA is stopped, queue is cleared and we can return */
@@ -324,8 +321,7 @@ static void update_cdma_locked(struct host1x_cdma *cdma)
 	 * to consume as many sync queue entries as possible without blocking
 	 */
 	list_for_each_entry_safe(job, n, &cdma->sync_queue, list) {
-		struct host1x_syncpt *sp =
-			host1x_syncpt_get(host1x, job->syncpt_id);
+		struct host1x_syncpt *sp = job->syncpt;
 
 		/* Check whether this syncpt has completed, and bail if not */
 		if (!host1x_syncpt_is_expired(sp, job->syncpt_end)) {
@@ -499,8 +495,7 @@ int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job)
 		if (!cdma->timeout.initialized) {
 			int err;
 
-			err = host1x_hw_cdma_timeout_init(host1x, cdma,
-							  job->syncpt_id);
+			err = host1x_hw_cdma_timeout_init(host1x, cdma);
 			if (err) {
 				mutex_unlock(&cdma->lock);
 				return err;
drivers/gpu/host1x/dev.h +3 -4
index f781a9b0f39d..63010ae37a97 100644
@@ -37,7 +37,7 @@ struct host1x_cdma_ops {
 	void (*start)(struct host1x_cdma *cdma);
 	void (*stop)(struct host1x_cdma *cdma);
 	void (*flush)(struct  host1x_cdma *cdma);
-	int (*timeout_init)(struct host1x_cdma *cdma, unsigned int syncpt);
+	int (*timeout_init)(struct host1x_cdma *cdma);
 	void (*timeout_destroy)(struct host1x_cdma *cdma);
 	void (*freeze)(struct host1x_cdma *cdma);
 	void (*resume)(struct host1x_cdma *cdma, u32 getptr);
@@ -261,10 +261,9 @@ static inline void host1x_hw_cdma_flush(struct host1x *host,
 }
 
 static inline int host1x_hw_cdma_timeout_init(struct host1x *host,
-					      struct host1x_cdma *cdma,
-					      unsigned int syncpt)
+					      struct host1x_cdma *cdma)
 {
-	return host->cdma_op->timeout_init(cdma, syncpt);
+	return host->cdma_op->timeout_init(cdma);
 }
 
 static inline void host1x_hw_cdma_timeout_destroy(struct host1x *host,
drivers/gpu/host1x/hw/cdma_hw.c +1 -1
index 2f3bf94cf365..e49cd5b8f735 100644
@@ -295,7 +295,7 @@ static void cdma_timeout_handler(struct work_struct *work)
 /*
  * Init timeout resources
  */
-static int cdma_timeout_init(struct host1x_cdma *cdma, unsigned int syncpt)
+static int cdma_timeout_init(struct host1x_cdma *cdma)
 {
 	INIT_DELAYED_WORK(&cdma->timeout.wq, cdma_timeout_handler);
 	cdma->timeout.initialized = true;
drivers/gpu/host1x/hw/channel_hw.c +4 -6
index 5eaa29d171c9..d4c28faf27d1 100644
@@ -86,8 +86,7 @@ static void submit_gathers(struct host1x_job *job)
 
 static inline void synchronize_syncpt_base(struct host1x_job *job)
 {
-	struct host1x *host = dev_get_drvdata(job->channel->dev->parent);
-	struct host1x_syncpt *sp = host->syncpt + job->syncpt_id;
+	struct host1x_syncpt *sp = job->syncpt;
 	unsigned int id;
 	u32 value;
 
@@ -118,7 +117,7 @@ static void host1x_channel_set_streamid(struct host1x_channel *channel)
 static int channel_submit(struct host1x_job *job)
 {
 	struct host1x_channel *ch = job->channel;
-	struct host1x_syncpt *sp;
+	struct host1x_syncpt *sp = job->syncpt;
 	u32 user_syncpt_incrs = job->syncpt_incrs;
 	u32 prev_max = 0;
 	u32 syncval;
@@ -126,10 +125,9 @@ static int channel_submit(struct host1x_job *job)
 	struct host1x_waitlist *completed_waiter = NULL;
 	struct host1x *host = dev_get_drvdata(ch->dev->parent);
 
-	sp = host->syncpt + job->syncpt_id;
 	trace_host1x_channel_submit(dev_name(ch->dev),
 				    job->num_gathers, job->num_relocs,
-				    job->syncpt_id, job->syncpt_incrs);
+				    job->syncpt->id, job->syncpt_incrs);
 
 	/* before error checks, return current max */
 	prev_max = job->syncpt_end = host1x_syncpt_read_max(sp);
@@ -163,7 +161,7 @@ static int channel_submit(struct host1x_job *job)
 		host1x_cdma_push(&ch->cdma,
 				 host1x_opcode_setclass(HOST1X_CLASS_HOST1X,
 					host1x_uclass_wait_syncpt_r(), 1),
-				 host1x_class_host_wait_syncpt(job->syncpt_id,
+				 host1x_class_host_wait_syncpt(job->syncpt->id,
 					host1x_syncpt_read_max(sp)));
 	}
 
drivers/gpu/host1x/hw/debug_hw.c +1 -1
index f31bcfa1b837..ceb48229d14b 100644
@@ -204,7 +204,7 @@ static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma)
 		unsigned int i;
 
 		host1x_debug_output(o, "\n%p: JOB, syncpt_id=%d, syncpt_val=%d, first_get=%08x, timeout=%d num_slots=%d, num_handles=%d\n",
-				    job, job->syncpt_id, job->syncpt_end,
+				    job, job->syncpt->id, job->syncpt_end,
 				    job->first_get, job->timeout,
 				    job->num_slots, job->num_unpins);
 
drivers/gpu/host1x/job.c +4 -1
index 89b6c14b7392..d8345d3bf0b3 100644
@@ -79,6 +79,9 @@ static void job_free(struct kref *ref)
 {
 	struct host1x_job *job = container_of(ref, struct host1x_job, ref);
 
+	if (job->syncpt)
+		host1x_syncpt_put(job->syncpt);
+
 	kfree(job);
 }
 
@@ -680,7 +683,7 @@ EXPORT_SYMBOL(host1x_job_unpin);
  */
 void host1x_job_dump(struct device *dev, struct host1x_job *job)
 {
-	dev_dbg(dev, "    SYNCPT_ID   %d\n", job->syncpt_id);
+	dev_dbg(dev, "    SYNCPT_ID   %d\n", job->syncpt->id);
 	dev_dbg(dev, "    SYNCPT_VAL  %d\n", job->syncpt_end);
 	dev_dbg(dev, "    FIRST_GET   0x%x\n", job->first_get);
 	dev_dbg(dev, "    TIMEOUT     %d\n", job->timeout);
drivers/gpu/host1x/syncpt.c +57 -18

113 lines not on this page · raw message

drivers/gpu/host1x/syncpt.h +3 -0
index 77e7206cc316..eb49d7003743 100644
@@ -11,6 +11,7 @@
 #include <linux/atomic.h>
 #include <linux/host1x.h>
 #include <linux/kernel.h>
+#include <linux/kref.h>
 #include <linux/sched.h>
 
 #include "intr.h"
@@ -26,6 +27,8 @@ struct host1x_syncpt_base {
 };
 
 struct host1x_syncpt {
+	struct kref ref;
+
 	unsigned int id;
 	atomic_t min_val;
 	atomic_t max_val;
include/linux/host1x.h +5 -3
index f711fc0154f4..da87ceb33c2d 100644
@@ -142,7 +142,9 @@ struct host1x_syncpt_base;
 struct host1x_syncpt;
 struct host1x;
 
-struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, u32 id);
+struct host1x_syncpt *host1x_syncpt_get_by_id(struct host1x *host, u32 id);
+struct host1x_syncpt *host1x_syncpt_get_by_id_noref(struct host1x *host, u32 id);
+struct host1x_syncpt *host1x_syncpt_get(struct host1x_syncpt *sp);
 u32 host1x_syncpt_id(struct host1x_syncpt *sp);
 u32 host1x_syncpt_read_min(struct host1x_syncpt *sp);
 u32 host1x_syncpt_read_max(struct host1x_syncpt *sp);
@@ -153,7 +155,7 @@ int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
 		       u32 *value);
 struct host1x_syncpt *host1x_syncpt_request(struct host1x_client *client,
 					    unsigned long flags);
-void host1x_syncpt_free(struct host1x_syncpt *sp);
+void host1x_syncpt_put(struct host1x_syncpt *sp);
 
 struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
 u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
@@ -218,7 +220,7 @@ struct host1x_job {
 	dma_addr_t *reloc_addr_phys;
 
 	/* Sync point id, number of increments and end related to the submit */
-	u32 syncpt_id;
+	struct host1x_syncpt *syncpt;
 	u32 syncpt_incrs;
 	u32 syncpt_end;
 
Signature · 1 line
2.28.0
#7 lore raw

Re: [RFC PATCH v2 06/17] gpu: host1x: Cleanup and refcounting for syncpoints

05.09.2020 13:34, Mikko Perttunen пишет:
...

Quoted 61 lines
drivers/gpu/host1x/syncpt.c +44 -3
+
+/**
+ * host1x_syncpt_put() - free a requested syncpoint
+ * @sp: host1x syncpoint
+ *
+ * Release a syncpoint previously allocated using host1x_syncpt_request(). A
+ * host1x client driver should call this when the syncpoint is no longer in
+ * use.
+ */
+void host1x_syncpt_put(struct host1x_syncpt *sp)
+{
+	if (!sp)
+		return;
+
+	kref_put(&sp->ref, syncpt_release);
+}
+EXPORT_SYMBOL(host1x_syncpt_put);
 
 void host1x_syncpt_deinit(struct host1x *host)
 {
@@ -471,16 +478,48 @@ unsigned int host1x_syncpt_nb_mlocks(struct host1x *host)
 }
 
 /**
- * host1x_syncpt_get() - obtain a syncpoint by ID
+ * host1x_syncpt_get_by_id() - obtain a syncpoint by ID
+ * @host: host1x controller
+ * @id: syncpoint ID
+ */
+struct host1x_syncpt *host1x_syncpt_get_by_id(struct host1x *host,
+					      unsigned int id)
+{
+	if (id >= host->info->nb_pts)
+		return NULL;
+
+	if (kref_get_unless_zero(&host->syncpt[id].ref))
+		return &host->syncpt[id];
+	else
+		return NULL;
+}
+EXPORT_SYMBOL(host1x_syncpt_get_by_id);
+
+/**
+ * host1x_syncpt_get_by_id_noref() - obtain a syncpoint by ID but don't
+ * 	increase the refcount.
  * @host: host1x controller
  * @id: syncpoint ID
  */
-struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, unsigned int id)
+struct host1x_syncpt *host1x_syncpt_get_by_id_noref(struct host1x *host,
+						    unsigned int id)
 {
 	if (id >= host->info->nb_pts)
 		return NULL;
 
-	return host->syncpt + id;
+	return &host->syncpt[id];
+}
+EXPORT_SYMBOL(host1x_syncpt_get_by_id_noref);
+
+/**

drivers/gpu/host1x/syncpt.c unsigned int host1x_syncpt_nb_mlocks(struct host1x *host) · line 524

Quoted 10 lines
drivers/gpu/host1x/syncpt.c +8 -0
+ * host1x_syncpt_get() - increment syncpoint refcount
+ * @sp: syncpoint
+ */
+struct host1x_syncpt *host1x_syncpt_get(struct host1x_syncpt *sp)
+{
+	kref_get(&sp->ref);
+
+	return sp;
 }
 EXPORT_SYMBOL(host1x_syncpt_get);

Hello, Mikko!

What do you think about to open-code all the host1x structs by moving them all out into the public linux/host1x.h? Then we could inline all these trivial single-line functions by having them defined in the public header. This will avoid all the unnecessary overhead by allowing compiler to optimize the code nicely.

Of course this could be a separate change and it could be done sometime later, I just wanted to share this quick thought for the start of the review.

#8 lore raw

Re: [RFC PATCH v2 06/17] gpu: host1x: Cleanup and refcounting for syncpoints

Quoted 82 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:
...

Quoted 61 lines
drivers/gpu/host1x/syncpt.c +44 -3
+
+/**
+ * host1x_syncpt_put() - free a requested syncpoint
+ * @sp: host1x syncpoint
+ *
+ * Release a syncpoint previously allocated using host1x_syncpt_request(). A
+ * host1x client driver should call this when the syncpoint is no longer in
+ * use.
+ */
+void host1x_syncpt_put(struct host1x_syncpt *sp)
+{
+	if (!sp)
+		return;
+
+	kref_put(&sp->ref, syncpt_release);
+}
+EXPORT_SYMBOL(host1x_syncpt_put);
 
  void host1x_syncpt_deinit(struct host1x *host)
  {
@@ -471,16 +478,48 @@ unsigned int host1x_syncpt_nb_mlocks(struct host1x *host)
  }
 
  /**
- * host1x_syncpt_get() - obtain a syncpoint by ID
+ * host1x_syncpt_get_by_id() - obtain a syncpoint by ID
+ * @host: host1x controller
+ * @id: syncpoint ID
+ */
+struct host1x_syncpt *host1x_syncpt_get_by_id(struct host1x *host,
+					      unsigned int id)
+{
+	if (id >= host->info->nb_pts)
+		return NULL;
+
+	if (kref_get_unless_zero(&host->syncpt[id].ref))
+		return &host->syncpt[id];
+	else
+		return NULL;
+}
+EXPORT_SYMBOL(host1x_syncpt_get_by_id);
+
+/**
+ * host1x_syncpt_get_by_id_noref() - obtain a syncpoint by ID but don't
+ * 	increase the refcount.
   * @host: host1x controller
   * @id: syncpoint ID
   */
-struct host1x_syncpt *host1x_syncpt_get(struct host1x *host, unsigned int id)
+struct host1x_syncpt *host1x_syncpt_get_by_id_noref(struct host1x *host,
+						    unsigned int id)
  {
  	if (id >= host->info->nb_pts)
  		return NULL;
 
-	return host->syncpt + id;
+	return &host->syncpt[id];
+}
+EXPORT_SYMBOL(host1x_syncpt_get_by_id_noref);
+
+/**

drivers/gpu/host1x/syncpt.c unsigned int host1x_syncpt_nb_mlocks(struct host1x *host) · line 524

Quoted 10 lines
drivers/gpu/host1x/syncpt.c +8 -0
+ * host1x_syncpt_get() - increment syncpoint refcount
+ * @sp: syncpoint
+ */
+struct host1x_syncpt *host1x_syncpt_get(struct host1x_syncpt *sp)
+{
+	kref_get(&sp->ref);
+
+	return sp;
  }
  EXPORT_SYMBOL(host1x_syncpt_get);

Hello, Mikko!

What do you think about to open-code all the host1x structs by moving them all out into the public linux/host1x.h? Then we could inline all these trivial single-line functions by having them defined in the public header. This will avoid all the unnecessary overhead by allowing compiler to optimize the code nicely.

Quoted 4 lines

Of course this could be a separate change and it could be done sometime later, I just wanted to share this quick thought for the start of the review.

Hi :)

I think for such micro-optimizations we should have a benchmark to evaluate against. I'm not sure we have all that many function calls into here overall that it would make a noticeable difference. In any case, as you said, I'd prefer to keep further refactoring to a separate series to avoid growing this series too much.

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

#9 lore raw

Re: [RFC PATCH v2 06/17] gpu: host1x: Cleanup and refcounting for syncpoints

05.09.2020 17:53, Mikko Perttunen пишет:
...

Quoted 13 lines
Quoted 8 lines

Hello, Mikko!

What do you think about to open-code all the host1x structs by moving them all out into the public linux/host1x.h? Then we could inline all these trivial single-line functions by having them defined in the public header. This will avoid all the unnecessary overhead by allowing compiler to optimize the code nicely.

Quoted 4 lines

Of course this could be a separate change and it could be done sometime later, I just wanted to share this quick thought for the start of the review.

Quoted 7 lines

Hi :)

I think for such micro-optimizations we should have a benchmark to evaluate against. I'm not sure we have all that many function calls into here overall that it would make a noticeable difference. In any case, as you said, I'd prefer to keep further refactoring to a separate series to avoid growing this series too much.

The performance difference doesn't bother me, it should be insignificant in this particular case. The amount of the exported functions is what makes me feel uncomfortable, and especially that most of those functions are trivial.

My concern is that doing cleanups of the upstream drivers usually not easy. Hence it could be a good thing to put effort into restructuring the current code before new code is added. But at first we need to have a full-featured draft implementation that will show what parts of the driver require refactoring.

#10 lore raw

Re: [RFC PATCH v2 06/17] gpu: host1x: Cleanup and refcounting for syncpoints

Quoted 23 lines · Dmitry Osipenko

05.09.2020 17:53, Mikko Perttunen пишет:
...

Quoted 13 lines
Quoted 8 lines

Hello, Mikko!

What do you think about to open-code all the host1x structs by moving them all out into the public linux/host1x.h? Then we could inline all these trivial single-line functions by having them defined in the public header. This will avoid all the unnecessary overhead by allowing compiler to optimize the code nicely.

Quoted 4 lines

Of course this could be a separate change and it could be done sometime later, I just wanted to share this quick thought for the start of the review.

Quoted 7 lines

Hi :)

I think for such micro-optimizations we should have a benchmark to evaluate against. I'm not sure we have all that many function calls into here overall that it would make a noticeable difference. In any case, as you said, I'd prefer to keep further refactoring to a separate series to avoid growing this series too much.

Quoted 4 lines

The performance difference doesn't bother me, it should be insignificant in this particular case. The amount of the exported functions is what makes me feel uncomfortable, and especially that most of those functions are trivial.

I don't see a particular problem with this -- I think it's better to keep the data structures in the driver-internal headers to to improve modularization. I think we can get rid of the syncpt_get_by_id* functions once we remove the staging code, so that would clean up things as well.

Quoted 7 lines

My concern is that doing cleanups of the upstream drivers usually not easy. Hence it could be a good thing to put effort into restructuring the current code before new code is added. But at first we need to have a full-featured draft implementation that will show what parts of the driver require refactoring.

My feeling is that once we have the new UAPI implemented, refactoring will be easier because we have a better idea of what we need of the code, and we will be able to remove the staging code, allowing removal or easier refactoring of many old paths.

While doing that, some of the new code will have to be changed again as well, sure, but at least the entire time we will have a functional implementation.

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

author maintainer
#11 lore raw

RFC PATCH v2 7/17 gpu: host1x: Introduce UAPI header

In reply to Mikko Perttunen

Add the userspace interface header, specifying interfaces for allocating and accessing syncpoints from userspace, and for creating sync_file based fences based on syncpoint thresholds.

---
 include/uapi/linux/host1x.h | 134 ++++++++++++++++++++++++++++++++++++
 1 file changed, 134 insertions(+)
 create mode 100644 include/uapi/linux/host1x.h
include/uapi/linux/host1x.h new file +134 -0
new file mode 100644
index 000000000000..9c8fb9425cb2
@@ -0,0 +1,134 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* Copyright (c) 2020 NVIDIA Corporation */
+
+#ifndef _UAPI__LINUX_HOST1X_H
+#define _UAPI__LINUX_HOST1X_H
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+struct host1x_allocate_syncpoint {
+	/**
+	 * @fd: [out]
+	 *
+	 * New file descriptor representing the allocated syncpoint.
+	 */
+	__s32 fd;
+
+	__u32 reserved[3];
+};
+
+struct host1x_syncpoint_info {
+	/**
+	 * @id: [out]
+	 *
+	 * System-global ID of the syncpoint.
+	 */
+	__u32 id;
+
+	__u32 reserved[3];
+};
+
+struct host1x_syncpoint_increment {
+	/**
+	 * @count: [in]
+	 *
+	 * Number of times to increment the syncpoint. The syncpoint can
+	 * be observed at in-between values, but each increment is atomic.
+	 */
+	__u32 count;
+};
+
+struct host1x_read_syncpoint {
+	/**
+	 * @id: [in]
+	 *
+	 * ID of the syncpoint to read.
+	 */
+	__u32 id;
+
+	/**
+	 * @value: [out]
+	 *
+	 * Current value of the syncpoint.
+	 */
+	__u32 value;
+};
+
+struct host1x_create_fence {
+	/**
+	 * @id: [in]
+	 *
+	 * ID of the syncpoint to create a fence for.
+	 */
+	__u32 id;
+
+	/**
+	 * @threshold: [in]
+	 *
+	 * When the syncpoint reaches this value, the fence will be signaled.
+	 * The syncpoint is considered to have reached the threshold when the
+	 * following condition is true:
+	 *
+	 * 	((value - threshold) & 0x80000000U) == 0U
+	 *
+	 */
+	__u32 threshold;
+
+	/**
+	 * @fence_fd: [out]
+	 *
+	 * New sync_file file descriptor containing the created fence.
+	 */
+	__s32 fence_fd;
+
+	__u32 reserved[1];
+};
+
+struct host1x_fence_extract_fence {
+	__u32 id;
+	__u32 threshold;
+};
+
+struct host1x_fence_extract {
+	/**
+	 * @fence_fd: [in]
+	 *
+	 * sync_file file descriptor
+	 */
+	__s32 fence_fd;
+
+	/**
+	 * @num_fences: [in,out]
+	 *
+	 * In: size of the `fences_ptr` array counted in elements.
+	 * Out: required size of the `fences_ptr` array counted in elements.
+	 */
+	__u32 num_fences;
+
+	/**
+	 * @fences_ptr: [in]
+	 *
+	 * Pointer to array of `struct host1x_fence_extract_fence`.
+	 */
+	__u64 fences_ptr;
+
+	__u32 reserved[2];
+};
+
+#define HOST1X_IOCTL_ALLOCATE_SYNCPOINT  _IOWR('X', 0x00, struct host1x_allocate_syncpoint)
+#define HOST1X_IOCTL_READ_SYNCPOINT      _IOR ('X', 0x01, struct host1x_read_syncpoint)
+#define HOST1X_IOCTL_CREATE_FENCE        _IOWR('X', 0x02, struct host1x_create_fence)
+#define HOST1X_IOCTL_SYNCPOINT_INFO      _IOWR('X', 0x03, struct host1x_syncpoint_info)
+#define HOST1X_IOCTL_SYNCPOINT_INCREMENT _IOWR('X', 0x04, struct host1x_syncpoint_increment)
+#define HOST1X_IOCTL_FENCE_EXTRACT       _IOWR('X', 0x05, struct host1x_fence_extract)
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
Signature · 6 lines
2.28.0

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

RFC PATCH v2 8/17 gpu: host1x: Implement /dev/host1x device node

In reply to Mikko Perttunen

Add the /dev/host1x device node, implementing the following functionality:

- Reading syncpoint values
- Allocating syncpoints (providing syncpoint FDs)
- Incrementing syncpoints (based on syncpoint FD)

---
 drivers/gpu/host1x/Makefile |   1 +
 drivers/gpu/host1x/dev.c    |   9 ++
 drivers/gpu/host1x/dev.h    |   3 +
 drivers/gpu/host1x/uapi.c   | 275 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/host1x/uapi.h   |  22 +++
 include/linux/host1x.h      |   2 +
 6 files changed, 312 insertions(+)
 create mode 100644 drivers/gpu/host1x/uapi.c
 create mode 100644 drivers/gpu/host1x/uapi.h
drivers/gpu/host1x/Makefile +1 -0
index 096017b8789d..882f928d75e1 100644
@@ -9,6 +9,7 @@ host1x-y = \
 	job.o \
 	debug.o \
 	mipi.o \
+	uapi.o \
 	hw/host1x01.o \
 	hw/host1x02.o \
 	hw/host1x04.o \
drivers/gpu/host1x/dev.c +9 -0
index d0ebb70e2fdd..641317d23828 100644
@@ -461,6 +461,12 @@ static int host1x_probe(struct platform_device *pdev)
 		goto deinit_syncpt;
 	}
 
+	err = host1x_uapi_init(&host->uapi, host);
+	if (err) {
+		dev_err(&pdev->dev, "failed to initialize uapi\n");
+		goto deinit_intr;
+	}
+
 	host1x_debug_init(host);
 
 	if (host->info->has_hypervisor)
@@ -480,6 +486,8 @@ static int host1x_probe(struct platform_device *pdev)
 	host1x_unregister(host);
 deinit_debugfs:
 	host1x_debug_deinit(host);
+	host1x_uapi_deinit(&host->uapi);
+deinit_intr:
 	host1x_intr_deinit(host);
 deinit_syncpt:
 	host1x_syncpt_deinit(host);
@@ -501,6 +509,7 @@ static int host1x_remove(struct platform_device *pdev)
 
 	host1x_unregister(host);
 	host1x_debug_deinit(host);
+	host1x_uapi_deinit(&host->uapi);
 	host1x_intr_deinit(host);
 	host1x_syncpt_deinit(host);
 	reset_control_assert(host->rst);
drivers/gpu/host1x/dev.h +3 -0
index 63010ae37a97..7b8b7e20e32b 100644
@@ -17,6 +17,7 @@
 #include "intr.h"
 #include "job.h"
 #include "syncpt.h"
+#include "uapi.h"
 
 struct host1x_syncpt;
 struct host1x_syncpt_base;
@@ -143,6 +144,8 @@ struct host1x {
 	struct list_head list;
 
 	struct device_dma_parameters dma_parms;
+
+	struct host1x_uapi uapi;
 };
 
 void host1x_hypervisor_writel(struct host1x *host1x, u32 r, u32 v);
drivers/gpu/host1x/uapi.c new file +275 -0

275 lines not on this page · raw message

drivers/gpu/host1x/uapi.h new file +22 -0
new file mode 100644
index 000000000000..7beb5e44c1b1
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2020, NVIDIA Corporation.
+ */
+
+#ifndef HOST1X_UAPI_H
+#define HOST1X_UAPI_H
+
+#include <linux/cdev.h>
+
+struct host1x_uapi {
+	struct class *class;
+
+	struct cdev cdev;
+	struct device *dev;
+	dev_t dev_num;
+};
+
+int host1x_uapi_init(struct host1x_uapi *uapi, struct host1x *host1x);
+void host1x_uapi_deinit(struct host1x_uapi *uapi);
+
+#endif
include/linux/host1x.h +2 -0
index da87ceb33c2d..b970e1bbc29d 100644
@@ -160,6 +160,8 @@ void host1x_syncpt_put(struct host1x_syncpt *sp);
 struct host1x_syncpt_base *host1x_syncpt_get_base(struct host1x_syncpt *sp);
 u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
 
+struct host1x_syncpt *host1x_syncpt_fd_get(int fd);
+
 /*
  * host1x channel
  */
Signature · 6 lines
2.28.0

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

RFC PATCH v2 9/17 gpu: host1x: DMA fences and userspace fence creation

In reply to Mikko Perttunen

Add an implementation of dma_fences based on syncpoints. Syncpoint interrupts are used to signal fences. Additionally, after software signaling has been enabled, a 30 second timeout is started. If the syncpoint threshold is not reached within this period, the fence is signalled with an -ETIMEDOUT error code. This is to allow fences that would never reach their syncpoint threshold to be cleaned up.

Additionally, add a new /dev/host1x IOCTL for creating sync_file file descriptors backed by syncpoint fences.

---
 drivers/gpu/host1x/Makefile |   1 +
 drivers/gpu/host1x/fence.c  | 207 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/host1x/fence.h  |  15 +++
 drivers/gpu/host1x/intr.c   |   9 ++
 drivers/gpu/host1x/intr.h   |   2 +
 drivers/gpu/host1x/uapi.c   | 106 ++++++++++++++++++
 include/linux/host1x.h      |   3 +
 7 files changed, 343 insertions(+)
 create mode 100644 drivers/gpu/host1x/fence.c
 create mode 100644 drivers/gpu/host1x/fence.h
drivers/gpu/host1x/Makefile +1 -0
index 882f928d75e1..a48af2cefae1 100644
@@ -10,6 +10,7 @@ host1x-y = \
 	debug.o \
 	mipi.o \
 	uapi.o \
+	fence.o \
 	hw/host1x01.o \
 	hw/host1x02.o \
 	hw/host1x04.o \
drivers/gpu/host1x/fence.c new file +207 -0

207 lines not on this page · raw message

drivers/gpu/host1x/fence.h new file +15 -0
new file mode 100644
index 000000000000..e36dfc11cca4
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2020, NVIDIA Corporation.
+ */
+
+#ifndef HOST1X_FENCE_H
+#define HOST1X_FENCE_H
+
+struct host1x_syncpt_fence;
+
+bool host1x_fence_signal(struct host1x_syncpt_fence *fence);
+
+int host1x_fence_extract(struct dma_fence *fence, u32 *id, u32 *threshold);
+
+#endif
drivers/gpu/host1x/intr.c +9 -0
index 5d328d20ce6d..19b59c5c94d0 100644
@@ -13,6 +13,7 @@
 #include <trace/events/host1x.h>
 #include "channel.h"
 #include "dev.h"
+#include "fence.h"
 #include "intr.h"
 
 /* Wait list management */
@@ -121,12 +122,20 @@ static void action_wakeup_interruptible(struct host1x_waitlist *waiter)
 	wake_up_interruptible(wq);
 }
 
+static void action_signal_fence(struct host1x_waitlist *waiter)
+{
+	struct host1x_syncpt_fence *f = waiter->data;
+
+	host1x_fence_signal(f);
+}
+
 typedef void (*action_handler)(struct host1x_waitlist *waiter);
 
 static const action_handler action_handlers[HOST1X_INTR_ACTION_COUNT] = {
 	action_submit_complete,
 	action_wakeup,
 	action_wakeup_interruptible,
+	action_signal_fence,
 };
 
 static void run_handlers(struct list_head completed[HOST1X_INTR_ACTION_COUNT])
drivers/gpu/host1x/intr.h +2 -0
index aac38194398f..dedbd0f700fb 100644
@@ -33,6 +33,8 @@ enum host1x_intr_action {
 	 */
 	HOST1X_INTR_ACTION_WAKEUP_INTERRUPTIBLE,
 
+	HOST1X_INTR_ACTION_SIGNAL_FENCE,
+
 	HOST1X_INTR_ACTION_COUNT
 };
 
drivers/gpu/host1x/uapi.c +106 -0

126 lines not on this page · raw message

include/linux/host1x.h +3 -0
index b970e1bbc29d..73a247e180a9 100644
@@ -162,6 +162,9 @@ u32 host1x_syncpt_base_id(struct host1x_syncpt_base *base);
 
 struct host1x_syncpt *host1x_syncpt_fd_get(int fd);
 
+struct dma_fence *host1x_fence_create(struct host1x_syncpt *sp, u32 threshold);
+int host1x_fence_create_fd(struct host1x_syncpt *sp, u32 threshold);
+
 /*
  * host1x channel
  */
Signature · 6 lines
2.28.0

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

Re: [RFC PATCH v2 09/17] gpu: host1x: DMA fences and userspace fence creation

05.09.2020 13:34, Mikko Perttunen пишет:
...

Quoted 6 lines
drivers/gpu/host1x/intr.c +5 -0
+static void action_signal_fence(struct host1x_waitlist *waiter)
+{
+	struct host1x_syncpt_fence *f = waiter->data;
+
+	host1x_fence_signal(f);

drivers/gpu/host1x/intr.c static void action_wakeup_interruptible(struct host1x_waitlist *waiter) · line 139

Quoted 10 lines
drivers/gpu/host1x/intr.c +3 -0
+}
+
 typedef void (*action_handler)(struct host1x_waitlist *waiter);
 
 static const action_handler action_handlers[HOST1X_INTR_ACTION_COUNT] = {
 	action_submit_complete,
 	action_wakeup,
 	action_wakeup_interruptible,
+	action_signal_fence,
 };

My expectation is that we should remove the host1x-waiter entirely. It comes from 2011/2012 era of the host1x driver and now duplicates functionality provided by the dma-fence and drm-scheduler. Perhaps it could be okay to re-use existing code for the starter, but this is something to keep in mind that it may be better not to put much effort into the older code.

#15 lore raw

Re: [RFC PATCH v2 09/17] gpu: host1x: DMA fences and userspace fence creation

Quoted 12 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:
...

Quoted 10 lines
drivers/gpu/host1x/intr.c +7 -0
+static void action_signal_fence(struct host1x_waitlist *waiter)
+{
+	struct host1x_syncpt_fence *f = waiter->data;
+
+	host1x_fence_signal(f);
+}
+
  typedef void (*action_handler)(struct host1x_waitlist *waiter);
Quoted 14 lines

drivers/gpu/host1x/intr.c static void action_wakeup_interruptible(struct host1x_waitlist *waiter) · line 139

Quoted 6 lines
  static const action_handler action_handlers[HOST1X_INTR_ACTION_COUNT] = {
  	action_submit_complete,
  	action_wakeup,
  	action_wakeup_interruptible,
drivers/gpu/host1x/intr.c +1 -0
+	action_signal_fence,
  };

My expectation is that we should remove the host1x-waiter entirely. It comes from 2011/2012 era of the host1x driver and now duplicates functionality provided by the dma-fence and drm-scheduler. Perhaps it could be okay to re-use existing code for the starter, but this is something to keep in mind that it may be better not to put much effort into the older code.

Agreed, it should be cleaned up and probably replaced. I made only minimal changes here to get all my tests working, as I didn't want to do a full refactoring in this patch series.

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

author maintainer
#16 lore raw

RFC PATCH v2 10/17 WIP: gpu: host1x: Add no-recovery mode

In reply to Mikko Perttunen

Add a new property for jobs to enable or disable recovery i.e. CPU increments of syncpoints to max value on job timeout. This allows for a more solid model for hanged jobs, where userspace doesn't need to guess if a syncpoint increment happened because the job completed, or because job timeout was triggered.

On job timeout, we stop the channel, NOP all future jobs on the channel using the same syncpoint, mark the syncpoint as locked and resume the channel from the next job, if any.

The future jobs are NOPed, since because we don't do the CPU increments, the value of the syncpoint is no longer synchronized, and any waiters would become confused if a future job incremented the syncpoint. The syncpoint is marked locked to ensure that any future jobs cannot increment the syncpoint either, until the application has recognized the situation and reallocated the syncpoint.

WIP: There is a race condition between the locking and submission:
* Submission passes locking check
* Concurrent existing job timeouts, locking the syncpoint
* Submission still goes ahead

---
 drivers/gpu/drm/tegra/drm.c        |  1 +
 drivers/gpu/host1x/cdma.c          | 42 +++++++++++++++++++++++++-----
 drivers/gpu/host1x/hw/channel_hw.c |  6 ++++-
 drivers/gpu/host1x/job.c           |  4 +++
 drivers/gpu/host1x/syncpt.c        |  2 ++
 drivers/gpu/host1x/syncpt.h        | 12 +++++++++
 include/linux/host1x.h             |  9 +++++++
 7 files changed, 69 insertions(+), 7 deletions(-)
drivers/gpu/drm/tegra/drm.c +1 -0
index ceea9db341f0..7437c67924aa 100644
@@ -197,6 +197,7 @@ int tegra_drm_submit(struct tegra_drm_context *context,
 	job->client = client;
 	job->class = client->class;
 	job->serialize = true;
+	job->syncpt_recovery = true;
 
 	/*
 	 * Track referenced BOs so that they can be unreferenced after the
drivers/gpu/host1x/cdma.c +36 -6

69 lines not on this page · raw message

drivers/gpu/host1x/hw/channel_hw.c +5 -1
index d4c28faf27d1..145746c6f6fb 100644
@@ -129,6 +129,10 @@ static int channel_submit(struct host1x_job *job)
 				    job->num_gathers, job->num_relocs,
 				    job->syncpt->id, job->syncpt_incrs);
 
+	/* TODO this is racy */
+	if (job->syncpt->locked)
+		return -EPERM;
+
 	/* before error checks, return current max */
 	prev_max = job->syncpt_end = host1x_syncpt_read_max(sp);
 
@@ -191,7 +195,7 @@ static int channel_submit(struct host1x_job *job)
 	/* schedule a submit complete interrupt */
 	err = host1x_intr_add_action(host, sp, syncval,
 				     HOST1X_INTR_ACTION_SUBMIT_COMPLETE, ch,
-				     completed_waiter, NULL);
+				     completed_waiter, &job->waiter);
 	completed_waiter = NULL;
 	WARN(err, "Failed to set submit complete interrupt");
 
drivers/gpu/host1x/job.c +4 -0
index d8345d3bf0b3..e4f16fc899b0 100644
@@ -79,6 +79,10 @@ static void job_free(struct kref *ref)
 {
 	struct host1x_job *job = container_of(ref, struct host1x_job, ref);
 
+	if (job->waiter)
+		host1x_intr_put_ref(job->syncpt->host, job->syncpt->id,
+				    job->waiter);
+
 	if (job->syncpt)
 		host1x_syncpt_put(job->syncpt);
 
drivers/gpu/host1x/syncpt.c +2 -0
index b31b994624fa..2fad8b2a55cc 100644
@@ -385,6 +385,8 @@ static void syncpt_release(struct kref *ref)
 {
 	struct host1x_syncpt *sp = container_of(ref, struct host1x_syncpt, ref);
 
+	sp->locked = false;
+
 	mutex_lock(&sp->host->syncpt_mutex);
 
 	host1x_syncpt_base_free(sp->base);
drivers/gpu/host1x/syncpt.h +12 -0
index eb49d7003743..d19461704ea2 100644
@@ -40,6 +40,13 @@ struct host1x_syncpt {
 
 	/* interrupt data */
 	struct host1x_syncpt_intr intr;
+
+	/* 
+	 * If a submission incrementing this syncpoint fails, lock it so that
+	 * further submission cannot be made until application has handled the
+	 * failure.
+	 */
+	bool locked;
 };
 
 /* Initialize sync point array  */
@@ -120,4 +127,9 @@ struct host1x_syncpt *host1x_syncpt_alloc(struct host1x *host,
 					  struct host1x_client *client,
 					  unsigned long flags);
 
+static inline void host1x_syncpt_set_locked(struct host1x_syncpt *sp)
+{
+	sp->locked = true;
+}
+
 #endif
include/linux/host1x.h +9 -0
index 73a247e180a9..3ffe16152ebc 100644
@@ -229,9 +229,15 @@ struct host1x_job {
 	u32 syncpt_incrs;
 	u32 syncpt_end;
 
+	/* Completion waiter ref */
+	void *waiter;
+
 	/* Maximum time to wait for this job */
 	unsigned int timeout;
 
+	/* Job has timed out and should be released */
+	bool cancelled;
+
 	/* Index and number of slots used in the push buffer */
 	unsigned int first_get;
 	unsigned int num_slots;
@@ -252,6 +258,9 @@ struct host1x_job {
 
 	/* Add a channel wait for previous ops to complete */
 	bool serialize;
+
+	/* Fast-forward syncpoint increments on job timeout */
+	bool syncpt_recovery;
 };
 
 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
Signature · 6 lines
2.28.0

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

Re: [RFC PATCH v2 10/17] WIP: gpu: host1x: Add no-recovery mode

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 11 lines
drivers/gpu/host1x/cdma.c +11 -0
+	} else {
+		struct host1x_job *failed_job = job;
+
+		host1x_job_dump(dev, job);
+
+		host1x_syncpt_set_locked(job->syncpt);
+		failed_job->cancelled = true;
+
+		list_for_each_entry_continue(job, &cdma->sync_queue, list) {
+			unsigned int i;
+

drivers/gpu/host1x/cdma.c void host1x_cdma_update_sync_queue(struct host1x_cdma *cdma, · line 456

Quoted 10 lines
drivers/gpu/host1x/cdma.c +10 -0
+			if (job->syncpt != failed_job->syncpt)
+				continue;
+
+			for (i = 0; i < job->num_slots; i++) {
+				unsigned int slot = (job->first_get/8 + i) %
+						    HOST1X_PUSHBUFFER_SLOTS;
+				u32 *mapped = cdma->push_buffer.mapped;
+
+				mapped[2*slot+0] = 0x1bad0000;
+				mapped[2*slot+1] = 0x1bad0000;

The 0x1bad0000 is a valid memory address on Tegra20.

The 0x60000000 is invalid phys address for all hardware generations. It's used by grate-kernel [1] and VDE driver [2]. Note that the 0x6 << 28 is also invalid Host1x opcode, while 0x1 should break CDMA parser during of PB debug-dumping.

[1]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/drm/tegra/gem.h#L16

[2]
https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/staging/media/tegra-vde/iommu.c#L99

The VDE driver reserves the trapping IOVA addresses, I assume the Host1x driver should do the same.

#18 lore raw

Re: [RFC PATCH v2 10/17] WIP: gpu: host1x: Add no-recovery mode

Quoted 30 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 11 lines
drivers/gpu/host1x/cdma.c +11 -0
+	} else {
+		struct host1x_job *failed_job = job;
+
+		host1x_job_dump(dev, job);
+
+		host1x_syncpt_set_locked(job->syncpt);
+		failed_job->cancelled = true;
+
+		list_for_each_entry_continue(job, &cdma->sync_queue, list) {
+			unsigned int i;
+

drivers/gpu/host1x/cdma.c void host1x_cdma_update_sync_queue(struct host1x_cdma *cdma, · line 456

Quoted 10 lines
drivers/gpu/host1x/cdma.c +10 -0
+			if (job->syncpt != failed_job->syncpt)
+				continue;
+
+			for (i = 0; i < job->num_slots; i++) {
+				unsigned int slot = (job->first_get/8 + i) %
+						    HOST1X_PUSHBUFFER_SLOTS;
+				u32 *mapped = cdma->push_buffer.mapped;
+
+				mapped[2*slot+0] = 0x1bad0000;
+				mapped[2*slot+1] = 0x1bad0000;

The 0x1bad0000 is a valid memory address on Tegra20.

The 0x60000000 is invalid phys address for all hardware generations. It's used by grate-kernel [1] and VDE driver [2]. Note that the 0x6 << 28 is also invalid Host1x opcode, while 0x1 should break CDMA parser during of PB debug-dumping.

Quoted 9 lines

[1]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/drm/tegra/gem.h#L16

[2]
https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/staging/media/tegra-vde/iommu.c#L99

The VDE driver reserves the trapping IOVA addresses, I assume the Host1x driver should do the same.

The 0x1bad0000's are not intended to be memory addresses, they are NOOP opcodes (INCR of 0 words to offset 0xbad). I'll fix this to use proper functions to construct the opcodes and add some comments. These need to be NOOP opcodes so the command parser skips over these "cancelled" jobs when the channel is resumed.

BTW, 0x60000000 is valid on Tegra194 and later.

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

#19 lore raw

Re: [RFC PATCH v2 10/17] WIP: gpu: host1x: Add no-recovery mode

12.09.2020 01:11, Mikko Perttunen пишет:

Quoted 43 lines · Dmitry Osipenko
Quoted 34 lines

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 11 lines

+    } else {
+        struct host1x_job *failed_job = job;

drivers/gpu/host1x/cdma.c +9 -0
+
+        host1x_job_dump(dev, job);
+
+        host1x_syncpt_set_locked(job->syncpt);
+        failed_job->cancelled = true;
+
+        list_for_each_entry_continue(job, &cdma->sync_queue, list) {
+            unsigned int i;
+

drivers/gpu/host1x/cdma.c void host1x_cdma_update_sync_queue(struct host1x_cdma *cdma, · line 456

Quoted 10 lines
drivers/gpu/host1x/cdma.c +10 -0
+            if (job->syncpt != failed_job->syncpt)
+                continue;
+
+            for (i = 0; i < job->num_slots; i++) {
+                unsigned int slot = (job->first_get/8 + i) %
+                            HOST1X_PUSHBUFFER_SLOTS;
+                u32 *mapped = cdma->push_buffer.mapped;
+
+                mapped[2*slot+0] = 0x1bad0000;
+                mapped[2*slot+1] = 0x1bad0000;

The 0x1bad0000 is a valid memory address on Tegra20.

The 0x60000000 is invalid phys address for all hardware generations. It's used by grate-kernel [1] and VDE driver [2]. Note that the 0x6 << 28 is also invalid Host1x opcode, while 0x1 should break CDMA parser during of PB debug-dumping.

[1]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/drm/tegra/gem.h#L16

Quoted 7 lines

[2]
https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/staging/media/tegra-vde/iommu.c#L99

The VDE driver reserves the trapping IOVA addresses, I assume the Host1x driver should do the same.

Quoted 7 lines

The 0x1bad0000's are not intended to be memory addresses, they are NOOP opcodes (INCR of 0 words to offset 0xbad). I'll fix this to use proper functions to construct the opcodes and add some comments. These need to be NOOP opcodes so the command parser skips over these "cancelled" jobs when the channel is resumed.

BTW, 0x60000000 is valid on Tegra194 and later.

At a quick glance it looked like a memory address :)

I'm now taking a closer look at this patch and it raises some more questions, like for example by looking at the "On job timeout, we stop the channel, NOP all future jobs on the channel using the same syncpoint ..." through the prism of grate-kernel experience, I'm not sure how it could co-exist with the drm-scheduler and why it's needed at all. But I think we need a feature-complete version (at least a rough version), so that we could start the testing, and then it should be easier to review and discuss such things.

#20 lore raw

Re: [RFC PATCH v2 10/17] WIP: gpu: host1x: Add no-recovery mode

Quoted 50 lines · Dmitry Osipenko

12.09.2020 01:11, Mikko Perttunen пишет:

Quoted 49 lines · Dmitry Osipenko
Quoted 34 lines

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 11 lines

+    } else {
+        struct host1x_job *failed_job = job;

drivers/gpu/host1x/cdma.c +9 -0
+
+        host1x_job_dump(dev, job);
+
+        host1x_syncpt_set_locked(job->syncpt);
+        failed_job->cancelled = true;
+
+        list_for_each_entry_continue(job, &cdma->sync_queue, list) {
+            unsigned int i;
+

drivers/gpu/host1x/cdma.c void host1x_cdma_update_sync_queue(struct host1x_cdma *cdma, · line 456

Quoted 10 lines
drivers/gpu/host1x/cdma.c +10 -0
+            if (job->syncpt != failed_job->syncpt)
+                continue;
+
+            for (i = 0; i < job->num_slots; i++) {
+                unsigned int slot = (job->first_get/8 + i) %
+                            HOST1X_PUSHBUFFER_SLOTS;
+                u32 *mapped = cdma->push_buffer.mapped;
+
+                mapped[2*slot+0] = 0x1bad0000;
+                mapped[2*slot+1] = 0x1bad0000;

The 0x1bad0000 is a valid memory address on Tegra20.

The 0x60000000 is invalid phys address for all hardware generations. It's used by grate-kernel [1] and VDE driver [2]. Note that the 0x6 << 28 is also invalid Host1x opcode, while 0x1 should break CDMA parser during of PB debug-dumping.

[1]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/drm/tegra/gem.h#L16

Quoted 7 lines

[2]
https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/staging/media/tegra-vde/iommu.c#L99

The VDE driver reserves the trapping IOVA addresses, I assume the Host1x driver should do the same.

The 0x1bad0000's are not intended to be memory addresses, they are NOOP opcodes (INCR of 0 words to offset 0xbad). I'll fix this to use proper functions to construct the opcodes and add some comments. These need to be NOOP opcodes so the command parser skips over these "cancelled" jobs when the channel is resumed.

Quoted 3 lines
Quoted 1 line

BTW, 0x60000000 is valid on Tegra194 and later.

At a quick glance it looked like a memory address :)

It does look a bit like one :) I'll add a comment to make it clear.

Quoted 10 lines

I'm now taking a closer look at this patch and it raises some more questions, like for example by looking at the "On job timeout, we stop the channel, NOP all future jobs on the channel using the same syncpoint ..." through the prism of grate-kernel experience, I'm not sure how it could co-exist with the drm-scheduler and why it's needed at all. But I think we need a feature-complete version (at least a rough version), so that we could start the testing, and then it should be easier to review and discuss such things.

The reason this is needed is that if a job times out and we don't do its syncpoint increments on the CPU, then a successive job incrementing that same syncpoint would cause fences to signal incorrectly. The job that was supposed to signal those fences didn't actually run; and any data those fences were protecting would still be garbage.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#21 lore raw

Re: [RFC PATCH v2 10/17] WIP: gpu: host1x: Add no-recovery mode

12.09.2020 16:31, Mikko Perttunen пишет:
...

Quoted 10 lines
Quoted 9 lines

I'm now taking a closer look at this patch and it raises some more questions, like for example by looking at the "On job timeout, we stop the channel, NOP all future jobs on the channel using the same syncpoint ..." through the prism of grate-kernel experience, I'm not sure how it could co-exist with the drm-scheduler and why it's needed at all. But I think we need a feature-complete version (at least a rough version), so that we could start the testing, and then it should be easier to review and discuss such things.

Quoted 5 lines

The reason this is needed is that if a job times out and we don't do its syncpoint increments on the CPU, then a successive job incrementing that same syncpoint would cause fences to signal incorrectly. The job that was supposed to signal those fences didn't actually run; and any data those fences were protecting would still be garbage.

I'll need to re-read the previous discussion because IIRC, I was suggesting that once job is hung, all jobs should be removed from queue/PB and re-submitted, then the re-submitted jobs will use the new/updated sync point base.

And we probably should need another drm_tegra_submit_cmd type that waits for a relative sync point increment. The drm_tegra_submit_cmd_wait_syncpt uses absolute sync point value and it shouldn't be used for sync point increments that are internal to a job because it complicates the recovery.

All waits that are internal to a job should only wait for relative sync point increments.

In the grate-kernel every job uses unique-and-clean sync point (which is also internal to the kernel driver) and a relative wait [1] is used for the job's internal sync point increments [2][3][4], and thus, kernel driver simply jumps over a hung job by updating DMAGET to point at the start of a next job.

[1]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/drm/tegra/uapi/patching.c#L367

[2]
https://github.com/grate-driver/xf86-video-opentegra/blob/master/src/gpu/gr3d.c#L486
[3]
https://github.com/grate-driver/xf86-video-opentegra/blob/master/src/exa/copy_2d.c#L389
[4]
https://github.com/grate-driver/xf86-video-opentegra/blob/master/src/gpu/tegra_stream_v2.c#L536

#22 lore raw

Re: [RFC PATCH v2 10/17] WIP: gpu: host1x: Add no-recovery mode

Quoted 28 lines · Dmitry Osipenko

12.09.2020 16:31, Mikko Perttunen пишет:
...

Quoted 10 lines
Quoted 9 lines

I'm now taking a closer look at this patch and it raises some more questions, like for example by looking at the "On job timeout, we stop the channel, NOP all future jobs on the channel using the same syncpoint ..." through the prism of grate-kernel experience, I'm not sure how it could co-exist with the drm-scheduler and why it's needed at all. But I think we need a feature-complete version (at least a rough version), so that we could start the testing, and then it should be easier to review and discuss such things.

Quoted 5 lines

The reason this is needed is that if a job times out and we don't do its syncpoint increments on the CPU, then a successive job incrementing that same syncpoint would cause fences to signal incorrectly. The job that was supposed to signal those fences didn't actually run; and any data those fences were protecting would still be garbage.

I'll need to re-read the previous discussion because IIRC, I was suggesting that once job is hung, all jobs should be removed from queue/PB and re-submitted, then the re-submitted jobs will use the new/updated sync point base. >
And we probably should need another drm_tegra_submit_cmd type that waits for a relative sync point increment. The drm_tegra_submit_cmd_wait_syncpt uses absolute sync point value and it shouldn't be used for sync point increments that are internal to a job because it complicates the recovery.

Quoted 7 lines

All waits that are internal to a job should only wait for relative sync point increments. >
In the grate-kernel every job uses unique-and-clean sync point (which is also internal to the kernel driver) and a relative wait [1] is used for the job's internal sync point increments [2][3][4], and thus, kernel driver simply jumps over a hung job by updating DMAGET to point at the start of a next job.

Issues I have with this approach:

* Both this and my approach have the requirement for userspace, that if a job hangs, the userspace must ensure all external waiters have timed out / been stopped before the syncpoint can be freed, as if the syncpoint gets reused before then, false waiter completions can happen.

So freeing the syncpoint must be exposed to userspace. The kernel cannot do this since there may be waiters that the kernel is not aware of. My proposal only has one syncpoint, which I feel makes this part simpler, too.

* I believe this proposal requires allocating a syncpoint for each externally visible syncpoint increment that the job does. This can use up quite a few syncpoints, and it makes syncpoints a dynamically allocated resource with unbounded allocation latency. This is a problem for safety-related systems.

* If a job fails on a "virtual channel" (userctx), I think it's a reasonable expectation that further jobs on that "virtual channel" will not execute, and I think implementing that model is simpler than doing recovery.

Mikko

Quoted 11 lines

[1]
https://github.com/grate-driver/linux/blob/master/drivers/gpu/drm/tegra/uapi/patching.c#L367

[2]
https://github.com/grate-driver/xf86-video-opentegra/blob/master/src/gpu/gr3d.c#L486
[3]
https://github.com/grate-driver/xf86-video-opentegra/blob/master/src/exa/copy_2d.c#L389
[4]
https://github.com/grate-driver/xf86-video-opentegra/blob/master/src/gpu/tegra_stream_v2.c#L536

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

#23 lore raw

Re: [RFC PATCH v2 10/17] WIP: gpu: host1x: Add no-recovery mode

13.09.2020 12:51, Mikko Perttunen пишет:
...

Quoted 19 lines
Quoted 7 lines

All waits that are internal to a job should only wait for relative sync point increments. >
In the grate-kernel every job uses unique-and-clean sync point (which is also internal to the kernel driver) and a relative wait [1] is used for the job's internal sync point increments [2][3][4], and thus, kernel driver simply jumps over a hung job by updating DMAGET to point at the start of a next job.

Issues I have with this approach:

* Both this and my approach have the requirement for userspace, that if a job hangs, the userspace must ensure all external waiters have timed out / been stopped before the syncpoint can be freed, as if the syncpoint gets reused before then, false waiter completions can happen.

So freeing the syncpoint must be exposed to userspace. The kernel cannot do this since there may be waiters that the kernel is not aware of. My proposal only has one syncpoint, which I feel makes this part simpler, too.

Quoted 5 lines

* I believe this proposal requires allocating a syncpoint for each externally visible syncpoint increment that the job does. This can use up quite a few syncpoints, and it makes syncpoints a dynamically allocated resource with unbounded allocation latency. This is a problem for safety-related systems.

Maybe we could have a special type of a "shared" sync point that is allocated per-hardware engine? Then shared SP won't be a scarce resource and job won't depend on it. The kernel or userspace driver may take care of recovering the counter value of a shared SP when job hangs or do whatever else is needed without affecting the job's sync point.

Primarily I'm not feeling very happy about retaining the job's sync point recovery code because it was broken the last time I touched it and grate-kernel works fine without it.

Quoted 4 lines

* If a job fails on a "virtual channel" (userctx), I think it's a reasonable expectation that further jobs on that "virtual channel" will not execute, and I think implementing that model is simpler than doing recovery.

Couldn't jobs just use explicit fencing? Then a second job won't be executed if first job hangs and explicit dependency is expressed. I'm not sure that concept of a "virtual channel" is applicable to drm-scheduler.

I'll need to see a full-featured driver implementation and the test cases that cover all the problems that you're worried about because I'm not aware about all the T124+ needs and seeing code should help. Maybe in the end yours approach will be the best, but for now it's not clear :)

#24 lore raw

Re: [RFC PATCH v2 10/17] WIP: gpu: host1x: Add no-recovery mode

Quoted 27 lines · Dmitry Osipenko

13.09.2020 12:51, Mikko Perttunen пишет:
...

Quoted 19 lines
Quoted 7 lines

All waits that are internal to a job should only wait for relative sync point increments. >
In the grate-kernel every job uses unique-and-clean sync point (which is also internal to the kernel driver) and a relative wait [1] is used for the job's internal sync point increments [2][3][4], and thus, kernel driver simply jumps over a hung job by updating DMAGET to point at the start of a next job.

Issues I have with this approach:

* Both this and my approach have the requirement for userspace, that if a job hangs, the userspace must ensure all external waiters have timed out / been stopped before the syncpoint can be freed, as if the syncpoint gets reused before then, false waiter completions can happen.

So freeing the syncpoint must be exposed to userspace. The kernel cannot do this since there may be waiters that the kernel is not aware of. My proposal only has one syncpoint, which I feel makes this part simpler, too.

Quoted 5 lines

* I believe this proposal requires allocating a syncpoint for each externally visible syncpoint increment that the job does. This can use up quite a few syncpoints, and it makes syncpoints a dynamically allocated resource with unbounded allocation latency. This is a problem for safety-related systems.

Quoted 5 lines

Maybe we could have a special type of a "shared" sync point that is allocated per-hardware engine? Then shared SP won't be a scarce resource and job won't depend on it. The kernel or userspace driver may take care of recovering the counter value of a shared SP when job hangs or do whatever else is needed without affecting the job's sync point.

Having a shared syncpoint opens up possibilities for interference between jobs (if we're not using the firewall, the HW cannot distinguish between jobs on the same channel), and doesn't work if there are multiple channels using the same engine, which we want to do for newer chips (for performance and virtualization reasons).

Even then, even if we need to allocate one syncpoint per job, the issue seems to be there.

Quoted 4 lines

Primarily I'm not feeling very happy about retaining the job's sync point recovery code because it was broken the last time I touched it and grate-kernel works fine without it.

I'm not planning to retain it any longer than necessary, which is until the staging interface is removed. Technically I can already remove it now -- that would cause any users of the staging interface to potentially behave weirdly if a job times out, but maybe we don't care about that all that much?

Quoted 9 lines
Quoted 5 lines

* If a job fails on a "virtual channel" (userctx), I think it's a reasonable expectation that further jobs on that "virtual channel" will not execute, and I think implementing that model is simpler than doing recovery.

Couldn't jobs just use explicit fencing? Then a second job won't be executed if first job hangs and explicit dependency is expressed. I'm not sure that concept of a "virtual channel" is applicable to drm-scheduler.

I assume what you mean is that each job incrementing a syncpoint would first wait for the preceding job incrementing that syncpoint to complete, by waiting for the preceding job's fence value.

I would consider what I do in this patch to be an optimization of that. Let's say we detect a timed out job and just skip that job in the CDMA pushbuffer (but do not CPU-increment syncpoints), then at every subsequent job using that syncpoint, we will be detecting a timeout and skipping it eventually. With the "NOPping" in this patch we just pre-emptively cancel those jobs so that we don't have to spend time waiting for timeouts in the future. Functionally these should be the same, though.

The wait-for-preceding-job-to-complete thing should already be there in form of the "serialize" operation if the jobs use the same syncpoint.

So, if DRM scheduler's current operation is just skipping the timing out job and continuing from the next job, that's functionally fine. But we could improve DRM scheduler to allow for also cancelling future jobs that we know will time out. That would be in essence "virtual channel" support.

Userspace still has options -- if it puts in other prefences, timeouts will happen as usual. If it wants to have multiple "threads" of execution where a timeout on one doesn't affect the others, it can use different syncpoints for them.

Quoted 6 lines

I'll need to see a full-featured driver implementation and the test cases that cover all the problems that you're worried about because I'm not aware about all the T124+ needs and seeing code should help. Maybe in the end yours approach will be the best, but for now it's not clear :)

My primary goal is simplicity of programming model and implementation. Regarding the resource management concerns, I can of course create a test case that allocates a lot of resources, but what I'm afraid about is that once we put this into a big system, with several VMs with their own resource reservations (including syncpoints), and the GPU and camera subsystems using hundreds of syncpoints, dynamic usage of those resources will create uncertainty in the system, and bug reports.

And of course, if we want to make a safety-related system, you also need to document before-hand how you are ensuring that e.g. job submission (including syncpoint allocation if that is dynamic) happens under x microseconds.

I don't think the model used in the grate host1x driver is bad, and I think the code there and its integration with the existing kernel frameworks are beautiful, and that is definitely a goal for the mainline driver as well. But I think we can make things even simpler overall and more reliable.

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

author maintainer
#25 lore raw

RFC PATCH v2 11/17 gpu: host1x: Add job release callback

In reply to Mikko Perttunen

Add a callback field to the job structure, to be called just before the job is to be freed. This allows the job's submitter to clean up any of its own state, like decrement runtime PM refcounts.

---
 drivers/gpu/host1x/job.c | 3 +++
 include/linux/host1x.h   | 4 ++++
 2 files changed, 7 insertions(+)
drivers/gpu/host1x/job.c +3 -0
index e4f16fc899b0..acf322beb56c 100644
@@ -79,6 +79,9 @@ static void job_free(struct kref *ref)
 {
 	struct host1x_job *job = container_of(ref, struct host1x_job, ref);
 
+	if (job->release)
+		job->release(job);
+
 	if (job->waiter)
 		host1x_intr_put_ref(job->syncpt->host, job->syncpt->id,
 				    job->waiter);
include/linux/host1x.h +4 -0
index 3ffe16152ebc..cabc5bef5bae 100644
@@ -261,6 +261,10 @@ struct host1x_job {
 
 	/* Fast-forward syncpoint increments on job timeout */
 	bool syncpt_recovery;
+
+	/* Callback called when job is freed */
+	void (*release)(struct host1x_job *job);
+	void *user_data;
 };
 
 struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
Signature · 6 lines
2.28.0

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

RFC PATCH v2 12/17 gpu: host1x: Add support for syncpoint waits in CDMA pushbuffer

In reply to Mikko Perttunen

Add support for inserting syncpoint waits in the CDMA pushbuffer. These waits need to be done in HOST1X class, while gather submitted by the application execute in engine class.

Support is added by converting the gather list of job into a command list that can include both gathers and waits. When the job is submitted, these commands are pushed as the appropriate opcodes on the CDMA pushbuffer.

---
 drivers/gpu/host1x/hw/channel_hw.c | 51 +++++++++++++++--------
 drivers/gpu/host1x/hw/debug_hw.c   |  9 +++-
 drivers/gpu/host1x/job.c           | 67 +++++++++++++++++++++---------
 drivers/gpu/host1x/job.h           | 14 +++++++
 include/linux/host1x.h             |  5 ++-
 5 files changed, 105 insertions(+), 41 deletions(-)
drivers/gpu/host1x/hw/channel_hw.c +33 -18
index 145746c6f6fb..57e99de528de 100644
@@ -55,31 +55,46 @@ static void submit_gathers(struct host1x_job *job)
 #endif
 	unsigned int i;
 
-	for (i = 0; i < job->num_gathers; i++) {
-		struct host1x_job_gather *g = &job->gathers[i];
-		dma_addr_t addr = g->base + g->offset;
-		u32 op2, op3;
+	for (i = 0; i < job->num_cmds; i++) {
+		struct host1x_job_cmd *cmd = &job->cmds[i];
 
-		op2 = lower_32_bits(addr);
-		op3 = upper_32_bits(addr);
+		if (cmd->is_wait) {
+			/* TODO use modern wait */
+			host1x_cdma_push(cdma,
+				 host1x_opcode_setclass(HOST1X_CLASS_HOST1X,
+					host1x_uclass_wait_syncpt_r(), 1),
+				 host1x_class_host_wait_syncpt(cmd->wait.id,
+					cmd->wait.threshold));
+			host1x_cdma_push(
+				cdma, host1x_opcode_setclass(job->class, 0, 0),
+				HOST1X_OPCODE_NOP);
+		} else {
+			struct host1x_job_gather *g = &cmd->gather;
 
-		trace_write_gather(cdma, g->bo, g->offset, g->words);
+			dma_addr_t addr = g->base + g->offset;
+			u32 op2, op3;
 
-		if (op3 != 0) {
+			op2 = lower_32_bits(addr);
+			op3 = upper_32_bits(addr);
+
+			trace_write_gather(cdma, g->bo, g->offset, g->words);
+
+			if (op3 != 0) {
 #if HOST1X_HW >= 6
-			u32 op1 = host1x_opcode_gather_wide(g->words);
-			u32 op4 = HOST1X_OPCODE_NOP;
+				u32 op1 = host1x_opcode_gather_wide(g->words);
+				u32 op4 = HOST1X_OPCODE_NOP;
 
-			host1x_cdma_push_wide(cdma, op1, op2, op3, op4);
+				host1x_cdma_push_wide(cdma, op1, op2, op3, op4);
 #else
-			dev_err(dev, "invalid gather for push buffer %pad\n",
-				&addr);
-			continue;
+				dev_err(dev, "invalid gather for push buffer %pad\n",
+					&addr);
+				continue;
 #endif
-		} else {
-			u32 op1 = host1x_opcode_gather(g->words);
+			} else {
+				u32 op1 = host1x_opcode_gather(g->words);
 
-			host1x_cdma_push(cdma, op1, op2);
+				host1x_cdma_push(cdma, op1, op2);
+			}
 		}
 	}
 }
@@ -126,7 +141,7 @@ static int channel_submit(struct host1x_job *job)
 	struct host1x *host = dev_get_drvdata(ch->dev->parent);
 
 	trace_host1x_channel_submit(dev_name(ch->dev),
-				    job->num_gathers, job->num_relocs,
+				    job->num_cmds, job->num_relocs,
 				    job->syncpt->id, job->syncpt_incrs);
 
 	/* TODO this is racy */
drivers/gpu/host1x/hw/debug_hw.c +7 -2
index ceb48229d14b..35952fd5597e 100644
@@ -208,10 +208,15 @@ static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma)
 				    job->first_get, job->timeout,
 				    job->num_slots, job->num_unpins);
 
-		for (i = 0; i < job->num_gathers; i++) {
-			struct host1x_job_gather *g = &job->gathers[i];
+		for (i = 0; i < job->num_cmds; i++) {
+			struct host1x_job_gather *g;
 			u32 *mapped;
 
+			if (job->cmds[i].is_wait)
+				continue;
+
+			g = &job->cmds[i].gather;
+
 			if (job->gather_copy_mapped)
 				mapped = (u32 *)job->gather_copy_mapped;
 			else
drivers/gpu/host1x/job.c +48 -19

145 lines not on this page · raw message

drivers/gpu/host1x/job.h +14 -0
index 94bc2e4ae241..33adfaede842 100644
@@ -18,6 +18,20 @@ struct host1x_job_gather {
 	bool handled;
 };
 
+struct host1x_job_wait {
+	u32 id;
+	u32 threshold;
+};
+
+struct host1x_job_cmd {
+	bool is_wait;
+
+	union {
+		struct host1x_job_gather gather;
+		struct host1x_job_wait wait;
+	};
+};
+
 struct host1x_job_unpin_data {
 	struct host1x_bo *bo;
 	struct sg_table *sgt;
include/linux/host1x.h +3 -2
index cabc5bef5bae..78ea56230b97 100644
@@ -211,8 +211,8 @@ struct host1x_job {
 	struct host1x_client *client;
 
 	/* Gathers and their memory */
-	struct host1x_job_gather *gathers;
-	unsigned int num_gathers;
+	struct host1x_job_cmd *cmds;
+	unsigned int num_cmds;
 
 	/* Array of handles to be pinned & unpinned */
 	struct host1x_reloc *relocs;
@@ -271,6 +271,7 @@ struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
 				    u32 num_cmdbufs, u32 num_relocs);
 void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *bo,
 			   unsigned int words, unsigned int offset);
+void host1x_job_add_wait(struct host1x_job *job, u32 id, u32 thresh);
 struct host1x_job *host1x_job_get(struct host1x_job *job);
 void host1x_job_put(struct host1x_job *job);
 int host1x_job_pin(struct host1x_job *job, struct device *dev);
Signature · 1 line
2.28.0
author maintainer
#27 lore raw

RFC PATCH v2 13/17 gpu: host1x: Reset max value when freeing a syncpoint

In reply to Mikko Perttunen

With job recovery becoming optional, syncpoints may have a mismatch between their value and max value when freed. As such, when freeing, set the max value to the current value of the syncpoint so that it is in a sane state for the next user.

---
 drivers/gpu/host1x/syncpt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/host1x/syncpt.c +1 -0
index 2fad8b2a55cc..82ecb4ac387e 100644
@@ -385,6 +385,7 @@ static void syncpt_release(struct kref *ref)
 {
 	struct host1x_syncpt *sp = container_of(ref, struct host1x_syncpt, ref);
 
+	atomic_set(&sp->max_val, host1x_syncpt_read_min(sp));
 	sp->locked = false;
 
 	mutex_lock(&sp->host->syncpt_mutex);
Signature · 1 line
2.28.0
#28 lore raw

Re: [RFC PATCH v2 13/17] gpu: host1x: Reset max value when freeing a syncpoint

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 16 lines

With job recovery becoming optional, syncpoints may have a mismatch between their value and max value when freed. As such, when freeing, set the max value to the current value of the syncpoint so that it is in a sane state for the next user.

---
 drivers/gpu/host1x/syncpt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/host1x/syncpt.c +0 -0
index 2fad8b2a55cc..82ecb4ac387e 100644

drivers/gpu/host1x/syncpt.c static void syncpt_release(struct kref *ref) · line 391

Quoted 7 lines
drivers/gpu/host1x/syncpt.c +1 -0
@@ -385,6 +385,7 @@ static void syncpt_release(struct kref *ref)
 {
 	struct host1x_syncpt *sp = container_of(ref, struct host1x_syncpt, ref);
 
+	atomic_set(&sp->max_val, host1x_syncpt_read_min(sp));
 	sp->locked = false;
 
 	mutex_lock(&sp->host->syncpt_mutex);

Please note that the sync point state actually needs to be completely reset at the sync point request-time because both downstream fastboot and upstream u-boot [1] are needlessly enabling display VBLANK interrupt that continuously increments sync point #26 during of kernel boot until display controller is reset.

[1] https://github.com/u-boot/u-boot/blob/master/drivers/video/tegra.c#L155

Hence once sync point #26 is requested, it will have a dirty state. So far this doesn't have any visible effect because sync points aren't used much.

#29 lore raw

Re: [RFC PATCH v2 13/17] gpu: host1x: Reset max value when freeing a syncpoint

Quoted 31 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 16 lines

With job recovery becoming optional, syncpoints may have a mismatch between their value and max value when freed. As such, when freeing, set the max value to the current value of the syncpoint so that it is in a sane state for the next user.

---
  drivers/gpu/host1x/syncpt.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/host1x/syncpt.c +0 -0
index 2fad8b2a55cc..82ecb4ac387e 100644

drivers/gpu/host1x/syncpt.c static void syncpt_release(struct kref *ref) · line 391

Quoted 7 lines
drivers/gpu/host1x/syncpt.c +1 -0
@@ -385,6 +385,7 @@ static void syncpt_release(struct kref *ref)
  {
  	struct host1x_syncpt *sp = container_of(ref, struct host1x_syncpt, ref);
 
+	atomic_set(&sp->max_val, host1x_syncpt_read_min(sp));
  	sp->locked = false;
 
  	mutex_lock(&sp->host->syncpt_mutex);

Please note that the sync point state actually needs to be completely reset at the sync point request-time because both downstream fastboot and upstream u-boot [1] are needlessly enabling display VBLANK interrupt that continuously increments sync point #26 during of kernel boot until display controller is reset.

Quoted 6 lines

[1] https://github.com/u-boot/u-boot/blob/master/drivers/video/tegra.c#L155

Hence once sync point #26 is requested, it will have a dirty state. So far this doesn't have any visible effect because sync points aren't used much.

Maybe we can instead reserve syncpoints that might be used by the boot chain, and only allow allocating them once the display driver has acked that the syncpoint will no longer be incremented? That way if the display driver is disabled for some reason we'll still be fine.

Looking at the downstream driver, it (still, on new chips..) reserves the following syncpoints:

- 10 (AVP)
- 22 (3D)
- 26 (VBLANK0)
- 27 (VBLANK1)

and says that this applies to T20, T30, T114 and T148.

I suppose if you haven't observed this happening to other syncpoints than 26, then reserving 26 would probably be enough.

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

#30 lore raw

Re: [RFC PATCH v2 13/17] gpu: host1x: Reset max value when freeing a syncpoint

16.09.2020 23:43, Mikko Perttunen пишет:
...

Quoted 14 lines
Quoted 6 lines

Please note that the sync point state actually needs to be completely reset at the sync point request-time because both downstream fastboot and upstream u-boot [1] are needlessly enabling display VBLANK interrupt that continuously increments sync point #26 during of kernel boot until display controller is reset.

Quoted 7 lines

[1]
https://github.com/u-boot/u-boot/blob/master/drivers/video/tegra.c#L155

Hence once sync point #26 is requested, it will have a dirty state. So far this doesn't have any visible effect because sync points aren't used much.

Quoted 4 lines

Maybe we can instead reserve syncpoints that might be used by the boot chain, and only allow allocating them once the display driver has acked that the syncpoint will no longer be incremented? That way if the display driver is disabled for some reason we'll still be fine.

sounds good

Quoted 8 lines

Looking at the downstream driver, it (still, on new chips..) reserves the following syncpoints:

- 10 (AVP)
- 22 (3D)
- 26 (VBLANK0)
- 27 (VBLANK1)

Quoted 4 lines

and says that this applies to T20, T30, T114 and T148.

I suppose if you haven't observed this happening to other syncpoints than 26, then reserving 26 would probably be enough.

I only saw SP 26 being used by the DC, but perhaps that may vary from device to device and SP 27 could actually be used in a wild as well.

I think the AVP SP should only relate to the AVP-firmware that upstream doesn't support, so we can ignore its reservation.

I've no idea what may use the 3D SP.

#31 lore raw

Re: [RFC PATCH v2 13/17] gpu: host1x: Reset max value when freeing a syncpoint

Quoted 36 lines · Dmitry Osipenko

16.09.2020 23:43, Mikko Perttunen пишет:
...

Quoted 14 lines
Quoted 6 lines

Please note that the sync point state actually needs to be completely reset at the sync point request-time because both downstream fastboot and upstream u-boot [1] are needlessly enabling display VBLANK interrupt that continuously increments sync point #26 during of kernel boot until display controller is reset.

Quoted 7 lines

[1]
https://github.com/u-boot/u-boot/blob/master/drivers/video/tegra.c#L155

Hence once sync point #26 is requested, it will have a dirty state. So far this doesn't have any visible effect because sync points aren't used much.

Quoted 4 lines

Maybe we can instead reserve syncpoints that might be used by the boot chain, and only allow allocating them once the display driver has acked that the syncpoint will no longer be incremented? That way if the display driver is disabled for some reason we'll still be fine.

sounds good

Quoted 8 lines

Looking at the downstream driver, it (still, on new chips..) reserves the following syncpoints:

- 10 (AVP)
- 22 (3D)
- 26 (VBLANK0)
- 27 (VBLANK1)

Quoted 4 lines

and says that this applies to T20, T30, T114 and T148.

I suppose if you haven't observed this happening to other syncpoints than 26, then reserving 26 would probably be enough.

Quoted 8 lines

I only saw SP 26 being used by the DC, but perhaps that may vary from device to device and SP 27 could actually be used in a wild as well.

I think the AVP SP should only relate to the AVP-firmware that upstream doesn't support, so we can ignore its reservation.

I've no idea what may use the 3D SP.

My guess is that some very old code used fixed syncpoint numbers so these were added to the reservation list. Let's reserve 26 and 27, that should be simple enough since both would be "released" by the display driver.

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

author maintainer
#32 lore raw

RFC PATCH v2 14/17 drm/tegra: Add new UAPI to header

In reply to Mikko Perttunen

Update the tegra_drm.h UAPI header, adding the new proposed UAPI. The old staging UAPI is left in for now, with minor modification to avoid name collisions.

---
 include/uapi/drm/tegra_drm.h | 431 ++++++++++++++++++++++++++++++++---
 1 file changed, 404 insertions(+), 27 deletions(-)
include/uapi/drm/tegra_drm.h +404 -27
index c4df3c3668b3..6db5fa242715 100644
@@ -1,24 +1,5 @@
-/*
- * Copyright (c) 2012-2013, NVIDIA CORPORATION.  All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
+/* SPDX-License-Identifier: MIT */
+/* Copyright (c) 2012-2020 NVIDIA Corporation */
 
 #ifndef _UAPI_TEGRA_DRM_H_
 #define _UAPI_TEGRA_DRM_H_
@@ -29,6 +10,8 @@
 extern "C" {
 #endif
 
+/* TegraDRM legacy UAPI. Only enabled with STAGING */
+
 #define DRM_TEGRA_GEM_CREATE_TILED     (1 << 0)
 #define DRM_TEGRA_GEM_CREATE_BOTTOM_UP (1 << 1)
 
@@ -644,13 +627,13 @@ struct drm_tegra_gem_get_flags {
 	__u32 flags;
 };
 
-#define DRM_TEGRA_GEM_CREATE		0x00
-#define DRM_TEGRA_GEM_MMAP		0x01
+#define DRM_TEGRA_GEM_CREATE_LEGACY	0x00
+#define DRM_TEGRA_GEM_MMAP_LEGACY	0x01
 #define DRM_TEGRA_SYNCPT_READ		0x02
 #define DRM_TEGRA_SYNCPT_INCR		0x03
 #define DRM_TEGRA_SYNCPT_WAIT		0x04
-#define DRM_TEGRA_OPEN_CHANNEL		0x05
-#define DRM_TEGRA_CLOSE_CHANNEL		0x06
+#define DRM_TEGRA_OPEN_CHANNEL	        0x05
+#define DRM_TEGRA_CLOSE_CHANNEL	        0x06
 #define DRM_TEGRA_GET_SYNCPT		0x07
 #define DRM_TEGRA_SUBMIT		0x08
 #define DRM_TEGRA_GET_SYNCPT_BASE	0x09
@@ -659,8 +642,8 @@ struct drm_tegra_gem_get_flags {
 #define DRM_TEGRA_GEM_SET_FLAGS		0x0c
 #define DRM_TEGRA_GEM_GET_FLAGS		0x0d
 
-#define DRM_IOCTL_TEGRA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_CREATE, struct drm_tegra_gem_create)
-#define DRM_IOCTL_TEGRA_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_MMAP, struct drm_tegra_gem_mmap)
+#define DRM_IOCTL_TEGRA_GEM_CREATE_LEGACY DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_CREATE_LEGACY, struct drm_tegra_gem_create)
+#define DRM_IOCTL_TEGRA_GEM_MMAP_LEGACY DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_MMAP_LEGACY, struct drm_tegra_gem_mmap)
 #define DRM_IOCTL_TEGRA_SYNCPT_READ DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_READ, struct drm_tegra_syncpt_read)
 #define DRM_IOCTL_TEGRA_SYNCPT_INCR DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_INCR, struct drm_tegra_syncpt_incr)
 #define DRM_IOCTL_TEGRA_SYNCPT_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_SYNCPT_WAIT, struct drm_tegra_syncpt_wait)
@@ -674,6 +657,400 @@ struct drm_tegra_gem_get_flags {
 #define DRM_IOCTL_TEGRA_GEM_SET_FLAGS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_SET_FLAGS, struct drm_tegra_gem_set_flags)
 #define DRM_IOCTL_TEGRA_GEM_GET_FLAGS DRM_IOWR(DRM_COMMAND_BASE + DRM_TEGRA_GEM_GET_FLAGS, struct drm_tegra_gem_get_flags)
 
+/* New TegraDRM UAPI */
+
+struct drm_tegra_channel_open {
+	/**
+	 * @host1x_class: [in]
+	 *
+	 * Host1x class of the engine that will be programmed using this
+	 * channel.
+	 */
+	__u32 host1x_class;
+
+	/**
+	 * @flags: [in]
+	 *
+	 * Flags.
+	 */
+	__u32 flags;
+
+	/**
+	 * @channel_ctx: [out]
+	 *
+	 * Opaque identifier corresponding to the opened channel.
+	 */
+	__u32 channel_ctx;
+
+	/**
+	 * @hardware_version: [out]
+	 *
+	 * Version of the engine hardware. This can be used by userspace
+	 * to determine how the engine needs to be programmed.
+	 */
+	__u32 hardware_version;
+
+	__u32 reserved[2];
+};
+
+struct drm_tegra_channel_close {
+	/**
+	 * @channel_ctx: [in]
+	 *
+	 * Identifier of the channel to close.
+	 */
+	__u32 channel_ctx;
+
+	__u32 reserved[1];
+};
+
+#define DRM_TEGRA_CHANNEL_MAP_READWRITE			(1<<0)
+
+struct drm_tegra_channel_map {
+	/**
+	 * @channel_ctx: [in]
+	 *
+	 * Identifier of the channel to which make memory available for.
+	 */
+	__u32 channel_ctx;
+
+	/**
+	 * @handle: [in]
+	 *
+	 * GEM handle of the memory to map.
+	 */
+	__u32 handle;
+
+	/**
+	 * @offset: [in]
+	 *
+	 * Offset in the GEM handle's underlying memory to start the
+	 * mapping from.
+	 */
+	__u64 offset;
+
+	/**
+	 * @length: [in]
+	 *
+	 * Length of memory to map.
+	 */
+	__u64 length;
+
+	/**
+	 * @iova: [out]
+	 *
+	 * IOVA of mapped memory. Only available if hardware memory
+	 * isolation is supported. If provided, userspace can program this
+	 * address directly to the engine to skip using relocations.
+	 *
+	 * Will be set to U64_MAX if unavailable.
+	 */
+	__u64 iova;
+
+	/**
+	 * @mapping_id: [out]
+	 *
+	 * Identifier corresponding to the mapping, to be used for
+	 * relocations or unmapping later.
+	 */
+	__u32 mapping_id;
+
+	/**
+	 * @flags: [in]
+	 *
+	 * Flags.
+	 */
+	__u32 flags;
+
+	__u32 reserved[2];
+};
+
+struct drm_tegra_channel_unmap {
+	/**
+	 * @channel_ctx: [in]
+	 *
+	 * Channel identifier of the channel to unmap memory from.
+	 */
+	__u32 channel_ctx;
+
+	/**
+	 * @mapping_id: [in]
+	 *
+	 * Mapping identifier of the memory mapping to unmap.
+	 */
+	__u32 mapping_id;
+
+	__u32 reserved[2];
+};
+
+/* Submission */
+
+/** Patch address of the specified mapping in the submitted gather. */
+#define DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC		(1<<0)
+/**
+ * Specify that bit 39 of the patched-in address should be set to
+ * trigger layout swizzling between Tegra and non-Tegra Blocklinear
+ * layout on systems that store surfaces in system memory in non-Tegra
+ * Blocklinear layout.
+ */
+#define DRM_TEGRA_SUBMIT_BUF_RELOC_BLOCKLINEAR		(1<<1)
+/**
+ * Specify that any implicit fences required to read this buffer
+ * should be waited before executing the job.
+ */
+#define DRM_TEGRA_SUBMIT_BUF_RESV_READ			(1<<2)
+/**
+ * Specify that any implicit fences required to write this buffer
+ * should be waited before executing the job.
+ */
+#define DRM_TEGRA_SUBMIT_BUF_RESV_WRITE			(1<<3)
+
+struct drm_tegra_submit_buf {
+	/**
+	 * @mapping_id: [in]
+	 *
+	 * Identifier of the mapping to use in the submission.
+	 */
+	__u32 mapping_id;
+
+	/**
+	 * @flags: [in]
+	 *
+	 * Flags.
+	 */
+	__u32 flags;
+
+	struct {
+		/**
+		 * @target_offset: [in]
+		 *
+		 * Offset from the start of the mapping of the data whose
+		 * address is to be patched into the gather.
+		 */
+		__u64 target_offset;
+
+		/**
+		 * @gather_offset_words: [in]
+		 *
+		 * Offset in words from the start of the gather data to
+		 * where the address should be patched into.
+		 */
+		__u32 gather_offset_words;
+
+		/**
+		 * @shift: [in]
+		 *
+		 * Number of bits the address should be shifted right before
+		 * patching in.
+		 */
+		__u32 shift;
+	} reloc;
+
+	__u32 reserved[2];
+};
+
+#define DRM_TEGRA_SUBMIT_SYNCPT_INCR_CREATE_SYNC_FILE  (1<<0)
+
+struct drm_tegra_submit_syncpt_incr {
+	/**
+	 * @syncpt_fd: [in]
+	 *
+	 * Syncpoint file descriptor of the syncpoint that the job will
+	 * increment.
+	 */
+	__s32 syncpt_fd;
+
+	/**
+	 * @flags: [in]
+	 *
+	 * Flags.
+	 */
+	__u32 flags;
+
+	/**
+	 * @num_incrs: [in]
+	 *
+	 * Number of times the job will increment this syncpoint.
+	 */
+	__u32 num_incrs;
+
+	/**
+	 * @fence_value: [out]
+	 *
+	 * Value the syncpoint will have once the job has completed all
+	 * its specified syncpoint increments.
+	 *
+	 * Note that the kernel may increment the syncpoint before or after
+	 * the job. These increments are not reflected in this field.
+	 *
+	 * If the job hangs or times out, not all of the increments may
+	 * get executed.
+	 */
+	__u32 fence_value;
+
+	/**
+	 * @sync_file_fd: [out]
+	 *
+	 * Created sync_file file descriptor corresponding to the threshold
+	 * specified by `fence_value`. Only set if the CREATE_SYNC_FILE
+	 * flag is specified.
+	 */
+	__s32 sync_file_fd;
+
+	__u32 reserved[3];
+};
+
+/**
+ * Execute `words` words of Host1x opcodes specified in the `gather_data_ptr`
+ * buffer. Each GATHER_UPTR command uses successive words from the buffer.
+ */
+#define DRM_TEGRA_SUBMIT_CMD_GATHER_UPTR		0
+/**
+ * Wait for a syncpoint to reach a value before continuing with further
+ * commands.
+ */
+#define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT		1
+/**
+ * Wait for the fence represented by the sync_file file descriptor to be
+ * signaled before continuing with further commands. This command may be
+ * executed before submission of the job to hardware.
+ */
+#define DRM_TEGRA_SUBMIT_CMD_WAIT_SYNC_FILE		2
+
+/**
+ * If set, the driver is allowed to skip execution of this command if
+ * the previous job executed by the engine was from the same channel
+ * context as this job.
+ */
+#define DRM_TEGRA_SUBMIT_CONTEXT_SETUP			(1<<0)
+
+struct drm_tegra_submit_cmd_gather_uptr {
+	__u32 words;
+	__u32 reserved[3];
+};
+
+struct drm_tegra_submit_cmd_wait_syncpt {
+	__u32 id;
+	__u32 threshold;
+	__u32 reserved[2];
+};
+
+struct drm_tegra_submit_cmd_wait_sync_file {
+	__s32 fd;
+	__u32 reserved[3];
+};
+
+struct drm_tegra_submit_cmd {
+	/**
+	 * @type: [in]
+	 *
+	 * Command type to execute. One of the DRM_TEGRA_SUBMIT_CMD*
+	 * defines.
+	 */
+	__u32 type;
+
+	/**
+	 * @flags: [in]
+	 *
+	 * Flags.
+	 */
+	__u32 flags;
+
+	union {
+		struct drm_tegra_submit_cmd_gather_uptr gather_uptr;
+		struct drm_tegra_submit_cmd_wait_syncpt wait_syncpt;
+		struct drm_tegra_submit_cmd_wait_sync_file wait_sync_file;
+		__u32 reserved[4];
+	};
+};
+
+struct drm_tegra_channel_submit {
+	/**
+	 * @channel_ctx: [in]
+	 *
+	 * Identifier of the channel to submit this job to.
+	 */
+	__u32 channel_ctx;
+
+	/**
+	 * @timeout_us: [in]
+	 *
+	 * Timeout in microseconds after which the kernel may consider
+	 * the job hung and may clean up the job and any dependent jobs.
+	 *
+	 * This value may be capped by the kernel.
+	 */
+	__u32 timeout_us;
+
+	/**
+	 * @syncpt_incrs_ptr: [in]
+	 *
+	 * Pointer to an array of drm_tegra_submit_syncpt_incr structures.
+	 */
+	__u64 syncpt_incrs_ptr;
+
+	/**
+	 * @bufs_ptr: [in]
+	 *
+	 * Pointer to an array of drm_tegra_submit_buf structures.
+	 */
+	__u64 bufs_ptr;
+
+	/**
+	 * @cmds_ptr: [in]
+	 *
+	 * Pointer to an array of drm_tegra_submit_cmd structures.
+	 */
+	__u64 cmds_ptr;
+
+	/**
+	 * @gather_data_ptr: [in]
+	 *
+	 * Pointer to an array of Host1x opcodes to be used by GATHER_UPTR
+	 * commands.
+	 */
+	__u64 gather_data_ptr;
+
+	/**
+	 * @num_syncpt_incrs: [in]
+	 *
+	 * Number of elements in the `syncpt_incrs_ptr` array.
+	 */
+	__u32 num_syncpt_incrs;
+
+	/**
+	 * @num_bufs: [in]
+	 *
+	 * Number of elements in the `bufs_ptr` array.
+	 */
+	__u32 num_bufs;
+
+	/**
+	 * @num_cmds: [in]
+	 *
+	 * Number of elements in the `cmds_ptr` array.
+	 */
+	__u32 num_cmds;
+
+	/**
+	 * @gather_data_words: [in]
+	 *
+	 * Number of 32-bit words in the `gather_data_ptr` array.
+	 */
+	__u32 gather_data_words;
+
+	__u32 reserved[4];
+};
+
+#define DRM_IOCTL_TEGRA_CHANNEL_OPEN     DRM_IOWR(DRM_COMMAND_BASE + 0x10, struct drm_tegra_channel_open)
+#define DRM_IOCTL_TEGRA_CHANNEL_CLOSE    DRM_IOWR(DRM_COMMAND_BASE + 0x11, struct drm_tegra_channel_close)
+#define DRM_IOCTL_TEGRA_CHANNEL_MAP      DRM_IOWR(DRM_COMMAND_BASE + 0x12, struct drm_tegra_channel_map)
+#define DRM_IOCTL_TEGRA_CHANNEL_UNMAP    DRM_IOWR(DRM_COMMAND_BASE + 0x13, struct drm_tegra_channel_unmap)
+#define DRM_IOCTL_TEGRA_CHANNEL_SUBMIT   DRM_IOWR(DRM_COMMAND_BASE + 0x14, struct drm_tegra_channel_submit)
+
+#define DRM_IOCTL_TEGRA_GEM_CREATE       DRM_IOWR(DRM_COMMAND_BASE + 0x15, struct drm_tegra_gem_create)
+#define DRM_IOCTL_TEGRA_GEM_MMAP         DRM_IOWR(DRM_COMMAND_BASE + 0x16, struct drm_tegra_gem_mmap)
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.28.0
#33 lore raw

Re: DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC

05.09.2020 13:34, Mikko Perttunen пишет:
...

include/uapi/drm/tegra_drm.h struct drm_tegra_gem_get_flags { · line 789

Quoted 4 lines
include/uapi/drm/tegra_drm.h +4 -0
+/* Submission */
+
+/** Patch address of the specified mapping in the submitted gather. */
+#define DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC		(1<<0)

Shouldn't the kernel driver be aware about what relocations need to be patched? Could you please explain the purpose of this flag?

#34 lore raw

Re: DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC

Quoted 10 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:
...

include/uapi/drm/tegra_drm.h struct drm_tegra_gem_get_flags { · line 789

Quoted 4 lines
include/uapi/drm/tegra_drm.h +4 -0
+/* Submission */
+
+/** Patch address of the specified mapping in the submitted gather. */
+#define DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC		(1<<0)

Shouldn't the kernel driver be aware about what relocations need to be patched? Could you please explain the purpose of this flag?

Sure, the kernel knows if it returned the IOVA to the user or not, so we could remove this flag and determine it implicitly. I don't think there is much harm in it though; if we have the flag an application can decide to ignore the iova field and just pass WRITE_RELOC always, and it's not really any extra code on kernel side.

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

#35 lore raw

Re: DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC

09.09.2020 11:10, Mikko Perttunen пишет:

Quoted 12 lines · Dmitry Osipenko
Quoted 10 lines

05.09.2020 13:34, Mikko Perttunen пишет:
...

include/uapi/drm/tegra_drm.h struct drm_tegra_gem_get_flags { · line 789

Quoted 4 lines
include/uapi/drm/tegra_drm.h +4 -0
+/* Submission */
+
+/** Patch address of the specified mapping in the submitted gather. */
+#define DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC        (1<<0)

Shouldn't the kernel driver be aware about what relocations need to be patched? Could you please explain the purpose of this flag?

Quoted 5 lines

Sure, the kernel knows if it returned the IOVA to the user or not, so we could remove this flag and determine it implicitly. I don't think there is much harm in it though; if we have the flag an application can decide to ignore the iova field and just pass WRITE_RELOC always, and it's not really any extra code on kernel side.

Sounds like there is no real practical use for this flag other than for testing purposes, correct?

#36 lore raw

Re: DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC

Quoted 13 lines · Dmitry Osipenko

09.09.2020 11:10, Mikko Perttunen пишет:

Quoted 12 lines · Dmitry Osipenko
Quoted 10 lines

05.09.2020 13:34, Mikko Perttunen пишет:
...

include/uapi/drm/tegra_drm.h struct drm_tegra_gem_get_flags { · line 789

Quoted 4 lines
include/uapi/drm/tegra_drm.h +4 -0
+/* Submission */
+
+/** Patch address of the specified mapping in the submitted gather. */
+#define DRM_TEGRA_SUBMIT_BUF_WRITE_RELOC        (1<<0)

Shouldn't the kernel driver be aware about what relocations need to be patched? Could you please explain the purpose of this flag?

Quoted 9 lines
Quoted 5 lines

Sure, the kernel knows if it returned the IOVA to the user or not, so we could remove this flag and determine it implicitly. I don't think there is much harm in it though; if we have the flag an application can decide to ignore the iova field and just pass WRITE_RELOC always, and it's not really any extra code on kernel side.

Sounds like there is no real practical use for this flag other than for testing purposes, correct?

Patching depending just on if the MAP IOCTL returned an IOVA or not seems a bit "spooky action at a distance"-ish to me, but maybe it's not so bad.. I'll consider removing it.

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

author maintainer
#37 lore raw

RFC PATCH v2 15/17 drm/tegra: Add power_on/power_off engine callbacks

In reply to Mikko Perttunen

With the new UAPI implementation, engines are powered on and off when there are active jobs, and the core code handles channel allocation. To accommodate that, add the power_on and power_off callbacks. The open_channel and close_channel callbacks are now only used for the staging path.

---
 drivers/gpu/drm/tegra/drm.h |  11 +++-
 drivers/gpu/drm/tegra/vic.c | 127 ++++++++++++++++++++----------------
 2 files changed, 78 insertions(+), 60 deletions(-)
drivers/gpu/drm/tegra/drm.h +8 -3
index b25443255be6..b915a3946ad4 100644
@@ -67,14 +67,19 @@ struct tegra_drm_context {
 };
 
 struct tegra_drm_client_ops {
-	int (*open_channel)(struct tegra_drm_client *client,
-			    struct tegra_drm_context *context);
-	void (*close_channel)(struct tegra_drm_context *context);
+	int (*power_on)(struct tegra_drm_client *client);
+	void (*power_off)(struct tegra_drm_client *client);
+
 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
 	int (*is_valid_class)(u32 class);
 	int (*submit)(struct tegra_drm_context *context,
 		      struct drm_tegra_submit *args, struct drm_device *drm,
 		      struct drm_file *file);
+
+	/* Legacy UAPI callbacks */
+	int (*open_channel)(struct tegra_drm_client *client,
+			    struct tegra_drm_context *context);
+	void (*close_channel)(struct tegra_drm_context *context);
 };
 
 int tegra_drm_submit(struct tegra_drm_context *context,
drivers/gpu/drm/tegra/vic.c +70 -57

165 lines not on this page · raw message

Signature · 6 lines
2.28.0

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

Re: [RFC PATCH v2 15/17] drm/tegra: Add power_on/power_off engine callbacks

05.09.2020 13:34, Mikko Perttunen пишет:
...

drivers/gpu/drm/tegra/vic.c static int vic_load_firmware(struct vic *vic) · line 326

Quoted 5 lines
drivers/gpu/drm/tegra/vic.c +5 -0
+static int vic_power_on(struct tegra_drm_client *client)
+{
+	struct vic *vic = to_vic(client);
+
+	return pm_runtime_get_sync(vic->dev);

Please keep in mind that RPM needs to be put in a case of error.

Maybe it would be better if driver-core could take care of resuming/suspending client's RPM instead of putting that burden on each client individually?

#39 lore raw

Re: [RFC PATCH v2 15/17] drm/tegra: Add power_on/power_off engine callbacks

Quoted 10 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:
...

drivers/gpu/drm/tegra/vic.c static int vic_load_firmware(struct vic *vic) · line 326

Quoted 5 lines
drivers/gpu/drm/tegra/vic.c +5 -0
+static int vic_power_on(struct tegra_drm_client *client)
+{
+	struct vic *vic = to_vic(client);
+
+	return pm_runtime_get_sync(vic->dev);

Please keep in mind that RPM needs to be put in a case of error.

Quoted 4 lines

Maybe it would be better if driver-core could take care of resuming/suspending client's RPM instead of putting that burden on each client individually?

Good point, we should be able to just make RPM calls from the core code. I'll change it so (and fix the refcounting).

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

author maintainer
#40 lore raw

RFC PATCH v2 16/17 drm/tegra: Allocate per-engine channel in core code

In reply to Mikko Perttunen

To avoid duplication, allocate the per-engine shared channel in the core code instead. Once MLOCKs are implemented on Host1x side, we can also update this to avoid allocating a shared channel when MLOCKs are enabled.

---
 drivers/gpu/drm/tegra/drm.c | 11 +++++++++++
 drivers/gpu/drm/tegra/drm.h |  4 ++++
 2 files changed, 15 insertions(+)
drivers/gpu/drm/tegra/drm.c +11 -0
index 7437c67924aa..7124b0b0154b 100644
@@ -887,6 +887,14 @@ static struct drm_driver tegra_drm_driver = {
 int tegra_drm_register_client(struct tegra_drm *tegra,
 			      struct tegra_drm_client *client)
 {
+	/*
+	 * When MLOCKs are implemented, change to allocate a shared channel
+	 * only when MLOCKs are disabled.
+	 */
+	client->shared_channel = host1x_channel_request(&client->base);
+	if (!client->shared_channel)
+		return -EBUSY;
+
 	mutex_lock(&tegra->clients_lock);
 	list_add_tail(&client->list, &tegra->clients);
 	client->drm = tegra;
@@ -903,6 +911,9 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
 	client->drm = NULL;
 	mutex_unlock(&tegra->clients_lock);
 
+	if (client->shared_channel)
+		host1x_channel_put(client->shared_channel);
+
 	return 0;
 }
 
drivers/gpu/drm/tegra/drm.h +4 -0
index b915a3946ad4..984925d0ad3e 100644
@@ -91,8 +91,12 @@ struct tegra_drm_client {
 	struct list_head list;
 	struct tegra_drm *drm;
 
+	/* Set by driver */
 	unsigned int version;
 	const struct tegra_drm_client_ops *ops;
+
+	/* Set by TegraDRM core */
+	struct host1x_channel *shared_channel;
 };
 
 static inline struct tegra_drm_client *
Signature · 1 line
2.28.0
author maintainer
#41 lore raw

RFC PATCH v2 17/17 WIP: drm/tegra: Implement new UAPI

In reply to Mikko Perttunen

Implement the new UAPI, and bump the TegraDRM major version.

WIP:
- Wait DMA reservations
- Implement firewall on TegraDRM side

---
 drivers/gpu/drm/tegra/Makefile      |   2 +
 drivers/gpu/drm/tegra/drm.c         |  46 +-
 drivers/gpu/drm/tegra/drm.h         |   5 +
 drivers/gpu/drm/tegra/uapi.h        |  59 +++
 drivers/gpu/drm/tegra/uapi/submit.c | 687 ++++++++++++++++++++++++++++
 drivers/gpu/drm/tegra/uapi/uapi.c   | 328 +++++++++++++
 6 files changed, 1109 insertions(+), 18 deletions(-)
 create mode 100644 drivers/gpu/drm/tegra/uapi.h
 create mode 100644 drivers/gpu/drm/tegra/uapi/submit.c
 create mode 100644 drivers/gpu/drm/tegra/uapi/uapi.c
drivers/gpu/drm/tegra/Makefile +2 -0
index d6cf202414f0..d480491564b7 100644
@@ -3,6 +3,8 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG
 
 tegra-drm-y := \
 	drm.o \
+	uapi/uapi.o \
+	uapi/submit.o \
 	gem.o \
 	fb.o \
 	dp.o \
drivers/gpu/drm/tegra/drm.c +28 -18

121 lines not on this page · raw message

drivers/gpu/drm/tegra/drm.h +5 -0
index 984925d0ad3e..fbacb0b35189 100644
@@ -58,6 +58,11 @@ struct tegra_drm {
 	struct tegra_display_hub *hub;
 };
 
+static inline struct host1x *tegra_drm_to_host1x(struct tegra_drm *tegra)
+{
+	return dev_get_drvdata(tegra->drm->dev->parent);
+}
+
 struct tegra_drm_client;
 
 struct tegra_drm_context {
drivers/gpu/drm/tegra/uapi.h new file +59 -0

59 lines not on this page · raw message

drivers/gpu/drm/tegra/uapi/submit.c new file +687 -0

687 lines not on this page · raw message

drivers/gpu/drm/tegra/uapi/uapi.c new file +328 -0

328 lines not on this page · raw message

Signature · 6 lines
2.28.0

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

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

05.09.2020 13:34, Mikko Perttunen пишет:

drivers/gpu/drm/tegra/uapi/submit.c line 301

Quoted 8 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +8 -0
+static int submit_process_bufs(struct drm_device *drm, struct gather_bo *bo,
+			       struct tegra_drm_job_data *job_data,
+			       struct tegra_drm_channel_ctx *ctx,
+			       struct drm_tegra_channel_submit *args,
+			       struct ww_acquire_ctx *acquire_ctx)
+{
+	struct drm_tegra_submit_buf __user *user_bufs_ptr =
+		u64_to_user_ptr(args->bufs_ptr);

If assignment makes line too long, then factor it out.

struct drm_tegra_submit_buf __user *user_bufs_ptr;

  user_bufs_ptr = u64_to_user_ptr(args->bufs_ptr);

drivers/gpu/drm/tegra/uapi/submit.c line 309

Quoted 8 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +8 -0
+	struct tegra_drm_mapping *mapping;
+	struct drm_tegra_submit_buf buf;
+	unsigned long copy_err;
+	int err;
+	u32 i;
+
+	job_data->used_mappings =
+		kcalloc(args->num_bufs, sizeof(*job_data->used_mappings), GFP_KERNEL);

The checkpatch should disallow this coding style. I'd write it as:

size_t size;

size = sizeof(*job_data->used_mappings); job_data->used_mappings = kcalloc(args->num_bufs, size..);

drivers/gpu/drm/tegra/uapi/submit.c line 314

Quoted 5 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +5 -0
+	if (!job_data->used_mappings)
+		return -ENOMEM;
+
+	for (i = 0; i < args->num_bufs; i++) {
+		copy_err = copy_from_user(&buf, user_bufs_ptr+i, sizeof(buf));

Whole array always should be copied at once. Please keep in mind that each copy_from_user() has a cpu-time cost, there should maximum up to 2 copyings per job.

#43 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

Quoted 27 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:

drivers/gpu/drm/tegra/uapi/submit.c line 301

Quoted 8 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +8 -0
+static int submit_process_bufs(struct drm_device *drm, struct gather_bo *bo,
+			       struct tegra_drm_job_data *job_data,
+			       struct tegra_drm_channel_ctx *ctx,
+			       struct drm_tegra_channel_submit *args,
+			       struct ww_acquire_ctx *acquire_ctx)
+{
+	struct drm_tegra_submit_buf __user *user_bufs_ptr =
+		u64_to_user_ptr(args->bufs_ptr);

If assignment makes line too long, then factor it out.

   struct drm_tegra_submit_buf __user *user_bufs_ptr;

   user_bufs_ptr = u64_to_user_ptr(args->bufs_ptr);

drivers/gpu/drm/tegra/uapi/submit.c line 309

Quoted 8 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +8 -0
+	struct tegra_drm_mapping *mapping;
+	struct drm_tegra_submit_buf buf;
+	unsigned long copy_err;
+	int err;
+	u32 i;
+
+	job_data->used_mappings =
+		kcalloc(args->num_bufs, sizeof(*job_data->used_mappings), GFP_KERNEL);

The checkpatch should disallow this coding style. I'd write it as:

Quoted 4 lines

size_t size;

size = sizeof(*job_data->used_mappings); job_data->used_mappings = kcalloc(args->num_bufs, size..);

I'll make these cleaner for next version.

Quoted 11 lines

drivers/gpu/drm/tegra/uapi/submit.c line 314

Quoted 6 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +5 -0
+	if (!job_data->used_mappings)
+		return -ENOMEM;
+
+	for (i = 0; i < args->num_bufs; i++) {
+		copy_err = copy_from_user(&buf, user_bufs_ptr+i, sizeof(buf));

Whole array always should be copied at once. Please keep in mind that each copy_from_user() has a cpu-time cost, there should maximum up to 2 copyings per job.

OK. BTW, do you have some reference/numbers for this or is it based on grate-driver experience?

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

#44 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

09.09.2020 11:19, Mikko Perttunen пишет:
...

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

+    if (!job_data->used_mappings)
+        return -ENOMEM;
+
+    for (i = 0; i < args->num_bufs; i++) {
+        copy_err = copy_from_user(&buf, user_bufs_ptr+i, sizeof(buf));

Quoted 7 lines
Quoted 4 lines

Whole array always should be copied at once. Please keep in mind that each copy_from_user() has a cpu-time cost, there should maximum up to 2 copyings per job.

OK. BTW, do you have some reference/numbers for this or is it based on grate-driver experience?

I had numbers about 2 years ago while was profiling job submission latency using host1x-tests and for a simple jobs there was a visible difference caused by each copy_from_user(), kmalloc() and having firewall functions uninlined.

Of course it wasn't critical, but it's also not difficult to optimize such things.

#45 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI (submit_handle_syncpts)

In reply to Mikko Perttunen

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 33 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +33 -0
+int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data,
+				   struct drm_file *file)
+{
+	struct tegra_drm_file *fpriv = file->driver_priv;
+	struct drm_tegra_channel_submit *args = data;
+	struct drm_tegra_submit_syncpt_incr incr;
+	struct tegra_drm_job_data *job_data;
+	struct ww_acquire_ctx acquire_ctx;
+	struct tegra_drm_channel_ctx *ctx;
+	struct host1x_job *job;
+	struct gather_bo *bo;
+	u32 i;
+	int err;
+
+	if (args->reserved[0] || args->reserved[1] || args->reserved[2] ||
+	    args->reserved[3])
+		return -EINVAL;
+
+	ctx = tegra_drm_channel_ctx_lock(fpriv, args->channel_ctx);
+	if (!ctx)
+		return -EINVAL;
+
+	err = submit_copy_gather_data(drm, &bo, args);
+	if (err)
+		goto unlock;
+
+	job_data = kzalloc(sizeof(*job_data), GFP_KERNEL);
+	if (!job_data) {
+		err = -ENOMEM;
+		goto put_bo;
+	}
+
+	err = submit_process_bufs(drm, bo, job_data, ctx, args, &acquire_ctx);

drivers/gpu/drm/tegra/uapi/submit.c line 631

Quoted 10 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +10 -0
+	if (err)
+		goto free_job_data;
+
+	err = submit_create_job(drm, &job, bo, ctx, args, file);
+	if (err)
+		goto free_job_data;
+
+	err = submit_handle_syncpts(drm, job, &incr, args);
+	if (err)
+		goto put_job;

How many sync points would use an average job? Maybe it should be better to have the predefined array of sync points within the struct drm_tegra_channel_submit?

#46 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI (submit_handle_syncpts)

09.09.2020 04:13, Dmitry Osipenko пишет:
...

Quoted 4 lines

How many sync points would use an average job? Maybe it should be better to have the predefined array of sync points within the struct drm_tegra_channel_submit?

The same question regarding the commands.

Wouldn't it be a good idea to make both usrptr arrays of sync points and commands optional by having a small fixed-size buffers within drm_tegra_channel_submit? Then a majority of jobs would only need to copy the gather data from userspace.

#47 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI (submit_handle_syncpts)

Quoted 7 lines · Dmitry Osipenko

09.09.2020 04:13, Dmitry Osipenko пишет:
...

Quoted 4 lines

How many sync points would use an average job? Maybe it should be better to have the predefined array of sync points within the struct drm_tegra_channel_submit?

Quoted 7 lines

The same question regarding the commands.

Wouldn't it be a good idea to make both usrptr arrays of sync points and commands optional by having a small fixed-size buffers within drm_tegra_channel_submit? Then a majority of jobs would only need to copy the gather data from userspace.

Sure, I'll look into it. For syncpoints, it would be usually 1 but sometimes 2, so maybe make it 2. For commands, at least for downstream it would typically be 2 (one wait and one gather). Any opinion from grate-driver's point of view? Not sure if there is any recommendation regarding the max size of IOCTL data.

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

#48 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI (submit_handle_syncpts)

09.09.2020 11:26, Mikko Perttunen пишет:

Quoted 16 lines · Dmitry Osipenko
Quoted 7 lines

09.09.2020 04:13, Dmitry Osipenko пишет:
...

Quoted 4 lines

How many sync points would use an average job? Maybe it should be better to have the predefined array of sync points within the struct drm_tegra_channel_submit?

Quoted 7 lines

The same question regarding the commands.

Wouldn't it be a good idea to make both usrptr arrays of sync points and commands optional by having a small fixed-size buffers within drm_tegra_channel_submit? Then a majority of jobs would only need to copy the gather data from userspace.

Quoted 5 lines

Sure, I'll look into it. For syncpoints, it would be usually 1 but sometimes 2, so maybe make it 2. For commands, at least for downstream it would typically be 2 (one wait and one gather). Any opinion from grate-driver's point of view? Not sure if there is any recommendation regarding the max size of IOCTL data.

The Opentegra will need more than 2 commands. We'll need to take a look at what are the min/max/average numbers of commands are used by Opentegra since it combines multiple jobs into one and each job may have several wait commands.

#49 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

In reply to Mikko Perttunen

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 31 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +31 -0
+int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data,
+				 struct drm_file *file)
+{
+	struct tegra_drm_file *fpriv = file->driver_priv;
+	struct tegra_drm *tegra = drm->dev_private;
+	struct drm_tegra_channel_open *args = data;
+	struct tegra_drm_client *client = NULL;
+	struct tegra_drm_channel_ctx *ctx;
+	int err;
+
+	if (args->flags || args->reserved[0] || args->reserved[1])
+		return -EINVAL;
+
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	err = -ENODEV;
+	list_for_each_entry(client, &tegra->clients, list) {
+		if (client->base.class == args->host1x_class) {
+			err = 0;
+			break;
+		}
+	}
+	if (err)
+		goto free_ctx;
+
+	if (client->shared_channel) {
+		ctx->channel = host1x_channel_get(client->shared_channel);
+	} else {
+		ctx->channel = host1x_channel_request(&client->base);

drivers/gpu/drm/tegra/uapi/uapi.c line 122

Quoted 10 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +10 -0
+		if (!ctx->channel) {
+			err = -EBUSY;
+			goto free_ctx;
+		}
+	}
+
+	err = xa_alloc(&fpriv->contexts, &args->channel_ctx, ctx,
+		       XA_LIMIT(1, U32_MAX), GFP_KERNEL);
+	if (err < 0) {
+		mutex_unlock(&fpriv->lock);

Looks like the lock was never taken.

drivers/gpu/drm/tegra/uapi/uapi.c line 127

Quoted 5 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +5 -0
+		goto put_channel;
+	}
+
+	ctx->client = client;
+	xa_init_flags(&ctx->mappings, XA_FLAGS_ALLOC);

Why not XA_FLAGS_ALLOC1?

#50 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

Quoted 36 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 35 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +35 -0
+int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data,
+				 struct drm_file *file)
+{
+	struct tegra_drm_file *fpriv = file->driver_priv;
+	struct tegra_drm *tegra = drm->dev_private;
+	struct drm_tegra_channel_open *args = data;
+	struct tegra_drm_client *client = NULL;
+	struct tegra_drm_channel_ctx *ctx;
+	int err;
+
+	if (args->flags || args->reserved[0] || args->reserved[1])
+		return -EINVAL;
+
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	err = -ENODEV;
+	list_for_each_entry(client, &tegra->clients, list) {
+		if (client->base.class == args->host1x_class) {
+			err = 0;
+			break;
+		}
+	}
+	if (err)
+		goto free_ctx;
+
+	if (client->shared_channel) {
+		ctx->channel = host1x_channel_get(client->shared_channel);
+	} else {
+		ctx->channel = host1x_channel_request(&client->base);
+		if (!ctx->channel) {
+			err = -EBUSY;
+			goto free_ctx;
+		}
Quoted 8 lines

drivers/gpu/drm/tegra/uapi/uapi.c line 122

Quoted 6 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +6 -0
+	}
+
+	err = xa_alloc(&fpriv->contexts, &args->channel_ctx, ctx,
+		       XA_LIMIT(1, U32_MAX), GFP_KERNEL);
+	if (err < 0) {
+		mutex_unlock(&fpriv->lock);

Looks like the lock was never taken.

Thanks, will fix.

Quoted 9 lines

drivers/gpu/drm/tegra/uapi/uapi.c line 127

Quoted 6 lines
drivers/gpu/drm/tegra/uapi/uapi.c new file +5 -0
+		goto put_channel;
+	}
+
+	ctx->client = client;
+	xa_init_flags(&ctx->mappings, XA_FLAGS_ALLOC);

Why not XA_FLAGS_ALLOC1?

Will fix as well.

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

#51 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

In reply to Mikko Perttunen

05.09.2020 13:34, Mikko Perttunen пишет:

drivers/gpu/drm/tegra/uapi/submit.c line 643

Quoted 3 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +3 -0
+	job->timeout = min(args->timeout_us / 1000, 10000U);
+	if (job->timeout == 0)
+		job->timeout = 1;

clamp()

#52 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

09.09.2020 05:10, Dmitry Osipenko пишет:

Quoted 7 lines

05.09.2020 13:34, Mikko Perttunen пишет:

drivers/gpu/drm/tegra/uapi/submit.c line 643

Quoted 3 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +3 -0
+	job->timeout = min(args->timeout_us / 1000, 10000U);
+	if (job->timeout == 0)
+		job->timeout = 1;

clamp()

Does it make sense to have timeout in microseconds?

#53 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

Quoted 8 lines · Dmitry Osipenko

09.09.2020 05:10, Dmitry Osipenko пишет:

Quoted 7 lines

05.09.2020 13:34, Mikko Perttunen пишет:

drivers/gpu/drm/tegra/uapi/submit.c line 643

Quoted 3 lines
drivers/gpu/drm/tegra/uapi/submit.c new file +3 -0
+	job->timeout = min(args->timeout_us / 1000, 10000U);
+	if (job->timeout == 0)
+		job->timeout = 1;

clamp()

Will fix.

Quoted 3 lines

Does it make sense to have timeout in microseconds?

Not sure, but better have it a bit more fine-grained rather than coarse-grained. This still gives a maximum timeout of 71 minutes so I don't think it has any negatives compared to milliseconds.

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

#54 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

09.09.2020 11:36, Mikko Perttunen пишет:
...

Quoted 7 lines
Quoted 3 lines

Does it make sense to have timeout in microseconds?

Not sure, but better have it a bit more fine-grained rather than coarse-grained. This still gives a maximum timeout of 71 minutes so I don't think it has any negatives compared to milliseconds.

If there is no good reason to use microseconds right now, then should be better to default to milliseconds, IMO. It shouldn't be a problem to extend the IOCLT with a microseconds entry, if ever be needed.

{
	__u32 timeout_ms;
...
	__u32 timeout_us;
}

timeout = timeout_ms + 1000 * timeout_us;

There shouldn't be a need for a long timeouts, since a job that takes over 100ms is probably too unpractical. It also should be possible to detect a progressing job and then defer timeout in the driver. At least this is what other drivers do, like etnaviv driver for example:

https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/gpu/drm/etnaviv/etnaviv_sched.c#L107

#55 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

Quoted 20 lines · Dmitry Osipenko

09.09.2020 11:36, Mikko Perttunen пишет:
...

Quoted 7 lines
Quoted 3 lines

Does it make sense to have timeout in microseconds?

Not sure, but better have it a bit more fine-grained rather than coarse-grained. This still gives a maximum timeout of 71 minutes so I don't think it has any negatives compared to milliseconds.

If there is no good reason to use microseconds right now, then should be better to default to milliseconds, IMO. It shouldn't be a problem to extend the IOCLT with a microseconds entry, if ever be needed.

{
	__u32 timeout_ms;
...
	__u32 timeout_us;
}
Quoted 9 lines

timeout = timeout_ms + 1000 * timeout_us;

There shouldn't be a need for a long timeouts, since a job that takes over 100ms is probably too unpractical. It also should be possible to detect a progressing job and then defer timeout in the driver. At least this is what other drivers do, like etnaviv driver for example:

https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/gpu/drm/etnaviv/etnaviv_sched.c#L107

I still don't quite understand why it's better to default to milliseconds? As you say, there is no need to have a long timeout, and if we go microseconds now, then there wouldn't be a need to extend in the future.

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

#56 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

11.09.2020 12:59, Mikko Perttunen пишет:

Quoted 28 lines · Dmitry Osipenko
Quoted 27 lines

09.09.2020 11:36, Mikko Perttunen пишет:
...

Quoted 7 lines
Quoted 3 lines

Does it make sense to have timeout in microseconds?

Not sure, but better have it a bit more fine-grained rather than coarse-grained. This still gives a maximum timeout of 71 minutes so I don't think it has any negatives compared to milliseconds.

If there is no good reason to use microseconds right now, then should be better to default to milliseconds, IMO. It shouldn't be a problem to extend the IOCLT with a microseconds entry, if ever be needed.

{
    __u32 timeout_ms;
...
    __u32 timeout_us;
}

timeout = timeout_ms + 1000 * timeout_us;

There shouldn't be a need for a long timeouts, since a job that takes over 100ms is probably too unpractical. It also should be possible to detect a progressing job and then defer timeout in the driver. At least this is what other drivers do, like etnaviv driver for example:

Quoted 8 lines
Quoted 3 lines

https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/gpu/drm/etnaviv/etnaviv_sched.c#L107

I still don't quite understand why it's better to default to milliseconds? As you say, there is no need to have a long timeout, and if we go microseconds now, then there wouldn't be a need to extend in the future.

It will nicer to avoid unnecessary unit-conversions in the code in order to keep it cleaner.

I'm now also a bit dubious about that the timeout field of the submit IOCTL will be in the final UAPI version because it should become obsolete once drm-scheduler will be hooked up, since the hung-check timeout will be specified per-hardware engine within the kernel driver and there won't be much use for the user-defined timeout.

#57 lore raw

Re: [RFC PATCH v2 17/17] WIP: drm/tegra: Implement new UAPI

Quoted 33 lines · Dmitry Osipenko

11.09.2020 12:59, Mikko Perttunen пишет:

Quoted 32 lines · Dmitry Osipenko
Quoted 30 lines

09.09.2020 11:36, Mikko Perttunen пишет:
...

Quoted 7 lines
Quoted 3 lines

Does it make sense to have timeout in microseconds?

Not sure, but better have it a bit more fine-grained rather than coarse-grained. This still gives a maximum timeout of 71 minutes so I don't think it has any negatives compared to milliseconds.

If there is no good reason to use microseconds right now, then should be better to default to milliseconds, IMO. It shouldn't be a problem to extend the IOCLT with a microseconds entry, if ever be needed.

{
    __u32 timeout_ms;
...
    __u32 timeout_us;
}

timeout = timeout_ms + 1000 * timeout_us;

There shouldn't be a need for a long timeouts, since a job that takes over 100ms is probably too unpractical. It also should be possible to detect a progressing job and then defer timeout in the driver. At least this is what other drivers do, like etnaviv driver for example:

https://elixir.bootlin.com/linux/v5.9-rc4/source/drivers/gpu/drm/etnaviv/etnaviv_sched.c#L107

Quoted 7 lines
Quoted 4 lines

I still don't quite understand why it's better to default to milliseconds? As you say, there is no need to have a long timeout, and if we go microseconds now, then there wouldn't be a need to extend in the future.

It will nicer to avoid unnecessary unit-conversions in the code in order to keep it cleaner.

We can change all the internals to use microseconds as well. We eventually have to convert it to jiffies anyway, so the unit before that shouldn't matter much.

Quoted 7 lines

I'm now also a bit dubious about that the timeout field of the submit IOCTL will be in the final UAPI version because it should become obsolete once drm-scheduler will be hooked up, since the hung-check timeout will be specified per-hardware engine within the kernel driver and there won't be much use for the user-defined timeout.

Perhaps we can omit this field for now. Looking at it, it's primarily used for tests, and for that we could add a debugfs knob to adjust the timeout if needed.

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

#58 lore raw
In reply to Mikko Perttunen

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 6 lines

Hi all,

here's a second revision of the Host1x/TegraDRM UAPI proposal, hopefully with most issues from v1 resolved, and also with an implementation. There are still open issues with the implementation:

Could you please clarify the current status of the DMA heaps. Are we still going to use DMA heaps?

#59 lore raw
Quoted 10 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 6 lines

Hi all,

here's a second revision of the Host1x/TegraDRM UAPI proposal, hopefully with most issues from v1 resolved, and also with an implementation. There are still open issues with the implementation:

Could you please clarify the current status of the DMA heaps. Are we still going to use DMA heaps?

Sorry, should have mentioned the status in the cover letter. I sent an email to dri-devel about how DMA heaps should be used -- I believe the conclusion was that it's not entirely clear, but dma-bufs should only be used for buffers shared between engines. So for the time being, we should still implement GEM for intra-TegraDRM buffers. There seems to be some planning ongoing to see if the different subsystem allocators can be unified (see dma-buf heaps talk from linux plumbers conference), but for now we should go for GEM.

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

#60 lore raw

09.09.2020 11:40, Mikko Perttunen пишет:

Quoted 12 lines · Dmitry Osipenko
Quoted 10 lines

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 6 lines

Hi all,

here's a second revision of the Host1x/TegraDRM UAPI proposal, hopefully with most issues from v1 resolved, and also with an implementation. There are still open issues with the implementation:

Could you please clarify the current status of the DMA heaps. Are we still going to use DMA heaps?

Quoted 8 lines

Sorry, should have mentioned the status in the cover letter. I sent an email to dri-devel about how DMA heaps should be used -- I believe the conclusion was that it's not entirely clear, but dma-bufs should only be used for buffers shared between engines. So for the time being, we should still implement GEM for intra-TegraDRM buffers. There seems to be some planning ongoing to see if the different subsystem allocators can be unified (see dma-buf heaps talk from linux plumbers conference), but for now we should go for GEM.

Thanks!

#61 lore raw
In reply to Mikko Perttunen

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 31 lines

Hi all,

here's a second revision of the Host1x/TegraDRM UAPI proposal, hopefully with most issues from v1 resolved, and also with an implementation. There are still open issues with the implementation:

* Relocs are now handled on TegraDRM side instead of Host1x, so the firewall is not aware of them, causing submission failure where the firewall is enabled. Proposed solution is to move the firewall to TegraDRM side, but this hasn't been done yet.
* For the new UAPI, syncpoint recovery on job timeout is disabled. What this means is that upon job timeout, all further jobs using that syncpoint are cancelled, and the syncpoint is marked unusable until it is freed. However, there is currently a race between the timeout handler and job submission, where submission can observe the syncpoint in non-locked state and yet the job cancellations won't cancel the new job.
* Waiting for DMA reservation fences is not implemented yet.
* I have only tested on Tegra186.

The series consists of three parts:

* The first part contains some fixes and improvements to the Host1x driver of more general nature,
* The second part adds the Host1x side UAPI, as well as Host1x-side changes needed for the new TegraDRM UAPI,
* The third part adds the new TegraDRM UAPI.

Quoted 4 lines

I have written some tests to test the new interface, see https://github.com/cyndis/uapi-test. Porting of proper userspace (e.g. opentegra, vdpau-tegra) will come once there is some degree of conclusion on the UAPI definition.

Could you please enumerate all the currently opened questions?

#62 lore raw
Quoted 32 lines · Dmitry Osipenko

05.09.2020 13:34, Mikko Perttunen пишет:

Quoted 31 lines

Hi all,

here's a second revision of the Host1x/TegraDRM UAPI proposal, hopefully with most issues from v1 resolved, and also with an implementation. There are still open issues with the implementation:

* Relocs are now handled on TegraDRM side instead of Host1x, so the firewall is not aware of them, causing submission failure where the firewall is enabled. Proposed solution is to move the firewall to TegraDRM side, but this hasn't been done yet.
* For the new UAPI, syncpoint recovery on job timeout is disabled. What this means is that upon job timeout, all further jobs using that syncpoint are cancelled, and the syncpoint is marked unusable until it is freed. However, there is currently a race between the timeout handler and job submission, where submission can observe the syncpoint in non-locked state and yet the job cancellations won't cancel the new job.
* Waiting for DMA reservation fences is not implemented yet.
* I have only tested on Tegra186.

The series consists of three parts:

* The first part contains some fixes and improvements to the Host1x driver of more general nature,
* The second part adds the Host1x side UAPI, as well as Host1x-side changes needed for the new TegraDRM UAPI,
* The third part adds the new TegraDRM UAPI.

Quoted 7 lines
Quoted 4 lines

I have written some tests to test the new interface, see https://github.com/cyndis/uapi-test. Porting of proper userspace (e.g. opentegra, vdpau-tegra) will come once there is some degree of conclusion on the UAPI definition.

Could you please enumerate all the currently opened questions?

Which open questions do you refer to? The open items of v1 should be closed now; for fences we setup an SW timeout to prevent them from sticking around forever, and regarding GEM the GEM IOCTLs are again being used.

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

#63 lore raw

09.09.2020 11:44, Mikko Perttunen пишет:
...

Quoted 4 lines
Quoted 2 lines

Could you please enumerate all the currently opened questions?

Which open questions do you refer to?

Anything related to the UAPI definition that needs more thought. If there is nothing outstanding, then good!

Quoted 5 lines

The open items of v1 should be
closed now; for fences we setup an SW timeout to prevent them from sticking around forever, and regarding GEM the GEM IOCTLs are again being used.

We'll see how it will be in practice! For now it's a bit difficult to decide what is good and what needs more improvement.