drm: Standardize device reset notification
Subsystems (5)
v3 cover drm: Standardize device reset notification
Hi,
This is a new version of the documentation for DRM device resets. As I dived more in the subject, I started to believe that part of the problem was the lack of a DRM API to get reset information from the driver. With an API, we can better standardize reset queries, increase common code from both DRM and Mesa, and make easier to write end-to-end tests.
So this patchset, along with the documentation, comes with a new IOCTL and two implementations of it for amdgpu and i915 (although just the former was really tested). This IOCTL uses the "context id" to query reset information, but this might be not generic enough to be included in a DRM API. At least for amdgpu, this information is encapsulated by libdrm so one can't just call the ioctl directly from the UMD as I was planning to, but a small refactor can be done to expose the id. Anyway, I'm sharing it as it is to gather feedback if this seems to work.
The amdgpu and i915 implementations are provided as a mean of testing and as exemplification, and not as reference code yet, as the goal is more about the interface itself then the driver parts.
For the documentation itself, after spending some time reading the reset path in the kernel in Mesa, I decide to rewrite it to better reflect how it works, from bottom to top.
You can check the userspace side of the IOCLT here:
Mesa: https://gitlab.freedesktop.org/andrealmeid/mesa/-/commit/cd687b22fb32c21b23596c607003e2a495f465
libdrm: https://gitlab.freedesktop.org/andrealmeid/libdrm/-/commit/b31e5404893ee9a85d1aa67e81c2f58c1dac3c46
For testing, I use this vulkan app that has an infinity loop in the shader:
https://github.com/andrealmeid/vulkan-triangle-v1
Feedbacks are welcomed!
Thanks,
André
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
André Almeida (4):
drm/doc: Document DRM device reset expectations
drm: Create DRM_IOCTL_GET_RESET
drm/amdgpu: Implement DRM_IOCTL_GET_RESET
drm/i915: Implement DRM_IOCTL_GET_RESET
Documentation/gpu/drm-uapi.rst | 51 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 35 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 5 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 + drivers/gpu/drm/drm_debugfs.c | 2 + drivers/gpu/drm/drm_ioctl.c | 58 +++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_context.c | 18 ++++++ drivers/gpu/drm/i915/gem/i915_gem_context.h | 2 + .../gpu/drm/i915/gem/i915_gem_context_types.h | 2 + drivers/gpu/drm/i915/i915_driver.c | 2 + include/drm/drm_device.h | 3 + include/drm/drm_drv.h | 3 + include/uapi/drm/drm.h | 21 +++++++ include/uapi/drm/drm_mode.h | 15 +++++ 17 files changed, 233 insertions(+), 3 deletions(-)
Signature · 1 line
2.41.0
RFC PATCH v3 1/4 drm/doc: Document DRM device reset expectations
Create a section that specifies how to deal with DRM device resets for kernel and userspace drivers.
--- Documentation/gpu/drm-uapi.rst | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)
Documentation/gpu/drm-uapi.rst +65 -0
@@ -285,6 +285,71 @@ for GPU1 and GPU2 from different vendors, and a third handler for mmapped regular files. Threads cause additional pain with signal handling as well. +Device reset +============ + +The GPU stack is really complex and is prone to errors, from hardware bugs, +faulty applications and everything in between the many layers. To recover +from this kind of state, sometimes is needed to reset the device. This section +describes what's the expectations for DRM and usermode drivers when a device +resets and how to propagate the reset status. + +Kernel Mode Driver +------------------ + +The KMD is responsible for checking if the device needs a reset, and to perform +it as needed. Usually a hung is detected when a job gets stuck executing. KMD +then update it's internal reset tracking to be ready when userspace asks the +kernel about reset information. Drivers should implement the DRM_IOCTL_GET_RESET +for that. + +User Mode Driver +---------------- + +The UMD should check before submitting new commands to the KMD if the device has +been reset, and this can be checked more often if it requires to. The +DRM_IOCTL_GET_RESET is the default interface for those kind of checks. After +detecting a reset, UMD will then proceed to report it to the application using +the appropriated API error code, as explained in the bellow section about +robustness. + +Robustness +---------- + +The only way to try to keep an application working after a reset is if it +complies with the robustness aspects of the graphical API that is using. + +Graphical APIs provide ways to application to deal with device resets. However, +there's no guarantee that the app will be correctly using such features, and UMD +can implement policies to close the app if it's a repeating offender, likely in +a broken loop. This is done to ensure that it doesn't keeps blocking the user +interface to be correctly displayed. + +OpenGL +~~~~~~ + +Apps using OpenGL can rely on ``GL_ARB_robustness`` to be robust. This extension +tells if a reset has happened, and if so, all the context state is considered +lost and the app proceeds by creating new ones. If robustness isn't in use, UMD +will terminate the app when a reset is detected, giving that the contexts are +lost and the app won't be able to figure this out and recreate the contexts. + +Vulkan +~~~~~~ + +Apps using Vulkan should check for ``VK_ERROR_DEVICE_LOST`` for submissions. +This error code means, among other things, that a device reset has happened and +it needs to recreate the contexts to keep going. + +Reporting resets causes +----------------------- + +Apart from propagating the reset through the stack so apps can recover, it's +really useful for driver developers to learn more about what caused the reset in +first place. DRM devices should make use of devcoredump to store relevant +information about the reset, so this information can be added to user bug +reports. + .. _drm_driver_ioctl: IOCTL Support on Device Nodes
Signature · 1 line
2.41.0
Re: [RFC PATCH v3 1/4] drm/doc: Document DRM device reset expectations
Quoted 4 lines · On Tue, 20 Jun 2023 21:57:16 -0300 André Almeida <[email protected]> wrote:
Create a section that specifies how to deal with DRM device resets for kernel and userspace drivers.
Signed-off-by André Almeida <[email protected]>
Hi André,
nice to see this! I ended up giving lots of grammar comments, but I'm not a native speaker. Generally it looks good to me.
Quoted 9 lines
--- Documentation/gpu/drm-uapi.rst | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)Documentation/gpu/drm-uapi.rst +0
-0
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 293
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +6
-0@@ -285,6 +285,71 @@ for GPU1 and GPU2 from different vendors, and a third handler for mmapped regular files. Threads cause additional pain with signal handling as well. +Device reset +============ + +The GPU stack is really complex and is prone to errors, from hardware bugs, +faulty applications and everything in between the many layers. To recover +from this kind of state, sometimes is needed to reset the device. This section
It seems unclear what "this kind of state" refers to, so maybe just write "errors"?
Maybe:
Some errors require resetting the device in order to make the device usable again.
I presume that recovery does not mean that the failed job could recover.
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 301
Quoted 8 lines
Documentation/gpu/drm-uapi.rst +8
-0+describes what's the expectations for DRM and usermode drivers when a device +resets and how to propagate the reset status. + +Kernel Mode Driver +------------------ + +The KMD is responsible for checking if the device needs a reset, and to perform +it as needed. Usually a hung is detected when a job gets stuck executing. KMD
s/hung/hang/ ?
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 302
Quoted 1 line
Documentation/gpu/drm-uapi.rst +1
-0+then update it's internal reset tracking to be ready when userspace asks the
updates its
"update reset tracking"... do you mean that KMD records information about the reset in case userspace asks for it later?
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 304
Quoted 2 lines
Documentation/gpu/drm-uapi.rst +2
-0+kernel about reset information. Drivers should implement the DRM_IOCTL_GET_RESET +for that.
At this point, I'm not sure what "reset tracking" or "reset information" entails. Could something be said about those?
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 313
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +9
-0+ +User Mode Driver +---------------- + +The UMD should check before submitting new commands to the KMD if the device has +been reset, and this can be checked more often if it requires to. The +DRM_IOCTL_GET_RESET is the default interface for those kind of checks. After +detecting a reset, UMD will then proceed to report it to the application using +the appropriated API error code, as explained in the bellow section about
s/bellow/below/
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 320
Quoted 7 lines
Documentation/gpu/drm-uapi.rst +7
-0+robustness. + +Robustness +---------- + +The only way to try to keep an application working after a reset is if it +complies with the robustness aspects of the graphical API that is using.
that it is using.
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 322
Quoted 2 lines
Documentation/gpu/drm-uapi.rst +2
-0+ +Graphical APIs provide ways to application to deal with device resets. However,
provide ways for applications to deal with
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 325
Quoted 3 lines
Documentation/gpu/drm-uapi.rst +3
-0+there's no guarantee that the app will be correctly using such features, and UMD +can implement policies to close the app if it's a repeating offender, likely in +a broken loop. This is done to ensure that it doesn't keeps blocking the user
does not keep
I think contractions are usually avoided in documents, but I'm not bothering to flag them all.
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 326
Quoted 1 line
Documentation/gpu/drm-uapi.rst +1
-0+interface to be correctly displayed.
interface from being correctly displayed.
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 335
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +9
-0+ +OpenGL +~~~~~~ + +Apps using OpenGL can rely on ``GL_ARB_robustness`` to be robust. This extension +tells if a reset has happened, and if so, all the context state is considered +lost and the app proceeds by creating new ones. If robustness isn't in use, UMD +will terminate the app when a reset is detected, giving that the contexts are +lost and the app won't be able to figure this out and recreate the contexts.
What about GL ES? Is GL_ARB_robustness implemented or even defined there?
What about EGL returning errors like EGL_CONTEXT_LOST, would handling that not be enough from the app? The documented expectation is: "The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering."
Quoted 10 lines
Documentation/gpu/drm-uapi.rst +10
-0+ +Vulkan +~~~~~~ + +Apps using Vulkan should check for ``VK_ERROR_DEVICE_LOST`` for submissions. +This error code means, among other things, that a device reset has happened and +it needs to recreate the contexts to keep going. + +Reporting resets causes +-----------------------
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 355
Quoted 10 lines
Documentation/gpu/drm-uapi.rst +7
-0+ +Apart from propagating the reset through the stack so apps can recover, it's +really useful for driver developers to learn more about what caused the reset in +first place. DRM devices should make use of devcoredump to store relevant +information about the reset, so this information can be added to user bug +reports. + .. _drm_driver_ioctl: IOCTL Support on Device Nodes
What about VRAM contents? If userspace holds a dmabuf handle, can a GPU reset wipe that buffer? How would that be communicated?
The dmabuf may have originated in another process.
Thanks,
pq
Re: [RFC PATCH v3 1/4] drm/doc: Document DRM device reset expectations
Em 21/06/2023 04:58, Pekka Paalanen escreveu:
Quoted 6 lines
Quoted 3 lines · On Tue, 20 Jun 2023 21:57:16 -0300 André Almeida <[email protected]> wrote:
Create a section that specifies how to deal with DRM device resets for kernel and userspace drivers.
Quoted 6 lines
Quoted 1 line
Signed-off-by André Almeida <[email protected]>Hi André,
nice to see this! I ended up giving lots of grammar comments, but I'm not a native speaker. Generally it looks good to me.
Thank you for your feedback :)
Quoted 40 lines
Quoted 10 lines
--- Documentation/gpu/drm-uapi.rst | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)Documentation/gpu/drm-uapi.rst +0
-0Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 293
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +6
-0@@ -285,6 +285,71 @@ for GPU1 and GPU2 from different vendors, and a third handler for mmapped regular files. Threads cause additional pain with signal handling as well. +Device reset +============ + +The GPU stack is really complex and is prone to errors, from hardware bugs, +faulty applications and everything in between the many layers. To recover +from this kind of state, sometimes is needed to reset the device. This sectionIt seems unclear what "this kind of state" refers to, so maybe just write "errors"?
Maybe:
Some errors require resetting the device in order to make the device usable again.
I presume that recovery does not mean that the failed job could recover.
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 301
Quoted 8 lines
Documentation/gpu/drm-uapi.rst +8
-0+describes what's the expectations for DRM and usermode drivers when a device +resets and how to propagate the reset status. + +Kernel Mode Driver +------------------ + +The KMD is responsible for checking if the device needs a reset, and to perform +it as needed. Usually a hung is detected when a job gets stuck executing. KMDs/hung/hang/ ?
Quoted 6 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 302
Quoted 1 line
Documentation/gpu/drm-uapi.rst +1
-0+then update it's internal reset tracking to be ready when userspace asks theupdates its
"update reset tracking"... do you mean that KMD records information about the reset in case userspace asks for it later?
Yes, kernel drivers do annotate whenever a reset happens, so it can report to userspace when it asks about resets.
For instance, this is the amdgpu implementation of AMDGPU_CTX_OP_QUERY_STATE2:
https://elixir.bootlin.com/linux/v6.3.8/source/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c#L548
You can see there stored information about resets.
Quoted 46 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 304
Quoted 3 lines
Documentation/gpu/drm-uapi.rst +2
-0+kernel about reset information. Drivers should implement the DRM_IOCTL_GET_RESET +for that.At this point, I'm not sure what "reset tracking" or "reset information" entails. Could something be said about those?
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 313
Quoted 9 lines
Quoted 1 line
+
Documentation/gpu/drm-uapi.rst +8
-0+User Mode Driver +---------------- + +The UMD should check before submitting new commands to the KMD if the device has +been reset, and this can be checked more often if it requires to. The +DRM_IOCTL_GET_RESET is the default interface for those kind of checks. After +detecting a reset, UMD will then proceed to report it to the application using +the appropriated API error code, as explained in the bellow section abouts/bellow/below/
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 320
Quoted 7 lines
Documentation/gpu/drm-uapi.rst +7
-0+robustness. + +Robustness +---------- + +The only way to try to keep an application working after a reset is if it +complies with the robustness aspects of the graphical API that is using.that it is using.
Documentation/gpu/drm-uapi.rst
Quoted 2 lines
Documentation/gpu/drm-uapi.rst +2
-0+ +Graphical APIs provide ways to application to deal with device resets. However,provide ways for applications to deal with
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 325
Quoted 3 lines
Documentation/gpu/drm-uapi.rst +3
-0+there's no guarantee that the app will be correctly using such features, and UMD +can implement policies to close the app if it's a repeating offender, likely in +a broken loop. This is done to ensure that it doesn't keeps blocking the userdoes not keep
I think contractions are usually avoided in documents, but I'm not bothering to flag them all.
Quoted 1 line
+interface to be correctly displayed.
interface from being correctly displayed.
Quoted 12 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 335
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +9
-0+ +OpenGL +~~~~~~ + +Apps using OpenGL can rely on ``GL_ARB_robustness`` to be robust. This extension +tells if a reset has happened, and if so, all the context state is considered +lost and the app proceeds by creating new ones. If robustness isn't in use, UMD +will terminate the app when a reset is detected, giving that the contexts are +lost and the app won't be able to figure this out and recreate the contexts.What about GL ES? Is
GL_ARB_robustnessimplemented or even defined there?
I found this: https://registry.khronos.org/OpenGL/extensions/EXT/EXT_robustness.txt
"Since this is intended to be a version of ARB_robustness for OpenGL ES, it should be named accordingly."
I can add this to this paragraph.
Quoted 4 lines
What about EGL returning errors like
EGL_CONTEXT_LOST, would handling that not be enough from the app? The documented expectation is: "The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering."
I couldn't find the spec for EGL_CONTEXT_LOST, but I found for GL_CONTEXT_LOST, which I assume is similar.
GL_CONTEXT_LOST is only returned in some specific commands (that might cause a polling application to block indefinitely), so I don't think it's enough, given that the we can't guarantee that the application will call such commands after a reset, thus not being able to notice a reset.
https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetGraphicsResetStatus.xhtml
Quoted 20 lines
Quoted 20 lines
Documentation/gpu/drm-uapi.rst +17
-0+ +Vulkan +~~~~~~ + +Apps using Vulkan should check for ``VK_ERROR_DEVICE_LOST`` for submissions. +This error code means, among other things, that a device reset has happened and +it needs to recreate the contexts to keep going. + +Reporting resets causes +----------------------- + +Apart from propagating the reset through the stack so apps can recover, it's +really useful for driver developers to learn more about what caused the reset in +first place. DRM devices should make use of devcoredump to store relevant +information about the reset, so this information can be added to user bug +reports. + .. _drm_driver_ioctl:
Quoted 5 lines
Quoted 1 line
IOCTL Support on Device Nodes
What about VRAM contents? If userspace holds a dmabuf handle, can a GPU reset wipe that buffer? How would that be communicated?
Yes, it can.
Quoted 2 lines
The dmabuf may have originated in another process.
Indeed, I think we might need to add an error code for dmabuf calls so the buffer user knows that it's invalid now because a reset has happened in the other device. I will need to read more dmabuf code to make sure how this would be possible.
Quoted 3 lines
Thanks,
pq
Re: [RFC PATCH v3 1/4] drm/doc: Document DRM device reset expectations
Quoted 66 lines · On Wed, 21 Jun 2023 13:28:34 -0300 André Almeida <[email protected]> wrote:
Em 21/06/2023 04:58, Pekka Paalanen escreveu:
Quoted 6 lines
Quoted 3 lines · On Tue, 20 Jun 2023 21:57:16 -0300 André Almeida <[email protected]> wrote:
Create a section that specifies how to deal with DRM device resets for kernel and userspace drivers.
Quoted 6 lines
Quoted 1 line
Signed-off-by André Almeida <[email protected]>Hi André,
nice to see this! I ended up giving lots of grammar comments, but I'm not a native speaker. Generally it looks good to me.
Thank you for your feedback :)
Quoted 40 lines
Quoted 10 lines
--- Documentation/gpu/drm-uapi.rst | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)Documentation/gpu/drm-uapi.rst +0
-0Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 293
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +6
-0@@ -285,6 +285,71 @@ for GPU1 and GPU2 from different vendors, and a third handler for mmapped regular files. Threads cause additional pain with signal handling as well. +Device reset +============ + +The GPU stack is really complex and is prone to errors, from hardware bugs, +faulty applications and everything in between the many layers. To recover +from this kind of state, sometimes is needed to reset the device. This sectionIt seems unclear what "this kind of state" refers to, so maybe just write "errors"?
Maybe:
Some errors require resetting the device in order to make the device usable again.
I presume that recovery does not mean that the failed job could recover.
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 301
Quoted 8 lines
Documentation/gpu/drm-uapi.rst +8
-0+describes what's the expectations for DRM and usermode drivers when a device +resets and how to propagate the reset status. + +Kernel Mode Driver +------------------ + +The KMD is responsible for checking if the device needs a reset, and to perform +it as needed. Usually a hung is detected when a job gets stuck executing. KMDs/hung/hang/ ?
Quoted 6 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 302
Quoted 1 line
Documentation/gpu/drm-uapi.rst +1
-0+then update it's internal reset tracking to be ready when userspace asks theupdates its
"update reset tracking"... do you mean that KMD records information about the reset in case userspace asks for it later?
Yes, kernel drivers do annotate whenever a reset happens, so it can report to userspace when it asks about resets.
Quoted 7 lines
For instance, this is the amdgpu implementation of
AMDGPU_CTX_OP_QUERY_STATE2:https://elixir.bootlin.com/linux/v6.3.8/source/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c#L548
You can see there stored information about resets.
Hi André,
right. What I mean is, if I have to ask this, then that implies that the wording could be more clear.
I don't know if "reset tracking" is some sub-system that is turned on and off as needed or what updating it would mean.
Quoted 59 lines
Quoted 46 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 304
Quoted 3 lines
Documentation/gpu/drm-uapi.rst +2
-0+kernel about reset information. Drivers should implement the DRM_IOCTL_GET_RESET +for that.At this point, I'm not sure what "reset tracking" or "reset information" entails. Could something be said about those?
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 313
Quoted 9 lines
Quoted 1 line
+
Documentation/gpu/drm-uapi.rst +8
-0+User Mode Driver +---------------- + +The UMD should check before submitting new commands to the KMD if the device has +been reset, and this can be checked more often if it requires to. The +DRM_IOCTL_GET_RESET is the default interface for those kind of checks. After +detecting a reset, UMD will then proceed to report it to the application using +the appropriated API error code, as explained in the bellow section abouts/bellow/below/
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 320
Quoted 7 lines
Documentation/gpu/drm-uapi.rst +7
-0+robustness. + +Robustness +---------- + +The only way to try to keep an application working after a reset is if it +complies with the robustness aspects of the graphical API that is using.that it is using.
Documentation/gpu/drm-uapi.rst
Quoted 2 lines
Documentation/gpu/drm-uapi.rst +2
-0+ +Graphical APIs provide ways to application to deal with device resets. However,provide ways for applications to deal with
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 325
Quoted 3 lines
Documentation/gpu/drm-uapi.rst +3
-0+there's no guarantee that the app will be correctly using such features, and UMD +can implement policies to close the app if it's a repeating offender, likely in +a broken loop. This is done to ensure that it doesn't keeps blocking the userdoes not keep
I think contractions are usually avoided in documents, but I'm not bothering to flag them all.
Quoted 1 line
+interface to be correctly displayed.
interface from being correctly displayed.
Quoted 12 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 335
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +9
-0+ +OpenGL +~~~~~~ + +Apps using OpenGL can rely on ``GL_ARB_robustness`` to be robust. This extension +tells if a reset has happened, and if so, all the context state is considered +lost and the app proceeds by creating new ones. If robustness isn't in use, UMD +will terminate the app when a reset is detected, giving that the contexts are +lost and the app won't be able to figure this out and recreate the contexts.What about GL ES? Is
GL_ARB_robustnessimplemented or even defined there?
Quoted 7 lines
I found this:
https://registry.khronos.org/OpenGL/extensions/EXT/EXT_robustness.txt"Since this is intended to be a version of
ARB_robustnessfor OpenGL ES, it should be named accordingly."I can add this to this paragraph.
Yes, please!
I suppose there could be even more extensions with similar benefits, so maybe these extension should be mentioned as examples. Right now the wording sounds like these are the chosen extensions, and if you don't use one, the process will be terminated.
Quoted 8 lines
Quoted 5 lines
What about EGL returning errors like
EGL_CONTEXT_LOST, would handling that not be enough from the app? The documented expectation is: "The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering."I couldn't find the spec for
EGL_CONTEXT_LOST, but I found forGL_CONTEXT_LOST, which I assume is similar.
EGL Version 1.5 - August 27, 2014
Section 2.7 Power Management
Following a power management event, calls to eglSwapBuffers, eglCopyBuffers, or eglMakeCurrent will indicate failure by returning EGL_FALSE. The error EGL_CONTEXT_LOST will be returned if a power management event has occurred.
On detection of this error, the application must destroy all contexts (by calling eglDestroyContext for each context). To continue rendering the application must recreate any contexts it requires, and subsequently restore any client API state and objects it wishes to use.
It is talking about power management which is not quite GPU reset, but I see so much similarity that I'd say it doesn't matter which one actually happened. The only difference is that power management events are not caused by application bugs, which means that the application will simply re-initialize and retry, which may result in a reset loop.
You already wrote provision to handle reset loops, and I'm not sure applications handling EGL_CONTEXT_LOST would/could ever infer that they are the culprit without using robustness extensions.
I can see how EGL_CONTEXT_LOST could be deemed unsuitable for resets, too.
Quoted 7 lines
GL_CONTEXT_LOSTis only returned in some specific commands (that might cause a polling application to block indefinitely), so I don't think it's enough, given that the we can't guarantee that the application will call such commands after a reset, thus not being able to notice a reset.https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetGraphicsResetStatus.xhtml
Ok, another API for a similar thing.
So in that case, the app does not need to use a robustness extension if it uses OpenGL 4.5 and bothers to check.
This makes the wording "If robustness is not in use" problematic, because it seems complicated to determine if robusteness is in use in any particular application. I suppose Mesa would track if the app ever called glGetGraphicsResetStatus() before drawing after reset?
Thanks,
pq
Quoted 39 lines
Quoted 20 lines
Quoted 20 lines
Documentation/gpu/drm-uapi.rst +17
-0+ +Vulkan +~~~~~~ + +Apps using Vulkan should check for ``VK_ERROR_DEVICE_LOST`` for submissions. +This error code means, among other things, that a device reset has happened and +it needs to recreate the contexts to keep going. + +Reporting resets causes +----------------------- + +Apart from propagating the reset through the stack so apps can recover, it's +really useful for driver developers to learn more about what caused the reset in +first place. DRM devices should make use of devcoredump to store relevant +information about the reset, so this information can be added to user bug +reports. + .. _drm_driver_ioctl:Quoted 5 lines
Quoted 1 line
IOCTL Support on Device Nodes
What about VRAM contents? If userspace holds a dmabuf handle, can a GPU reset wipe that buffer? How would that be communicated?
Yes, it can.
Quoted 2 lines
The dmabuf may have originated in another process.
Indeed, I think we might need to add an error code for dmabuf calls so the buffer user knows that it's invalid now because a reset has happened in the other device. I will need to read more dmabuf code to make sure how this would be possible.
Quoted 3 lines
Thanks,
pq
Re: [RFC PATCH v3 1/4] drm/doc: Document DRM device reset expectations
Em 22/06/2023 05:12, Pekka Paalanen escreveu:
Quoted 77 lines
Quoted 66 lines · On Wed, 21 Jun 2023 13:28:34 -0300 André Almeida <[email protected]> wrote:
Em 21/06/2023 04:58, Pekka Paalanen escreveu:
Quoted 6 lines
Quoted 3 lines · On Tue, 20 Jun 2023 21:57:16 -0300 André Almeida <[email protected]> wrote:
Create a section that specifies how to deal with DRM device resets for kernel and userspace drivers.
Quoted 6 lines
Quoted 1 line
Signed-off-by André Almeida <[email protected]>Hi André,
nice to see this! I ended up giving lots of grammar comments, but I'm not a native speaker. Generally it looks good to me.
Thank you for your feedback :)
Quoted 40 lines
Quoted 10 lines
--- Documentation/gpu/drm-uapi.rst | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)Documentation/gpu/drm-uapi.rst +0
-0Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 293
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +6
-0@@ -285,6 +285,71 @@ for GPU1 and GPU2 from different vendors, and a third handler for mmapped regular files. Threads cause additional pain with signal handling as well. +Device reset +============ + +The GPU stack is really complex and is prone to errors, from hardware bugs, +faulty applications and everything in between the many layers. To recover +from this kind of state, sometimes is needed to reset the device. This sectionIt seems unclear what "this kind of state" refers to, so maybe just write "errors"?
Maybe:
Some errors require resetting the device in order to make the device usable again.
I presume that recovery does not mean that the failed job could recover.
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 301
Quoted 8 lines
Documentation/gpu/drm-uapi.rst +8
-0+describes what's the expectations for DRM and usermode drivers when a device +resets and how to propagate the reset status. + +Kernel Mode Driver +------------------ + +The KMD is responsible for checking if the device needs a reset, and to perform +it as needed. Usually a hung is detected when a job gets stuck executing. KMDs/hung/hang/ ?
Quoted 6 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 302
Quoted 1 line
Documentation/gpu/drm-uapi.rst +1
-0+then update it's internal reset tracking to be ready when userspace asks theupdates its
"update reset tracking"... do you mean that KMD records information about the reset in case userspace asks for it later?
Yes, kernel drivers do annotate whenever a reset happens, so it can report to userspace when it asks about resets.
Quoted 7 lines
For instance, this is the amdgpu implementation of
AMDGPU_CTX_OP_QUERY_STATE2:https://elixir.bootlin.com/linux/v6.3.8/source/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c#L548
You can see there stored information about resets.
Quoted 8 lines
Hi André,
right. What I mean is, if I have to ask this, then that implies that the wording could be more clear.
I don't know if "reset tracking" is some sub-system that is turned on and off as needed or what updating it would mean.
Understood, I'll rewrite it to be more clear.
Quoted 104 lines
Quoted 59 lines
Quoted 46 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 304
Quoted 3 lines
Documentation/gpu/drm-uapi.rst +2
-0+kernel about reset information. Drivers should implement the DRM_IOCTL_GET_RESET +for that.At this point, I'm not sure what "reset tracking" or "reset information" entails. Could something be said about those?
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 313
Quoted 9 lines
Quoted 1 line
+
Documentation/gpu/drm-uapi.rst +8
-0+User Mode Driver +---------------- + +The UMD should check before submitting new commands to the KMD if the device has +been reset, and this can be checked more often if it requires to. The +DRM_IOCTL_GET_RESET is the default interface for those kind of checks. After +detecting a reset, UMD will then proceed to report it to the application using +the appropriated API error code, as explained in the bellow section abouts/bellow/below/
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 320
Quoted 7 lines
Documentation/gpu/drm-uapi.rst +7
-0+robustness. + +Robustness +---------- + +The only way to try to keep an application working after a reset is if it +complies with the robustness aspects of the graphical API that is using.that it is using.
Documentation/gpu/drm-uapi.rst
Quoted 2 lines
Documentation/gpu/drm-uapi.rst +2
-0+ +Graphical APIs provide ways to application to deal with device resets. However,provide ways for applications to deal with
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 325
Quoted 3 lines
Documentation/gpu/drm-uapi.rst +3
-0+there's no guarantee that the app will be correctly using such features, and UMD +can implement policies to close the app if it's a repeating offender, likely in +a broken loop. This is done to ensure that it doesn't keeps blocking the userdoes not keep
I think contractions are usually avoided in documents, but I'm not bothering to flag them all.
Quoted 1 line
+interface to be correctly displayed.
interface from being correctly displayed.
Quoted 12 lines
Documentation/gpu/drm-uapi.rst for GPU1 and GPU2 from different vendors, and a third handler for · line 335
Quoted 9 lines
Documentation/gpu/drm-uapi.rst +9
-0+ +OpenGL +~~~~~~ + +Apps using OpenGL can rely on ``GL_ARB_robustness`` to be robust. This extension +tells if a reset has happened, and if so, all the context state is considered +lost and the app proceeds by creating new ones. If robustness isn't in use, UMD +will terminate the app when a reset is detected, giving that the contexts are +lost and the app won't be able to figure this out and recreate the contexts.What about GL ES? Is
GL_ARB_robustnessimplemented or even defined there?Quoted 7 lines
I found this:
https://registry.khronos.org/OpenGL/extensions/EXT/EXT_robustness.txt"Since this is intended to be a version of
ARB_robustnessfor OpenGL ES, it should be named accordingly."I can add this to this paragraph.
Yes, please!
I suppose there could be even more extensions with similar benefits, so maybe these extension should be mentioned as examples. Right now the wording sounds like these are the chosen extensions, and if you don't use one, the process will be terminated.
Quoted 8 lines
Quoted 5 lines
What about EGL returning errors like
EGL_CONTEXT_LOST, would handling that not be enough from the app? The documented expectation is: "The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering."I couldn't find the spec for
EGL_CONTEXT_LOST, but I found forGL_CONTEXT_LOST, which I assume is similar.EGL Version 1.5 - August 27, 2014
Section 2.7 Power Management
Following a power management event, calls to eglSwapBuffers, eglCopyBuffers, or eglMakeCurrent will indicate failure by returning
EGL_FALSE. The errorEGL_CONTEXT_LOSTwill be returned if a power management event has occurred.On detection of this error, the application must destroy all contexts (by calling eglDestroyContext for each context). To continue rendering the application must recreate any contexts it requires, and subsequently restore any client API state and objects it wishes to use.
It is talking about power management which is not quite GPU reset, but I see so much similarity that I'd say it doesn't matter which one actually happened. The only difference is that power management events are not caused by application bugs, which means that the application will simply re-initialize and retry, which may result in a reset loop.
Quoted 7 lines
You already wrote provision to handle reset loops, and I'm not sure applications handling
EGL_CONTEXT_LOSTwould/could ever infer that they are the culprit without using robustness extensions.I can see how
EGL_CONTEXT_LOSTcould be deemed unsuitable for resets, too.
Indeed, this is tricky. However, I believe that the complex nature of the stack can lead to situations where an app is causing the hardware to change it's power management settings. Even though the app isn't doing it on purpose, as stated in the introduction of this section, resets can be caused by hardware bugs, so unfortunately apps might not be able to run correctly and will get reset notifications, and even get terminate.
Quoted 10 lines
Quoted 7 lines
GL_CONTEXT_LOSTis only returned in some specific commands (that might cause a polling application to block indefinitely), so I don't think it's enough, given that the we can't guarantee that the application will call such commands after a reset, thus not being able to notice a reset.https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetGraphicsResetStatus.xhtml
Ok, another API for a similar thing.
Quoted 9 lines
So in that case, the app does not need to use a robustness extension if it uses OpenGL 4.5 and bothers to check.
This makes the wording "If robustness is not in use" problematic, because it seems complicated to determine if robusteness is in use in any particular application. I suppose Mesa would track if the app ever called
glGetGraphicsResetStatus()before drawing after reset?
I agree, I think tracking glGetGraphicsResetStatus() should be enough, but I will let this part of the documentation as this for now:
If it's _possible to guarantee_ that robustness is not in use [...]
Quoted 43 lines
Thanks,
pqQuoted 39 lines
Quoted 20 lines
Quoted 20 lines
Documentation/gpu/drm-uapi.rst +17
-0+ +Vulkan +~~~~~~ + +Apps using Vulkan should check for ``VK_ERROR_DEVICE_LOST`` for submissions. +This error code means, among other things, that a device reset has happened and +it needs to recreate the contexts to keep going. + +Reporting resets causes +----------------------- + +Apart from propagating the reset through the stack so apps can recover, it's +really useful for driver developers to learn more about what caused the reset in +first place. DRM devices should make use of devcoredump to store relevant +information about the reset, so this information can be added to user bug +reports. + .. _drm_driver_ioctl:Quoted 5 lines
Quoted 1 line
IOCTL Support on Device Nodes
What about VRAM contents? If userspace holds a dmabuf handle, can a GPU reset wipe that buffer? How would that be communicated?
Yes, it can.
Quoted 2 lines
The dmabuf may have originated in another process.
Indeed, I think we might need to add an error code for dmabuf calls so the buffer user knows that it's invalid now because a reset has happened in the other device. I will need to read more dmabuf code to make sure how this would be possible.
Quoted 3 lines
Thanks,
pq
RFC PATCH v3 2/4 drm: Create DRM_IOCTL_GET_RESET
In reply to André AlmeidaCreate a new DRM ioctl operation to get the numbers of resets for a given context. The numbers reflect just the resets that happened after the context was created, and not since the machine was booted.
Create a debugfs interface to make easier to test the API without real resets.
--- drivers/gpu/drm/drm_debugfs.c | 2 ++ drivers/gpu/drm/drm_ioctl.c | 58 +++++++++++++++++++++++++++++++++++ include/drm/drm_device.h | 3 ++ include/drm/drm_drv.h | 3 ++ include/uapi/drm/drm.h | 21 +++++++++++++ include/uapi/drm/drm_mode.h | 15 +++++++++ 6 files changed, 102 insertions(+)
drivers/gpu/drm/drm_debugfs.c +2 -0
@@ -251,6 +251,8 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,list_del (&entry->list); } +debugfs_create_bool ("drm_reset_spoof" ,0644 , minor->debugfs_root, &dev->reset_spoof); +return 0 ; }
drivers/gpu/drm/drm_ioctl.c +58 -0
70 lines not on this page · raw message
include/drm/drm_device.h +3 -0
@@ -326,6 +326,9 @@ struct drm_device {*/ struct list_head debugfs_list; +/* Spoof device reset for testing */ +bool reset_spoof; +/* Everything below here is for legacy driver, never use! */ /* private: */ #if IS_ENABLED (CONFIG_DRM_LEGACY )
include/drm/drm_drv.h +3 -0
@@ -401,6 +401,9 @@ struct drm_driver { struct drm_device *dev, uint32_t handle, uint64_t *offset); +int (*get_reset)(struct drm_file *file_priv, +struct drm_device *dev,struct drm_get_reset *reset); +/** * @show_fdinfo: *
include/uapi/drm/drm.h +21 -0
@@ -1169,6 +1169,27 @@ extern "C" {*/ #define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2) +/** +* DRM_IOCTL_GET_RESET - Get information about device resets +* +* This operation requests from the device information about resets. It should +* consider only resets that happens after the context is created, therefore, +* the counter should be zero during context creation. +* +* dev_reset_count tells how many resets have happened on this device, and +* ctx_reset_count tells how many of such resets were caused by this context. +* +* Flags can be used to tell if a reset is in progress, and userspace should +* wait until it's not in progress anymore to be able to create a new context; +* and to tell if the VRAM is considered lost. There's no safe way to clean this +* flag so if a context see this flag set, it should be like that until the end +* of the context. +*/ +#define DRM_IOCTL_GET_RESET DRM_IOWR(0xCF, struct drm_get_reset) + +#define DRM_RESET_IN_PROGRESS 0x1 +#define DRM_RESET_VRAM_LOST 0x2 +/* * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x9f.
include/uapi/drm/drm_mode.h +15 -0
@@ -1308,6 +1308,21 @@ struct drm_mode_rect {__s32 y2; }; +/** +* struct drm_get_reset - Get information about a DRM device resets +* @ctx_id: the context id to be queried about resets +* @flags: flags +* @dev_reset_count: global counter of resets for a given DRM device +* @ctx_reset_count: of all the resets counted by this device, how many were +* caused by this context. +*/ +struct drm_get_reset { +__u32 ctx_id; +__u32 flags; +__u64 dev_reset_count; +__u64 ctx_reset_count; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.41.0
Re: [RFC PATCH v3 2/4] drm: Create DRM_IOCTL_GET_RESET
Quoted 16 lines · On Tue, 20 Jun 2023 21:57:17 -0300 André Almeida <[email protected]> wrote:
Create a new DRM ioctl operation to get the numbers of resets for a given context. The numbers reflect just the resets that happened after the context was created, and not since the machine was booted.
Create a debugfs interface to make easier to test the API without real resets.
Signed-off-by André Almeida <[email protected]>--- drivers/gpu/drm/drm_debugfs.c | 2 ++ drivers/gpu/drm/drm_ioctl.c | 58 +++++++++++++++++++++++++++++++++++ include/drm/drm_device.h | 3 ++ include/drm/drm_drv.h | 3 ++ include/uapi/drm/drm.h | 21 +++++++++++++ include/uapi/drm/drm_mode.h | 15 +++++++++ 6 files changed, 102 insertions(+)
...
Quoted 13 lines
include/uapi/drm/drm.h +5
-0@@ -1169,6 +1169,27 @@ extern "C" {*/ #define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2) +/** +* DRM_IOCTL_GET_RESET - Get information about device resets +* +* This operation requests from the device information about resets. It should +* consider only resets that happens after the context is created, therefore,
include/uapi/drm/drm.h extern "C" { · line 1186
Quoted 10 lines
include/uapi/drm/drm.h +10
-0+* the counter should be zero during context creation. +* +* dev_reset_count tells how many resets have happened on this device, and +* ctx_reset_count tells how many of such resets were caused by this context. +* +* Flags can be used to tell if a reset is in progress, and userspace should +* wait until it's not in progress anymore to be able to create a new context; +* and to tell if the VRAM is considered lost. There's no safe way to clean this +* flag so if a context see this flag set, it should be like that until the end +* of the context.
Is "this flag" the VRAM_LOST? Or any flag?
Does this mean that not all resets are fatal to the context? Is there any kind of reset that should not be fatal to a context? All the rendering APIs seem to assume that any reset is fatal and the context must be destroyed.
include/uapi/drm/drm.h extern "C" { · line 1191
Quoted 5 lines
include/uapi/drm/drm.h +5
-0+*/ +#define DRM_IOCTL_GET_RESET DRM_IOWR(0xCF, struct drm_get_reset) + +#define DRM_RESET_IN_PROGRESS 0x1 +#define DRM_RESET_VRAM_LOST 0x2
Ok, so the dmabuf lost is being communicated here, but how would a userspace process know on which device a dmabuf resides on?
Let's assume process A uses device 1 to draw, exports a dmabuf, sends it to process B which imports it to device 2. Device 1 resets and loses VRAM contents. How would process B notice that the dmabuf is lost when it never touches device 1 itself?
Quoted 20 lines
include/uapi/drm/drm.h +1
-0+/* * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x9f. include/uapi/drm/drm_mode.h +8
-0@@ -1308,6 +1308,21 @@ struct drm_mode_rect {__s32 y2; }; +/** +* struct drm_get_reset - Get information about a DRM device resets +* @ctx_id: the context id to be queried about resets +* @flags: flags +* @dev_reset_count: global counter of resets for a given DRM device +* @ctx_reset_count: of all the resets counted by this device, how many were +* caused by this context. +*/
include/uapi/drm/drm_mode.h struct drm_mode_rect { · line 1328
Quoted 10 lines
include/uapi/drm/drm_mode.h +7
-0+struct drm_get_reset { +__u32 ctx_id; +__u32 flags; +__u64 dev_reset_count; +__u64 ctx_reset_count; +}; +#if defined(__cplusplus) }#endif
Thanks,
pq
Re: [RFC PATCH v3 2/4] drm: Create DRM_IOCTL_GET_RESET
Em 21/06/2023 05:09, Pekka Paalanen escreveu:
Quoted 48 lines
Quoted 16 lines · On Tue, 20 Jun 2023 21:57:17 -0300 André Almeida <[email protected]> wrote:
Create a new DRM ioctl operation to get the numbers of resets for a given context. The numbers reflect just the resets that happened after the context was created, and not since the machine was booted.
Create a debugfs interface to make easier to test the API without real resets.
Signed-off-by André Almeida <[email protected]>--- drivers/gpu/drm/drm_debugfs.c | 2 ++ drivers/gpu/drm/drm_ioctl.c | 58 +++++++++++++++++++++++++++++++++++ include/drm/drm_device.h | 3 ++ include/drm/drm_drv.h | 3 ++ include/uapi/drm/drm.h | 21 +++++++++++++ include/uapi/drm/drm_mode.h | 15 +++++++++ 6 files changed, 102 insertions(+)...
Quoted 13 lines
include/uapi/drm/drm.h +5
-0@@ -1169,6 +1169,27 @@ extern "C" {*/ #define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2) +/** +* DRM_IOCTL_GET_RESET - Get information about device resets +* +* This operation requests from the device information about resets. It should +* consider only resets that happens after the context is created, therefore, include/uapi/drm/drm.h extern "C" { · line 1186
Quoted 10 lines
include/uapi/drm/drm.h +10
-0+* the counter should be zero during context creation. +* +* dev_reset_count tells how many resets have happened on this device, and +* ctx_reset_count tells how many of such resets were caused by this context. +* +* Flags can be used to tell if a reset is in progress, and userspace should +* wait until it's not in progress anymore to be able to create a new context; +* and to tell if the VRAM is considered lost. There's no safe way to clean this +* flag so if a context see this flag set, it should be like that until the end +* of the context. Is "this flag" the
VRAM_LOST? Or any flag?
Quoted 4 lines
Does this mean that not all resets are fatal to the context? Is there any kind of reset that should not be fatal to a context? All the rendering APIs seem to assume that any reset is fatal and the context must be destroyed.
I got this flag from the AMDGPU_CTX_OP_QUERY_STATE2 operation, and it's used to notify that the reset was fatal for a giving context, although the idea of non-fatal resets seems to be a bit controversial for now, so I think it will be better if I leave this flag for latter improvements of the API.
Quoted 48 lines
include/uapi/drm/drm.h extern "C" { · line 1191
Quoted 6 lines
include/uapi/drm/drm.h +5
-0+*/ +#define DRM_IOCTL_GET_RESET DRM_IOWR(0xCF, struct drm_get_reset) + +#define DRM_RESET_IN_PROGRESS 0x1 +#define DRM_RESET_VRAM_LOST 0x2Ok, so the dmabuf lost is being communicated here, but how would a userspace process know on which device a dmabuf resides on?
Let's assume process A uses device 1 to draw, exports a dmabuf, sends it to process B which imports it to device 2. Device 1 resets and loses VRAM contents. How would process B notice that the dmabuf is lost when it never touches device 1 itself?
Quoted 20 lines
include/uapi/drm/drm.h +1
-0+/* * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x9f. include/uapi/drm/drm_mode.h +8
-0@@ -1308,6 +1308,21 @@ struct drm_mode_rect {__s32 y2; }; +/** +* struct drm_get_reset - Get information about a DRM device resets +* @ctx_id: the context id to be queried about resets +* @flags: flags +* @dev_reset_count: global counter of resets for a given DRM device +* @ctx_reset_count: of all the resets counted by this device, how many were +* caused by this context. +*/ include/uapi/drm/drm_mode.h struct drm_mode_rect { · line 1328
Quoted 10 lines
include/uapi/drm/drm_mode.h +7
-0+struct drm_get_reset { +__u32 ctx_id; +__u32 flags; +__u64 dev_reset_count; +__u64 ctx_reset_count; +}; +#if defined(__cplusplus) }#endif Thanks,
pq
Re: [RFC PATCH v3 2/4] drm: Create DRM_IOCTL_GET_RESET
Quoted 54 lines · On Wed, 21 Jun 2023 13:33:56 -0300 André Almeida <[email protected]> wrote:
Em 21/06/2023 05:09, Pekka Paalanen escreveu:
Quoted 48 lines
Quoted 16 lines · On Tue, 20 Jun 2023 21:57:17 -0300 André Almeida <[email protected]> wrote:
Create a new DRM ioctl operation to get the numbers of resets for a given context. The numbers reflect just the resets that happened after the context was created, and not since the machine was booted.
Create a debugfs interface to make easier to test the API without real resets.
Signed-off-by André Almeida <[email protected]>--- drivers/gpu/drm/drm_debugfs.c | 2 ++ drivers/gpu/drm/drm_ioctl.c | 58 +++++++++++++++++++++++++++++++++++ include/drm/drm_device.h | 3 ++ include/drm/drm_drv.h | 3 ++ include/uapi/drm/drm.h | 21 +++++++++++++ include/uapi/drm/drm_mode.h | 15 +++++++++ 6 files changed, 102 insertions(+)...
Quoted 13 lines
include/uapi/drm/drm.h +5
-0@@ -1169,6 +1169,27 @@ extern "C" {*/ #define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2) +/** +* DRM_IOCTL_GET_RESET - Get information about device resets +* +* This operation requests from the device information about resets. It should +* consider only resets that happens after the context is created, therefore, include/uapi/drm/drm.h extern "C" { · line 1186
Quoted 10 lines
include/uapi/drm/drm.h +10
-0+* the counter should be zero during context creation. +* +* dev_reset_count tells how many resets have happened on this device, and +* ctx_reset_count tells how many of such resets were caused by this context. +* +* Flags can be used to tell if a reset is in progress, and userspace should +* wait until it's not in progress anymore to be able to create a new context; +* and to tell if the VRAM is considered lost. There's no safe way to clean this +* flag so if a context see this flag set, it should be like that until the end +* of the context. Is "this flag" the
VRAM_LOST? Or any flag?Quoted 4 lines
Does this mean that not all resets are fatal to the context? Is there any kind of reset that should not be fatal to a context? All the rendering APIs seem to assume that any reset is fatal and the context must be destroyed.
Quoted 5 lines
I got this flag from the
AMDGPU_CTX_OP_QUERY_STATE2operation, and it's used to notify that the reset was fatal for a giving context, although the idea of non-fatal resets seems to be a bit controversial for now, so I think it will be better if I leave this flag for latter improvements of the API.
Which flag is "this flag"? There are RESET_IN_PROGRESS and VRAM_LOST. Both are fine by me to exist.
I think I made a wrong conclusion here. Somehow I read that it would be possible to have a reset happen, and if VRAM is not lost, then the context could work again.
Should there be some wording added to say the context is permanently broken on any kind of reset? Or is that for UMD to decide?
Thanks,
pq
Quoted 48 lines
Quoted 48 lines
include/uapi/drm/drm.h extern "C" { · line 1191
Quoted 6 lines
include/uapi/drm/drm.h +5
-0+*/ +#define DRM_IOCTL_GET_RESET DRM_IOWR(0xCF, struct drm_get_reset) + +#define DRM_RESET_IN_PROGRESS 0x1 +#define DRM_RESET_VRAM_LOST 0x2Ok, so the dmabuf lost is being communicated here, but how would a userspace process know on which device a dmabuf resides on?
Let's assume process A uses device 1 to draw, exports a dmabuf, sends it to process B which imports it to device 2. Device 1 resets and loses VRAM contents. How would process B notice that the dmabuf is lost when it never touches device 1 itself?
Quoted 20 lines
include/uapi/drm/drm.h +1
-0+/* * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x9f. include/uapi/drm/drm_mode.h +8
-0@@ -1308,6 +1308,21 @@ struct drm_mode_rect {__s32 y2; }; +/** +* struct drm_get_reset - Get information about a DRM device resets +* @ctx_id: the context id to be queried about resets +* @flags: flags +* @dev_reset_count: global counter of resets for a given DRM device +* @ctx_reset_count: of all the resets counted by this device, how many were +* caused by this context. +*/ include/uapi/drm/drm_mode.h struct drm_mode_rect { · line 1328
Quoted 10 lines
include/uapi/drm/drm_mode.h +7
-0+struct drm_get_reset { +__u32 ctx_id; +__u32 flags; +__u64 dev_reset_count; +__u64 ctx_reset_count; +}; +#if defined(__cplusplus) }#endif Thanks,
pq
Christian König
maintainerRe: [RFC PATCH v3 2/4] drm: Create DRM_IOCTL_GET_RESET
Am 22.06.23 um 10:22 schrieb Pekka Paalanen:
Quoted 59 lines
Quoted 51 lines · On Wed, 21 Jun 2023 13:33:56 -0300 André Almeida <[email protected]> wrote:
Em 21/06/2023 05:09, Pekka Paalanen escreveu:
Quoted 46 lines
Quoted 16 lines · On Tue, 20 Jun 2023 21:57:17 -0300 André Almeida <[email protected]> wrote:
Create a new DRM ioctl operation to get the numbers of resets for a given context. The numbers reflect just the resets that happened after the context was created, and not since the machine was booted.
Create a debugfs interface to make easier to test the API without real resets.
Signed-off-by André Almeida <[email protected]>--- drivers/gpu/drm/drm_debugfs.c | 2 ++ drivers/gpu/drm/drm_ioctl.c | 58 +++++++++++++++++++++++++++++++++++ include/drm/drm_device.h | 3 ++ include/drm/drm_drv.h | 3 ++ include/uapi/drm/drm.h | 21 +++++++++++++ include/uapi/drm/drm_mode.h | 15 +++++++++ 6 files changed, 102 insertions(+)...
Quoted 13 lines
include/uapi/drm/drm.h +5
-0@@ -1169,6 +1169,27 @@ extern "C" {*/ #define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xCE, struct drm_mode_fb_cmd2) +/** +* DRM_IOCTL_GET_RESET - Get information about device resets +* +* This operation requests from the device information about resets. It should +* consider only resets that happens after the context is created, therefore, include/uapi/drm/drm.h extern "C" { · line 1186
Quoted 10 lines
include/uapi/drm/drm.h +10
-0+* the counter should be zero during context creation. +* +* dev_reset_count tells how many resets have happened on this device, and +* ctx_reset_count tells how many of such resets were caused by this context. +* +* Flags can be used to tell if a reset is in progress, and userspace should +* wait until it's not in progress anymore to be able to create a new context; +* and to tell if the VRAM is considered lost. There's no safe way to clean this +* flag so if a context see this flag set, it should be like that until the end +* of the context. Is "this flag" the
VRAM_LOST? Or any flag?Quoted 4 lines
Does this mean that not all resets are fatal to the context? Is there any kind of reset that should not be fatal to a context? All the rendering APIs seem to assume that any reset is fatal and the context must be destroyed.
Quoted 5 lines
I got this flag from the
AMDGPU_CTX_OP_QUERY_STATE2operation, and it's used to notify that the reset was fatal for a giving context, although the idea of non-fatal resets seems to be a bit controversial for now, so I think it will be better if I leave this flag for latter improvements of the API.
Quoted 6 lines
Which flag is "this flag"? There are
RESET_IN_PROGRESSandVRAM_LOST. Both are fine by me to exist.I think I made a wrong conclusion here. Somehow I read that it would be possible to have a reset happen, and if VRAM is not lost, then the context could work again.
Yeah, that's exactly what AMD tries to do.
And no, I'm absolutely not keen about that idea.
Regards,
Christian.
Quoted 53 lines
Should there be some wording added to say the context is permanently broken on any kind of reset? Or is that for UMD to decide?
Thanks,
pqQuoted 46 lines
Quoted 46 lines
include/uapi/drm/drm.h extern "C" { · line 1191
Quoted 6 lines
include/uapi/drm/drm.h +5
-0+*/ +#define DRM_IOCTL_GET_RESET DRM_IOWR(0xCF, struct drm_get_reset) + +#define DRM_RESET_IN_PROGRESS 0x1 +#define DRM_RESET_VRAM_LOST 0x2Ok, so the dmabuf lost is being communicated here, but how would a userspace process know on which device a dmabuf resides on?
Let's assume process A uses device 1 to draw, exports a dmabuf, sends it to process B which imports it to device 2. Device 1 resets and loses VRAM contents. How would process B notice that the dmabuf is lost when it never touches device 1 itself?
Quoted 20 lines
include/uapi/drm/drm.h +1
-0+/* * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x9f. include/uapi/drm/drm_mode.h +8
-0@@ -1308,6 +1308,21 @@ struct drm_mode_rect {__s32 y2; }; +/** +* struct drm_get_reset - Get information about a DRM device resets +* @ctx_id: the context id to be queried about resets +* @flags: flags +* @dev_reset_count: global counter of resets for a given DRM device +* @ctx_reset_count: of all the resets counted by this device, how many were +* caused by this context. +*/ include/uapi/drm/drm_mode.h struct drm_mode_rect { · line 1328
Quoted 10 lines
include/uapi/drm/drm_mode.h +7
-0+struct drm_get_reset { +__u32 ctx_id; +__u32 flags; +__u64 dev_reset_count; +__u64 ctx_reset_count; +}; +#if defined(__cplusplus) }#endif Thanks,
pq
RFC PATCH v3 3/4 drm/amdgpu: Implement DRM_IOCTL_GET_RESET
In reply to André AlmeidaImplement get_reset ioctl for amdgpu
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 35 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 5 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 +++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ 6 files changed, 56 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
@@ -1262,8 +1262,10 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,uint64_t seq;int r; -for (i =0 ; i < p->gang_size; ++i) +for (i =0 ; i < p->gang_size; ++i) { + p->jobs[i]->ctx = p->ctx;drm_sched_job_arm (&p->jobs[i]->base); + }for (i =0 ; i < p->gang_size; ++i) {struct dma_fence *fence;
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +35 -0
@@ -322,6 +322,9 @@ static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority, ctx->init_priority = priority; ctx->override_priority =AMDGPU_CTX_PRIORITY_UNSET ; + ctx->global_reset_counter =atomic_read (&mgr->adev->gpu_reset_counter); + ctx->local_reset_counter =0 ; + r =amdgpu_ctx_get_stable_pstate (ctx, ¤t_stable_pstate);if (r)return r;
@@ -963,3 +966,35 @@ void amdgpu_ctx_mgr_usage(struct amdgpu_ctx_mgr *mgr, }mutex_unlock (&mgr->lock); } + +int amdgpu_get_reset (struct drm_file *filp,struct drm_device *dev, +struct drm_get_reset *reset) +{ +struct amdgpu_device *adev =drm_to_adev (dev); +struct amdgpu_ctx *ctx; +struct amdgpu_ctx_mgr *mgr; +unsigned int id = reset->ctx_id; +struct amdgpu_fpriv *fpriv = filp->driver_priv; + + mgr = &fpriv->ctx_mgr; +mutex_lock (&mgr->lock); + ctx =idr_find (&mgr->ctx_handles, id); +if (!ctx) { +mutex_unlock (&mgr->lock); +return -EINVAL ; + } + + reset->dev_reset_count = +atomic_read (&adev->gpu_reset_counter) - ctx->global_reset_counter; + + reset->ctx_reset_count = ctx->local_reset_counter; + +if (amdgpu_in_reset (adev)) + reset->flags |=DRM_RESET_IN_PROGRESS ; + +if (ctx->vram_lost_counter !=atomic_read (&adev->vram_lost_counter)) + reset->flags |=DRM_RESET_VRAM_LOST ; + +mutex_unlock (&mgr->lock); +return 0 ; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +5 -0
@@ -57,6 +57,9 @@ struct amdgpu_ctx {unsigned long ras_counter_ce;unsigned long ras_counter_ue;uint32_t stable_pstate; + +uint64_t global_reset_counter; +uint64_t local_reset_counter; };struct amdgpu_ctx_mgr {
@@ -97,4 +100,6 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);void amdgpu_ctx_mgr_usage (struct amdgpu_ctx_mgr *mgr,ktime_t usage[AMDGPU_HW_IP_NUM ]); +int amdgpu_get_reset (struct drm_file *file_priv,struct drm_device *dev, +struct drm_get_reset *reset);#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2805,6 +2805,7 @@ static const struct drm_driver amdgpu_kms_driver = {#ifdef CONFIG_PROC_FS .show_fdinfo = amdgpu_show_fdinfo, #endif + .get_reset = amdgpu_get_reset, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10 -2
@@ -35,11 +35,20 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) {struct amdgpu_ring *ring =to_amdgpu_ring (s_job->sched);struct amdgpu_job *job =to_amdgpu_job (s_job); +struct drm_sched_entity *entity = job->base.entity;struct amdgpu_task_info ti;struct amdgpu_device *adev = ring->adev;int idx;int r; +memset (&ti,0 ,sizeof (struct amdgpu_task_info )); +amdgpu_vm_get_task_info (ring->adev, job->pasid, &ti); + +if (job->ctx) { +DRM_INFO ("Increasing ctx reset count for %s (%d)\n" , ti.process_name, ti.pid); + job->ctx->local_reset_counter++; + } +if (!drm_dev_enter (adev_to_drm (adev), &idx)) {DRM_INFO ("%s - device unplugged skipping recovery on scheduler:%s" , __func__, s_job->sched->name);
@@ -48,7 +57,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)return DRM_GPU_SCHED_STAT_ENODEV ; } -memset (&ti,0 ,sizeof (struct amdgpu_task_info )); adev->job_hang = true; if (amdgpu_gpu_recovery &&
@@ -58,7 +66,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) goto exit; } -amdgpu_vm_get_task_info (ring->adev, job->pasid, &ti);DRM_ERROR ("ring %s timeout, signaled seq=%u, emitted seq=%u\n" , job->base.sched->name,atomic_read (&ring->fence_drv.last_seq), ring->fence_drv.sync_seq);
@@ -105,6 +112,7 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,*/ (*job)->base.sched = &adev->rings[0 ]->sched; (*job)->vm = vm; + (*job)->ctx =NULL ;amdgpu_sync_create (&(*job)->explicit_sync); (*job)->vram_lost_counter =atomic_read (&adev->vram_lost_counter);
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -0
@@ -63,6 +63,8 @@ struct amdgpu_job {uint32_t oa_base, oa_size;uint32_t vram_lost_counter; +struct amdgpu_ctx *ctx; +/* user fence handling */ uint64_t uf_addr;uint64_t uf_sequence;
Signature · 1 line
2.41.0
Christian König
maintainerRe: [RFC PATCH v3 3/4] drm/amdgpu: Implement DRM_IOCTL_GET_RESET
Am 21.06.23 um 02:57 schrieb André Almeida:
Quoted 1 line
Implement
get_resetioctl for amdgpu
Well that pretty much won't work since the jobs are destroyed much later than the contexts.
Christian.
Quoted 172 lines
Signed-off-by André Almeida <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 35 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 5 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 +++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ 6 files changed, 56 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3
-1@@ -1262,8 +1262,10 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,uint64_t seq;int r; -for (i =0 ; i < p->gang_size; ++i) +for (i =0 ; i < p->gang_size; ++i) { + p->jobs[i]->ctx = p->ctx;drm_sched_job_arm (&p->jobs[i]->base); + }for (i =0 ; i < p->gang_size; ++i) {struct dma_fence *fence;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +35
-0@@ -322,6 +322,9 @@ static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority, ctx->init_priority = priority; ctx->override_priority =AMDGPU_CTX_PRIORITY_UNSET ; + ctx->global_reset_counter =atomic_read (&mgr->adev->gpu_reset_counter); + ctx->local_reset_counter =0 ; + r =amdgpu_ctx_get_stable_pstate (ctx, ¤t_stable_pstate);if (r)return r;@@ -963,3 +966,35 @@ void amdgpu_ctx_mgr_usage(struct amdgpu_ctx_mgr *mgr, }mutex_unlock (&mgr->lock); } + +int amdgpu_get_reset (struct drm_file *filp,struct drm_device *dev, +struct drm_get_reset *reset) +{ +struct amdgpu_device *adev =drm_to_adev (dev); +struct amdgpu_ctx *ctx; +struct amdgpu_ctx_mgr *mgr; +unsigned int id = reset->ctx_id; +struct amdgpu_fpriv *fpriv = filp->driver_priv; + + mgr = &fpriv->ctx_mgr; +mutex_lock (&mgr->lock); + ctx =idr_find (&mgr->ctx_handles, id); +if (!ctx) { +mutex_unlock (&mgr->lock); +return -EINVAL ; + } + + reset->dev_reset_count = +atomic_read (&adev->gpu_reset_counter) - ctx->global_reset_counter; + + reset->ctx_reset_count = ctx->local_reset_counter; + +if (amdgpu_in_reset (adev)) + reset->flags |=DRM_RESET_IN_PROGRESS ; + +if (ctx->vram_lost_counter !=atomic_read (&adev->vram_lost_counter)) + reset->flags |=DRM_RESET_VRAM_LOST ; + +mutex_unlock (&mgr->lock); +return 0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +5
-0@@ -57,6 +57,9 @@ struct amdgpu_ctx {unsigned long ras_counter_ce;unsigned long ras_counter_ue;uint32_t stable_pstate; + +uint64_t global_reset_counter; +uint64_t local_reset_counter; };struct amdgpu_ctx_mgr {@@ -97,4 +100,6 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);void amdgpu_ctx_mgr_usage (struct amdgpu_ctx_mgr *mgr,ktime_t usage[AMDGPU_HW_IP_NUM ]); +int amdgpu_get_reset (struct drm_file *file_priv,struct drm_device *dev, +struct drm_get_reset *reset);#endif drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -2805,6 +2805,7 @@ static const struct drm_driver amdgpu_kms_driver = {#ifdef CONFIG_PROC_FS .show_fdinfo = amdgpu_show_fdinfo, #endif + .get_reset = amdgpu_get_reset, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10
-2@@ -35,11 +35,20 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) {struct amdgpu_ring *ring =to_amdgpu_ring (s_job->sched);struct amdgpu_job *job =to_amdgpu_job (s_job); +struct drm_sched_entity *entity = job->base.entity;struct amdgpu_task_info ti;struct amdgpu_device *adev = ring->adev;int idx;int r; +memset (&ti,0 ,sizeof (struct amdgpu_task_info )); +amdgpu_vm_get_task_info (ring->adev, job->pasid, &ti); + +if (job->ctx) { +DRM_INFO ("Increasing ctx reset count for %s (%d)\n" , ti.process_name, ti.pid); + job->ctx->local_reset_counter++; + } +if (!drm_dev_enter (adev_to_drm (adev), &idx)) {DRM_INFO ("%s - device unplugged skipping recovery on scheduler:%s" , __func__, s_job->sched->name);@@ -48,7 +57,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)return DRM_GPU_SCHED_STAT_ENODEV ; } -memset (&ti,0 ,sizeof (struct amdgpu_task_info )); adev->job_hang = true; if (amdgpu_gpu_recovery &&@@ -58,7 +66,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) goto exit; } -amdgpu_vm_get_task_info (ring->adev, job->pasid, &ti);DRM_ERROR ("ring %s timeout, signaled seq=%u, emitted seq=%u\n" , job->base.sched->name,atomic_read (&ring->fence_drv.last_seq), ring->fence_drv.sync_seq);@@ -105,6 +112,7 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,*/ (*job)->base.sched = &adev->rings[0 ]->sched; (*job)->vm = vm; + (*job)->ctx =NULL ;amdgpu_sync_create (&(*job)->explicit_sync); (*job)->vram_lost_counter =atomic_read (&adev->vram_lost_counter);drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2
-0@@ -63,6 +63,8 @@ struct amdgpu_job {uint32_t oa_base, oa_size;uint32_t vram_lost_counter; +struct amdgpu_ctx *ctx; +/* user fence handling */ uint64_t uf_addr;uint64_t uf_sequence;
Re: [RFC PATCH v3 3/4] drm/amdgpu: Implement DRM_IOCTL_GET_RESET
Em 21/06/2023 04:40, Christian König escreveu:
Quoted 5 lines
Am 21.06.23 um 02:57 schrieb André Almeida:
Quoted 1 line
Implement
get_resetioctl for amdgpuWell that pretty much won't work since the jobs are destroyed much later than the contexts.
Why does this prevents the code to work? If the context is detroyed, it can't be queried anyway.
Quoted 174 lines
Christian.
Quoted 171 lines
Signed-off-by André Almeida <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++-drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 35 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 5 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 +++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ 6 files changed, 56 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3
-1@@ -1262,8 +1262,10 @@ static int amdgpu_cs_submit(structamdgpu_cs_parser *p, uint64_t seq; int r; - for (i = 0; i < p->gang_size; ++i) + for (i = 0; i < p->gang_size; ++i) { + p->jobs[i]->ctx = p->ctx; drm_sched_job_arm(&p->jobs[i]->base); + } for (i = 0; i < p->gang_size; ++i) { struct dma_fence *fence;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3
-0@@ -322,6 +322,9 @@ static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority, ctx->init_priority = priority; ctx->override_priority = AMDGPU_CTX_PRIORITY_UNSET; + ctx->global_reset_counter =atomic_read (&mgr->adev->gpu_reset_counter); + ctx->local_reset_counter = 0; + r = amdgpu_ctx_get_stable_pstate(ctx, ¤t_stable_pstate); if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0
-0@@ -963,3 +966,35 @@ void amdgpu_ctx_mgr_usage(struct amdgpu_ctx_mgr *mgr, } mutex_unlock(&mgr->lock);}
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +20
-0+ +int amdgpu_get_reset (struct drm_file *filp,struct drm_device *dev, + struct drm_get_reset *reset) +{ + struct amdgpu_device *adev = drm_to_adev(dev); + struct amdgpu_ctx *ctx; + struct amdgpu_ctx_mgr *mgr; + unsigned int id = reset->ctx_id; + struct amdgpu_fpriv *fpriv = filp->driver_priv; + + mgr = &fpriv->ctx_mgr; + mutex_lock(&mgr->lock); + ctx = idr_find(&mgr->ctx_handles, id); + if (!ctx) { + mutex_unlock(&mgr->lock); + return -EINVAL; + } + + reset->dev_reset_count = + atomic_read(&adev->gpu_reset_counter) -
ctx->global_reset_counter;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +12
-0+ + reset->ctx_reset_count = ctx->local_reset_counter; + + if (amdgpu_in_reset(adev)) + reset->flags |= DRM_RESET_IN_PROGRESS; + + if (ctx->vram_lost_counter != atomic_read(&adev->vram_lost_counter)) + reset->flags |= DRM_RESET_VRAM_LOST; + + mutex_unlock(&mgr->lock); + return 0; +}drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +5
-0@@ -57,6 +57,9 @@ struct amdgpu_ctx { unsigned long ras_counter_ce; unsigned long ras_counter_ue; uint32_t stable_pstate; + + uint64_t global_reset_counter; + uint64_t local_reset_counter; }; struct amdgpu_ctx_mgr {@@ -97,4 +100,6 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr); void amdgpu_ctx_mgr_usage(struct amdgpu_ctx_mgr *mgr, ktime_t usage[AMDGPU_HW_IP_NUM]); +int amdgpu_get_reset (struct drm_file *file_priv,struct drm_device *dev, + struct drm_get_reset *reset); #endifdrivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -2805,6 +2805,7 @@ static const struct drm_driver amdgpu_kms_driver = { #ifdef CONFIG_PROC_FS .show_fdinfo = amdgpu_show_fdinfo, #endif + .get_reset = amdgpu_get_reset, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0@@ -35,11 +35,20 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) { struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched); struct amdgpu_job *job = to_amdgpu_job(s_job); + struct drm_sched_entity *entity = job->base.entity; struct amdgpu_task_info ti; struct amdgpu_device *adev = ring->adev; int idx; int r; + memset(&ti, 0, sizeof(struct amdgpu_task_info)); + amdgpu_vm_get_task_info(ring->adev, job->pasid, &ti); + + if (job->ctx) { + DRM_INFO("Increasing ctx reset count for %s (%d)\n", ti.process_name, ti.pid); + job->ctx->local_reset_counter++; + } + if (!drm_dev_enter(adev_to_drm(adev), &idx)) { DRM_INFO("%s - device unplugged skipping recovery on scheduler:%s",
__func__,s_job->sched->name);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-1@@ -48,7 +57,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) return DRM_GPU_SCHED_STAT_ENODEV; } - memset(&ti, 0, sizeof(struct amdgpu_task_info)); adev->job_hang = true;if (
amdgpu_gpu_recovery&&drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1
-1@@ -58,7 +66,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) goto exit; } - amdgpu_vm_get_task_info(ring->adev, job->pasid, &ti); DRM_ERROR("ring %s timeout, signaled seq=%u, emitted seq=%u\n", job->base.sched->name, atomic_read(&ring->fence_drv.last_seq), ring->fence_drv.sync_seq);@@ -105,6 +112,7 @@ int amdgpu_job_alloc(struct amdgpu_device *adev,struct amdgpu_vm *vm, */ (*job)->base.sched = &adev->rings[0]->sched; (*job)->vm = vm; + (*job)->ctx = NULL; amdgpu_sync_create(&(*job)->explicit_sync); (*job)->vram_lost_counter = atomic_read(&adev->vram_lost_counter);drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2
-0@@ -63,6 +63,8 @@ struct amdgpu_job { uint32_t oa_base, oa_size; uint32_t vram_lost_counter; + struct amdgpu_ctx *ctx; + /* user fence handling */ uint64_t uf_addr; uint64_t uf_sequence;
Christian König
maintainerRe: [RFC PATCH v3 3/4] drm/amdgpu: Implement DRM_IOCTL_GET_RESET
Am 21.06.23 um 18:38 schrieb André Almeida:
Quoted 8 lines
Em 21/06/2023 04:40, Christian König escreveu:
Quoted 5 lines
Am 21.06.23 um 02:57 schrieb André Almeida:
Quoted 1 line
Implement
get_resetioctl for amdgpuWell that pretty much won't work since the jobs are destroyed much later than the contexts.
Why does this prevents the code to work? If the context is detroyed, it can't be queried anyway.
Yeah, but you cause use after free issues with that!
The references are ctx->entit->job->fence, so that ctx and entity can be destroyed first without destroying the job or fence.
If the job has a back reference that whole stuff doesn't work any more and the pointer is potentially dangling.
Christian.
Quoted 179 lines
Quoted 179 lines
Christian.
Quoted 175 lines
Signed-off-by André Almeida <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++-drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c| 35
+++++++++++++++++++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 5 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 +++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ 6 files changed, 56 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3
-1@@ -1262,8 +1262,10 @@ static int amdgpu_cs_submit(structamdgpu_cs_parser *p, uint64_t seq; int r; - for (i = 0; i < p->gang_size; ++i) + for (i = 0; i < p->gang_size; ++i) { + p->jobs[i]->ctx = p->ctx; drm_sched_job_arm(&p->jobs[i]->base); + } for (i = 0; i < p->gang_size; ++i) { struct dma_fence *fence;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3
-0@@ -322,6 +322,9 @@ static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority, ctx->init_priority = priority; ctx->override_priority = AMDGPU_CTX_PRIORITY_UNSET; + ctx->global_reset_counter =atomic_read (&mgr->adev->gpu_reset_counter); + ctx->local_reset_counter = 0; + r = amdgpu_ctx_get_stable_pstate(ctx, ¤t_stable_pstate); if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0
-0@@ -963,3 +966,35 @@ void amdgpu_ctx_mgr_usage(struct amdgpu_ctx_mgr *mgr, } mutex_unlock(&mgr->lock);}
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +20
-0+ +int amdgpu_get_reset (struct drm_file *filp,struct drm_device *dev, + struct drm_get_reset *reset) +{ + struct amdgpu_device *adev = drm_to_adev(dev); + struct amdgpu_ctx *ctx; + struct amdgpu_ctx_mgr *mgr; + unsigned int id = reset->ctx_id; + struct amdgpu_fpriv *fpriv = filp->driver_priv; + + mgr = &fpriv->ctx_mgr; + mutex_lock(&mgr->lock); + ctx = idr_find(&mgr->ctx_handles, id); + if (!ctx) { + mutex_unlock(&mgr->lock); + return -EINVAL; + } + + reset->dev_reset_count = + atomic_read(&adev->gpu_reset_counter) -
ctx->global_reset_counter;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +7
-0+ + reset->ctx_reset_count = ctx->local_reset_counter; + + if (amdgpu_in_reset(adev)) + reset->flags |= DRM_RESET_IN_PROGRESS; + + if (ctx->vram_lost_counter !=
atomic_read(&adev->vram_lost_counter))
+reset->flags|=DRM_RESET_VRAM_LOST;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +4
-0+ + mutex_unlock(&mgr->lock); + return 0; +}drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +5
-0@@ -57,6 +57,9 @@ struct amdgpu_ctx { unsigned long ras_counter_ce; unsigned long ras_counter_ue; uint32_t stable_pstate; + + uint64_t global_reset_counter; + uint64_t local_reset_counter; }; struct amdgpu_ctx_mgr {@@ -97,4 +100,6 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr); void amdgpu_ctx_mgr_usage(struct amdgpu_ctx_mgr *mgr, ktime_t usage[AMDGPU_HW_IP_NUM]); +int amdgpu_get_reset (struct drm_file *file_priv,struct drm_device *dev, + struct drm_get_reset *reset);#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -2805,6 +2805,7 @@ static const struct drm_driver amdgpu_kms_driver = { #ifdef CONFIG_PROC_FS .show_fdinfo = amdgpu_show_fdinfo, #endif + .get_reset = amdgpu_get_reset, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle,drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +9
-0@@ -35,11 +35,20 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) { struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched); struct amdgpu_job *job = to_amdgpu_job(s_job); + struct drm_sched_entity *entity = job->base.entity; struct amdgpu_task_info ti; struct amdgpu_device *adev = ring->adev; int idx; int r; + memset(&ti, 0, sizeof(struct amdgpu_task_info)); + amdgpu_vm_get_task_info(ring->adev, job->pasid, &ti); + + if (job->ctx) { + DRM_INFO("Increasing ctx reset count for %s (%d)\n", ti.process_name, ti.pid); + job->ctx->local_reset_counter++; + } + if (!drm_dev_enter(adev_to_drm(adev), &idx)) { DRM_INFO("%s - device unplugged skipping recovery on scheduler:%s",
__func__,s_job->sched->name);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-1@@ -48,7 +57,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) return DRM_GPU_SCHED_STAT_ENODEV; } - memset(&ti, 0, sizeof(struct amdgpu_task_info)); adev->job_hang = true;if (
amdgpu_gpu_recovery&&drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1
-1@@ -58,7 +66,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) goto exit; } - amdgpu_vm_get_task_info(ring->adev, job->pasid, &ti); DRM_ERROR("ring %s timeout, signaled seq=%u, emitted seq=%u\n", job->base.sched->name, atomic_read(&ring->fence_drv.last_seq), ring->fence_drv.sync_seq);@@ -105,6 +112,7 @@ int amdgpu_job_alloc(struct amdgpu_device *adev,struct amdgpu_vm *vm, */ (*job)->base.sched = &adev->rings[0]->sched; (*job)->vm = vm; + (*job)->ctx = NULL; amdgpu_sync_create(&(*job)->explicit_sync); (*job)->vram_lost_counter = atomic_read(&adev->vram_lost_counter);drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2
-0@@ -63,6 +63,8 @@ struct amdgpu_job { uint32_t oa_base, oa_size; uint32_t vram_lost_counter; + struct amdgpu_ctx *ctx; + /* user fence handling */ uint64_t uf_addr; uint64_t uf_sequence;
RFC PATCH v3 4/4 drm/i915: Implement DRM_IOCTL_GET_RESET
In reply to André AlmeidaImplement get_reset ioctl for i915.
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 18 ++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_context.h | 2 ++ .../gpu/drm/i915/gem/i915_gem_context_types.h | 2 ++ drivers/gpu/drm/i915/i915_driver.c | 2 ++ 4 files changed, 24 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_context.c +18 -0
@@ -1666,6 +1666,8 @@ i915_gem_create_context(struct drm_i915_private *i915, ctx->uses_protected_content = true; } + ctx->dev_reset_counter =i915_reset_count (&i915->gpu_error); +trace_i915_context_create (ctx);return ctx;
@@ -2558,6 +2560,22 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,return 0 ; } +int i915_gem_get_reset (struct drm_file *filp,struct drm_device *dev, +struct drm_get_reset *reset) +{ +struct i915_gem_context *ctx; + + ctx =i915_gem_context_lookup (file->driver_priv, reset->ctx_id); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + + reset->dev_reset_count =i915_reset_count (&i915->gpu_error) - ctx->dev_reset_count; + reset->ctx_reset_count = ctx->guilty_count; + +i915_gem_context_put (ctx); +return 0 ; +} +/* GEM context-engines iterator: for_each_gem_engine() */ struct intel_context *i915_gem_engines_iter_next (struct i915_gem_engines_iter *it)
drivers/gpu/drm/i915/gem/i915_gem_context.h +2 -0
@@ -138,6 +138,8 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);int i915_gem_context_reset_stats_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int i915_gem_get_reset (struct drm_file *file_priv,struct drm_device *dev, +struct drm_get_reset *reset);struct i915_gem_context *i915_gem_context_lookup (struct drm_i915_file_private *file_priv,u32 id);
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +2 -0
@@ -414,6 +414,8 @@ struct i915_gem_context {/** @engines: list of stale engines */ struct list_head engines; } stale; + +uint64_t dev_reset_counter; };#endif /* __I915_GEM_CONTEXT_TYPES_H__ */
drivers/gpu/drm/i915/i915_driver.c +2 -0
@@ -1805,6 +1805,8 @@ static const struct drm_driver i915_drm_driver = { .postclose = i915_driver_postclose, .show_fdinfo = i915_drm_client_fdinfo, + .get_reset = i915_gem_get_reset, + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = i915_gem_prime_import,
Signature · 1 line
2.41.0
Jani Nikula
maintainerRe: [RFC PATCH v3 4/4] drm/i915: Implement DRM_IOCTL_GET_RESET
Quoted 30 lines · André Almeida
Implement
get_resetioctl for i915.Signed-off-by André Almeida <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 18 ++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_context.h | 2 ++ .../gpu/drm/i915/gem/i915_gem_context_types.h | 2 ++ drivers/gpu/drm/i915/i915_driver.c | 2 ++ 4 files changed, 24 insertions(+)drivers/gpu/drm/i915/gem/i915_gem_context.c +5
-0@@ -1666,6 +1666,8 @@ i915_gem_create_context(struct drm_i915_private *i915, ctx->uses_protected_content = true; } + ctx->dev_reset_counter =i915_reset_count (&i915->gpu_error); +trace_i915_context_create (ctx);return ctx;@@ -2558,6 +2560,22 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev,return 0 ; } +int i915_gem_get_reset (struct drm_file *filp,struct drm_device *dev, +struct drm_get_reset *reset) +{
drivers/gpu/drm/i915/gem/i915_gem_context.c int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, · line 2575
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +10
-0+struct i915_gem_context *ctx; + + ctx =i915_gem_context_lookup (file->driver_priv, reset->ctx_id); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + + reset->dev_reset_count =i915_reset_count (&i915->gpu_error) - ctx->dev_reset_count; + reset->ctx_reset_count = ctx->guilty_count; + +i915_gem_context_put (ctx);
Usually return is preceded by a blank line.
Quoted 24 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +3
-0+return 0 ; +} +/* GEM context-engines iterator: for_each_gem_engine() */ struct intel_context *i915_gem_engines_iter_next (struct i915_gem_engines_iter *it)drivers/gpu/drm/i915/gem/i915_gem_context.h +2
-0@@ -138,6 +138,8 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv);int i915_gem_context_reset_stats_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int i915_gem_get_reset (struct drm_file *file_priv,struct drm_device *dev, +struct drm_get_reset *reset);struct i915_gem_context *i915_gem_context_lookup (struct drm_i915_file_private *file_priv,u32 id);drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0
drivers/gpu/drm/i915/gem/i915_gem_context_types.h struct i915_gem_context { · line 418
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +2
-0@@ -414,6 +414,8 @@ struct i915_gem_context {/** @engines: list of stale engines */ struct list_head engines; } stale; + +uint64_t dev_reset_counter;
u64 please. i915 only uses the kernel fixed types.
Please do wait for review on the actual content before reposting.
BR,
Jani.
Quoted 16 lines
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +0
-0};#endif /* __I915_GEM_CONTEXT_TYPES_H__ */ drivers/gpu/drm/i915/i915_driver.c +2
-0@@ -1805,6 +1805,8 @@ static const struct drm_driver i915_drm_driver = { .postclose = i915_driver_postclose, .show_fdinfo = i915_drm_client_fdinfo, + .get_reset = i915_gem_get_reset, + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = i915_gem_prime_import,
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Christian König
maintainerAm 21.06.23 um 02:57 schrieb André Almeida:
Quoted 8 lines
Hi,
This is a new version of the documentation for DRM device resets. As I dived more in the subject, I started to believe that part of the problem was the lack of a DRM API to get reset information from the driver. With an API, we can better standardize reset queries, increase common code from both DRM and Mesa, and make easier to write end-to-end tests.
Quoted 4 lines
So this patchset, along with the documentation, comes with a new IOCTL and two implementations of it for amdgpu and i915 (although just the former was really tested). This IOCTL uses the "context id" to query reset information, but this might be not generic enough to be included in a DRM API.
Well the basic problem with that is that we don't have a standard DRM context defined.
If you want to do this you should probably start there first.
Apart from that this looks like a really really good idea to me, especially that we document the reset expectations.
Regards,
Christian.
Quoted 54 lines
At least for amdgpu,
this information is encapsulated by libdrm so one can't just call the ioctl directly from the UMD as I was planning to, but a small refactor can be done to expose the id. Anyway, I'm sharing it as it is to gather feedback if this seems to work.The amdgpu and i915 implementations are provided as a mean of testing and as exemplification, and not as reference code yet, as the goal is more about the interface itself then the driver parts.
For the documentation itself, after spending some time reading the reset path in the kernel in Mesa, I decide to rewrite it to better reflect how it works, from bottom to top.
You can check the userspace side of the IOCLT here:
Mesa: https://gitlab.freedesktop.org/andrealmeid/mesa/-/commit/cd687b22fb32c21b23596c607003e2a495f465
libdrm: https://gitlab.freedesktop.org/andrealmeid/libdrm/-/commit/b31e5404893ee9a85d1aa67e81c2f58c1dac3c46For testing, I use this vulkan app that has an infinity loop in the shader:
https://github.com/andrealmeid/vulkan-triangle-v1Feedbacks are welcomed!
Thanks,
Andrév2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/André Almeida (4):
drm/doc: Document DRM device reset expectations
drm: CreateDRM_IOCTL_GET_RESETdrm/amdgpu: ImplementDRM_IOCTL_GET_RESETdrm/i915: ImplementDRM_IOCTL_GET_RESETDocumentation/gpu/drm-uapi.rst | 51 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 35 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 5 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 + drivers/gpu/drm/drm_debugfs.c | 2 + drivers/gpu/drm/drm_ioctl.c | 58 +++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_context.c | 18 ++++++ drivers/gpu/drm/i915/gem/i915_gem_context.h | 2 + .../gpu/drm/i915/gem/i915_gem_context_types.h | 2 + drivers/gpu/drm/i915/i915_driver.c | 2 + include/drm/drm_device.h | 3 + include/drm/drm_drv.h | 3 + include/uapi/drm/drm.h | 21 +++++++ include/uapi/drm/drm_mode.h | 15 +++++ 17 files changed, 233 insertions(+), 3 deletions(-)
Em 21/06/2023 04:42, Christian König escreveu:
Quoted 9 lines
Am 21.06.23 um 02:57 schrieb André Almeida:
Quoted 8 lines
Hi,
This is a new version of the documentation for DRM device resets. As I dived more in the subject, I started to believe that part of the problem was the lack of a DRM API to get reset information from the driver. With an API, we can better standardize reset queries, increase common code from both DRM and Mesa, and make easier to write end-to-end tests.
Quoted 8 lines
Quoted 4 lines
So this patchset, along with the documentation, comes with a new IOCTL and two implementations of it for amdgpu and i915 (although just the former was really tested). This IOCTL uses the "context id" to query reset information, but this might be not generic enough to be included in a DRM API.
Well the basic problem with that is that we don't have a standard DRM context defined.
If you want to do this you should probably start there first.
Any idea on how to start this? I tried to find previous work about that, but I didn't find.
Quoted 2 lines
Apart from that this looks like a really really good idea to me, especially that we document the reset expectations.
I think I'll submit just the doc for the next version then, given that the IOCTL will need a lot of rework.
Quoted 59 lines
Regards,
Christian.Quoted 54 lines
At least for amdgpu,
this information is encapsulated by libdrm so one can't just call the ioctl directly from the UMD as I was planning to, but a small refactor can be done to expose the id. Anyway, I'm sharing it as it is to gather feedback if this seems to work.The amdgpu and i915 implementations are provided as a mean of testing and as exemplification, and not as reference code yet, as the goal is more about the interface itself then the driver parts.
For the documentation itself, after spending some time reading the reset path in the kernel in Mesa, I decide to rewrite it to better reflect how it works, from bottom to top.
You can check the userspace side of the IOCLT here:
Mesa: https://gitlab.freedesktop.org/andrealmeid/mesa/-/commit/cd687b22fb32c21b23596c607003e2a495f465
libdrm: https://gitlab.freedesktop.org/andrealmeid/libdrm/-/commit/b31e5404893ee9a85d1aa67e81c2f58c1dac3c46For testing, I use this vulkan app that has an infinity loop in the shader:
https://github.com/andrealmeid/vulkan-triangle-v1Feedbacks are welcomed!
Thanks,
Andrév2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/André Almeida (4):
drm/doc: Document DRM device reset expectations
drm: CreateDRM_IOCTL_GET_RESETdrm/amdgpu: ImplementDRM_IOCTL_GET_RESETdrm/i915: ImplementDRM_IOCTL_GET_RESETDocumentation/gpu/drm-uapi.rst | 51 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 35 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 5 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 +drivers/gpu/drm/drm_debugfs.c | 2 + drivers/gpu/drm/drm_ioctl.c | 58 +++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_context.c | 18 ++++++ drivers/gpu/drm/i915/gem/i915_gem_context.h | 2 +
.../gpu/drm/i915/gem/i915_gem_context_types.h| 2 + drivers/gpu/drm/i915/i915_driver.c | 2 + include/drm/drm_device.h | 3 + include/drm/drm_drv.h | 3 + include/uapi/drm/drm.h | 21 +++++++ include/uapi/drm/drm_mode.h | 15 +++++17 files changed, 233 insertions(+), 3 deletions(-)
Christian König
maintainerAm 21.06.23 um 17:06 schrieb André Almeida:
Quoted 15 lines
Em 21/06/2023 04:42, Christian König escreveu:
Quoted 14 lines
Am 21.06.23 um 02:57 schrieb André Almeida:
Quoted 12 lines
Hi,
This is a new version of the documentation for DRM device resets. As I dived more in the subject, I started to believe that part of the problem was the lack of a DRM API to get reset information from the driver. With an API, we can better standardize reset queries, increase common code from both DRM and Mesa, and make easier to write end-to-end tests.
So this patchset, along with the documentation, comes with a new IOCTL and two implementations of it for amdgpu and i915 (although just the former was really tested). This IOCTL uses the "context id" to query reset information, but this might be not generic enough to be included in a DRM API.
Quoted 5 lines
Quoted 3 lines
Well the basic problem with that is that we don't have a standard DRM context defined.
If you want to do this you should probably start there first.
Any idea on how to start this? I tried to find previous work about that, but I didn't find.
I'm not aware of any work in this area, maybe ping on the Mesa list as well.
Could be that someone looked into that but never send anything out.
Quoted 5 lines
Quoted 3 lines
Apart from that this looks like a really really good idea to me, especially that we document the reset expectations.
I think I'll submit just the doc for the next version then, given that the IOCTL will need a lot of rework.
Yeah, agree completely.
Thanks,
Christian.
Quoted 61 lines
Quoted 61 lines
Regards,
Christian.Quoted 55 lines
At least for amdgpu,
this information is encapsulated by libdrm so one can't just call the ioctl directly from the UMD as I was planning to, but a small refactor can be done to expose the id. Anyway, I'm sharing it as it is to gather feedback if this seems to work.The amdgpu and i915 implementations are provided as a mean of testing and as exemplification, and not as reference code yet, as the goal is more about the interface itself then the driver parts.
For the documentation itself, after spending some time reading the reset path in the kernel in Mesa, I decide to rewrite it to better reflect how it works, from bottom to top.
You can check the userspace side of the IOCLT here:
Mesa: https://gitlab.freedesktop.org/andrealmeid/mesa/-/commit/cd687b22fb32c21b23596c607003e2a495f465
libdrm: https://gitlab.freedesktop.org/andrealmeid/libdrm/-/commit/b31e5404893ee9a85d1aa67e81c2f58c1dac3c46For testing, I use this vulkan app that has an infinity loop in the shader:
https://github.com/andrealmeid/vulkan-triangle-v1Feedbacks are welcomed!
Thanks,
Andrév2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/André Almeida (4):
drm/doc: Document DRM device reset expectations
drm: CreateDRM_IOCTL_GET_RESETdrm/amdgpu: ImplementDRM_IOCTL_GET_RESETdrm/i915: ImplementDRM_IOCTL_GET_RESETDocumentation/gpu/drm-uapi.rst | 51 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 35 +++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 5 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 12 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 +drivers/gpu/drm/drm_debugfs.c | 2 + drivers/gpu/drm/drm_ioctl.c | 58
+++++++++++++++++++
drivers/gpu/drm/i915/gem/i915_gem_context.c | 18 ++++++ drivers/gpu/drm/i915/gem/i915_gem_context.h | 2 +.../gpu/drm/i915/gem/i915_gem_context_types.h| 2 + drivers/gpu/drm/i915/i915_driver.c | 2 + include/drm/drm_device.h | 3 + include/drm/drm_drv.h | 3 + include/uapi/drm/drm.h | 21 +++++++ include/uapi/drm/drm_mode.h | 15 +++++17 files changed, 233 insertions(+), 3 deletions(-)