i-g-t: flip_test: add vblank test cases
cover i-g-t: flip_test: add vblank test cases
Some refactoring, fixes and a few test cases for the DRM_IOCTL_WAIT_VBLANK IOCTL.
Tested on IVB using the drm-intel-nightly kernel branch.
Imre Deak (22):
drmtest: add function to remove an DRM FB
flip_test: free FBs after each test run
flip_test: reset the state for each test run
flip_test: check drmHandleEvents()' return value
test_flip: fix checking for delayed event reception
flip_test: store fb width, height in test context object
flip_test: factor out drmModePageFlip
flip_test: move output panning inside the flip_handler
flip_test: factor out the event loop/wait for event logic
flip_test: factor out the final state check
flip_test: store current flip/received timestamps in the context obj
flip_test: split the flip handler into logical parts
flip_test: swap the order of check state/run test step
flip_test: factor out the event state
flip_test: don't skip checks for sequence #1
flip_test: store crtc_idx in the test context obj
flip_test: unify the name of the current test in status messages
flip_test: make page flip tests conditional
flip_test: add logic to track pending events
flip_test: add event sequence number tracking
flip_test: add check to see if any event has occured
flip_test: add wait-for-vblank tests
lib/drmtest.c | 5 + lib/drmtest.h | 1 + tests/flip_test.c | 584 +++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 440 insertions(+), 150 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/22 drmtest: add function to remove an DRM FB
--- lib/drmtest.c | 5 +++++ lib/drmtest.h | 1 + 2 files changed, 6 insertions(+)
lib/drmtest.c +5 -0
@@ -829,6 +829,11 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,return fb_id; } +void kmstest_remove_fb (int fd,int fb_id) +{ +do_or_die (drmModeRmFB (fd, fb_id)); +} +void kmstest_dump_mode (drmModeModeInfo *mode) { printf(" %s %d %d %d %d %d %d %d %d %d 0x%x 0x%x %d\n",
lib/drmtest.h +1 -0
@@ -105,6 +105,7 @@ unsigned int kmstest_create_fb(int fd, int width, int height, int bpp,struct kmstest_fb *fb_info, kmstest_paint_func paint_func, void *func_arg); +void kmstest_remove_fb (int fd,int fb_id);void kmstest_dump_mode (drmModeModeInfo *mode);inline static void _do_or_die (const char *function,int line,int ret)
Signature · 1 line
1.7.9.5
PATCH 2/22 flip_test: free FBs after each test run
In reply to Imre DeakThough the FBs will be freed implicitly at process exit, with the growing number of test cases it's probably better not to let them accumulate and free them as soon as we can.
--- tests/flip_test.c | 3 +++ 1 file changed, 3 insertions(+)
tests/flip_test.c +3 -0
@@ -525,6 +525,9 @@ static void flip_mode(struct test_output *o, int crtc, int duration)fprintf (stdout,"\npage flipping on crtc %d, connector %d: PASSED\n" , crtc, o->id); +kmstest_remove_fb (drm_fd, o->fb_ids[1 ]); +kmstest_remove_fb (drm_fd, o->fb_ids[0 ]); +drmModeFreeEncoder (o->encoder);drmModeFreeConnector (o->connector); }
Signature · 1 line
1.7.9.5
PATCH 3/22 flip_test: reset the state for each test run
In reply to Imre DeakEach test run needs a clean state.
--- tests/flip_test.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
tests/flip_test.c +6 -4
@@ -546,11 +546,13 @@ static int run_test(int duration, int flags)/* Find any connected displays */ for (c =0 ; c < resources->count_connectors; c++) { -memset (&o,0 ,sizeof (o)); - o.id = resources->connectors[c]; - o.flags = flags; -for (i =0 ; i < resources->count_crtcs; i++) +for (i =0 ; i < resources->count_crtcs; i++) { +memset (&o,0 ,sizeof (o)); + o.id = resources->connectors[c]; + o.flags = flags; +flip_mode (&o, resources->crtcs[i], duration); + } }drmModeFreeResources (resources);
Signature · 1 line
1.7.9.5
PATCH 4/22 flip_test: check drmHandleEvents()' return value
In reply to Imre Deak--- tests/flip_test.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tests/flip_test.c +4 -2
@@ -494,12 +494,14 @@ static void flip_mode(struct test_output *o, int crtc, int duration) } } -drmHandleEvent (drm_fd, &evctx); + ret =drmHandleEvent (drm_fd, &evctx); +assert (ret ==0 ); }/* and drain the event queue */ evctx.page_flip_handler =NULL ; -drmHandleEvent (drm_fd, &evctx); + ret =drmHandleEvent (drm_fd, &evctx); +assert (ret ==0 );/* Verify we drop no frames, but only if it's not a TV encoder, since * those use some funny fake timings behind userspace's back. */
Signature · 1 line
1.7.9.5
PATCH 5/22 test_flip: fix checking for delayed event reception
In reply to Imre DeakThe intent for the time limit seems to be 2ms, but the current condition will result in a 1s limit and makes the check against tv_usec redundant. Fix the condition to check for a 2ms limit.
--- tests/flip_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/flip_test.c +1 -1
@@ -183,7 +183,7 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,timersub (&pageflip_ts, &now, &diff); -if (diff.tv_sec >0 || (diff.tv_sec >0 && diff.tv_usec >2000 )) { +if (diff.tv_sec >0 || (diff.tv_sec ==0 && diff.tv_usec >2000 )) {fprintf (stderr,"pageflip timestamp delayed for too long: %is, %iusec\n" , (int ) diff.tv_sec, (int ) diff.tv_usec);exit (5 );
Signature · 1 line
1.7.9.5
PATCH 6/22 flip_test: store fb width, height in test context object
In reply to Imre DeakWe will need these in event handlers, so store them where the handlers have access to them.
No functional change.
--- tests/flip_test.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
tests/flip_test.c +12 -11
@@ -73,6 +73,8 @@ struct test_output {int flags;int count;unsigned int current_fb_id; +unsigned int fb_width; +unsigned int fb_height;unsigned int fb_ids[2 ];struct kmstest_fb fb_info[2 ];struct timeval last_flip_received;
@@ -391,7 +393,6 @@ static void flip_mode(struct test_output *o, int crtc, int duration)int ret;int bpp =32 , depth =24 ;drmEventContext evctx; -int width, height;struct timeval end;connector_find_preferred_mode (o, crtc);
@@ -401,17 +402,17 @@ static void flip_mode(struct test_output *o, int crtc, int duration)fprintf (stdout,"Beginning page flipping on crtc %d, connector %d\n" , crtc, o->id); - width = o->mode.hdisplay; - height = o->mode.vdisplay; + o->fb_width = o->mode.hdisplay; + o->fb_height = o->mode.vdisplay;if (o->flags &TEST_PAN ) - width *=2 ; + o->fb_width *=2 ; - o->fb_ids[0 ] =kmstest_create_fb (drm_fd, width, height, bpp, depth, - false, &o->fb_info[0 ], + o->fb_ids[0 ] =kmstest_create_fb (drm_fd, o->fb_width, o->fb_height, bpp, + depth, false, &o->fb_info[0 ], paint_flip_mode, (void *)false); - o->fb_ids[1 ] =kmstest_create_fb (drm_fd, width, height, bpp, depth, - false, &o->fb_info[1 ], + o->fb_ids[1 ] =kmstest_create_fb (drm_fd, o->fb_width, o->fb_height, bpp, + depth, false, &o->fb_info[1 ], paint_flip_mode, (void *)true);if (!o->fb_ids[0 ] || !o->fb_ids[1 ]) {
@@ -423,7 +424,7 @@ static void flip_mode(struct test_output *o, int crtc, int duration)if (drmModeSetCrtc (drm_fd, o->crtc, o->fb_ids[0 ],0 ,0 , &o->id,1 , &o->mode)) {fprintf (stderr,"failed to set mode (%dx%d@%dHz): %s\n" , - width, height, o->mode.vrefresh, + o->fb_width, o->fb_height, o->mode.vrefresh,strerror (errno));exit (3 ); }
@@ -488,8 +489,8 @@ static void flip_mode(struct test_output *o, int crtc, int duration) x_ofs, 0, &o->id, 1, &o->mode)) {fprintf (stderr,"failed to pan (%dx%d@%dHz): %s\n" , - width, height, o->mode.vrefresh, -strerror (errno)); + o->fb_width, o->fb_height, + o->mode.vrefresh,strerror (errno));exit (7 ); } }
Signature · 1 line
1.7.9.5
PATCH 7/22 flip_test: factor out drmModePageFlip
In reply to Imre DeakFor better readability and to prepare for the upcoming patch marking pending flip events with a flag.
No functional change.
--- tests/flip_test.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
tests/flip_test.c +11 -10
@@ -157,6 +157,12 @@ static int set_dpms(struct test_output *o, int mode)return drmModeConnectorSetProperty (drm_fd, o->id, dpms, mode); } +static int do_page_flip (struct test_output *o,int fb_id) +{ +return drmModePageFlip (drm_fd, o->crtc, fb_id,DRM_MODE_PAGE_FLIP_EVENT , + o); +} +static bool analog_tv_connector (struct test_output *o) {
@@ -220,8 +226,7 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, new_fb_id = o->fb_ids[o->current_fb_id];if (o->flags &TEST_EINVAL && o->count >1 ) -assert (drmModePageFlip (drm_fd, o->crtc, new_fb_id, -DRM_MODE_PAGE_FLIP_EVENT , o) == expected_einval); +assert (do_page_flip (o, new_fb_id) == expected_einval);if (o->flags &TEST_MODESET ) { if (drmModeSetCrtc(drm_fd, o->crtc,
@@ -240,12 +245,10 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, o->count++;printf ("." );fflush (stdout); -do_or_die (drmModePageFlip (drm_fd, o->crtc, new_fb_id, -DRM_MODE_PAGE_FLIP_EVENT , o)); +do_or_die (do_page_flip (o, new_fb_id));if (o->flags &TEST_EBUSY ) -assert (drmModePageFlip (drm_fd, o->crtc, new_fb_id, -DRM_MODE_PAGE_FLIP_EVENT , o) == -EBUSY ); +assert (do_page_flip (o, new_fb_id) == -EBUSY );if (o->flags &TEST_DPMS )do_or_die (set_dpms (o,DRM_MODE_DPMS_OFF ));
@@ -262,8 +265,7 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, }if (o->flags &TEST_EINVAL ) -assert (drmModePageFlip (drm_fd, o->crtc, new_fb_id, -DRM_MODE_PAGE_FLIP_EVENT , o) == expected_einval); +assert (do_page_flip (o, new_fb_id) == expected_einval); o->last_flip_received = now; o->last_flip_ts = pageflip_ts;
@@ -436,8 +438,7 @@ static void flip_mode(struct test_output *o, int crtc, int duration)gettimeofday (&o->last_flip_received,NULL ); -if (drmModePageFlip (drm_fd, o->crtc, o->fb_ids[1 ], -DRM_MODE_PAGE_FLIP_EVENT , o)) { +if (do_page_flip (o, o->fb_ids[1 ])) {fprintf (stderr,"failed to page flip: %s\n" ,strerror (errno));exit (4 ); }
Signature · 1 line
1.7.9.5
PATCH 8/22 flip_test: move output panning inside the flip_handler
In reply to Imre DeakMove the panning to a more logical place where the rest of the test steps are performed. This won't change things in practice, since the first thing drmHandleEvent does is call the flip_handler.
--- tests/flip_test.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
tests/flip_test.c +14 -15
@@ -218,6 +218,20 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, } } +/* pan before the flip completes */ +if (o->flags &TEST_PAN ) { +int x_ofs = o->count *10 > o->mode.hdisplay ? + o->mode.hdisplay : o->count *10 ; + +if (drmModeSetCrtc (drm_fd, o->crtc, o->fb_ids[o->current_fb_id], + x_ofs,0 , &o->id,1 , &o->mode)) { +fprintf (stderr,"failed to pan (%dx%d@%dHz): %s\n" , + o->fb_width, o->fb_height, + o->mode.vrefresh,strerror (errno)); +exit (7 ); + } + } +if (o->flags &TEST_WITH_DUMMY_LOAD )emit_dummy_load (o);
@@ -481,21 +495,6 @@ static void flip_mode(struct test_output *o, int crtc, int duration)break ; } -/* pan before the flip completes */ -if (o->flags &TEST_PAN ) { -int x_ofs = o->count *10 > o->mode.hdisplay ? o->mode.hdisplay : - o->count *10 ; - -if (drmModeSetCrtc (drm_fd, o->crtc, o->fb_ids[o->current_fb_id], - x_ofs,0 , - &o->id,1 , &o->mode)) { -fprintf (stderr,"failed to pan (%dx%d@%dHz): %s\n" , - o->fb_width, o->fb_height, - o->mode.vrefresh,strerror (errno)); -exit (7 ); - } - } - ret =drmHandleEvent (drm_fd, &evctx);assert (ret ==0 ); }
Signature · 1 line
1.7.9.5
Re: [PATCH 08/22] flip_test: move output panning inside the flip_handler
Quoted 5 lines · Imre Deak
Move the panning to a more logical place where the rest of the test steps are performed. This won't change things in practice, since the first thing drmHandleEvent does is call the
flip_handler.Signed-off-by Imre Deak <[email protected]>
Looking at this again I think the test is actually broken. It tries to check whether fb_set_base correclty waits for any outstanding flips (well, it can't really check that, but it should exercise the code at least). So the right place to call this is actually right _after_ issueing the flip, where the TEST_DPMS and TEST_MODESET cases are.
-Daniel
Quoted 58 lines
--- tests/flip_test.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)tests/flip_test.c +14
-15@@ -218,6 +218,20 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, } } +/* pan before the flip completes */ +if (o->flags &TEST_PAN ) { +int x_ofs = o->count *10 > o->mode.hdisplay ? + o->mode.hdisplay : o->count *10 ; + +if (drmModeSetCrtc (drm_fd, o->crtc, o->fb_ids[o->current_fb_id], + x_ofs,0 , &o->id,1 , &o->mode)) { +fprintf (stderr,"failed to pan (%dx%d@%dHz): %s\n" , + o->fb_width, o->fb_height, + o->mode.vrefresh,strerror (errno)); +exit (7 ); + } + } +if (o->flags &TEST_WITH_DUMMY_LOAD )emit_dummy_load (o);@@ -481,21 +495,6 @@ static void flip_mode(struct test_output *o, int crtc, int duration)break ; } -/* pan before the flip completes */ -if (o->flags &TEST_PAN ) { -int x_ofs = o->count *10 > o->mode.hdisplay ? o->mode.hdisplay : - o->count *10 ; - -if (drmModeSetCrtc (drm_fd, o->crtc, o->fb_ids[o->current_fb_id], - x_ofs,0 , - &o->id,1 , &o->mode)) { -fprintf (stderr,"failed to pan (%dx%d@%dHz): %s\n" , - o->fb_width, o->fb_height, - o->mode.vrefresh,strerror (errno)); -exit (7 ); - } - } - ret =drmHandleEvent (drm_fd, &evctx);assert (ret ==0 ); }Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH 9/22 flip_test: factor out the event loop/wait for event logic
In reply to Imre DeakNeeded by an upcoming patch where we want to wait for an event without starting a new round of test run.
No functional change.
--- tests/flip_test.c | 126 +++++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 56 deletions(-)
tests/flip_test.c +70 -56
@@ -404,12 +404,77 @@ fb_is_bound(struct test_output *o, int fb)return mode.mode_valid && mode.fb_id == fb; } +static void wait_for_events (struct test_output *o) +{ +drmEventContext evctx; +struct timeval timeout = { .tv_sec =3 , .tv_usec =0 }; +fd_set fds; +int ret; + +memset (&evctx,0 ,sizeof evctx); + evctx.version =DRM_EVENT_CONTEXT_VERSION ; + evctx.vblank_handler =NULL ; + evctx.page_flip_handler = page_flip_handler; + +/* make timeout lax with the dummy load */ +if (o->flags &TEST_WITH_DUMMY_LOAD ) + timeout.tv_sec *=10 ; + +FD_ZERO (&fds); +FD_SET (0 , &fds); +FD_SET (drm_fd, &fds); + ret =select (drm_fd +1 , &fds,NULL ,NULL , &timeout); + +if (ret <=0 ) { +fprintf (stderr,"select timed out or error (ret %d)\n" , + ret); +exit (1 ); + }else if (FD_ISSET (0 , &fds)) { +fprintf (stderr,"no fds active, breaking\n" ); +exit (2 ); + } + +drmHandleEvent (drm_fd, &evctx); +} + +/* Returned the ellapsed time in us */ +static unsigned event_loop (struct test_output *o,unsigned duration_sec) +{ +drmEventContext evctx; +int ret; +struct timeval start, end; +struct timeval tv_dur; + +gettimeofday (&start,NULL ); + end.tv_sec = start.tv_sec + duration_sec; + end.tv_usec = start.tv_usec; + +while (1 ) { +struct timeval now; + +wait_for_events (o); + +gettimeofday (&now,NULL ); + if (!timercmp(&now, &end, <)) +break ; + } + +gettimeofday (&end,NULL ); +timersub (&end, &start, &tv_dur); + +/* and drain the event queue */ +memset (&evctx,0 ,sizeof evctx); + evctx.page_flip_handler =NULL ; + ret =drmHandleEvent (drm_fd, &evctx); +assert (ret ==0 ); + +return tv_dur.tv_sec *1000 *1000 + tv_dur.tv_usec; +} +static void flip_mode (struct test_output *o,int crtc,int duration) { -int ret;int bpp =32 , depth =24 ; -drmEventContext evctx; -struct timeval end; +unsigned ellapsed;connector_find_preferred_mode (o, crtc);if (!o->mode_valid)
@@ -459,65 +524,14 @@ static void flip_mode(struct test_output *o, int crtc, int duration) o->current_fb_id =1 ; o->count =1 ;/* for the uncounted tail */ -memset (&evctx,0 ,sizeof evctx); - evctx.version =DRM_EVENT_CONTEXT_VERSION ; - evctx.vblank_handler =NULL ; - evctx.page_flip_handler = page_flip_handler; - -gettimeofday (&end,NULL ); - end.tv_sec += duration; - -while (1 ) { -struct timeval now, timeout = { .tv_sec =3 , .tv_usec =0 }; -fd_set fds; - -/* make timeout lax with the dummy load */ -if (o->flags &TEST_WITH_DUMMY_LOAD ) - timeout.tv_sec *=10 ; - -FD_ZERO (&fds); -FD_SET (0 , &fds); -FD_SET (drm_fd, &fds); - ret =select (drm_fd +1 , &fds,NULL ,NULL , &timeout); - -if (ret <=0 ) { -fprintf (stderr,"select timed out or error (ret %d)\n" , - ret); -exit (1 ); - }else if (FD_ISSET (0 , &fds)) { -fprintf (stderr,"no fds active, breaking\n" ); -exit (2 ); - } - -gettimeofday (&now,NULL ); -if (now.tv_sec > end.tv_sec || - (now.tv_sec == end.tv_sec && now.tv_usec >= end.tv_usec)) { -break ; - } - - ret =drmHandleEvent (drm_fd, &evctx); -assert (ret ==0 ); - } - -/* and drain the event queue */ - evctx.page_flip_handler =NULL ; - ret =drmHandleEvent (drm_fd, &evctx); -assert (ret ==0 ); + ellapsed =event_loop (o, duration);/* Verify we drop no frames, but only if it's not a TV encoder, since * those use some funny fake timings behind userspace's back. */ if (o->flags &TEST_CHECK_TS && !analog_tv_connector (o)) { -struct timeval now; -long us;int expected; -gettimeofday (&now,NULL ); - - us = duration *1000 *1000 ; - us += (now.tv_sec - end.tv_sec) *1000 *1000 ; - us += now.tv_usec - end.tv_usec; - - expected = us * o->mode.vrefresh / (1000 *1000 ); + expected = ellapsed * o->mode.vrefresh / (1000 *1000 );if (o->count < expected *99 /100 ) {fprintf (stderr,"dropped frames, expected %d, counted %d, encoder type %d\n" , expected, o->count, o->encoder->encoder_type);
Signature · 1 line
1.7.9.5
PATCH 10/22 flip_test: factor out the final state check
In reply to Imre DeakNeeded by an upcoming patch where we want to make a final state check for both the flip and vblank events.
No functional change.
--- tests/flip_test.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
tests/flip_test.c +17 -12
@@ -404,6 +404,22 @@ fb_is_bound(struct test_output *o, int fb)return mode.mode_valid && mode.fb_id == fb; } +static void check_final_state (struct test_output *o,unsigned int ellapsed) +{ +/* Verify we drop no frames, but only if it's not a TV encoder, since +* those use some funny fake timings behind userspace's back. */ +if (o->flags &TEST_CHECK_TS && !analog_tv_connector (o)) { +int expected; + + expected = ellapsed * o->mode.vrefresh / (1000 *1000 ); +if (o->count < expected *99 /100 ) { +fprintf (stderr,"dropped frames, expected %d, counted %d, encoder type %d\n" , + expected, o->count, o->encoder->encoder_type); +exit (3 ); + } + } +} +static void wait_for_events (struct test_output *o) {drmEventContext evctx;
@@ -526,18 +542,7 @@ static void flip_mode(struct test_output *o, int crtc, int duration) ellapsed =event_loop (o, duration); -/* Verify we drop no frames, but only if it's not a TV encoder, since -* those use some funny fake timings behind userspace's back. */ -if (o->flags &TEST_CHECK_TS && !analog_tv_connector (o)) { -int expected; - - expected = ellapsed * o->mode.vrefresh / (1000 *1000 ); -if (o->count < expected *99 /100 ) { -fprintf (stderr,"dropped frames, expected %d, counted %d, encoder type %d\n" , - expected, o->count, o->encoder->encoder_type); -exit (3 ); - } - } +check_final_state (o, ellapsed);fprintf (stdout,"\npage flipping on crtc %d, connector %d: PASSED\n" , crtc, o->id);
Signature · 1 line
1.7.9.5
PATCH 11/22 flip_test: store current flip/received timestamps in the context obj
In reply to Imre DeakThis is needed by the next patch that splits the flip handler function into logical parts. Make the timestamps accesible to these parts.
No functional change.
--- tests/flip_test.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
tests/flip_test.c +12 -10
@@ -77,6 +77,8 @@ struct test_output {unsigned int fb_height;unsigned int fb_ids[2 ];struct kmstest_fb fb_info[2 ]; +struct timeval current_flip_received; +struct timeval current_flip_ts;struct timeval last_flip_received;struct timeval last_flip_ts; };
@@ -179,17 +181,17 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, {struct test_output *o = data;unsigned int new_fb_id; -struct timeval now, diff, pageflip_ts; +struct timeval diff;double usec_interflip;/* for funny reasons page_flip returns -EBUSY on disabled crtcs ... */ int expected_einval = o->flags &TEST_MODESET ? -EBUSY : -EINVAL ; - pageflip_ts.tv_sec = sec; - pageflip_ts.tv_usec = usec; + o->current_flip_ts.tv_sec = sec; + o->current_flip_ts.tv_usec = usec; -gettimeofday (&now,NULL ); +gettimeofday (&o->current_flip_received,NULL ); -timersub (&pageflip_ts, &now, &diff); +timersub (&o->current_flip_ts, &o->current_flip_received, &diff);if (diff.tv_sec >0 || (diff.tv_sec ==0 && diff.tv_usec >2000 )) { fprintf(stderr, "pageflip timestamp delayed for too long: %is, %iusec\n",
@@ -197,16 +199,16 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,exit (5 ); } - if (!timercmp(&o->last_flip_received, &pageflip_ts, <)) { + if (!timercmp(&o->last_flip_received, &o->current_flip_ts, <)) {fprintf (stderr,"pageflip ts before the pageflip was issued!\n" ); -timersub (&pageflip_ts, &o->last_flip_received, &diff); +timersub (&o->current_flip_ts, &o->last_flip_received, &diff);fprintf (stderr,"timerdiff %is, %ius\n" , (int ) diff.tv_sec, (int ) diff.tv_usec);exit (6 ); }if (o->count >1 && o->flags &TEST_CHECK_TS && !analog_tv_connector (o)) { -timersub (&pageflip_ts, &o->last_flip_ts, &diff); +timersub (&o->current_flip_ts, &o->last_flip_ts, &diff); usec_interflip =1.0 / ((double ) o->mode.vrefresh) *1000.0 *1000.0 ;if (fabs ((((double ) diff.tv_usec) - usec_interflip) / usec_interflip) >0.005 ) {
@@ -281,8 +283,8 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,if (o->flags &TEST_EINVAL )assert (do_page_flip (o, new_fb_id) == expected_einval); - o->last_flip_received = now; - o->last_flip_ts = pageflip_ts; + o->last_flip_received = o->current_flip_received; + o->last_flip_ts = o->current_flip_ts; }static void connector_find_preferred_mode (struct test_output *o,int crtc_id)
Signature · 1 line
1.7.9.5
PATCH 12/22 flip_test: split the flip handler into logical parts
In reply to Imre DeakThe handler consits of handle_event/run_test/check_state/update_state logical steps, split the function accordingly. This is needed by the following patches that need to do part of these steps for both flip and vblank events.
No functional change.
--- tests/flip_test.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
tests/flip_test.c +19 -5
@@ -180,16 +180,17 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data) { struct test_output *o = data; -unsigned int new_fb_id; -struct timeval diff; -double usec_interflip; -/* for funny reasons page_flip returns -EBUSY on disabled crtcs ... */ -int expected_einval = o->flags &TEST_MODESET ? -EBUSY : -EINVAL ; o->current_flip_ts.tv_sec = sec; o->current_flip_ts.tv_usec = usec;gettimeofday (&o->current_flip_received,NULL ); +} + +static void check_all_state (struct test_output *o) +{ +struct timeval diff; +double usec_interflip;timersub (&o->current_flip_ts, &o->current_flip_received, &diff);
@@ -219,6 +220,13 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,//exit(9); } } +} + +static void run_test_step (struct test_output *o) +{ +unsigned int new_fb_id; +/* for funny reasons page_flip returns -EBUSY on disabled crtcs ... */ +int expected_einval = o->flags &TEST_MODESET ? -EBUSY : -EINVAL ;/* pan before the flip completes */ if (o->flags &TEST_PAN ) {
@@ -282,7 +290,10 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,if (o->flags &TEST_EINVAL )assert (do_page_flip (o, new_fb_id) == expected_einval); +} +static void update_all_state (struct test_output *o) +{ o->last_flip_received = o->current_flip_received; o->last_flip_ts = o->current_flip_ts; }
@@ -471,6 +482,9 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)struct timeval now;wait_for_events (o); +check_all_state (o); +run_test_step (o); +update_all_state (o);gettimeofday (&now,NULL ); if (!timercmp(&now, &end, <))
Signature · 1 line
1.7.9.5
PATCH 13/22 flip_test: swap the order of check state/run test step
In reply to Imre DeakAt the moment we first check the state then run the test step in our test loop. Swapping the order makes the starting state of each iteration better defined, allowing an easier extension of these steps in the future.
Since now it's guaranteed that we exit the event loop with no pending flips, we can also get rid of the final flushing of events.
We don't want the first initializing flip to affect the test loop other than setting an initial FB, so before starting the test loop wait for it to complete by calling wait_for_events() and leave the flip event counter at zero.
--- tests/flip_test.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
tests/flip_test.c +3 -10
@@ -469,8 +469,6 @@ static void wait_for_events(struct test_output *o)/* Returned the ellapsed time in us */ static unsigned event_loop (struct test_output *o,unsigned duration_sec) { -drmEventContext evctx; -int ret;struct timeval start, end;struct timeval tv_dur;
@@ -481,9 +479,9 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)while (1 ) {struct timeval now; +run_test_step (o);wait_for_events (o);check_all_state (o); -run_test_step (o);update_all_state (o);gettimeofday (&now,NULL );
@@ -494,12 +492,6 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)gettimeofday (&end,NULL );timersub (&end, &start, &tv_dur); -/* and drain the event queue */ -memset (&evctx,0 ,sizeof evctx); - evctx.page_flip_handler =NULL ; - ret =drmHandleEvent (drm_fd, &evctx); -assert (ret ==0 ); -return tv_dur.tv_sec *1000 *1000 + tv_dur.tv_usec; }
@@ -553,8 +545,9 @@ static void flip_mode(struct test_output *o, int crtc, int duration)fprintf (stderr,"failed to page flip: %s\n" ,strerror (errno));exit (4 ); } +wait_for_events (o); + o->current_fb_id =1 ; - o->count =1 ;/* for the uncounted tail */ ellapsed =event_loop (o, duration);
Signature · 1 line
1.7.9.5
PATCH 14/22 flip_test: factor out the event state
In reply to Imre DeakFactor out the status vars that are specific to the flip events into a separate structure. This will allow us tracking the vblank events with the same code.
We move the increment of the flip event counter to the end of the test loop, but this shouldn't affect anything. This is the only functional change.
--- tests/flip_test.c | 105 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 33 deletions(-)
tests/flip_test.c +72 -33
@@ -63,6 +63,26 @@ struct type_name {const char *name; }; +struct event_state { +const char *name; + +/* +* Event data for the last event that has already passed our check. +* Updated using the below current_* vars in update_state(). +*/ +struct timeval last_ts;/* kernel reported timestamp */ +struct timeval last_received_ts;/* the moment we received it */ + +/* +* Event data for for the current event that we just received and +* going to check for validity. Set in event_handler(). +*/ +struct timeval current_ts;/* kernel reported timestamp */ +struct timeval current_received_ts;/* the moment we received it */ + +int count;/* # of events of this type */ +}; +struct test_output {uint32_t id;int mode_valid;
@@ -71,16 +91,13 @@ struct test_output {drmModeConnector *connector;int crtc;int flags; -int count;unsigned int current_fb_id;unsigned int fb_width;unsigned int fb_height;unsigned int fb_ids[2 ];struct kmstest_fb fb_info[2 ]; -struct timeval current_flip_received; -struct timeval current_flip_ts; -struct timeval last_flip_received; -struct timeval last_flip_ts; + +struct event_state flip_state; };static void emit_dummy_load (struct test_output *o)
@@ -176,44 +193,52 @@ analog_tv_connector(struct test_output *o) connector_type == DRM_MODE_CONNECTOR_Composite; } +static void event_handler (struct event_state *es,unsigned int frame, +unsigned int sec,unsigned int usec) +{ +gettimeofday (&es->current_received_ts,NULL ); + es->current_ts.tv_sec = sec; + es->current_ts.tv_usec = usec; +} +static void page_flip_handler (int fd,unsigned int frame,unsigned int sec,unsigned int usec,void *data) {struct test_output *o = data; - o->current_flip_ts.tv_sec = sec; - o->current_flip_ts.tv_usec = usec; - -gettimeofday (&o->current_flip_received,NULL ); +event_handler (&o->flip_state, frame, sec, usec); } -static void check_all_state (struct test_output *o) +static void check_state (struct test_output *o,struct event_state *es) {struct timeval diff;double usec_interflip; -timersub (&o->current_flip_ts, &o->current_flip_received, &diff); - +timersub (&es->current_ts, &es->current_received_ts, &diff);if (diff.tv_sec >0 || (diff.tv_sec ==0 && diff.tv_usec >2000 )) { -fprintf (stderr,"pageflip timestamp delayed for too long: %is, %iusec\n" , - (int ) diff.tv_sec, (int ) diff.tv_usec); +fprintf (stderr,"%s ts delayed for too long: %is, %iusec\n" , + es->name, (int )diff.tv_sec, (int )diff.tv_usec);exit (5 ); } - if (!timercmp(&o->last_flip_received, &o->current_flip_ts, <)) { -fprintf (stderr,"pageflip ts before the pageflip was issued!\n" ); -timersub (&o->current_flip_ts, &o->last_flip_received, &diff); + if (!timercmp(&es->last_received_ts, &es->current_ts, <)) { +fprintf (stderr,"%s ts before the %s was issued!\n" , + es->name, es->name); + +timersub (&es->current_ts, &es->last_received_ts, &diff);fprintf (stderr,"timerdiff %is, %ius\n" , (int ) diff.tv_sec, (int ) diff.tv_usec);exit (6 ); } -if (o->count >1 && o->flags &TEST_CHECK_TS && !analog_tv_connector (o)) { -timersub (&o->current_flip_ts, &o->last_flip_ts, &diff); - usec_interflip =1.0 / ((double ) o->mode.vrefresh) *1000.0 *1000.0 ; -if (fabs ((((double ) diff.tv_usec) - usec_interflip) / usec_interflip) >0.005 ) { -fprintf (stderr,"inter-flip timestamp jitter: %is, %ius\n" , +if (es->count >1 && (o->flags &TEST_CHECK_TS ) && (!analog_tv_connector (o))) { +timersub (&es->current_ts, &es->last_ts, &diff); + usec_interflip =1.0 / ((double )o->mode.vrefresh) *1000.0 *1000.0 ; +if (fabs ((((double ) diff.tv_usec) - usec_interflip) / + usec_interflip) >0.005 ) { +fprintf (stderr,"inter-%s ts jitter: %is, %ius\n" , + es->name, (int ) diff.tv_sec, (int ) diff.tv_usec);/* atm this is way too easy to hit, thanks to the hpd * poll helper :( hence make it non-fatal for now */
@@ -222,6 +247,11 @@ static void check_all_state(struct test_output *o) } } +static void check_all_state (struct test_output *o) +{ +check_state (o, &o->flip_state); +} +static void run_test_step (struct test_output *o) {unsigned int new_fb_id;
@@ -230,8 +260,9 @@ static void run_test_step(struct test_output *o)/* pan before the flip completes */ if (o->flags &TEST_PAN ) { -int x_ofs = o->count *10 > o->mode.hdisplay ? - o->mode.hdisplay : o->count *10 ; +int count = o->flip_state.count; +int x_ofs = count *10 > o->mode.hdisplay ? + o->mode.hdisplay : count *10 ;if (drmModeSetCrtc (drm_fd, o->crtc, o->fb_ids[o->current_fb_id], x_ofs,0 , &o->id,1 , &o->mode)) {
@@ -249,7 +280,7 @@ static void run_test_step(struct test_output *o) o->current_fb_id = !o->current_fb_id; new_fb_id = o->fb_ids[o->current_fb_id]; -if (o->flags &TEST_EINVAL && o->count >1 ) +if ((o->flags &TEST_EINVAL ) && o->flip_state.count >1 )assert (do_page_flip (o, new_fb_id) == expected_einval);if (o->flags &TEST_MODESET ) {
@@ -266,7 +297,6 @@ static void run_test_step(struct test_output *o)if (o->flags &TEST_DPMS )do_or_die (set_dpms (o,DRM_MODE_DPMS_ON )); - o->count++;printf ("." );fflush (stdout);do_or_die (do_page_flip (o, new_fb_id));
@@ -292,10 +322,16 @@ static void run_test_step(struct test_output *o)assert (do_page_flip (o, new_fb_id) == expected_einval); } +static void update_state (struct event_state *es) +{ + es->last_received_ts = es->current_received_ts; + es->last_ts = es->current_ts; + es->count++; +} +static void update_all_state (struct test_output *o) { - o->last_flip_received = o->current_flip_received; - o->last_flip_ts = o->current_flip_ts; +update_state (&o->flip_state); }static void connector_find_preferred_mode (struct test_output *o,int crtc_id)
@@ -417,17 +453,19 @@ fb_is_bound(struct test_output *o, int fb)return mode.mode_valid && mode.fb_id == fb; } -static void check_final_state (struct test_output *o,unsigned int ellapsed) +static void check_final_state (struct test_output *o,struct event_state *es, +unsigned int ellapsed) {/* Verify we drop no frames, but only if it's not a TV encoder, since * those use some funny fake timings behind userspace's back. */ if (o->flags &TEST_CHECK_TS && !analog_tv_connector (o)) {int expected; +int count = es->count; expected = ellapsed * o->mode.vrefresh / (1000 *1000 ); -if (o->count < expected *99 /100 ) { +if (count < expected *99 /100 ) {fprintf (stderr,"dropped frames, expected %d, counted %d, encoder type %d\n" , - expected, o->count, o->encoder->encoder_type); + expected, count, o->encoder->encoder_type);exit (3 ); } }
@@ -539,7 +577,7 @@ static void flip_mode(struct test_output *o, int crtc, int duration)if (o->flags &TEST_CHECK_TS )sleep (1 ); -gettimeofday (&o->last_flip_received,NULL ); +gettimeofday (&o->flip_state.last_ts,NULL );if (do_page_flip (o, o->fb_ids[1 ])) {fprintf (stderr,"failed to page flip: %s\n" ,strerror (errno));
@@ -551,7 +589,7 @@ static void flip_mode(struct test_output *o, int crtc, int duration) ellapsed =event_loop (o, duration); -check_final_state (o, ellapsed); +check_final_state (o, &o->flip_state, ellapsed);fprintf (stdout,"\npage flipping on crtc %d, connector %d: PASSED\n" , crtc, o->id);
@@ -581,6 +619,7 @@ static int run_test(int duration, int flags)memset (&o,0 ,sizeof (o)); o.id = resources->connectors[c]; o.flags = flags; + o.flip_state.name ="flip" ;flip_mode (&o, resources->crtcs[i], duration); }
Signature · 1 line
1.7.9.5
PATCH 15/22 flip_test: don't skip checks for sequence #1
In reply to Imre DeakSo far we skipped some tests for seq#0 and #1, since at that point we were missing the 'last' state against which we could compare the current state. Since in the previous patches we fixed the ordering in the test loop and moved the increment of count to the update state phase, we have a proper 'last' state for seq#1, so enable the tests already at that point.
--- tests/flip_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/flip_test.c +2 -2
@@ -232,7 +232,7 @@ static void check_state(struct test_output *o, struct event_state *es) } -if (es->count >1 && (o->flags &TEST_CHECK_TS ) && (!analog_tv_connector (o))) { +if (es->count >0 && (o->flags &TEST_CHECK_TS ) && (!analog_tv_connector (o))) {timersub (&es->current_ts, &es->last_ts, &diff); usec_interflip =1.0 / ((double )o->mode.vrefresh) *1000.0 *1000.0 ; if (fabs((((double) diff.tv_usec) - usec_interflip) /
@@ -280,7 +280,7 @@ static void run_test_step(struct test_output *o) o->current_fb_id = !o->current_fb_id; new_fb_id = o->fb_ids[o->current_fb_id]; -if ((o->flags &TEST_EINVAL ) && o->flip_state.count >1 ) +if ((o->flags &TEST_EINVAL ) && o->flip_state.count >0 )assert (do_page_flip (o, new_fb_id) == expected_einval);if (o->flags &TEST_MODESET ) {
Signature · 1 line
1.7.9.5
PATCH 16/22 flip_test: store crtc_idx in the test context obj
In reply to Imre DeakFor DRM_IOCTL_WAIT_VBLANK we'll have to pass the crtc_idx - as opposed to the crtc id required by the rest of the IOCTLs we use.
No functional change.
--- tests/flip_test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tests/flip_test.c +6 -2
@@ -85,6 +85,7 @@ struct event_state {struct test_output {uint32_t id; +int crtc_idx;int mode_valid;drmModeModeInfo mode;drmModeEncoder *encoder;
@@ -533,11 +534,13 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)return tv_dur.tv_sec *1000 *1000 + tv_dur.tv_usec; } -static void flip_mode (struct test_output *o,int crtc,int duration) +static void flip_mode (struct test_output *o,int duration) {int bpp =32 , depth =24 ;unsigned ellapsed; +int crtc; + crtc = resources->crtcs[o->crtc_idx];connector_find_preferred_mode (o, crtc);if (!o->mode_valid)return ;
@@ -620,8 +623,9 @@ static int run_test(int duration, int flags) o.id = resources->connectors[c]; o.flags = flags; o.flip_state.name ="flip" ; + o.crtc_idx = i; -flip_mode (&o, resources->crtcs[i], duration); +flip_mode (&o, duration); } }
Signature · 1 line
1.7.9.5
PATCH 17/22 flip_test: unify the name of the current test in status messages
In reply to Imre Deak--- tests/flip_test.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
tests/flip_test.c +8 -6
@@ -84,6 +84,7 @@ struct event_state { };struct test_output { +const char *test_name;uint32_t id;int crtc_idx;int mode_valid;
@@ -545,8 +546,8 @@ static void flip_mode(struct test_output *o, int duration)if (!o->mode_valid)return ; -fprintf (stdout,"Beginning page flipping on crtc %d, connector %d\n" , - crtc, o->id); +fprintf (stdout,"Beginning %s on crtc %d, connector %d\n" , + o->test_name, crtc, o->id); o->fb_width = o->mode.hdisplay; o->fb_height = o->mode.vdisplay;
@@ -594,8 +595,8 @@ static void flip_mode(struct test_output *o, int duration)check_final_state (o, &o->flip_state, ellapsed); -fprintf (stdout,"\npage flipping on crtc %d, connector %d: PASSED\n" , - crtc, o->id); +fprintf (stdout,"\n%s on crtc %d, connector %d: PASSED\n\n" , + o->test_name, crtc, o->id);kmstest_remove_fb (drm_fd, o->fb_ids[1 ]);kmstest_remove_fb (drm_fd, o->fb_ids[0 ]);
@@ -604,7 +605,7 @@ static void flip_mode(struct test_output *o, int duration)drmModeFreeConnector (o->connector); } -static int run_test (int duration,int flags) +static int run_test (int duration,int flags,const char *test_name) {struct test_output o;int c, i;
@@ -620,6 +621,7 @@ static int run_test(int duration, int flags)for (c =0 ; c < resources->count_connectors; c++) {for (i =0 ; i < resources->count_crtcs; i++) {memset (&o,0 ,sizeof (o)); + o.test_name = test_name; o.id = resources->connectors[c]; o.flags = flags; o.flip_state.name ="flip" ;
@@ -658,7 +660,7 @@ int main(int argc, char **argv)for (i =0 ; i <sizeof (tests) /sizeof (tests[0 ]); i++) {printf ("running testcase: %s\n" , tests[i].name); -run_test (tests[i].duration, tests[i].flags); +run_test (tests[i].duration, tests[i].flags, tests[i].name); }close (drm_fd);
Signature · 1 line
1.7.9.5
PATCH 18/22 flip_test: make page flip tests conditional
In reply to Imre DeakSince later we want to add vblank tests where we don't want to flip, make the flips and corresponding state checks conditional.
No functional change.
--- tests/flip_test.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
tests/flip_test.c +20 -13
@@ -48,6 +48,7 @@#define TEST_CHECK_TS (1 << 4)#define TEST_EBUSY (1 << 5)#define TEST_EINVAL (1 << 6) +#define TEST_FLIP (1 << 7)drmModeRes *resources;int drm_fd;
@@ -251,7 +252,8 @@ static void check_state(struct test_output *o, struct event_state *es)static void check_all_state (struct test_output *o) { -check_state (o, &o->flip_state); +if (o->flags &TEST_FLIP ) +check_state (o, &o->flip_state); }static void run_test_step (struct test_output *o)
@@ -259,6 +261,9 @@ static void run_test_step(struct test_output *o)unsigned int new_fb_id;/* for funny reasons page_flip returns -EBUSY on disabled crtcs ... */ int expected_einval = o->flags &TEST_MODESET ? -EBUSY : -EINVAL ; +bool do_flip; + + do_flip = o->flags &TEST_FLIP ;/* pan before the flip completes */ if (o->flags &TEST_PAN ) {
@@ -282,7 +287,7 @@ static void run_test_step(struct test_output *o) o->current_fb_id = !o->current_fb_id; new_fb_id = o->fb_ids[o->current_fb_id]; -if ((o->flags &TEST_EINVAL ) && o->flip_state.count >0 ) +if (do_flip && (o->flags &TEST_EINVAL ) && o->flip_state.count >0 )assert (do_page_flip (o, new_fb_id) == expected_einval);if (o->flags &TEST_MODESET ) {
@@ -301,9 +306,10 @@ static void run_test_step(struct test_output *o)printf ("." );fflush (stdout); -do_or_die (do_page_flip (o, new_fb_id)); +if (do_flip) +do_or_die (do_page_flip (o, new_fb_id)); -if (o->flags &TEST_EBUSY ) +if (do_flip && (o->flags &TEST_EBUSY ))assert (do_page_flip (o, new_fb_id) == -EBUSY );if (o->flags &TEST_DPMS )
@@ -320,7 +326,7 @@ static void run_test_step(struct test_output *o) } } -if (o->flags &TEST_EINVAL ) +if (do_flip && (o->flags &TEST_EINVAL ))assert (do_page_flip (o, new_fb_id) == expected_einval); }
@@ -593,7 +599,8 @@ static void flip_mode(struct test_output *o, int duration) ellapsed =event_loop (o, duration); -check_final_state (o, &o->flip_state, ellapsed); +if (o->flags &TEST_FLIP ) +check_final_state (o, &o->flip_state, ellapsed);fprintf (stdout,"\n%s on crtc %d, connector %d: PASSED\n\n" , o->test_name, crtc, o->id);
@@ -642,13 +649,13 @@ int main(int argc, char **argv)int flags;const char *name; } tests[] = { - { 15, TEST_CHECK_TS | TEST_EBUSY , "plain flip" }, - { 30, TEST_DPMS | TEST_EINVAL, "flip vs dpms" }, - { 30, TEST_DPMS | TEST_WITH_DUMMY_LOAD, "delayed flip vs. dpms" }, - { 5, TEST_PAN, "flip vs panning" }, - { 30, TEST_PAN | TEST_WITH_DUMMY_LOAD, "delayed flip vs panning" }, - { 30, TEST_MODESET | TEST_EINVAL, "flip vs modeset" }, - { 30, TEST_MODESET | TEST_WITH_DUMMY_LOAD, "delayed flip vs modeset" }, + { 15, TEST_FLIP | TEST_CHECK_TS | TEST_EBUSY , "plain flip" }, + { 30, TEST_FLIP | TEST_DPMS | TEST_EINVAL, "flip vs dpms" }, + { 30, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_LOAD, "delayed flip vs dpms" }, + { 5, TEST_FLIP | TEST_PAN, "flip vs panning" }, + { 30, TEST_FLIP | TEST_PAN | TEST_WITH_DUMMY_LOAD, "delayed flip vs panning" }, + { 30, TEST_FLIP | TEST_MODESET | TEST_EINVAL, "flip vs modeset" }, + { 30, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_LOAD, "delayed flip vs modeset" }, }; int i;
Signature · 1 line
1.7.9.5
PATCH 19/22 flip_test: add logic to track pending events
In reply to Imre DeakWhen we add the vblank tests later, it can happen that one type of event is pending while we are servicing another. Prepare for that by maintaining a pending/completed event mask.
No functional change.
--- tests/flip_test.c | 68 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 12 deletions(-)
tests/flip_test.c +56 -12
@@ -50,6 +50,8 @@#define TEST_EINVAL (1 << 6)#define TEST_FLIP (1 << 7) +#define EVENT_FLIP (1 << 0) +drmModeRes *resources;int drm_fd;static drm_intel_bufmgr *bufmgr;
@@ -101,6 +103,7 @@ struct test_output {struct kmstest_fb fb_info[2 ];struct event_state flip_state; +unsigned int pending_events; };static void emit_dummy_load (struct test_output *o)
@@ -179,10 +182,28 @@ static int set_dpms(struct test_output *o, int mode)return drmModeConnectorSetProperty (drm_fd, o->id, dpms, mode); } +static void set_flag (unsigned int *v,unsigned int flag) +{ +assert (!(*v & flag)); + *v |= flag; +} + +static void clear_flag (unsigned int *v,unsigned int flag) +{ +assert (*v & flag); + *v &= ~flag; +} +static int do_page_flip (struct test_output *o,int fb_id) { -return drmModePageFlip (drm_fd, o->crtc, fb_id,DRM_MODE_PAGE_FLIP_EVENT , +int ret; + + ret =drmModePageFlip (drm_fd, o->crtc, fb_id,DRM_MODE_PAGE_FLIP_EVENT , o); +if (ret ==0 ) +set_flag (&o->pending_events,EVENT_FLIP ); + +return ret; } static bool
@@ -209,6 +230,7 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec, {struct test_output *o = data; +clear_flag (&o->pending_events,EVENT_FLIP );event_handler (&o->flip_state, frame, sec, usec); }
@@ -250,20 +272,23 @@ static void check_state(struct test_output *o, struct event_state *es) } } -static void check_all_state (struct test_output *o) +static void check_all_state (struct test_output *o, +unsigned int completed_events) { -if (o->flags &TEST_FLIP ) +if (completed_events &EVENT_FLIP )check_state (o, &o->flip_state); } -static void run_test_step (struct test_output *o) +/* Return mask of completed events. */ +static unsigned int run_test_step (struct test_output *o) {unsigned int new_fb_id;/* for funny reasons page_flip returns -EBUSY on disabled crtcs ... */ int expected_einval = o->flags &TEST_MODESET ? -EBUSY : -EINVAL ; +unsigned int completed_events =0 ;bool do_flip; - do_flip = o->flags &TEST_FLIP ; + do_flip = (o->flags &TEST_FLIP ) && !(o->pending_events &EVENT_FLIP );/* pan before the flip completes */ if (o->flags &TEST_PAN ) {
@@ -328,6 +353,8 @@ static void run_test_step(struct test_output *o)if (do_flip && (o->flags &TEST_EINVAL ))assert (do_page_flip (o, new_fb_id) == expected_einval); + +return completed_events; }static void update_state (struct event_state *es)
@@ -337,9 +364,11 @@ static void update_state(struct event_state *es) es->count++; } -static void update_all_state (struct test_output *o) +static void update_all_state (struct test_output *o, +unsigned int completed_events) { -update_state (&o->flip_state); +if (completed_events &EVENT_FLIP ) +update_state (&o->flip_state); }static void connector_find_preferred_mode (struct test_output *o,int crtc_id)
@@ -479,13 +508,21 @@ static void check_final_state(struct test_output *o, struct event_state *es, } } -static void wait_for_events (struct test_output *o) +/* +* Wait until at least one pending event completes. Return mask of completed +* events. +*/ +static unsigned int wait_for_events (struct test_output *o) {drmEventContext evctx;struct timeval timeout = { .tv_sec =3 , .tv_usec =0 };fd_set fds; +unsigned int event_mask;int ret; + event_mask = o->pending_events; +assert (event_mask); +memset (&evctx,0 ,sizeof evctx); evctx.version =DRM_EVENT_CONTEXT_VERSION ; evctx.vblank_handler =NULL ;
@@ -510,6 +547,11 @@ static void wait_for_events(struct test_output *o) }drmHandleEvent (drm_fd, &evctx); + + event_mask ^= o->pending_events; +assert (event_mask); + +return event_mask; }/* Returned the ellapsed time in us */
@@ -524,11 +566,13 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)while (1 ) {struct timeval now; +unsigned int completed_events; -run_test_step (o); -wait_for_events (o); -check_all_state (o); -update_all_state (o); + completed_events =run_test_step (o); +if (o->pending_events) + completed_events |=wait_for_events (o); +check_all_state (o, completed_events); +update_all_state (o, completed_events);gettimeofday (&now,NULL ); if (!timercmp(&now, &end, <))
Signature · 1 line
1.7.9.5
PATCH 20/22 flip_test: add event sequence number tracking
In reply to Imre Deak--- tests/flip_test.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
tests/flip_test.c +27 -2
@@ -75,6 +75,7 @@ struct event_state {*/ struct timeval last_ts;/* kernel reported timestamp */ struct timeval last_received_ts;/* the moment we received it */ +unsigned int last_seq;/* kernel reported seq. num */ /* * Event data for for the current event that we just received and
@@ -82,8 +83,12 @@ struct event_state {*/ struct timeval current_ts;/* kernel reported timestamp */ struct timeval current_received_ts;/* the moment we received it */ +unsigned int current_seq;/* kernel reported seq. num */ int count;/* # of events of this type */ + +/* Step between the current and next 'target' sequence number. */ +int seq_step; };struct test_output {
@@ -223,6 +228,7 @@ static void event_handler(struct event_state *es, unsigned int frame,gettimeofday (&es->current_received_ts,NULL ); es->current_ts.tv_sec = sec; es->current_ts.tv_usec = usec; + es->current_seq = frame; } static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,
@@ -256,10 +262,20 @@ static void check_state(struct test_output *o, struct event_state *es)exit (6 ); } +if (es->count ==0 ) +return ; -if (es->count >0 && (o->flags &TEST_CHECK_TS ) && (!analog_tv_connector (o))) { +/* This bounding matches the one in DRM_IOCTL_WAIT_VBLANK. */ +if (es->current_seq - (es->last_seq + es->seq_step) >1UL <<23 ) { +fprintf (stderr,"unexpected %s seq %u, should be >= %u\n" , + es->name, es->current_seq, es->last_seq + es->seq_step); +exit (10 ); + } + +if ((o->flags &TEST_CHECK_TS ) && (!analog_tv_connector (o))) {timersub (&es->current_ts, &es->last_ts, &diff); - usec_interflip =1.0 / ((double )o->mode.vrefresh) *1000.0 *1000.0 ; + usec_interflip = (double )es->seq_step / + ((double )o->mode.vrefresh) *1000.0 *1000.0 ;if (fabs ((((double ) diff.tv_usec) - usec_interflip) / usec_interflip) >0.005 ) { fprintf(stderr, "inter-%s ts jitter: %is, %ius\n",
@@ -269,6 +285,12 @@ static void check_state(struct test_output *o, struct event_state *es)* poll helper :( hence make it non-fatal for now */ //exit(9); } + +if (es->current_seq != es->last_seq + es->seq_step) +fprintf (stderr,"unexpected %s seq %u, expected %u\n" , + es->name, es->current_seq, + es->last_seq + es->seq_step); +/* no exit, due to the same reason as above */ } }
@@ -361,6 +383,7 @@ static void update_state(struct event_state *es) { es->last_received_ts = es->current_received_ts; es->last_ts = es->current_ts; + es->last_seq = es->current_seq; es->count++; }
@@ -499,6 +522,7 @@ static void check_final_state(struct test_output *o, struct event_state *es,int expected;int count = es->count; + count *= es->seq_step; expected = ellapsed * o->mode.vrefresh / (1000 *1000 );if (count < expected *99 /100 ) { fprintf(stderr, "dropped frames, expected %d, counted %d, encoder type %d\n",
@@ -640,6 +664,7 @@ static void flip_mode(struct test_output *o, int duration)wait_for_events (o); o->current_fb_id =1 ; + o->flip_state.seq_step =1 ; ellapsed =event_loop (o, duration);
Signature · 1 line
1.7.9.5
PATCH 21/22 flip_test: add check to see if any event has occured
In reply to Imre DeakAt the moment select() would time out in case we don't get any event. When we add vblank events in a later patch, it's possible that we receive one type of events but not the other type. In this case select() doesn't time out and we need another way to detect this.
--- tests/flip_test.c | 5 +++++ 1 file changed, 5 insertions(+)
tests/flip_test.c +5 -0
@@ -516,6 +516,11 @@ fb_is_bound(struct test_output *o, int fb)static void check_final_state (struct test_output *o,struct event_state *es,unsigned int ellapsed) { +if (es->count ==0 ) { +fprintf (stderr,"no %s event received\n" , es->name); +exit (12 ); + } +/* Verify we drop no frames, but only if it's not a TV encoder, since * those use some funny fake timings behind userspace's back. */ if (o->flags &TEST_CHECK_TS && !analog_tv_connector (o)) {
Signature · 1 line
1.7.9.5
PATCH 22/22 flip_test: add wait-for-vblank tests
In reply to Imre Deak--- tests/flip_test.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 4 deletions(-)
tests/flip_test.c +126 -4
@@ -49,8 +49,12 @@#define TEST_EBUSY (1 << 5)#define TEST_EINVAL (1 << 6)#define TEST_FLIP (1 << 7) +#define TEST_VBLANK (1 << 8) +#define TEST_VBLANK_BLOCK (1 << 9) +#define TEST_VBLANK_ABSOLUTE (1 << 10)#define EVENT_FLIP (1 << 0) +#define EVENT_VBLANK (1 << 1)drmModeRes *resources;int drm_fd;
@@ -108,6 +112,7 @@ struct test_output {struct kmstest_fb fb_info[2 ];struct event_state flip_state; +struct event_state vblank_state;unsigned int pending_events; };
@@ -211,6 +216,51 @@ static int do_page_flip(struct test_output *o, int fb_id)return ret; } +struct vblank_reply { +unsigned int sequence; +struct timeval ts; +}; + +static int do_wait_for_vblank (struct test_output *o,int crtc_idx, +int target_seq,struct vblank_reply *reply) +{ +drmVBlank wait_vbl; +int ret; +unsigned crtc_idx_mask; +bool event = !(o->flags &TEST_VBLANK_BLOCK ); + +memset (&wait_vbl,0 ,sizeof (wait_vbl)); + + crtc_idx_mask = crtc_idx <<DRM_VBLANK_HIGH_CRTC_SHIFT ; +assert (!(crtc_idx_mask & ~DRM_VBLANK_HIGH_CRTC_MASK )); + + wait_vbl.request.type = crtc_idx_mask; +if (o->flags &TEST_VBLANK_ABSOLUTE ) + wait_vbl.request.type |=DRM_VBLANK_ABSOLUTE ; +else + wait_vbl.request.type |=DRM_VBLANK_RELATIVE ; +if (event) { + wait_vbl.request.type |=DRM_VBLANK_EVENT ; + wait_vbl.request.signal = (unsigned long )o; + } + wait_vbl.request.sequence = target_seq; + + ret =drmWaitVBlank (drm_fd, &wait_vbl); + +if (ret ==0 ) { + reply->ts.tv_sec = wait_vbl.reply.tval_sec; + reply->ts.tv_usec = wait_vbl.reply.tval_usec; + reply->sequence = wait_vbl.reply.sequence; + +if (event) { +assert (!(o->pending_events &EVENT_VBLANK )); + o->pending_events |=EVENT_VBLANK ; + } + } + +return ret; +} +static bool analog_tv_connector (struct test_output *o) {
@@ -240,6 +290,15 @@ static void page_flip_handler(int fd, unsigned int frame, unsigned int sec,event_handler (&o->flip_state, frame, sec, usec); } +static void vblank_handler (int fd,unsigned int frame,unsigned int sec, +unsigned int usec,void *data) +{ +struct test_output *o = data; + +clear_flag (&o->pending_events,EVENT_VBLANK ); +event_handler (&o->vblank_state, frame, sec, usec); +} +static void check_state (struct test_output *o,struct event_state *es) {struct timeval diff;
@@ -299,6 +358,8 @@ static void check_all_state(struct test_output *o, {if (completed_events &EVENT_FLIP )check_state (o, &o->flip_state); +if (completed_events &EVENT_VBLANK ) +check_state (o, &o->vblank_state); }/* Return mask of completed events. */
@@ -309,12 +370,16 @@ static unsigned int run_test_step(struct test_output *o)int expected_einval = o->flags &TEST_MODESET ? -EBUSY : -EINVAL ;unsigned int completed_events =0 ;bool do_flip; +bool do_vblank; do_flip = (o->flags &TEST_FLIP ) && !(o->pending_events &EVENT_FLIP ); + do_vblank = (o->flags &TEST_VBLANK ) && + !(o->pending_events &EVENT_VBLANK );/* pan before the flip completes */ if (o->flags &TEST_PAN ) { -int count = o->flip_state.count; +int count = do_flip ? + o->flip_state.count : o->vblank_state.count;int x_ofs = count *10 > o->mode.hdisplay ? o->mode.hdisplay : count *10 ;
@@ -356,6 +421,24 @@ static unsigned int run_test_step(struct test_output *o)if (do_flip)do_or_die (do_page_flip (o, new_fb_id)); +if (do_vblank) { +struct vblank_reply vbl_reply; +unsigned int target_seq; + + target_seq = o->vblank_state.seq_step; +if (o->flags &TEST_VBLANK_ABSOLUTE ) + target_seq += o->vblank_state.last_seq; + +do_or_die (do_wait_for_vblank (o, o->crtc_idx, target_seq, + &vbl_reply)); +if (o->flags &TEST_VBLANK_BLOCK ) { +event_handler (&o->vblank_state, vbl_reply.sequence, + vbl_reply.ts.tv_sec, + vbl_reply.ts.tv_usec); + completed_events =EVENT_VBLANK ; + } + } +if (do_flip && (o->flags &TEST_EBUSY ))assert (do_page_flip (o, new_fb_id) == -EBUSY );
@@ -392,6 +475,9 @@ static void update_all_state(struct test_output *o, {if (completed_events &EVENT_FLIP )update_state (&o->flip_state); + +if (completed_events &EVENT_VBLANK ) +update_state (&o->vblank_state); }static void connector_find_preferred_mode (struct test_output *o,int crtc_id)
@@ -554,7 +640,7 @@ static unsigned int wait_for_events(struct test_output *o)memset (&evctx,0 ,sizeof evctx); evctx.version =DRM_EVENT_CONTEXT_VERSION ; - evctx.vblank_handler =NULL ; + evctx.vblank_handler = vblank_handler; evctx.page_flip_handler = page_flip_handler;/* make timeout lax with the dummy load */
@@ -611,10 +697,14 @@ static unsigned event_loop(struct test_output *o, unsigned duration_sec)gettimeofday (&end,NULL );timersub (&end, &start, &tv_dur); +/* Flush any remaining events */ +if (o->pending_events) +wait_for_events (o); +return tv_dur.tv_sec *1000 *1000 + tv_dur.tv_usec; } -static void flip_mode (struct test_output *o,int duration) +static void run_test_on_crtc (struct test_output *o,int duration) {int bpp =32 , depth =24 ;unsigned ellapsed;
@@ -661,6 +751,7 @@ static void flip_mode(struct test_output *o, int duration)sleep (1 );gettimeofday (&o->flip_state.last_ts,NULL ); +gettimeofday (&o->vblank_state.last_ts,NULL );if (do_page_flip (o, o->fb_ids[1 ])) {fprintf (stderr,"failed to page flip: %s\n" ,strerror (errno));
@@ -670,11 +761,17 @@ static void flip_mode(struct test_output *o, int duration) o->current_fb_id =1 ; o->flip_state.seq_step =1 ; +if (o->flags &TEST_VBLANK_ABSOLUTE ) + o->vblank_state.seq_step =5 ; +else + o->vblank_state.seq_step =1 ; ellapsed =event_loop (o, duration);if (o->flags &TEST_FLIP )check_final_state (o, &o->flip_state, ellapsed); +if (o->flags &TEST_VBLANK ) +check_final_state (o, &o->vblank_state, ellapsed);fprintf (stdout,"\n%s on crtc %d, connector %d: PASSED\n\n" , o->test_name, crtc, o->id);
@@ -706,9 +803,10 @@ static int run_test(int duration, int flags, const char *test_name) o.id = resources->connectors[c]; o.flags = flags; o.flip_state.name ="flip" ; + o.vblank_state.name ="vblank" ; o.crtc_idx = i; -flip_mode (&o, duration); +run_test_on_crtc (&o, duration); } }
@@ -723,6 +821,23 @@ int main(int argc, char **argv)int flags;const char *name; } tests[] = { + { 30, TEST_VBLANK | TEST_CHECK_TS, "wf-vblank" }, + { 30, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_CHECK_TS, + "blocking wf-vblank" }, + { 5, TEST_VBLANK | TEST_VBLANK_ABSOLUTE, + "absolute wf-vblank" }, + { 5, TEST_VBLANK | TEST_VBLANK_BLOCK | TEST_VBLANK_ABSOLUTE, + "blocking absolute wf-vblank" }, + { 5, TEST_VBLANK | TEST_DPMS, "wf-vblank vs dpms" }, + { 5, TEST_VBLANK | TEST_DPMS | TEST_WITH_DUMMY_LOAD, + "delayed wf-vblank vs dpms" }, + { 5, TEST_VBLANK | TEST_PAN, "wf-vblank vs panning" }, + { 5, TEST_VBLANK | TEST_PAN | TEST_WITH_DUMMY_LOAD, + "delayed wf-vblank vs panning" }, + { 5, TEST_VBLANK | TEST_MODESET, "wf-vblank vs modeset" }, + { 5, TEST_VBLANK | TEST_MODESET | TEST_WITH_DUMMY_LOAD, + "delayed wf-vblank vs modeset" }, + { 15, TEST_FLIP | TEST_CHECK_TS | TEST_EBUSY , "plain flip" }, { 30, TEST_FLIP | TEST_DPMS | TEST_EINVAL, "flip vs dpms" }, { 30, TEST_FLIP | TEST_DPMS | TEST_WITH_DUMMY_LOAD, "delayed flip vs dpms" },
@@ -730,6 +845,13 @@ int main(int argc, char **argv) { 30, TEST_FLIP | TEST_PAN | TEST_WITH_DUMMY_LOAD, "delayed flip vs panning" }, { 30, TEST_FLIP | TEST_MODESET | TEST_EINVAL, "flip vs modeset" }, { 30, TEST_FLIP | TEST_MODESET | TEST_WITH_DUMMY_LOAD, "delayed flip vs modeset" }, + + { 30, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_ABSOLUTE | + TEST_CHECK_TS, "flip vs absolute wf-vblank" }, + { 30, TEST_FLIP | TEST_VBLANK | TEST_CHECK_TS, + "flip vs wf-vblank" }, + { 30, TEST_FLIP | TEST_VBLANK | TEST_VBLANK_BLOCK | + TEST_CHECK_TS, "flip vs blocking wf-vblank" }, };int i;
Signature · 1 line
1.7.9.5