ddebug: simplify watchdog loop and fix crash in the no-timeout case
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 28 May 2018 15:30:25 +0000 (17:30 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 19 Dec 2018 10:59:10 +0000 (11:59 +0100)
commit539fdc49f1ef02f5a40c486fa940b3bfacb44a48
tree4eaa3b81ac493b01573ba7956f17ac71ed5aef7a
parent3627c9efff2f597fe2236b7f420a44ccba30a3b2
ddebug: simplify watchdog loop and fix crash in the no-timeout case

The following race condition could occur in the no-timeout case:

  API thread               Gallium thread            Watchdog
  ----------               --------------            --------
  dd_before_draw
  u_threaded_context draw
  dd_after_draw
    add to dctx->records
    signal watchdog
                                                     dump & destroy record
                           execute draw
                           dd_after_draw_async
                             use-after-free!

Alternatively, the same scenario would assert in a debug build when
destroying the record because record->driver_finished has not signaled.

Fix this and simplify the logic at the same time by
- handing the record pointers off to the watchdog thread *before* each
  draw call and
- waiting on the driver_finished fence in the watchdog thread

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/driver_ddebug/dd_context.c
src/gallium/auxiliary/driver_ddebug/dd_draw.c
src/gallium/auxiliary/driver_ddebug/dd_pipe.h