igt_flush_test.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * SPDX-License-Identifier: MIT
  3. *
  4. * Copyright © 2018 Intel Corporation
  5. */
  6. #include "../i915_drv.h"
  7. #include "../i915_selftest.h"
  8. #include "igt_flush_test.h"
  9. struct wedge_me {
  10. struct delayed_work work;
  11. struct drm_i915_private *i915;
  12. const void *symbol;
  13. };
  14. static void wedge_me(struct work_struct *work)
  15. {
  16. struct wedge_me *w = container_of(work, typeof(*w), work.work);
  17. pr_err("%pS timed out, cancelling all further testing.\n", w->symbol);
  18. GEM_TRACE("%pS timed out.\n", w->symbol);
  19. GEM_TRACE_DUMP();
  20. i915_gem_set_wedged(w->i915);
  21. }
  22. static void __init_wedge(struct wedge_me *w,
  23. struct drm_i915_private *i915,
  24. long timeout,
  25. const void *symbol)
  26. {
  27. w->i915 = i915;
  28. w->symbol = symbol;
  29. INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
  30. schedule_delayed_work(&w->work, timeout);
  31. }
  32. static void __fini_wedge(struct wedge_me *w)
  33. {
  34. cancel_delayed_work_sync(&w->work);
  35. destroy_delayed_work_on_stack(&w->work);
  36. w->i915 = NULL;
  37. }
  38. #define wedge_on_timeout(W, DEV, TIMEOUT) \
  39. for (__init_wedge((W), (DEV), (TIMEOUT), __builtin_return_address(0)); \
  40. (W)->i915; \
  41. __fini_wedge((W)))
  42. int igt_flush_test(struct drm_i915_private *i915, unsigned int flags)
  43. {
  44. struct wedge_me w;
  45. cond_resched();
  46. if (flags & I915_WAIT_LOCKED &&
  47. i915_gem_switch_to_kernel_context(i915)) {
  48. pr_err("Failed to switch back to kernel context; declaring wedged\n");
  49. i915_gem_set_wedged(i915);
  50. }
  51. wedge_on_timeout(&w, i915, HZ)
  52. i915_gem_wait_for_idle(i915, flags);
  53. return i915_terminally_wedged(&i915->gpu_error) ? -EIO : 0;
  54. }