Test for page flip hangs
cover Test for page flip hangs
Here's a test to go along with the
'[PATCH 0/6] drm/i915: Avoid stuck page flip waiters on GPU reset' kernel patches.
I'm not sure if this should really be in kms_flip since people might actually run that and not expect their machine to be useless afterwards. But kms_flip since it had most of the stuff I need anyway (fbs, flips, modeset) I just added it there.
PATCH 1/2 kms_flip: Make flip events optional
From: Ville Syrjälä <[email protected]>
Pass an argument to do_page_flip() telling it whether to request flip events.
--- tests/kms_flip.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
tests/kms_flip.c +9 -9
@@ -223,13 +223,13 @@ static void clear_flag(unsigned int *v, unsigned int flag) *v &= ~flag; } -static int do_page_flip (struct test_output *o,int fb_id) +static int do_page_flip (struct test_output *o,int fb_id,bool event) {int ret; - ret =drmModePageFlip (drm_fd, o->crtc, fb_id,DRM_MODE_PAGE_FLIP_EVENT , - o); -if (ret ==0 ) + ret =drmModePageFlip (drm_fd, o->crtc, fb_id, event ?DRM_MODE_PAGE_FLIP_EVENT :0 , + event ? o :NULL ); +if (ret ==0 && event)set_flag (&o->pending_events,EVENT_FLIP );return ret;
@@ -544,7 +544,7 @@ static unsigned int run_test_step(struct test_output *o) }if (do_flip && (o->flags &TEST_EINVAL ) && o->flip_state.count >0 ) -assert (do_page_flip (o, new_fb_id) == expected_einval); +assert (do_page_flip (o, new_fb_id, true) == expected_einval);if (do_vblank && (o->flags &TEST_EINVAL ) && o->vblank_state.count >0 ) assert(do_wait_for_vblank(o, o->pipe, target_seq, &vbl_reply)
@@ -567,7 +567,7 @@ static unsigned int run_test_step(struct test_output *o)printf ("." );fflush (stdout);if (do_flip) -do_or_die (do_page_flip (o, new_fb_id)); +do_or_die (do_page_flip (o, new_fb_id, true));if (do_vblank) { do_or_die(do_wait_for_vblank(o, o->pipe, target_seq,
@@ -581,7 +581,7 @@ static unsigned int run_test_step(struct test_output *o) }if (do_flip && (o->flags &TEST_EBUSY )) -assert (do_page_flip (o, new_fb_id) == -EBUSY ); +assert (do_page_flip (o, new_fb_id, true) == -EBUSY );if (do_flip && (o->flags &TEST_RMFB ))recreate_fb (o);
@@ -621,7 +621,7 @@ static unsigned int run_test_step(struct test_output *o) == -EINVAL);if (do_flip && (o->flags &TEST_EINVAL )) -assert (do_page_flip (o, new_fb_id) == expected_einval); +assert (do_page_flip (o, new_fb_id, true) == expected_einval);return completed_events; }
@@ -907,7 +907,7 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration)if (o->flags &TEST_CHECK_TS )sleep (1 ); -if (do_page_flip (o, o->fb_ids[1 ])) { +if (do_page_flip (o, o->fb_ids[1 ], true)) {fprintf (stderr,"failed to page flip: %s\n" ,strerror (errno));exit (4 ); }
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/2 kms_flip: Add flip-vs-modeset-vs-hang test
In reply to [email protected]From: Ville Syrjälä <[email protected]>
The flip-vs-modeset-vs-hang test will:
1. simulate a GPU hang
2. exec a nop batch
3. schedule a page flip
4. perform a modeset operation
With the current buggy kernel driver, the modeset operation will hang indefinitely waiting for the flip to complete. Since the rings are stopped, that will never happen. The current GPU reset code doesn't play well with page flips either, so a GPU reset won't fix things.
Once the kernel driver is fixed, the eventual GPU reset will save the day.
The nop batch buffer is required only because the kernel can't currently detect GPU hangs, unless there is at least one user submitted request pending.
--- tests/kms_flip.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-)
tests/kms_flip.c +86 -2
@@ -26,6 +26,7 @@#include <assert.h> #include <cairo.h> #include <errno.h> +#include <fcntl.h> #include <math.h> #include <stdint.h> #include <unistd.h>
@@ -55,6 +56,7 @@#define TEST_VBLANK_EXPIRED_SEQ (1 << 11)#define TEST_FB_RECREATE (1 << 12)#define TEST_RMFB (1 << 13) +#define TEST_HANG (1 << 14)#define EVENT_FLIP (1 << 0)#define EVENT_VBLANK (1 << 1)
@@ -493,6 +495,75 @@ static void recreate_fb(struct test_output *o) o->fb_info[o->current_fb_id].fb_id = new_fb_id; } +static int exec_nop (int fd,uint32_t handle) +{ +struct drm_i915_gem_execbuffer2 execbuf; +struct drm_i915_gem_exec_object2 gem_exec[1 ]; +uint32_t b[2 ] = {MI_BATCH_BUFFER_END }; +int r; + +gem_write (fd, handle,0 , b,sizeof (b)); + + gem_exec[0 ].handle = handle; + gem_exec[0 ].relocation_count =0 ; + gem_exec[0 ].relocs_ptr =0 ; + gem_exec[0 ].alignment =0 ; + gem_exec[0 ].offset =0 ; + gem_exec[0 ].flags =0 ; + gem_exec[0 ].rsvd1 =0 ; + gem_exec[0 ].rsvd2 =0 ; + + execbuf.buffers_ptr = (uintptr_t )gem_exec; + execbuf.buffer_count =1 ; + execbuf.batch_start_offset =0 ; + execbuf.batch_len =8 ; + execbuf.cliprects_ptr =0 ; + execbuf.num_cliprects =0 ; + execbuf.DR1 =0 ; + execbuf.DR4 =0 ; + execbuf.flags =I915_EXEC_RENDER ; +i915_execbuffer2_set_context_id (execbuf,0 ); + execbuf.rsvd2 =0 ; + + r =drmIoctl (fd, +DRM_IOCTL_I915_GEM_EXECBUFFER2 , + &execbuf); +if (r) +fprintf (stderr,"failed to exec: %s\n" , +strerror (errno)); +return r; +} + +static void hang_gpu (struct test_output *o) +{ +static const char dfs_base[] ="/sys/kernel/debug/dri" ; +static const char dfs_entry[] ="i915_ring_stop" ; +static const char data[] ="0xf" ; +char fname[FILENAME_MAX ]; +int card_index =drm_get_card (0 ); +int fd; +ssize_t r; + +assert (card_index !=-1 ); + +snprintf (fname,FILENAME_MAX ,"%s/%i/%s" , + dfs_base, card_index, dfs_entry); + + fd =open (fname,O_WRONLY ); +if (fd <0 ) { +fprintf (stderr,"failed to open '%s': %s\n" , + fname,strerror (errno)); +return ; + } + + r =write (fd, data,sizeof data); +if (r <0 ) +fprintf (stderr,"failed to write '%s': %s\n" , + fname,strerror (errno)); + +close (fd); +} +/* Return mask of completed events. */ static unsigned int run_test_step (struct test_output *o) {
@@ -504,6 +575,7 @@ static unsigned int run_test_step(struct test_output *o)bool do_vblank;struct vblank_reply vbl_reply;unsigned int target_seq; +uint32_t handle; target_seq = o->vblank_state.seq_step;if (o->flags &TEST_VBLANK_ABSOLUTE )
@@ -566,8 +638,14 @@ static unsigned int run_test_step(struct test_output *o)printf ("." );fflush (stdout); +if (do_flip && (o->flags &TEST_HANG )) { + handle =gem_create (drm_fd,4096 ); +hang_gpu (o); +exec_nop (drm_fd, handle); + } +if (do_flip) -do_or_die (do_page_flip (o, new_fb_id, true)); +do_or_die (do_page_flip (o, new_fb_id, !(o->flags &TEST_HANG )));if (do_vblank) { do_or_die(do_wait_for_vblank(o, o->pipe, target_seq,
@@ -623,6 +701,11 @@ static unsigned int run_test_step(struct test_output *o)if (do_flip && (o->flags &TEST_EINVAL ))assert (do_page_flip (o, new_fb_id, true) == expected_einval); +if (do_flip && (o->flags &TEST_HANG )) { +gem_sync (drm_fd, handle); +gem_close (drm_fd, handle); + } +return completed_events; }
@@ -922,7 +1005,7 @@ static void run_test_on_crtc(struct test_output *o, int crtc, int duration) ellapsed =event_loop (o, duration); -if (o->flags &TEST_FLIP ) +if (o->flags &TEST_FLIP && !(o->flags &TEST_HANG ))check_final_state (o, &o->flip_state, ellapsed);if (o->flags &TEST_VBLANK )check_final_state (o, &o->vblank_state, ellapsed);
@@ -1025,6 +1108,7 @@ int main(int argc, char **argv) "flip-vs-wf_vblank" }, {15 ,TEST_FLIP |TEST_VBLANK |TEST_VBLANK_BLOCK | TEST_CHECK_TS, "flip-vs-blocking-wf-vblank" }, + { 15, TEST_FLIP | TEST_MODESET | TEST_HANG , "flip-vs-modeset-vs-hang" }, };int i;
Signature · 6 lines
1.7.12.4 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 3 lines · On Wed, Jan 30, 2013 at 02:52:22PM +0200, [email protected] wrote:
Here's a test to go along with the
'[PATCH 0/6] drm/i915: Avoid stuck page flip waiters on GPU reset' kernel patches.
Very nice! I think for further mayhem around gpu hangs we could hang_gpu function into the drmtest library.
Quoted 4 lines
I'm not sure if this should really be in
kms_flipsince people might actually run that and not expect their machine to be useless afterwards. Butkms_flipsince it had most of the stuff I need anyway (fbs, flips, modeset) I just added it there.
I don't have any issues with i-g-t's killing the kernel, that's kinda the point ;-) And with the subtest infrastructure there's also no big issue with adding tons of different cases to the same binary imo.
For modeset test we might want to add some common filtering though to e.g. only test a given connector type. Otoh a single test usually runs down rather quickly.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 3 lines · On Wed, Jan 30, 2013 at 02:52:22PM +0200, [email protected] wrote:
Here's a test to go along with the
'[PATCH 0/6] drm/i915: Avoid stuck page flip waiters on GPU reset' kernel patches.
Very nice! I think for further mayhem around gpu hangs we could hang_gpu function into the drmtest library.
Quoted 4 lines
I'm not sure if this should really be in
kms_flipsince people might actually run that and not expect their machine to be useless afterwards. Butkms_flipsince it had most of the stuff I need anyway (fbs, flips, modeset) I just added it there.
I don't have any issues with i-g-t's killing the kernel, that's kinda the point ;-) And with the subtest infrastructure there's also no big issue with adding tons of different cases to the same binary imo.
For modeset test we might want to add some common filtering though to e.g. only test a given connector type. Otoh a single test usually runs down rather quickly.
I've gone right ahead and merged the tests.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch