Skip to contentSkip to conversation

drm/vc4: Binner BO management improvements

PATCH Superseded Paul Kocialkowski 4 participants 18 messages Mar 20, 2019 – Mar 29, 2019

Subsystems (3)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover drm/vc4: Binner BO management improvements

Changes since v1:
* Squashed the two final patches into one.

Paul Kocialkowski (2):
drm/file: Rehabilitate the firstopen hook for non-legacy drivers drm/vc4: Allocated/liberate the binner BO at firstopen/lastclose

 drivers/gpu/drm/drm_file.c    |  3 +--
 drivers/gpu/drm/vc4/vc4_drv.c | 26 ++++++++++++++++++++++++++
 drivers/gpu/drm/vc4/vc4_drv.h |  1 +
 drivers/gpu/drm/vc4/vc4_irq.c |  3 +++
 drivers/gpu/drm/vc4/vc4_v3d.c | 15 +--------------
 include/drm/drm_drv.h         |  2 +-
 6 files changed, 33 insertions(+), 17 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH v2 1/2 drm/file: Rehabilitate the firstopen hook for non-legacy drivers

The firstopen DRM driver hook was initially used to perform hardware initialization, which is now considered legacy. Only a single user of firstopen remains at this point (savage).

In some specific cases, non-legacy drivers may also need to implement these hooks. For instance on VC4, we need to allocate a 16 MiB buffer for the GPU. Because it's not required for fbcon, it's a waste to allocate it before userspace starts using the DRM device.

Using firstopen and lastclose for this allocation seems like the best fit, so re-habilitate the hook to allow it to be called for non-legacy drivers.

---
 drivers/gpu/drm/drm_file.c | 3 +--
 include/drm/drm_drv.h      | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_file.c +1 -2
index b1838a41ad43..c011b5cbfb6b 100644
@@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
 {
 	int ret;
 
-	if (dev->driver->firstopen &&
-	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
+	if (dev->driver->firstopen) {
 		ret = dev->driver->firstopen(dev);
 		if (ret != 0)
 			return ret;
include/drm/drm_drv.h +1 -1
index ca46a45a9cce..aa14607e54d4 100644
@@ -236,7 +236,7 @@ struct drm_driver {
 	 * to set/unset the VT into raw mode.
 	 *
 	 * Legacy drivers initialize the hardware in the @firstopen callback,
-	 * which isn't even called for modern drivers.
+	 * modern drivers can use it for other purposes only.
 	 */
 	void (*lastclose) (struct drm_device *);
 
Signature · 1 line
2.21.0
#2 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Quoted 38 lines · Paul Kocialkowski

The firstopen DRM driver hook was initially used to perform hardware initialization, which is now considered legacy. Only a single user of firstopen remains at this point (savage).

In some specific cases, non-legacy drivers may also need to implement these hooks. For instance on VC4, we need to allocate a 16 MiB buffer for the GPU. Because it's not required for fbcon, it's a waste to allocate it before userspace starts using the DRM device.

Using firstopen and lastclose for this allocation seems like the best fit, so re-habilitate the hook to allow it to be called for non-legacy drivers.

---
 drivers/gpu/drm/drm_file.c | 3 +--
 include/drm/drm_drv.h      | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_file.c +1 -2
index b1838a41ad43..c011b5cbfb6b 100644
@@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
 {
 	int ret;
 
-	if (dev->driver->firstopen &&
-	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
+	if (dev->driver->firstopen) {
 		ret = dev->driver->firstopen(dev);
 		if (ret != 0)
 			return ret;
include/drm/drm_drv.h +0 -0
index ca46a45a9cce..aa14607e54d4 100644

include/drm/drm_drv.h struct drm_driver { · line 241

Quoted 7 lines
include/drm/drm_drv.h +1 -1
@@ -236,7 +236,7 @@ struct drm_driver {
 	 * to set/unset the VT into raw mode.
 	 *
 	 * Legacy drivers initialize the hardware in the @firstopen callback,
-	 * which isn't even called for modern drivers.
+	 * modern drivers can use it for other purposes only.
 	 */
 	void (*lastclose) (struct drm_device *);

Our usage in vc4 is not very different from what we called "hardware initialization" in other devices. I would rather just delete this sentence entirely.

The only alternative I can think of to using a firstopen/lastclose-style allocation for this would be to allocate the bin bo on the first (non-dumb?) V3D BO allocation and refcount those to free the binner.

#3 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Hi,

Quoted 43 lines · Eric Anholt
Quoted 41 lines · Paul Kocialkowski

The firstopen DRM driver hook was initially used to perform hardware initialization, which is now considered legacy. Only a single user of firstopen remains at this point (savage).

In some specific cases, non-legacy drivers may also need to implement these hooks. For instance on VC4, we need to allocate a 16 MiB buffer for the GPU. Because it's not required for fbcon, it's a waste to allocate it before userspace starts using the DRM device.

Using firstopen and lastclose for this allocation seems like the best fit, so re-habilitate the hook to allow it to be called for non-legacy drivers.

---
 drivers/gpu/drm/drm_file.c | 3 +--
 include/drm/drm_drv.h      | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_file.c +1 -2
index b1838a41ad43..c011b5cbfb6b 100644
@@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
 {
 	int ret;
 
-	if (dev->driver->firstopen &&
-	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
+	if (dev->driver->firstopen) {
 		ret = dev->driver->firstopen(dev);
 		if (ret != 0)
 			return ret;
include/drm/drm_drv.h +0 -0
index ca46a45a9cce..aa14607e54d4 100644
@@ -236,7 +236,7 @@ struct drm_driver {
 	 * to set/unset the VT into raw mode.
 	 *
 	 * Legacy drivers initialize the hardware in the @firstopen callback,
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 241

Quoted 4 lines
include/drm/drm_drv.h +1 -1
-	 * which isn't even called for modern drivers.
+	 * modern drivers can use it for other purposes only.
 	 */
 	void (*lastclose) (struct drm_device *);

Our usage in vc4 is not very different from what we called "hardware initialization" in other devices. I would rather just delete this sentence entirely.

Sounds good to me!

Quoted 3 lines

The only alternative I can think of to using a firstopen/lastclose-style allocation for this would be to allocate the bin bo on the first (non-dumb?) V3D BO allocation and refcount those to free the binner.

I don't see other options either, and using firstclose/lastopen feels overall more readable in the driver code.

I'm not sure there is such a big overhead associated with allocating the binner BO (it seems that the current implementation tries to alloc until the specific memory constraints for the buffer are met, so perhaps that can take time). But if there is, I suppose it's best to have that when starting up rather than delaying the first render operation.

Cheers,

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
Reviewed-by
#4 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Quoted 55 lines · Paul Kocialkowski

Hi,

Quoted 43 lines · Eric Anholt
Quoted 41 lines · Paul Kocialkowski

The firstopen DRM driver hook was initially used to perform hardware initialization, which is now considered legacy. Only a single user of firstopen remains at this point (savage).

In some specific cases, non-legacy drivers may also need to implement these hooks. For instance on VC4, we need to allocate a 16 MiB buffer for the GPU. Because it's not required for fbcon, it's a waste to allocate it before userspace starts using the DRM device.

Using firstopen and lastclose for this allocation seems like the best fit, so re-habilitate the hook to allow it to be called for non-legacy drivers.

---
 drivers/gpu/drm/drm_file.c | 3 +--
 include/drm/drm_drv.h      | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_file.c +1 -2
index b1838a41ad43..c011b5cbfb6b 100644
@@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
 {
 	int ret;
 
-	if (dev->driver->firstopen &&
-	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
+	if (dev->driver->firstopen) {
 		ret = dev->driver->firstopen(dev);
 		if (ret != 0)
 			return ret;
include/drm/drm_drv.h +0 -0
index ca46a45a9cce..aa14607e54d4 100644
@@ -236,7 +236,7 @@ struct drm_driver {
 	 * to set/unset the VT into raw mode.
 	 *
 	 * Legacy drivers initialize the hardware in the @firstopen callback,
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 241

Quoted 4 lines
include/drm/drm_drv.h +1 -1
-	 * which isn't even called for modern drivers.
+	 * modern drivers can use it for other purposes only.
 	 */
 	void (*lastclose) (struct drm_device *);

Our usage in vc4 is not very different from what we called "hardware initialization" in other devices. I would rather just delete this sentence entirely.

Quoted 1 line

Sounds good to me!

With the delete, the series is:

but hopefully someone other than a vc4 developer (danvet?) can make the call on whether undeprecating firstopen/lastclose for this is reasonable.

#5 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

In reply to Paul Kocialkowski
Quoted 64 lines · Paul Kocialkowski

Hi,

Quoted 43 lines · Eric Anholt
Quoted 41 lines · Paul Kocialkowski

The firstopen DRM driver hook was initially used to perform hardware initialization, which is now considered legacy. Only a single user of firstopen remains at this point (savage).

In some specific cases, non-legacy drivers may also need to implement these hooks. For instance on VC4, we need to allocate a 16 MiB buffer for the GPU. Because it's not required for fbcon, it's a waste to allocate it before userspace starts using the DRM device.

Using firstopen and lastclose for this allocation seems like the best fit, so re-habilitate the hook to allow it to be called for non-legacy drivers.

---
 drivers/gpu/drm/drm_file.c | 3 +--
 include/drm/drm_drv.h      | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_file.c +1 -2
index b1838a41ad43..c011b5cbfb6b 100644
@@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
 {
 	int ret;
 
-	if (dev->driver->firstopen &&
-	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
+	if (dev->driver->firstopen) {
 		ret = dev->driver->firstopen(dev);
 		if (ret != 0)
 			return ret;
include/drm/drm_drv.h +0 -0
index ca46a45a9cce..aa14607e54d4 100644
@@ -236,7 +236,7 @@ struct drm_driver {
 	 * to set/unset the VT into raw mode.
 	 *
 	 * Legacy drivers initialize the hardware in the @firstopen callback,
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 241

Quoted 4 lines
include/drm/drm_drv.h +1 -1
-	 * which isn't even called for modern drivers.
+	 * modern drivers can use it for other purposes only.
 	 */
 	void (*lastclose) (struct drm_device *);

Our usage in vc4 is not very different from what we called "hardware initialization" in other devices. I would rather just delete this sentence entirely.

Sounds good to me!

Quoted 3 lines

The only alternative I can think of to using a firstopen/lastclose-style allocation for this would be to allocate the bin bo on the first (non-dumb?) V3D BO allocation and refcount those to free the binner.

I don't see other options either, and using firstclose/lastopen feels overall more readable in the driver code.

Quoted 6 lines

I'm not sure there is such a big overhead associated with allocating the binner BO (it seems that the current implementation tries to alloc until the specific memory constraints for the buffer are met, so perhaps that can take time). But if there is, I suppose it's best to have that when starting up rather than delaying the first render operation.

I'm not entirely buying the "we don't need this for fbcon only" argument - there's plenty of dumb kms clients too (boot splash and whatever else there might be). If you don't want to keep this around I think allocating on first non-dumb bo allocation and dropping it when the last such fd closes sounds like a much better idea. Needs a bit more state, you need to track per drm_file whether you've already allocated a non-dumb bo, and a drm_device refcount, but that's not much. Firstopen feels like the wrong thing.

Another option would be first_renderopen or something like that, except you can also render on the legacy node and I'm not sure how much there's a demand for this in other drivers. In the end you have open/close callbacks, you can do all the driver specific things you want to do in there.

Aside: I kinda also want to ditch lastclose usage. There's fbdev (we have a better solution with Noralf's drm_client for those) and runtime pm (which frankly is just a cheap hack, I want my gpu to susepend also when it's not in use when all the screens are off, not only when I killed X and everything).
-Daniel

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

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Hi,

Quoted 20 lines · Daniel Vetter
Quoted 9 lines · Paul Kocialkowski

I don't see other options either, and using firstclose/lastopen feels overall more readable in the driver code.

I'm not sure there is such a big overhead associated with allocating the binner BO (it seems that the current implementation tries to alloc until the specific memory constraints for the buffer are met, so perhaps that can take time). But if there is, I suppose it's best to have that when starting up rather than delaying the first render operation.

I'm not entirely buying the "we don't need this for fbcon only" argument - there's plenty of dumb kms clients too (boot splash and whatever else there might be). If you don't want to keep this around I think allocating on first non-dumb bo allocation and dropping it when the last such fd closes sounds like a much better idea. Needs a bit more state, you need to track per drm_file whether you've already allocated a non-dumb bo, and a drm_device refcount, but that's not much. Firstopen feels like the wrong thing.

Quoted 5 lines

Another option would be first_renderopen or something like that, except you can also render on the legacy node and I'm not sure how much there's a demand for this in other drivers. In the end you have open/close callbacks, you can do all the driver specific things you want to do in there.

I'd like to avoid doing it in open where possible, since that hurts device enumeration from userspace.

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

#7 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Hi,

Quoted 23 lines · Daniel Stone

Hi,

Quoted 20 lines · Daniel Vetter
Quoted 9 lines · Paul Kocialkowski

I don't see other options either, and using firstclose/lastopen feels overall more readable in the driver code.

I'm not sure there is such a big overhead associated with allocating the binner BO (it seems that the current implementation tries to alloc until the specific memory constraints for the buffer are met, so perhaps that can take time). But if there is, I suppose it's best to have that when starting up rather than delaying the first render operation.

I'm not entirely buying the "we don't need this for fbcon only" argument - there's plenty of dumb kms clients too (boot splash and whatever else there might be). If you don't want to keep this around I think allocating on first non-dumb bo allocation and dropping it when the last such fd closes sounds like a much better idea. Needs a bit more state, you need to track per drm_file whether you've already allocated a non-dumb bo, and a drm_device refcount, but that's not much. Firstopen feels like the wrong thing.

Quoted 8 lines
Quoted 5 lines

Another option would be first_renderopen or something like that, except you can also render on the legacy node and I'm not sure how much there's a demand for this in other drivers. In the end you have open/close callbacks, you can do all the driver specific things you want to do in there.

I'd like to avoid doing it in open where possible, since that hurts device enumeration from userspace.

I've noticed the same issue with firstopen, where our buffer is allocated/liberated a couple of times during enumeration, before the final open that stays alive during use.

I'm not sure what is preferable between that and allocating when the GPU is first used. Slowing down the first GPU operation with the allocation does not sound too great either and it feels like the buffer should have been allocated earlier.

To me, it feels I think it's better to have delays due to allocation at enumeration / startup rather than later on, but I might be missing some elements to have a clear idea.

What do you think?

Cheers,

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#8 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Quoted 44 lines · Paul Kocialkowski

Hi,

Quoted 23 lines · Daniel Stone

Hi,

Quoted 20 lines · Daniel Vetter
Quoted 9 lines · Paul Kocialkowski

I don't see other options either, and using firstclose/lastopen feels overall more readable in the driver code.

I'm not sure there is such a big overhead associated with allocating the binner BO (it seems that the current implementation tries to alloc until the specific memory constraints for the buffer are met, so perhaps that can take time). But if there is, I suppose it's best to have that when starting up rather than delaying the first render operation.

I'm not entirely buying the "we don't need this for fbcon only" argument - there's plenty of dumb kms clients too (boot splash and whatever else there might be). If you don't want to keep this around I think allocating on first non-dumb bo allocation and dropping it when the last such fd closes sounds like a much better idea. Needs a bit more state, you need to track per drm_file whether you've already allocated a non-dumb bo, and a drm_device refcount, but that's not much. Firstopen feels like the wrong thing.

Quoted 8 lines
Quoted 5 lines

Another option would be first_renderopen or something like that, except you can also render on the legacy node and I'm not sure how much there's a demand for this in other drivers. In the end you have open/close callbacks, you can do all the driver specific things you want to do in there.

I'd like to avoid doing it in open where possible, since that hurts device enumeration from userspace.

I've noticed the same issue with firstopen, where our buffer is allocated/liberated a couple of times during enumeration, before the final open that stays alive during use.

I'm not sure what is preferable between that and allocating when the GPU is first used. Slowing down the first GPU operation with the allocation does not sound too great either and it feels like the buffer should have been allocated earlier.

Quoted 5 lines

To me, it feels I think it's better to have delays due to allocation at enumeration / startup rather than later on, but I might be missing some elements to have a clear idea.

What do you think?

We'll have the delay somewhere on driver load. Better to have it only once (when the driver starts using gem for real), than a bunch of time, at least once while enumerating and then once more while actually initializing. I think if you allocat this on first non-dumb gem_create, and on first command submission (just so evil userspace can't screw up the hw too badly), that should be perfectly fine.

Only way to avoid that is to allocate at driver load and pin it, but that's what we're trying to avoid here.
-Daniel

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

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Hi,

Quoted 49 lines · Daniel Vetter
Quoted 48 lines · Paul Kocialkowski

Hi,

Quoted 23 lines · Daniel Stone

Hi,

Quoted 20 lines · Daniel Vetter
Quoted 9 lines · Paul Kocialkowski

I don't see other options either, and using firstclose/lastopen feels overall more readable in the driver code.

I'm not sure there is such a big overhead associated with allocating the binner BO (it seems that the current implementation tries to alloc until the specific memory constraints for the buffer are met, so perhaps that can take time). But if there is, I suppose it's best to have that when starting up rather than delaying the first render operation.

I'm not entirely buying the "we don't need this for fbcon only" argument - there's plenty of dumb kms clients too (boot splash and whatever else there might be). If you don't want to keep this around I think allocating on first non-dumb bo allocation and dropping it when the last such fd closes sounds like a much better idea. Needs a bit more state, you need to track per drm_file whether you've already allocated a non-dumb bo, and a drm_device refcount, but that's not much. Firstopen feels like the wrong thing.

Quoted 8 lines
Quoted 5 lines

Another option would be first_renderopen or something like that, except you can also render on the legacy node and I'm not sure how much there's a demand for this in other drivers. In the end you have open/close callbacks, you can do all the driver specific things you want to do in there.

I'd like to avoid doing it in open where possible, since that hurts device enumeration from userspace.

I've noticed the same issue with firstopen, where our buffer is allocated/liberated a couple of times during enumeration, before the final open that stays alive during use.

I'm not sure what is preferable between that and allocating when the GPU is first used. Slowing down the first GPU operation with the allocation does not sound too great either and it feels like the buffer should have been allocated earlier.

To me, it feels I think it's better to have delays due to allocation at enumeration / startup rather than later on, but I might be missing some elements to have a clear idea.

Quoted 8 lines
Quoted 1 line

What do you think?

We'll have the delay somewhere on driver load. Better to have it only once (when the driver starts using gem for real), than a bunch of time, at least once while enumerating and then once more while actually initializing. I think if you allocat this on first non-dumb gem_create, and on first command submission (just so evil userspace can't screw up the hw too badly), that should be perfectly fine.

I'm not totally convinced that it's okay to have a delay outside of init/enumeration, even if it's a smaller delay.

Eric, do you have an opinion on what is the preference with VC4?

Quoted 2 lines

Only way to avoid that is to allocate at driver load and pin it, but that's what we're trying to avoid here.

Exactly!

Cheers,

Paul

Signature · 8 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

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

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Quoted 61 lines · Paul Kocialkowski

Hi,

Quoted 49 lines · Daniel Vetter
Quoted 48 lines · Paul Kocialkowski

Hi,

Quoted 23 lines · Daniel Stone

Hi,

Quoted 20 lines · Daniel Vetter
Quoted 9 lines · Paul Kocialkowski

I don't see other options either, and using firstclose/lastopen feels overall more readable in the driver code.

I'm not sure there is such a big overhead associated with allocating the binner BO (it seems that the current implementation tries to alloc until the specific memory constraints for the buffer are met, so perhaps that can take time). But if there is, I suppose it's best to have that when starting up rather than delaying the first render operation.

I'm not entirely buying the "we don't need this for fbcon only" argument - there's plenty of dumb kms clients too (boot splash and whatever else there might be). If you don't want to keep this around I think allocating on first non-dumb bo allocation and dropping it when the last such fd closes sounds like a much better idea. Needs a bit more state, you need to track per drm_file whether you've already allocated a non-dumb bo, and a drm_device refcount, but that's not much. Firstopen feels like the wrong thing.

Quoted 8 lines
Quoted 5 lines

Another option would be first_renderopen or something like that, except you can also render on the legacy node and I'm not sure how much there's a demand for this in other drivers. In the end you have open/close callbacks, you can do all the driver specific things you want to do in there.

I'd like to avoid doing it in open where possible, since that hurts device enumeration from userspace.

I've noticed the same issue with firstopen, where our buffer is allocated/liberated a couple of times during enumeration, before the final open that stays alive during use.

I'm not sure what is preferable between that and allocating when the GPU is first used. Slowing down the first GPU operation with the allocation does not sound too great either and it feels like the buffer should have been allocated earlier.

To me, it feels I think it's better to have delays due to allocation at enumeration / startup rather than later on, but I might be missing some elements to have a clear idea.

Quoted 8 lines
Quoted 1 line

What do you think?

We'll have the delay somewhere on driver load. Better to have it only once (when the driver starts using gem for real), than a bunch of time, at least once while enumerating and then once more while actually initializing. I think if you allocat this on first non-dumb gem_create, and on first command submission (just so evil userspace can't screw up the hw too badly), that should be perfectly fine.

Quoted 2 lines

I'm not totally convinced that it's okay to have a delay outside of init/enumeration, even if it's a smaller delay.

You'll have non-dumb buffers created during GL context creation, so early in xserver or other KMS-and-GL-using application init anyway. Seems like a perfectly fine plan to me.

#11 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Hi,

Quoted 7 lines · Eric Anholt
Quoted 2 lines · Paul Kocialkowski

I'm not totally convinced that it's okay to have a delay outside of init/enumeration, even if it's a smaller delay.

You'll have non-dumb buffers created during GL context creation, so early in xserver or other KMS-and-GL-using application init anyway. Seems like a perfectly fine plan to me.

Yeah. The alternative is doing it once when Plymouth starts, and then maybe again when Weston/GNOME/Xorg/... starts, which isn't really ideal (or maybe even udev helpers). Doing it on probe also complicates profiling startup for those: if GL context or surface creation takes a long time, that's easy to reason about. If opening an FD takes ages, that makes figuring out why stuff is slow a lot more complicated. This used to happen with RPM resume for PCI devices to read the device ID & revision, which is why we now have an API that persists that to avoid the delay.

Sorry this feedback is coming quite late into development.

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

#12 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

Hi,

Quoted 11 lines · Daniel Stone

Hi,

Quoted 7 lines · Eric Anholt
Quoted 2 lines · Paul Kocialkowski

I'm not totally convinced that it's okay to have a delay outside of init/enumeration, even if it's a smaller delay.

You'll have non-dumb buffers created during GL context creation, so early in xserver or other KMS-and-GL-using application init anyway. Seems like a perfectly fine plan to me.

Quoted 9 lines

Yeah. The alternative is doing it once when Plymouth starts, and then maybe again when Weston/GNOME/Xorg/... starts, which isn't really ideal (or maybe even udev helpers). Doing it on probe also complicates profiling startup for those: if GL context or surface creation takes a long time, that's easy to reason about. If opening an FD takes ages, that makes figuring out why stuff is slow a lot more complicated. This used to happen with RPM resume for PCI devices to read the device ID & revision, which is why we now have an API that persists that to avoid the delay.

Sounds like we have a plan then, I'll spin up a new series allocating the binner BO at the first non-dumb BO alloc. Thanks for your input!

Quoted 1 line

Sorry this feedback is coming quite late into development.

The feedback is definitely quite welcome! I tried a few things that didn't pan out before using firstopen/lastclose and it's really interesting to refine the implementation based on the shortcomings of previous ideas.

Cheers,

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#13 lore raw

Re: [PATCH v2 1/2] drm/file: Rehabilitate the firstopen hook for non-legacy drivers

In reply to Daniel Vetter

Hi,

Quoted 72 lines · Daniel Vetter
Quoted 64 lines · Paul Kocialkowski

Hi,

Quoted 43 lines · Eric Anholt
Quoted 41 lines · Paul Kocialkowski

The firstopen DRM driver hook was initially used to perform hardware initialization, which is now considered legacy. Only a single user of firstopen remains at this point (savage).

In some specific cases, non-legacy drivers may also need to implement these hooks. For instance on VC4, we need to allocate a 16 MiB buffer for the GPU. Because it's not required for fbcon, it's a waste to allocate it before userspace starts using the DRM device.

Using firstopen and lastclose for this allocation seems like the best fit, so re-habilitate the hook to allow it to be called for non-legacy drivers.

---
 drivers/gpu/drm/drm_file.c | 3 +--
 include/drm/drm_drv.h      | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_file.c +1 -2
index b1838a41ad43..c011b5cbfb6b 100644
@@ -266,8 +266,7 @@ static int drm_setup(struct drm_device * dev)
 {
 	int ret;
 
-	if (dev->driver->firstopen &&
-	    drm_core_check_feature(dev, DRIVER_LEGACY)) {
+	if (dev->driver->firstopen) {
 		ret = dev->driver->firstopen(dev);
 		if (ret != 0)
 			return ret;
include/drm/drm_drv.h +0 -0
index ca46a45a9cce..aa14607e54d4 100644
@@ -236,7 +236,7 @@ struct drm_driver {
 	 * to set/unset the VT into raw mode.
 	 *
 	 * Legacy drivers initialize the hardware in the @firstopen callback,
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 241

Quoted 4 lines
include/drm/drm_drv.h +1 -1
-	 * which isn't even called for modern drivers.
+	 * modern drivers can use it for other purposes only.
 	 */
 	void (*lastclose) (struct drm_device *);

Our usage in vc4 is not very different from what we called "hardware initialization" in other devices. I would rather just delete this sentence entirely.

Sounds good to me!

Quoted 3 lines

The only alternative I can think of to using a firstopen/lastclose-style allocation for this would be to allocate the bin bo on the first (non-dumb?) V3D BO allocation and refcount those to free the binner.

I don't see other options either, and using firstclose/lastopen feels overall more readable in the driver code.

Quoted 6 lines

I'm not sure there is such a big overhead associated with allocating the binner BO (it seems that the current implementation tries to alloc until the specific memory constraints for the buffer are met, so perhaps that can take time). But if there is, I suppose it's best to have that when starting up rather than delaying the first render operation.

Quoted 8 lines

I'm not entirely buying the "we don't need this for fbcon only" argument - there's plenty of dumb kms clients too (boot splash and whatever else there might be). If you don't want to keep this around I think allocating on first non-dumb bo allocation and dropping it when the last such fd closes sounds like a much better idea. Needs a bit more state, you need to track per drm_file whether you've already allocated a non-dumb bo, and a drm_device refcount, but that's not much. Firstopen feels like the wrong thing.

This is quite a valid point, but we decided to go for a middle-ground between always allocating and allocating at the first GPU op, so that the operation is not significantly delayed by allocating the buffer.

Quoted 5 lines

Another option would be first_renderopen or something like that, except you can also render on the legacy node and I'm not sure how much there's a demand for this in other drivers. In the end you have open/close callbacks, you can do all the driver specific things you want to do in there.

Yes I've initially tried playing with that and reached the same
conclusion: there can be render ops on the legacy node too so this is just not reliable for what we're trying to do.

Quoted 5 lines

Aside: I kinda also want to ditch lastclose usage. There's fbdev (we have a better solution with Noralf's drm_client for those) and runtime pm (which frankly is just a cheap hack, I want my gpu to susepend also when it's not in use when all the screens are off, not only when I killed X and everything).

I understand that, yes. I don't see any issue with a implementation tracking the state in open if we really want firstopen/lastclose to disappear.

Cheers,

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#14 lore raw

PATCH v2 2/2 drm/vc4: Allocated/liberate the binner BO at firstopen/lastclose

In reply to Paul Kocialkowski

The binner BO is a pre-requisite to GPU operations, so we must ensure that it is always allocated when the GPU is in use. Currently, we are allocating it at probe time and liberating/allocating it during runtime pm cycles.

First, since the binner buffer is only required for GPU rendering, it's a waste to allocate it when the driver probes since internal users of the driver (such as fbcon) won't try to use the GPU.

Move the allocation/liberation to the firstopen/lastclose instead to only allocate it when userspace has opened the device and adapt the IRQ handler to return early when no binner BO was allocated yet.

Second, because the buffer is allocated from the same pool as other GPU buffers, we might run into a situation where we are out of memory at runtime resume. This causes the binner BO allocation to fail and results in all subsequent operations to fail, resulting in a major hang in userspace.

As a result, keep the buffer alive during runtime pm.

---
 drivers/gpu/drm/vc4/vc4_drv.c | 26 ++++++++++++++++++++++++++
 drivers/gpu/drm/vc4/vc4_drv.h |  1 +
 drivers/gpu/drm/vc4/vc4_irq.c |  3 +++
 drivers/gpu/drm/vc4/vc4_v3d.c | 15 +--------------
 4 files changed, 31 insertions(+), 14 deletions(-)
drivers/gpu/drm/vc4/vc4_drv.c +26 -0
index 3227706700f9..605dc50613e3 100644
@@ -134,6 +134,30 @@ static void vc4_close(struct drm_device *dev, struct drm_file *file)
 	kfree(vc4file);
 }
 
+static int vc4_firstopen(struct drm_device *drm)
+{
+	struct vc4_dev *vc4 = to_vc4_dev(drm);
+	int ret;
+
+	if (!vc4->bin_bo) {
+		ret = vc4_allocate_bin_bo(drm);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static void vc4_lastclose(struct drm_device *drm)
+{
+	struct vc4_dev *vc4 = to_vc4_dev(drm);
+
+	if (vc4->bin_bo) {
+		drm_gem_object_put_unlocked(&vc4->bin_bo->base.base);
+		vc4->bin_bo = NULL;
+	}
+}
+
 static const struct vm_operations_struct vc4_vm_ops = {
 	.fault = vc4_fault,
 	.open = drm_gem_vm_open,
@@ -180,6 +204,8 @@ static struct drm_driver vc4_drm_driver = {
 			    DRIVER_SYNCOBJ),
 	.open = vc4_open,
 	.postclose = vc4_close,
+	.firstopen = vc4_firstopen,
+	.lastclose = vc4_lastclose,
 	.irq_handler = vc4_irq,
 	.irq_preinstall = vc4_irq_preinstall,
 	.irq_postinstall = vc4_irq_postinstall,
drivers/gpu/drm/vc4/vc4_drv.h +1 -0
index 7a3c093e7443..f52bb21e9885 100644
@@ -808,6 +808,7 @@ extern struct platform_driver vc4_v3d_driver;
 int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
 int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
 int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
+int vc4_allocate_bin_bo(struct drm_device *drm);
 
 /* vc4_validate.c */
 int
drivers/gpu/drm/vc4/vc4_irq.c +3 -0
index 4cd2ccfe15f4..efaba2b02f6c 100644
@@ -64,6 +64,9 @@ vc4_overflow_mem_work(struct work_struct *work)
 	struct vc4_exec_info *exec;
 	unsigned long irqflags;
 
+	if (!bo)
+		return;
+
 	bin_bo_slot = vc4_v3d_get_bin_slot(vc4);
 	if (bin_bo_slot < 0) {
 		DRM_ERROR("Couldn't allocate binner overflow mem\n");
drivers/gpu/drm/vc4/vc4_v3d.c +1 -14
index e47e29426078..e04a51a75f01 100644
@@ -218,7 +218,7 @@ int vc4_v3d_get_bin_slot(struct vc4_dev *vc4)
  * overall CMA pool before they make scenes complicated enough to run
  * out of bin space.
  */
-static int vc4_allocate_bin_bo(struct drm_device *drm)
+int vc4_allocate_bin_bo(struct drm_device *drm)
 {
 	struct vc4_dev *vc4 = to_vc4_dev(drm);
 	struct vc4_v3d *v3d = vc4->v3d;
@@ -303,9 +303,6 @@ static int vc4_v3d_runtime_suspend(struct device *dev)
 
 	vc4_irq_uninstall(vc4->dev);
 
-	drm_gem_object_put_unlocked(&vc4->bin_bo->base.base);
-	vc4->bin_bo = NULL;
-
 	clk_disable_unprepare(v3d->clk);
 
 	return 0;
@@ -317,10 +314,6 @@ static int vc4_v3d_runtime_resume(struct device *dev)
 	struct vc4_dev *vc4 = v3d->vc4;
 	int ret;
 
-	ret = vc4_allocate_bin_bo(vc4->dev);
-	if (ret)
-		return ret;
-
 	ret = clk_prepare_enable(v3d->clk);
 	if (ret != 0)
 		return ret;
@@ -384,12 +377,6 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
 	if (ret != 0)
 		return ret;
 
-	ret = vc4_allocate_bin_bo(drm);
-	if (ret) {
-		clk_disable_unprepare(v3d->clk);
-		return ret;
-	}
-
 	/* Reset the binner overflow address/size at setup, to be sure
 	 * we don't reuse an old one.
 	 */
Signature · 6 lines
2.21.0

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

Re: [PATCH v2 2/2] drm/vc4: Allocated/liberate the binner BO at firstopen/lastclose

Quoted 29 lines · Paul Kocialkowski

The binner BO is a pre-requisite to GPU operations, so we must ensure that it is always allocated when the GPU is in use. Currently, we are allocating it at probe time and liberating/allocating it during runtime pm cycles.

First, since the binner buffer is only required for GPU rendering, it's a waste to allocate it when the driver probes since internal users of the driver (such as fbcon) won't try to use the GPU.

Move the allocation/liberation to the firstopen/lastclose instead to only allocate it when userspace has opened the device and adapt the IRQ handler to return early when no binner BO was allocated yet.

Second, because the buffer is allocated from the same pool as other GPU buffers, we might run into a situation where we are out of memory at runtime resume. This causes the binner BO allocation to fail and results in all subsequent operations to fail, resulting in a major hang in userspace.

As a result, keep the buffer alive during runtime pm.

---

drivers/gpu/drm/vc4/vc4_irq.c +0 -0
index 4cd2ccfe15f4..efaba2b02f6c 100644

drivers/gpu/drm/vc4/vc4_irq.c vc4_overflow_mem_work(struct work_struct *work) · line 72

Quoted 9 lines
drivers/gpu/drm/vc4/vc4_irq.c +3 -0
@@ -64,6 +64,9 @@ vc4_overflow_mem_work(struct work_struct *work)
 	struct vc4_exec_info *exec;
 	unsigned long irqflags;
 
+	if (!bo)
+		return;
+
 	bin_bo_slot = vc4_v3d_get_bin_slot(vc4);
 	if (bin_bo_slot < 0) {
 		DRM_ERROR("Couldn't allocate binner overflow mem\n");

Hmm. We take the OOM IRQ on poweron, have no bin BO since nobody's opened yet, and leave it. Do we ever get the OOM IRQ again after that? Seems like vc4_allocate_bin_bo() might need to kick something so that we can fill an OOM request.

#16 lore raw

Re: [PATCH v2 2/2] drm/vc4: Allocated/liberate the binner BO at firstopen/lastclose

Hi,

Quoted 33 lines · Eric Anholt
Quoted 31 lines · Paul Kocialkowski

The binner BO is a pre-requisite to GPU operations, so we must ensure that it is always allocated when the GPU is in use. Currently, we are allocating it at probe time and liberating/allocating it during runtime pm cycles.

First, since the binner buffer is only required for GPU rendering, it's a waste to allocate it when the driver probes since internal users of the driver (such as fbcon) won't try to use the GPU.

Move the allocation/liberation to the firstopen/lastclose instead to only allocate it when userspace has opened the device and adapt the IRQ handler to return early when no binner BO was allocated yet.

Second, because the buffer is allocated from the same pool as other GPU buffers, we might run into a situation where we are out of memory at runtime resume. This causes the binner BO allocation to fail and results in all subsequent operations to fail, resulting in a major hang in userspace.

As a result, keep the buffer alive during runtime pm.

---

drivers/gpu/drm/vc4/vc4_irq.c +0 -0
index 4cd2ccfe15f4..efaba2b02f6c 100644
@@ -64,6 +64,9 @@ vc4_overflow_mem_work(struct work_struct *work)
 	struct vc4_exec_info *exec;
 	unsigned long irqflags;
 
Quoted 11 lines

drivers/gpu/drm/vc4/vc4_irq.c vc4_overflow_mem_work(struct work_struct *work) · line 72

Quoted 6 lines
drivers/gpu/drm/vc4/vc4_irq.c +3 -0
+	if (!bo)
+		return;
+
 	bin_bo_slot = vc4_v3d_get_bin_slot(vc4);
 	if (bin_bo_slot < 0) {
 		DRM_ERROR("Couldn't allocate binner overflow mem\n");

Hmm. We take the OOM IRQ on poweron, have no bin BO since nobody's opened yet, and leave it. Do we ever get the OOM IRQ again after that? Seems like vc4_allocate_bin_bo() might need to kick something so that we can fill an OOM request.

I just had a look and it seems that we do get the OOM interrupt again after the bin BO is allocated. Actually, I can see it kicking from time to time when using X with glamor.

Quoted 1 line

From what I understood, this looks fairly legitimate. Should we be

worried about this?

Cheers,

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#17 lore raw

Re: [PATCH v2 2/2] drm/vc4: Allocated/liberate the binner BO at firstopen/lastclose

Quoted 48 lines · Paul Kocialkowski

Hi,

Quoted 33 lines · Eric Anholt
Quoted 31 lines · Paul Kocialkowski

The binner BO is a pre-requisite to GPU operations, so we must ensure that it is always allocated when the GPU is in use. Currently, we are allocating it at probe time and liberating/allocating it during runtime pm cycles.

First, since the binner buffer is only required for GPU rendering, it's a waste to allocate it when the driver probes since internal users of the driver (such as fbcon) won't try to use the GPU.

Move the allocation/liberation to the firstopen/lastclose instead to only allocate it when userspace has opened the device and adapt the IRQ handler to return early when no binner BO was allocated yet.

Second, because the buffer is allocated from the same pool as other GPU buffers, we might run into a situation where we are out of memory at runtime resume. This causes the binner BO allocation to fail and results in all subsequent operations to fail, resulting in a major hang in userspace.

As a result, keep the buffer alive during runtime pm.

---

drivers/gpu/drm/vc4/vc4_irq.c +0 -0
index 4cd2ccfe15f4..efaba2b02f6c 100644
@@ -64,6 +64,9 @@ vc4_overflow_mem_work(struct work_struct *work)
 	struct vc4_exec_info *exec;
 	unsigned long irqflags;
 
Quoted 11 lines

drivers/gpu/drm/vc4/vc4_irq.c vc4_overflow_mem_work(struct work_struct *work) · line 72

Quoted 6 lines
drivers/gpu/drm/vc4/vc4_irq.c +3 -0
+	if (!bo)
+		return;
+
 	bin_bo_slot = vc4_v3d_get_bin_slot(vc4);
 	if (bin_bo_slot < 0) {
 		DRM_ERROR("Couldn't allocate binner overflow mem\n");

Hmm. We take the OOM IRQ on poweron, have no bin BO since nobody's opened yet, and leave it. Do we ever get the OOM IRQ again after that? Seems like vc4_allocate_bin_bo() might need to kick something so that we can fill an OOM request.

Quoted 6 lines

I just had a look and it seems that we do get the OOM interrupt again after the bin BO is allocated. Actually, I can see it kicking from time to time when using X with glamor.

From what I understood, this looks fairly legitimate. Should we be worried about this?

Great. I think how it ends up working is that when the job is submitted, the bin allocation it supplies internally gets us out of the OOM condition, so OOM can edge trigger again later.