drm: Add sysrq handler to kill GPU
Subsystems (5)
Rob Clark
maintainercover drm: Add sysrq handler to kill GPU
Depending on contraints around preemption (ie. on what boundaries can the GPU preempt) and priority of other processes using the GPU, the compositor can get starved behind a long-running job.
This can be handled by a hangcheck timer that kills jobs that run too long, but then there is a conflict between legit long running jobs (opencl) and UI responsiveness.
This series adds a new sysrq key handler (SysRq-G because SysRq-g was already taken) that kills the current job running on the GPU. So a longer hangcheck timer could be used but the user could still reclaim their "hung" desktop by using SysRq-G to kill the background GPU job.
Sending this out as RFC to see what others think of the idea. Possibly the driver implementation should check how long the job has been running to make sure it is only killing a long running job. Possibly we should kill the process behind the long running job, or at least mark the context as unusable to prevent it from spamming more long running jobs. Etc.
Rob Clark (2):
drm: Add sysrq key to kill current job on GPU
drm/msm: Add sysrq_kill handler
drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_dev_sysrq.c | 67 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_drv.c | 3 ++ drivers/gpu/drm/drm_internal.h | 11 ++++++ drivers/gpu/drm/msm/msm_drv.c | 12 ++++++ drivers/gpu/drm/msm/msm_gpu.c | 18 +++++++++ drivers/gpu/drm/msm/msm_gpu.h | 1 + include/drm/drm_device.h | 8 ++++ include/drm/drm_drv.h | 7 ++++ 9 files changed, 128 insertions(+) create mode 100644 drivers/gpu/drm/drm_dev_sysrq.c
Signature · 1 line
2.53.0
Rob Clark
maintainerRFC 1/2 drm: Add sysrq key to kill current job on GPU
If your compositor is getting starved for GPU time, it is useful to have a way to kill the current thing that is hogging the GPU.
--- drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_dev_sysrq.c | 67 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_drv.c | 3 ++ drivers/gpu/drm/drm_internal.h | 11 ++++++ include/drm/drm_device.h | 8 ++++ include/drm/drm_drv.h | 7 ++++ 6 files changed, 97 insertions(+) create mode 100644 drivers/gpu/drm/drm_dev_sysrq.c
drivers/gpu/drm/Makefile +1 -0
@@ -44,6 +44,7 @@ drm-y := \ drm_colorop.o \ drm_connector.o \ drm_crtc.o \ + drm_dev_sysrq.o \ drm_displayid.o \ drm_drv.o \ drm_dumb_buffers.o \
drivers/gpu/drm/drm_dev_sysrq.c new file +67 -0
67 lines not on this page · raw message
drivers/gpu/drm/drm_drv.c +3 -0
@@ -734,6 +734,7 @@ static int drm_dev_init(struct drm_device *dev,INIT_LIST_HEAD (&dev->filelist_internal);INIT_LIST_HEAD (&dev->clientlist);INIT_LIST_HEAD (&dev->client_sysrq_list); +INIT_LIST_HEAD (&dev->dev_sysrq_list);INIT_LIST_HEAD (&dev->vblank_event_list);spin_lock_init (&dev->event_lock);
@@ -1102,6 +1103,7 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) }drm_panic_register (dev);drm_client_sysrq_register (dev); +drm_dev_sysrq_register (dev); DRM_INFO("Initialized %s %d.%d.%d for %s on minor %d\n", driver->name, driver->major, driver->minor,
@@ -1146,6 +1148,7 @@ void drm_dev_unregister(struct drm_device *dev) { dev->registered = false; +drm_dev_sysrq_unregister (dev);drm_client_sysrq_unregister (dev);drm_panic_unregister (dev);
drivers/gpu/drm/drm_internal.h +11 -0
@@ -67,6 +67,17 @@ static inline void drm_client_sysrq_unregister(struct drm_device *dev) { }#endif +/* drm_dev_sysrq.c */ +#ifdef CONFIG_MAGIC_SYSRQ +void drm_dev_sysrq_register (struct drm_device *dev); +void drm_dev_sysrq_unregister (struct drm_device *dev); +#else +static inline void drm_dev_sysrq_register (struct drm_device *dev) +{ } +static inline void drm_dev_sysrq_unregister (struct drm_device *dev) +{ } +#endif +/* drm_file.c */ extern struct mutex drm_global_mutex;bool drm_dev_needs_global_mutex (struct drm_device *dev);
include/drm/drm_device.h +8 -0
@@ -246,6 +246,14 @@ struct drm_device {*/ struct list_head client_sysrq_list; +/** +* @dev_sysrq_list: +* +* Entry into list of devices registered for sysrq to kill current +* GPU job. +*/ +struct list_head dev_sysrq_list; +/** * @vblank_disable_immediate: *
include/drm/drm_drv.h +7 -0
@@ -385,6 +385,13 @@ struct drm_driver {int (*fbdev_probe)(struct drm_fb_helper *fbdev_helper,struct drm_fb_helper_surface_size *sizes); +/** +* @sysrq_kill: +* +* Handler for magic sysrq key to kill current job on the GPU. +*/ +void (*sysrq_kill)(struct drm_device *dev); +/** * @show_fdinfo: *
Signature · 1 line
2.53.0
Rob Clark
maintainerRFC 2/2 drm/msm: Add sysrq_kill handler
In reply to Rob ClarkThis does the same thing as an immediately expiring hangcheck timer.
--- drivers/gpu/drm/msm/msm_drv.c | 12 ++++++++++++ drivers/gpu/drm/msm/msm_gpu.c | 18 ++++++++++++++++++ drivers/gpu/drm/msm/msm_gpu.h | 1 + 3 files changed, 31 insertions(+)
drivers/gpu/drm/msm/msm_drv.c +12 -0
@@ -812,6 +812,16 @@ static void msm_show_fdinfo(struct drm_printer *p, struct drm_file *file)drm_show_memory_stats (p, file); } +static void msm_sysrq_kill (struct drm_device *dev) +{ +struct msm_drm_private *priv = dev->dev_private; + +if (!priv->gpu) +return ; + +msm_gpu_sysrq_kill (priv->gpu); +} +static const struct file_operations fops = { .owner =THIS_MODULE ,DRM_GEM_FOPS ,
@@ -846,6 +856,7 @@ static const struct drm_driver msm_driver = {#endif MSM_FBDEV_DRIVER_OPS, .show_fdinfo = msm_show_fdinfo, + .sysrq_kill = msm_sysrq_kill, .ioctls = msm_ioctls, .num_ioctls = ARRAY_SIZE(msm_ioctls), .fops = &fops,
@@ -885,6 +896,7 @@ static const struct drm_driver msm_gpu_driver = { .debugfs_init = msm_debugfs_init, #endif .show_fdinfo = msm_show_fdinfo, + .sysrq_kill = msm_sysrq_kill, .ioctls = msm_ioctls, .num_ioctls = ARRAY_SIZE(msm_ioctls), .fops = &fops,
drivers/gpu/drm/msm/msm_gpu.c +18 -0
@@ -673,6 +673,24 @@ static void hangcheck_handler(struct timer_list *t)msm_gpu_retire (gpu); } +void msm_gpu_sysrq_kill (struct msm_gpu *gpu) +{ +struct msm_ringbuffer *ring = gpu->funcs->active_ring (gpu); +uint32_t fence = ring->memptrs->fence; +struct drm_device *dev = gpu->dev; + +if (fence_before (fence, ring->fctx->last_fence)) { +DRM_DEV_ERROR (dev->dev,"%s: sysrq kill job, rb %d!\n" , + gpu->name, ring->id); +DRM_DEV_ERROR (dev->dev,"%s: completed fence: %u\n" , + gpu->name, fence); +DRM_DEV_ERROR (dev->dev,"%s: submitted fence: %u\n" , + gpu->name, ring->fctx->last_fence); + +kthread_queue_work (gpu->worker, &gpu->recover_work); + } +} +/* * Performance Counters: */
drivers/gpu/drm/msm/msm_gpu.h +1 -0
@@ -696,6 +696,7 @@ int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,void msm_gpu_retire (struct msm_gpu *gpu);void msm_gpu_submit (struct msm_gpu *gpu,struct msm_gem_submit *submit); +void msm_gpu_sysrq_kill (struct msm_gpu *gpu); int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev, struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
Signature · 1 line
2.53.0