i915_gem_request.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright © 2016 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. */
  24. #include "../i915_selftest.h"
  25. #include "mock_gem_device.h"
  26. static int igt_add_request(void *arg)
  27. {
  28. struct drm_i915_private *i915 = arg;
  29. struct drm_i915_gem_request *request;
  30. int err = -ENOMEM;
  31. /* Basic preliminary test to create a request and let it loose! */
  32. mutex_lock(&i915->drm.struct_mutex);
  33. request = mock_request(i915->engine[RCS],
  34. i915->kernel_context,
  35. HZ / 10);
  36. if (!request)
  37. goto out_unlock;
  38. i915_add_request(request);
  39. err = 0;
  40. out_unlock:
  41. mutex_unlock(&i915->drm.struct_mutex);
  42. return err;
  43. }
  44. static int igt_wait_request(void *arg)
  45. {
  46. const long T = HZ / 4;
  47. struct drm_i915_private *i915 = arg;
  48. struct drm_i915_gem_request *request;
  49. int err = -EINVAL;
  50. /* Submit a request, then wait upon it */
  51. mutex_lock(&i915->drm.struct_mutex);
  52. request = mock_request(i915->engine[RCS], i915->kernel_context, T);
  53. if (!request) {
  54. err = -ENOMEM;
  55. goto out_unlock;
  56. }
  57. if (i915_wait_request(request, I915_WAIT_LOCKED, 0) != -ETIME) {
  58. pr_err("request wait (busy query) succeeded (expected timeout before submit!)\n");
  59. goto out_unlock;
  60. }
  61. if (i915_wait_request(request, I915_WAIT_LOCKED, T) != -ETIME) {
  62. pr_err("request wait succeeded (expected timeout before submit!)\n");
  63. goto out_unlock;
  64. }
  65. if (i915_gem_request_completed(request)) {
  66. pr_err("request completed before submit!!\n");
  67. goto out_unlock;
  68. }
  69. i915_add_request(request);
  70. if (i915_wait_request(request, I915_WAIT_LOCKED, 0) != -ETIME) {
  71. pr_err("request wait (busy query) succeeded (expected timeout after submit!)\n");
  72. goto out_unlock;
  73. }
  74. if (i915_gem_request_completed(request)) {
  75. pr_err("request completed immediately!\n");
  76. goto out_unlock;
  77. }
  78. if (i915_wait_request(request, I915_WAIT_LOCKED, T / 2) != -ETIME) {
  79. pr_err("request wait succeeded (expected timeout!)\n");
  80. goto out_unlock;
  81. }
  82. if (i915_wait_request(request, I915_WAIT_LOCKED, T) == -ETIME) {
  83. pr_err("request wait timed out!\n");
  84. goto out_unlock;
  85. }
  86. if (!i915_gem_request_completed(request)) {
  87. pr_err("request not complete after waiting!\n");
  88. goto out_unlock;
  89. }
  90. if (i915_wait_request(request, I915_WAIT_LOCKED, T) == -ETIME) {
  91. pr_err("request wait timed out when already complete!\n");
  92. goto out_unlock;
  93. }
  94. err = 0;
  95. out_unlock:
  96. mock_device_flush(i915);
  97. mutex_unlock(&i915->drm.struct_mutex);
  98. return err;
  99. }
  100. static int igt_fence_wait(void *arg)
  101. {
  102. const long T = HZ / 4;
  103. struct drm_i915_private *i915 = arg;
  104. struct drm_i915_gem_request *request;
  105. int err = -EINVAL;
  106. /* Submit a request, treat it as a fence and wait upon it */
  107. mutex_lock(&i915->drm.struct_mutex);
  108. request = mock_request(i915->engine[RCS], i915->kernel_context, T);
  109. if (!request) {
  110. err = -ENOMEM;
  111. goto out_locked;
  112. }
  113. mutex_unlock(&i915->drm.struct_mutex); /* safe as we are single user */
  114. if (dma_fence_wait_timeout(&request->fence, false, T) != -ETIME) {
  115. pr_err("fence wait success before submit (expected timeout)!\n");
  116. goto out_device;
  117. }
  118. mutex_lock(&i915->drm.struct_mutex);
  119. i915_add_request(request);
  120. mutex_unlock(&i915->drm.struct_mutex);
  121. if (dma_fence_is_signaled(&request->fence)) {
  122. pr_err("fence signaled immediately!\n");
  123. goto out_device;
  124. }
  125. if (dma_fence_wait_timeout(&request->fence, false, T / 2) != -ETIME) {
  126. pr_err("fence wait success after submit (expected timeout)!\n");
  127. goto out_device;
  128. }
  129. if (dma_fence_wait_timeout(&request->fence, false, T) <= 0) {
  130. pr_err("fence wait timed out (expected success)!\n");
  131. goto out_device;
  132. }
  133. if (!dma_fence_is_signaled(&request->fence)) {
  134. pr_err("fence unsignaled after waiting!\n");
  135. goto out_device;
  136. }
  137. if (dma_fence_wait_timeout(&request->fence, false, T) <= 0) {
  138. pr_err("fence wait timed out when complete (expected success)!\n");
  139. goto out_device;
  140. }
  141. err = 0;
  142. out_device:
  143. mutex_lock(&i915->drm.struct_mutex);
  144. out_locked:
  145. mock_device_flush(i915);
  146. mutex_unlock(&i915->drm.struct_mutex);
  147. return err;
  148. }
  149. int i915_gem_request_mock_selftests(void)
  150. {
  151. static const struct i915_subtest tests[] = {
  152. SUBTEST(igt_add_request),
  153. SUBTEST(igt_wait_request),
  154. SUBTEST(igt_fence_wait),
  155. };
  156. struct drm_i915_private *i915;
  157. int err;
  158. i915 = mock_gem_device();
  159. if (!i915)
  160. return -ENOMEM;
  161. err = i915_subtests(tests, i915);
  162. drm_dev_unref(&i915->drm);
  163. return err;
  164. }