igt_wedge_me.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * SPDX-License-Identifier: MIT
  3. *
  4. * Copyright © 2018 Intel Corporation
  5. */
  6. #ifndef IGT_WEDGE_ME_H
  7. #define IGT_WEDGE_ME_H
  8. #include <linux/workqueue.h>
  9. #include "../i915_gem.h"
  10. struct drm_i915_private;
  11. struct igt_wedge_me {
  12. struct delayed_work work;
  13. struct drm_i915_private *i915;
  14. const char *name;
  15. };
  16. static void __igt_wedge_me(struct work_struct *work)
  17. {
  18. struct igt_wedge_me *w = container_of(work, typeof(*w), work.work);
  19. pr_err("%s timed out, cancelling test.\n", w->name);
  20. GEM_TRACE("%s timed out.\n", w->name);
  21. GEM_TRACE_DUMP();
  22. i915_gem_set_wedged(w->i915);
  23. }
  24. static void __igt_init_wedge(struct igt_wedge_me *w,
  25. struct drm_i915_private *i915,
  26. long timeout,
  27. const char *name)
  28. {
  29. w->i915 = i915;
  30. w->name = name;
  31. INIT_DELAYED_WORK_ONSTACK(&w->work, __igt_wedge_me);
  32. schedule_delayed_work(&w->work, timeout);
  33. }
  34. static void __igt_fini_wedge(struct igt_wedge_me *w)
  35. {
  36. cancel_delayed_work_sync(&w->work);
  37. destroy_delayed_work_on_stack(&w->work);
  38. w->i915 = NULL;
  39. }
  40. #define igt_wedge_on_timeout(W, DEV, TIMEOUT) \
  41. for (__igt_init_wedge((W), (DEV), (TIMEOUT), __func__); \
  42. (W)->i915; \
  43. __igt_fini_wedge((W)))
  44. #endif /* IGT_WEDGE_ME_H */