drm/i915: Add gpu hw state capture helper
Subsystems (2)
PATCH 1/4 drm/i915: Add gpu hw state capture helper
In the following commits, we want to capture the hw state also without any errors. Carve out the helper out from error capture parts.
--- drivers/gpu/drm/i915/i915_gpu_error.c | 41 +++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/i915_gpu_error.c +27 -14
@@ -1265,28 +1265,17 @@ static void i915_capture_gen_state(struct drm_i915_private *dev_priv, error->suspend_count = dev_priv->suspend_count; } -/** -* i915_capture_error_state - capture an error record for later analysis -* @dev: drm device -* -* Should be called when an error is detected (either a hang or an error -* interrupt) to capture error state from the time of the error. Fills -* out a structure which becomes available in debugfs for user level tools -* to pick up. -*/ -void i915_capture_error_state (struct drm_device *dev,bool wedged, -const char *error_msg) +static struct drm_i915_error_state * +__i915_capture_gpu_state (struct drm_device *dev) { -static bool warned;struct drm_i915_private *dev_priv = dev->dev_private;struct drm_i915_error_state *error; -unsigned long flags;/* Account for pipe specific data like PIPE*STAT */ error =kzalloc (sizeof (*error),GFP_ATOMIC );if (!error) {DRM_DEBUG_DRIVER ("out of memory, not capturing error state\n" ); -return ; +return NULL ; }kref_init (&error->ref);
@@ -1302,6 +1291,30 @@ void i915_capture_error_state(struct drm_device *dev, bool wedged, error->overlay =intel_overlay_capture_error_state (dev); error->display =intel_display_capture_error_state (dev); +return error; +} + +/** +* i915_capture_error_state - capture an error record for later analysis +* @dev: drm device +* +* Should be called when an error is detected (either a hang or an error +* interrupt) to capture error state from the time of the error. Fills +* out a structure which becomes available in debugfs for user level tools +* to pick up. +*/ +void i915_capture_error_state (struct drm_device *dev,bool wedged, +const char *error_msg) +{ +static bool warned; +struct drm_i915_private *dev_priv = dev->dev_private; +struct drm_i915_error_state *error; +unsigned long flags; + + error =__i915_capture_gpu_state (dev); +if (error ==NULL ) +return ; +i915_error_capture_msg (dev, error, wedged, error_msg);DRM_INFO ("%s\n" , error->error_msg);
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/4 drm/i915: Add i915_gpu_state debugfs entry
'i915_gpu_state' debugfs entry can be used to capture the current gpu state. This is similar to what one would get from 'i915_error_state' if gpu error state would have been captured.
The motivation for this was to enhance our toolbox so that we can direct bug reporters to do things like:
'grep -i suspend /sys/kernel/debug/dri/0/i915_gpu_state'
pre and postmortem to gain insight in triaging and save ourselves from writing some new debugfs entries, when the information is already in our error state.
v2: - use symmetrical put/get (Chris)
- document the api (Daniel)
- take a mutex when capturing
--- drivers/gpu/drm/i915/i915_debugfs.c | 129 ++++++++++++++++++++++------------ drivers/gpu/drm/i915/i915_drv.h | 5 ++ drivers/gpu/drm/i915/i915_gpu_error.c | 57 +++++++++++++-- 3 files changed, 141 insertions(+), 50 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +86 -43
@@ -888,58 +888,41 @@ static int i915_hws_info(struct seq_file *m, void *data)return 0 ; } -static ssize_t -i915_error_state_write (struct file *filp, -const char __user *ubuf, -size_t cnt, -loff_t *ppos) -{ -struct i915_error_state_file_priv *error_priv = filp->private_data; -struct drm_device *dev = error_priv->dev; -int ret; - -DRM_DEBUG_DRIVER ("Resetting error state\n" ); - - ret =mutex_lock_interruptible (&dev->struct_mutex); -if (ret) -return ret; - -i915_destroy_error_state (dev); -mutex_unlock (&dev->struct_mutex); - -return cnt; -} - -static int i915_error_state_open (struct inode *inode,struct file *file) +static int i915_gpu_state_open (struct inode *inode,struct file *file) {struct drm_device *dev = inode->i_private; -struct i915_error_state_file_priv *error_priv; +struct i915_error_state_file_priv *state_priv; +int ret =0 ; - error_priv =kzalloc (sizeof (*error_priv),GFP_KERNEL ); -if (!error_priv) + state_priv =kzalloc (sizeof (*state_priv),GFP_KERNEL ); +if (!state_priv)return -ENOMEM ; - error_priv->dev = dev; - -i915_error_state_get (dev, error_priv); - - file->private_data = error_priv; + state_priv->dev = dev; -return 0 ; -} + ret =mutex_lock_interruptible (&dev->struct_mutex); +if (ret) +return ret; -static int i915_error_state_release (struct inode *inode,struct file *file) -{ -struct i915_error_state_file_priv *error_priv = file->private_data; + ret =i915_gpu_idle (dev); +if (ret) + goto unlock; -i915_error_state_put (error_priv); -kfree (error_priv); + state_priv->error =i915_gpu_state_capture (dev); +if (state_priv->error ==NULL ) { +kfree (state_priv); + ret = -ENOMEM ; + goto unlock; + } -return 0 ; + file->private_data = state_priv; +unlock: +mutex_unlock (&dev->struct_mutex); +return ret; } -static ssize_t i915_error_state_read (struct file *file,char __user *userbuf, -size_t count,loff_t *pos) +static ssize_t i915_gpu_state_read (struct file *file,char __user *userbuf, +size_t count,loff_t *pos) {struct i915_error_state_file_priv *error_priv = file->private_data;struct drm_i915_error_state_buf error_str;
@@ -968,13 +951,72 @@ out:return ret ?: ret_count; } +static int i915_gpu_state_release (struct inode *inode,struct file *file) +{ +struct i915_error_state_file_priv *state_priv = file->private_data; + +i915_gpu_state_put (state_priv->error); +kfree (state_priv); + +return 0 ; +} + +static const struct file_operations i915_gpu_state_fops = { + .owner =THIS_MODULE , + .open = i915_gpu_state_open, + .read = i915_gpu_state_read, + .write =NULL , + .llseek = default_llseek, + .release = i915_gpu_state_release, +}; + +static int i915_error_state_open (struct inode *inode,struct file *file) +{ +struct drm_device *dev = inode->i_private; +struct i915_error_state_file_priv *error_priv; + + error_priv =kzalloc (sizeof (*error_priv),GFP_KERNEL ); +if (!error_priv) +return -ENOMEM ; + + error_priv->dev = dev; + +i915_error_state_get (dev, error_priv); + + file->private_data = error_priv; + +return 0 ; +} + +static ssize_t +i915_error_state_write (struct file *filp, +const char __user *ubuf, +size_t cnt, +loff_t *ppos) +{ +struct i915_error_state_file_priv *error_priv = filp->private_data; +struct drm_device *dev = error_priv->dev; +int ret; + +DRM_DEBUG_DRIVER ("Resetting error state\n" ); + + ret =mutex_lock_interruptible (&dev->struct_mutex); +if (ret) +return ret; + +i915_destroy_error_state (dev); +mutex_unlock (&dev->struct_mutex); + +return cnt; +} +static const struct file_operations i915_error_state_fops = { .owner =THIS_MODULE , .open = i915_error_state_open, - .read = i915_error_state_read, + .read = i915_gpu_state_read, .write = i915_error_state_write, .llseek = default_llseek, - .release = i915_error_state_release, + .release = i915_gpu_state_release, }; static int
@@ -4367,6 +4409,7 @@ static const struct i915_debugfs_files { {"i915_ring_test_irq", &i915_ring_test_irq_fops}, {"i915_gem_drop_caches", &i915_drop_caches_fops}, {"i915_error_state", &i915_error_state_fops}, + {"i915_gpu_state", &i915_gpu_state_fops}, {"i915_next_seqno", &i915_next_seqno_fops}, {"i915_display_crc_ctl", &i915_display_crc_ctl_fops}, {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
drivers/gpu/drm/i915/i915_drv.h +5 -0
@@ -2866,6 +2866,11 @@ static inline void i915_error_state_buf_release( {kfree (eb->buf); } + +struct drm_i915_error_state *__must_check +i915_gpu_state_capture (struct drm_device *dev); +void i915_gpu_state_put (struct drm_i915_error_state *error); +void i915_capture_error_state (struct drm_device *dev,bool wedge,const char *error_msg); void i915_error_state_get(struct drm_device *dev,
drivers/gpu/drm/i915/i915_gpu_error.c +50 -7
105 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/4 drm/i915: Add i915_gpu_state_unsafe debugfs entry
In reply to Mika KuoppalaThis is a similar to 'i915_gpu_state' but more dangerous as it doesn't try to lock nor idle the gpu before grabbing the state. But the obvious advantages are that one can inspect the current running gpu state and also get a state dump even if mutex is hold.
As we don't want a unsuspecting user to trip into this by accident, there needs to be write into the debugfs node before any unsafe capturing can take place.
--- drivers/gpu/drm/i915/i915_debugfs.c | 55 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_drv.h | 4 +++ 2 files changed, 59 insertions(+)
drivers/gpu/drm/i915/i915_debugfs.c +55 -0
@@ -970,6 +970,60 @@ static const struct file_operations i915_gpu_state_fops = { .release = i915_gpu_state_release, }; +static int i915_gpu_state_open_unsafe (struct inode *inode,struct file *file) +{ +struct drm_device *dev = inode->i_private; +struct i915_error_state_file_priv *state_priv; +struct drm_i915_private *dev_priv = dev->dev_private; + + state_priv =kzalloc (sizeof (*state_priv),GFP_KERNEL ); +if (!state_priv) +return -ENOMEM ; + + state_priv->dev = dev; + +if (dev_priv->gpu_error.allow_unsafe_state_capture) { + state_priv->error =i915_gpu_state_capture (dev); +if (state_priv->error ==NULL ) { +kfree (state_priv); +return -ENOMEM ; + } + } + + file->private_data = state_priv; +return 0 ; +} + +static ssize_t +i915_gpu_state_write_unsafe (struct file *filp, +const char __user *ubuf, +size_t cnt, +loff_t *ppos) +{ +struct i915_error_state_file_priv *error_priv = filp->private_data; +struct drm_device *dev = error_priv->dev; +struct drm_i915_private *dev_priv = dev->dev_private; + + dev_priv->gpu_error.allow_unsafe_state_capture = ! + dev_priv->gpu_error.allow_unsafe_state_capture; + +if (dev_priv->gpu_error.allow_unsafe_state_capture) +DRM_DEBUG_DRIVER ("allowing unsafe, non locked gpu state dumps\n" ); +else +DRM_DEBUG_DRIVER ("denying unsafe, non locked gpu state dumps\n" ); + +return cnt; +} + +static const struct file_operations i915_gpu_state_unsafe_fops = { + .owner =THIS_MODULE , + .open = i915_gpu_state_open_unsafe, + .read = i915_gpu_state_read, + .write = i915_gpu_state_write_unsafe, + .llseek = default_llseek, + .release = i915_gpu_state_release, +}; +static int i915_error_state_open (struct inode *inode,struct file *file) {struct drm_device *dev = inode->i_private;
@@ -4410,6 +4464,7 @@ static const struct i915_debugfs_files { {"i915_gem_drop_caches", &i915_drop_caches_fops}, {"i915_error_state", &i915_error_state_fops}, {"i915_gpu_state", &i915_gpu_state_fops}, + {"i915_gpu_state_unsafe", &i915_gpu_state_unsafe_fops}, {"i915_next_seqno", &i915_next_seqno_fops}, {"i915_display_crc_ctl", &i915_display_crc_ctl_fops}, {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -1278,6 +1278,10 @@ struct i915_gpu_error {/* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */ bool reload_in_reset; + +/* Safety mechanism to prevent unsuspecting user to obtain nonlocked +* capture by accident */ +bool allow_unsafe_state_capture; };enum modeset_restore {
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 3/4] drm/i915: Add i915_gpu_state_unsafe debugfs entry
Quoted 9 lines · Mika Kuoppala
This is a similar to '
i915_gpu_state' but more dangerous as it doesn't try to lock nor idle the gpu before grabbing the state. But the obvious advantages are that one can inspect the current running gpu state and also get a state dump even if mutex is hold.As we don't want a unsuspecting user to trip into this by accident, there needs to be write into the debugfs node before any unsafe capturing can take place.
It shouldn't be called unsafe. It is precisely the mode in which the regular error capture runs and so the kernel is required to be robust. So just document that i915_gpu_state runs asynchronously to any client and the gpu, and caveat emptor.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/4 drm/i915: Rename drm_i915_error_state_buf to intel_strbuf
In reply to Mika KuoppalaEmphasize the more general applicability of the seekable string buffer by decoupling it from error handling.
--- drivers/gpu/drm/i915/i915_debugfs.c | 2 +- drivers/gpu/drm/i915/i915_drv.h | 14 +++---- drivers/gpu/drm/i915/i915_gpu_error.c | 74 ++++++++++++++++++++--------------- drivers/gpu/drm/i915/i915_sysfs.c | 2 +- drivers/gpu/drm/i915/intel_display.c | 4 +- drivers/gpu/drm/i915/intel_overlay.c | 8 ++-- 6 files changed, 58 insertions(+), 46 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
@@ -925,7 +925,7 @@ static ssize_t i915_gpu_state_read(struct file *file, char __user *userbuf, size_t count, loff_t *pos) { struct i915_error_state_file_priv *error_priv = file->private_data; -struct drm_i915_error_state_buf error_str; +struct intel_strbuf error_str;loff_t tmp_pos =0 ;ssize_t ret_count =0 ;int ret;
drivers/gpu/drm/i915/i915_drv.h +7 -7
@@ -1201,7 +1201,7 @@ struct i915_gem_mm {u32 object_count; }; -struct drm_i915_error_state_buf { +struct intel_strbuf {struct drm_i915_private *i915;unsigned bytes;unsigned size;
@@ -2859,14 +2859,14 @@ static inline void intel_display_crc_init(struct drm_device *dev) {}/* i915_gpu_error.c */ __printf(2, 3) -void i915_error_printf (struct drm_i915_error_state_buf *e,const char *f, ...); -int i915_error_state_to_str (struct drm_i915_error_state_buf *estr, +void intel_strbuf_printf (struct intel_strbuf *e,const char *f, ...); +int i915_error_state_to_str (struct intel_strbuf *estr,const struct i915_error_state_file_priv *error); -int i915_error_state_buf_init (struct drm_i915_error_state_buf *eb, +int i915_error_state_buf_init (struct intel_strbuf *eb,struct drm_i915_private *i915,size_t count,loff_t pos);static inline void i915_error_state_buf_release ( -struct drm_i915_error_state_buf *eb) +struct intel_strbuf *eb) {kfree (eb->buf); }
@@ -2995,11 +2995,11 @@ void intel_notify_mmio_flip(struct intel_engine_cs *ring);/* overlay */ extern struct intel_overlay_error_state *intel_overlay_capture_error_state (struct drm_device *dev); -extern void intel_overlay_print_error_state (struct drm_i915_error_state_buf *e, +extern void intel_overlay_print_error_state (struct intel_strbuf *e,struct intel_overlay_error_state *error);extern struct intel_display_error_state *intel_display_capture_error_state (struct drm_device *dev); -extern void intel_display_print_error_state (struct drm_i915_error_state_buf *e, +extern void intel_display_print_error_state (struct intel_strbuf *e,struct drm_device *dev,struct intel_display_error_state *error);
drivers/gpu/drm/i915/i915_gpu_error.c +43 -31
157 lines not on this page · raw message
drivers/gpu/drm/i915/i915_sysfs.c +1 -1
@@ -543,7 +543,7 @@ static ssize_t error_state_read(struct file *filp, struct kobject *kobj,struct drm_minor *minor =dev_to_drm_minor (kdev);struct drm_device *dev = minor->dev;struct i915_error_state_file_priv error_priv; -struct drm_i915_error_state_buf error_str; +struct intel_strbuf error_str;ssize_t ret_count =0 ;int ret;
drivers/gpu/drm/i915/intel_display.c +2 -2
@@ -13762,10 +13762,10 @@ intel_display_capture_error_state(struct drm_device *dev)return error; } -#define err_printf (e, ...) i915_error_printf(e, __VA_ARGS__) +#define err_printf (e, ...) intel_strbuf_printf(e, __VA_ARGS__)void -intel_display_print_error_state (struct drm_i915_error_state_buf *m, +intel_display_print_error_state (struct intel_strbuf *m,struct drm_device *dev,struct intel_display_error_state *error) {
drivers/gpu/drm/i915/intel_overlay.c +4 -4
@@ -1509,15 +1509,15 @@ err: }void -intel_overlay_print_error_state (struct drm_i915_error_state_buf *m, +intel_overlay_print_error_state (struct intel_strbuf *m,struct intel_overlay_error_state *error) { -i915_error_printf (m,"Overlay, status: 0x%08x, interrupt: 0x%08x\n" , +intel_strbuf_printf (m,"Overlay, status: 0x%08x, interrupt: 0x%08x\n" , error->dovsta, error->isr); -i915_error_printf (m," Register file at 0x%08lx:\n" , +intel_strbuf_printf (m," Register file at 0x%08lx:\n" , error->base); -#define P (x) i915_error_printf(m, " " #x ": 0x%08x\n", error->regs.x) +#define P (x) intel_strbuf_printf(m, " " #x ": 0x%08x\n", error->regs.x)P (OBUF_0Y );P (OBUF_1Y );P (OBUF_0U );
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 4/4] drm/i915: Rename drm_i915_error_state_buf to intel_strbuf
-------------------------------------Summary-------------------------------------
Platform Delta drm-intel-nightly Series Applied
PNV 364/364 364/364
ILK +1 364/366 365/366
SNB 448/450 448/450 IVB 497/498 497/498 BYT 289/289 289/289
HSW -1 563/564 562/564
BDW 417/417 417/417
-------------------------------------Detailed-------------------------------------
Platform Test drm-intel-nightly Series Applied
ILK igt_kms_flip_wf_vblank-ts-check DMESG_WARN(1, M26)PASS(11, M26M37) PASS(1, M37)
*HSW igt_pm_rpm_debugfs-read PASS(3, M40M20) DMESG_WARN(1, M20)
Note: You need to pay more attention to line start with '*'
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 3 lines · Mika Kuoppala
In the following commits, we want to capture the hw state also without any errors. Carve out the helper out from error capture parts.
As an aside i915_gpu_state is a better name throughout for struct drm_i915_error_state. Afterwards, only the i915_gpu_state singleton we capture upon a hang gets associated with the actual error state. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx