lib/igt_aux: Polish docs for igt_interruptible
PATCH 1/2 lib/igt_aux: Polish docs for igt_interruptible
- Give __ prefix to internal funcstion and structs, only igt_interruptible is used by tests.
- Move docs to igt_interruptible and adjust.
- Explain more clearly how the timeout is getting doubled each iteration until no more interruptions happen. Also rename the argument to give it a more meaningful name in the docs.
- Link from other functions to this one for cross-referencing.
- Rename to igt_do_interruptible to make it clearer it's a loop, inspired by do {} while () loops.
Signed-off-by Daniel Vetter <[email protected]>
--- lib/igt_aux.c | 37 ++++++++----------------------------- lib/igt_aux.h | 29 +++++++++++++++++++++++++---- tests/gem_concurrent_all.c | 4 ++-- tests/gem_ctx_switch.c | 2 +- tests/gem_exec_flush.c | 8 ++++---- tests/gem_exec_whisper.c | 2 +- tests/gem_ringfill.c | 2 +- tests/gem_softpin.c | 6 +++--- tests/prime_mmap_coherency.c | 2 +- 9 files changed, 46 insertions(+), 46 deletions(-)
lib/igt_aux.c +8 -29
@@ -84,7 +84,7 @@#define gettid () syscall(__NR_gettid)#define sigev_notify_thread_id _sigev_un._tid -static struct __igt_sigiter { +static struct __igt_sigiter_global { pid_t tid; timer_t timer; struct timespec offset;
@@ -159,7 +159,7 @@ sig_ioctl(int fd, unsigned long request, void *arg)return ret ?-1 :0 ; } -static bool igt_sigiter_start (struct igt_sigiter *iter,bool enable) +static bool igt_sigiter_start (struct __igt_sigiter *iter,bool enable) {/* Note that until we can automatically clean up on failed/skipped * tests, we cannot assume the state of the igt_ioctl indirection.
@@ -218,7 +218,7 @@ static bool igt_sigiter_start(struct igt_sigiter *iter, bool enable)return true; } -static bool igt_sigiter_stop (struct igt_sigiter *iter,bool enable) +static bool igt_sigiter_stop (struct __igt_sigiter *iter,bool enable) {if (enable) {struct sigaction act;
@@ -240,32 +240,7 @@ static bool igt_sigiter_stop(struct igt_sigiter *iter, bool enable)return false; } -/** -* igt_sigiter_continue: -* @iter: the control struct -* @enable: a boolean as to whether or not we want to enable interruptions -* -* Provides control flow such that all drmIoctl() (strictly igt_ioctl()) -* within the loop are forcibly injected with signals (SIGRTMIN). -* -* This is useful to exercise ioctl error paths, at least where those can be -* exercises by interrupting blocking waits, like stalling for the gpu. -* -* igt_sigiter_continue() returns false when it has detected that it -* cannot inject any more signals in the ioctls from previous runs. -* -* Typical usage is -* struct igt_sigiter iter = {}; -* while (igt_sigiter_continue(&iter, test_flags & TEST_INTERRUPTIBLE)) -* do_test(); -* -* This is condensed into the igt_interruptible() macro. -* -* Note that since this overloads the igt_ioctl(), this method is not useful -* for widespread signal injection, for example providing coverage of -* pagefaults. To interrupt everything, see igt_fork_signal_helper(). -*/ -bool igt_sigiter_continue (struct igt_sigiter *iter,bool enable) +bool __igt_sigiter_continue (struct __igt_sigiter *iter,bool enable) {if (iter->pass++ ==0 )return igt_sigiter_start (iter, enable);
@@ -329,6 +304,10 @@ static void sig_handler(int i)* * In tests with subtests this function can be called outside of failure * catching code blocks like #igt_fixture or #igt_subtest. +* +* Note that this just spews signals at the current process unconditionally and +* hence incurs quite a bit of overhead. For a more focuses approach, with less +* overhead, look at the #igt_interruptible code block macro. */ void igt_fork_signal_helper (void ) {
lib/igt_aux.h +25 -4
@@ -43,13 +43,34 @@ void igt_stop_signal_helper(void);void igt_fork_hang_detector (int fd);void igt_stop_hang_detector (void ); -struct igt_sigiter { +struct __igt_sigiter {unsigned pass; }; -bool igt_sigiter_continue (struct igt_sigiter *iter,bool interrupt); -#define igt_interruptible (E ) \ - for (struct igt_sigiter iter__={}; igt_sigiter_continue(&iter__, (E)); ) +bool __igt_sigiter_continue (struct __igt_sigiter *iter,bool interrupt); + +/** +* igt_do_interruptible: +* @enable: enable igt_ioctl interrupting or not +* +* Provides control flow such that all drmIoctl() (strictly igt_ioctl()) +* within the loop are forcibly injected with signals (SIGRTMIN). +* +* This is useful to exercise ioctl error paths, at least where those can be +* exercises by interrupting blocking waits, like stalling for the gpu. +* +* The code block attached to this macro is run in a loop with doubling the +* interrupt timeout on each ioctl for every run, until no ioctl gets +* interrupted any more. The starting timeout is taken to be the signal deliver +* latency, measured at runtime. This way the any ioctls called from this code +* block should be exaustively tested for all signal interruption paths. +* +* Note that since this overloads the igt_ioctl(), this method is not useful +* for widespread signal injection, for example providing coverage of +* pagefaults. To interrupt everything, see igt_fork_signal_helper(). +*/ +#define igt_do_interruptible (enable) \ + for (struct __igt_sigiter iter__={}; __igt_sigiter_continue(&iter__, (enable)); )#define igt_timeout (T ) \ for (struct timespec t__={}; igt_seconds_elapsed(&t__) < (T); )
tests/gem_concurrent_all.c +2 -2
@@ -1294,7 +1294,7 @@ static void run_interruptible(struct buffers *buffers, do_hang do_hang_func) { pass =0 ; -igt_interruptible (true) +igt_do_interruptible (true)do_test_func (buffers, do_copy_func, do_hang_func);igt_assert_eq (intel_detect_and_clear_missed_interrupts (fd),0 ); }
@@ -1340,7 +1340,7 @@ static void __run_forked(struct buffers *buffers,buffers_reset (buffers, true);buffers_create (buffers); -igt_interruptible (interrupt) { +igt_do_interruptible (interrupt) {for (pass =0 ; pass < loops; pass++) do_test_func(buffers, do_copy_func,
tests/gem_ctx_switch.c +1 -1
@@ -116,7 +116,7 @@ static void single(int fd, uint32_t handle,clock_gettime (CLOCK_MONOTONIC , &start); do { - igt_interruptible(flags & INTERRUPTIBLE) { + igt_do_interruptible(flags & INTERRUPTIBLE) { for (int loop = 0; loop < 1024; loop++) { execbuf.rsvd1 = contexts[loop % 64]; reloc.presumed_offset = 0;
tests/gem_exec_flush.c +4 -4
@@ -216,7 +216,7 @@ overwrite:if (flags &SET_DOMAIN ) {unsigned domain = flags &WC ?I915_GEM_DOMAIN_GTT :I915_GEM_DOMAIN_CPU ; - igt_interruptible(flags & INTERRUPTIBLE) + igt_do_interruptible(flags & INTERRUPTIBLE)gem_set_domain (fd, obj[0 ].handle, domain, (flags &WRITE ) ? domain :0 );
@@ -230,7 +230,7 @@ overwrite: }else if (flags &KERNEL ) {uint32_t val; - igt_interruptible(flags & INTERRUPTIBLE) + igt_do_interruptible(flags & INTERRUPTIBLE)gem_read (fd, obj[0 ].handle, i*sizeof (uint32_t ), &val,sizeof (val));
@@ -242,13 +242,13 @@ overwrite:if (flags &WRITE ) { val =0xdeadbeef ; - igt_interruptible(flags & INTERRUPTIBLE) + igt_do_interruptible(flags & INTERRUPTIBLE)gem_write (fd, obj[0 ].handle, i*sizeof (uint32_t ), &val,sizeof (val)); } }else { - igt_interruptible(flags & INTERRUPTIBLE) + igt_do_interruptible(flags & INTERRUPTIBLE)gem_sync (fd, obj[0 ].handle); if (!(flags & (BEFORE | COHERENT)) &&
tests/gem_exec_whisper.c +1 -1
@@ -225,7 +225,7 @@ static void whisper(int fd, unsigned engine, unsigned flags)gem_write (fd, batches[n].handle,0 , batch,sizeof (batch)); } - igt_interruptible(flags & INTERRUPTIBLE) { + igt_do_interruptible(flags & INTERRUPTIBLE) {for (pass =0 ; pass <1024 ; pass++) {uint64_t offset;
tests/gem_ringfill.c +1 -1
@@ -75,7 +75,7 @@ static void fill_ring(int fd,* doing this, we aren't likely to with this test. */ igt_debug ("Executing execbuf %d times\n" ,128 *1024 /(8 *4 )); - igt_interruptible(flags & INTERRUPTIBLE) { + igt_do_interruptible(flags & INTERRUPTIBLE) {for (int i =0 ; i <128 *1024 / (8 *4 ); i++)gem_execbuf (fd, execbuf); }
tests/gem_softpin.c +3 -3
@@ -492,7 +492,7 @@ igt_main igt_subtest("noreloc")test_noreloc (fd,NOSLEEP ); igt_subtest("noreloc-interruptible") -igt_interruptible (true)test_noreloc (fd, NOSLEEP); +igt_do_interruptible (true)test_noreloc (fd, NOSLEEP); igt_subtest("noreloc-S3")test_noreloc (fd,SUSPEND );igt_subtest ("noreloc-S4" )
@@ -500,9 +500,9 @@ igt_mainfor (int signal =0 ; signal <=1 ; signal++) { igt_subtest_f("evict-active%s", signal ? "-interruptible" : "") -igt_interruptible (signal)test_evict_active (fd); +igt_do_interruptible (signal)test_evict_active (fd); igt_subtest_f("evict-snoop%s", signal ? "-interruptible" : "") -igt_interruptible (signal)test_evict_snoop (fd); +igt_do_interruptible (signal)test_evict_snoop (fd); } igt_subtest("evict-hang")test_evict_hang (fd);
tests/prime_mmap_coherency.c +1 -1
@@ -277,7 +277,7 @@ static void test_ioctl_errors(void) } igt_fork(child, num_children) -igt_interruptible (true)blit_and_cmp (); +igt_do_interruptible (true)blit_and_cmp ();igt_waitchildren (); } }
Signature · 6 lines
2.8.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/2 lib/igt_aux: Polish docs for igt_timeout
Add docs, rename parameter and rename the macro to igt_do_timeout to make it clear it works like a loop.
Signed-off-by Daniel Vetter <[email protected]>
--- lib/igt_aux.h | 14 ++++++++++++-- tests/gem_close_race.c | 2 +- tests/gem_exec_flush.c | 4 ++-- tests/gem_shrink.c | 6 +++--- 4 files changed, 18 insertions(+), 8 deletions(-)
lib/igt_aux.h +12 -2
@@ -72,8 +72,18 @@ bool __igt_sigiter_continue(struct __igt_sigiter *iter, bool interrupt);#define igt_do_interruptible (enable) \ for (struct __igt_sigiter iter__={}; __igt_sigiter_continue(&iter__, (enable)); ) -#define igt_timeout (T ) \ - for (struct timespec t__={}; igt_seconds_elapsed(&t__) < (T); ) +/** +* igt_do_timeout: +* @timeout: timeout in seconds +* +* Convenience loop to run the provided code block in a loop until the timeout +* has expired. Of course when an individual execution takes too long, the +* actual execution time could be a lot longer. +* +* The code block will be executed at least once. +*/ +#define igt_do_timeout (timeout) \ + for (struct timespec t__={}; igt_seconds_elapsed(&t__) < (timeout); )void igt_exchange_int (void *array,unsigned i,unsigned j); void igt_permute_array(void *array, unsigned size,
tests/gem_close_race.c +1 -1
@@ -187,7 +187,7 @@ static void threads(int timeout) fd =open (device,O_RDWR ); name.name =gem_flink (fd,gem_create (fd,OBJECT_SIZE )); -igt_timeout (timeout) { +igt_do_timeout (timeout) { crashme.fd =open (device,O_RDWR );memset (&its,0 ,sizeof (its));
tests/gem_exec_flush.c +2 -2
@@ -196,7 +196,7 @@ static void run(int fd, unsigned ring, int nchild, int timeout, }munmap (ptr,64 *1024 ); -igt_timeout (timeout) { +igt_do_timeout (timeout) {bool xor = false;int idx = cycles++ %1024 ;
@@ -369,7 +369,7 @@ static void batch(int fd, unsigned ring, int nchild, int timeout, reloc.read_domains =I915_GEM_DOMAIN_INSTRUCTION ; reloc.write_domain =I915_GEM_DOMAIN_INSTRUCTION ; -igt_timeout (timeout) { +igt_do_timeout (timeout) { execbuf.batch_start_offset =0 ; reloc.offset =sizeof (uint32_t );if (gen >=4 && gen <8 )
tests/gem_shrink.c +3 -3
@@ -231,7 +231,7 @@ static void run_test(int nchildren, uint64_t alloc,/* Background load */ if (flags &OOM ) { igt_fork(child, nchildren) { -igt_timeout (timeout) { +igt_do_timeout (timeout) {int fd =drm_open_driver (DRIVER_INTEL );for (int pass =0 ; pass < nchildren; pass++)leak (fd, alloc);
@@ -243,7 +243,7 @@ static void run_test(int nchildren, uint64_t alloc,if (flags &USERPTR ) {igt_require (has_userptr ()); igt_fork(child, (nchildren + 1)/2) { -igt_timeout (timeout) { +igt_do_timeout (timeout) {int fd =drm_open_driver (DRIVER_INTEL );for (int pass =0 ; pass < nchildren; pass++)userptr (fd, alloc);
@@ -255,7 +255,7 @@ static void run_test(int nchildren, uint64_t alloc,/* Exercise major ioctls */ igt_fork(child, nchildren) { -igt_timeout (timeout) { +igt_do_timeout (timeout) {int fd =drm_open_driver (DRIVER_INTEL );for (int pass =0 ; pass < nchildren; pass++)func (fd, alloc);
Signature · 6 lines
2.8.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx