amdgpu_benchmark.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Copyright 2009 Jerome Glisse.
  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 shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Jerome Glisse
  23. */
  24. #include <drm/drmP.h>
  25. #include <drm/amdgpu_drm.h>
  26. #include "amdgpu.h"
  27. #define AMDGPU_BENCHMARK_ITERATIONS 1024
  28. #define AMDGPU_BENCHMARK_COMMON_MODES_N 17
  29. static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,
  30. uint64_t saddr, uint64_t daddr, int n)
  31. {
  32. unsigned long start_jiffies;
  33. unsigned long end_jiffies;
  34. struct fence *fence = NULL;
  35. int i, r;
  36. start_jiffies = jiffies;
  37. for (i = 0; i < n; i++) {
  38. struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
  39. r = amdgpu_copy_buffer(ring, saddr, daddr, size, NULL, &fence);
  40. if (r)
  41. goto exit_do_move;
  42. r = fence_wait(fence, false);
  43. if (r)
  44. goto exit_do_move;
  45. fence_put(fence);
  46. }
  47. end_jiffies = jiffies;
  48. r = jiffies_to_msecs(end_jiffies - start_jiffies);
  49. exit_do_move:
  50. if (fence)
  51. fence_put(fence);
  52. return r;
  53. }
  54. static void amdgpu_benchmark_log_results(int n, unsigned size,
  55. unsigned int time,
  56. unsigned sdomain, unsigned ddomain,
  57. char *kind)
  58. {
  59. unsigned int throughput = (n * (size >> 10)) / time;
  60. DRM_INFO("amdgpu: %s %u bo moves of %u kB from"
  61. " %d to %d in %u ms, throughput: %u Mb/s or %u MB/s\n",
  62. kind, n, size >> 10, sdomain, ddomain, time,
  63. throughput * 8, throughput);
  64. }
  65. static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
  66. unsigned sdomain, unsigned ddomain)
  67. {
  68. struct amdgpu_bo *dobj = NULL;
  69. struct amdgpu_bo *sobj = NULL;
  70. uint64_t saddr, daddr;
  71. int r, n;
  72. int time;
  73. n = AMDGPU_BENCHMARK_ITERATIONS;
  74. r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, sdomain, 0, NULL,
  75. NULL, &sobj);
  76. if (r) {
  77. goto out_cleanup;
  78. }
  79. r = amdgpu_bo_reserve(sobj, false);
  80. if (unlikely(r != 0))
  81. goto out_cleanup;
  82. r = amdgpu_bo_pin(sobj, sdomain, &saddr);
  83. amdgpu_bo_unreserve(sobj);
  84. if (r) {
  85. goto out_cleanup;
  86. }
  87. r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, ddomain, 0, NULL,
  88. NULL, &dobj);
  89. if (r) {
  90. goto out_cleanup;
  91. }
  92. r = amdgpu_bo_reserve(dobj, false);
  93. if (unlikely(r != 0))
  94. goto out_cleanup;
  95. r = amdgpu_bo_pin(dobj, ddomain, &daddr);
  96. amdgpu_bo_unreserve(dobj);
  97. if (r) {
  98. goto out_cleanup;
  99. }
  100. if (adev->mman.buffer_funcs) {
  101. time = amdgpu_benchmark_do_move(adev, size, saddr, daddr, n);
  102. if (time < 0)
  103. goto out_cleanup;
  104. if (time > 0)
  105. amdgpu_benchmark_log_results(n, size, time,
  106. sdomain, ddomain, "dma");
  107. }
  108. out_cleanup:
  109. if (sobj) {
  110. r = amdgpu_bo_reserve(sobj, false);
  111. if (likely(r == 0)) {
  112. amdgpu_bo_unpin(sobj);
  113. amdgpu_bo_unreserve(sobj);
  114. }
  115. amdgpu_bo_unref(&sobj);
  116. }
  117. if (dobj) {
  118. r = amdgpu_bo_reserve(dobj, false);
  119. if (likely(r == 0)) {
  120. amdgpu_bo_unpin(dobj);
  121. amdgpu_bo_unreserve(dobj);
  122. }
  123. amdgpu_bo_unref(&dobj);
  124. }
  125. if (r) {
  126. DRM_ERROR("Error while benchmarking BO move.\n");
  127. }
  128. }
  129. void amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
  130. {
  131. int i;
  132. int common_modes[AMDGPU_BENCHMARK_COMMON_MODES_N] = {
  133. 640 * 480 * 4,
  134. 720 * 480 * 4,
  135. 800 * 600 * 4,
  136. 848 * 480 * 4,
  137. 1024 * 768 * 4,
  138. 1152 * 768 * 4,
  139. 1280 * 720 * 4,
  140. 1280 * 800 * 4,
  141. 1280 * 854 * 4,
  142. 1280 * 960 * 4,
  143. 1280 * 1024 * 4,
  144. 1440 * 900 * 4,
  145. 1400 * 1050 * 4,
  146. 1680 * 1050 * 4,
  147. 1600 * 1200 * 4,
  148. 1920 * 1080 * 4,
  149. 1920 * 1200 * 4
  150. };
  151. switch (test_number) {
  152. case 1:
  153. /* simple test, VRAM to GTT and GTT to VRAM */
  154. amdgpu_benchmark_move(adev, 1024*1024, AMDGPU_GEM_DOMAIN_GTT,
  155. AMDGPU_GEM_DOMAIN_VRAM);
  156. amdgpu_benchmark_move(adev, 1024*1024, AMDGPU_GEM_DOMAIN_VRAM,
  157. AMDGPU_GEM_DOMAIN_GTT);
  158. break;
  159. case 2:
  160. /* simple test, VRAM to VRAM */
  161. amdgpu_benchmark_move(adev, 1024*1024, AMDGPU_GEM_DOMAIN_VRAM,
  162. AMDGPU_GEM_DOMAIN_VRAM);
  163. break;
  164. case 3:
  165. /* GTT to VRAM, buffer size sweep, powers of 2 */
  166. for (i = 1; i <= 16384; i <<= 1)
  167. amdgpu_benchmark_move(adev, i * AMDGPU_GPU_PAGE_SIZE,
  168. AMDGPU_GEM_DOMAIN_GTT,
  169. AMDGPU_GEM_DOMAIN_VRAM);
  170. break;
  171. case 4:
  172. /* VRAM to GTT, buffer size sweep, powers of 2 */
  173. for (i = 1; i <= 16384; i <<= 1)
  174. amdgpu_benchmark_move(adev, i * AMDGPU_GPU_PAGE_SIZE,
  175. AMDGPU_GEM_DOMAIN_VRAM,
  176. AMDGPU_GEM_DOMAIN_GTT);
  177. break;
  178. case 5:
  179. /* VRAM to VRAM, buffer size sweep, powers of 2 */
  180. for (i = 1; i <= 16384; i <<= 1)
  181. amdgpu_benchmark_move(adev, i * AMDGPU_GPU_PAGE_SIZE,
  182. AMDGPU_GEM_DOMAIN_VRAM,
  183. AMDGPU_GEM_DOMAIN_VRAM);
  184. break;
  185. case 6:
  186. /* GTT to VRAM, buffer size sweep, common modes */
  187. for (i = 0; i < AMDGPU_BENCHMARK_COMMON_MODES_N; i++)
  188. amdgpu_benchmark_move(adev, common_modes[i],
  189. AMDGPU_GEM_DOMAIN_GTT,
  190. AMDGPU_GEM_DOMAIN_VRAM);
  191. break;
  192. case 7:
  193. /* VRAM to GTT, buffer size sweep, common modes */
  194. for (i = 0; i < AMDGPU_BENCHMARK_COMMON_MODES_N; i++)
  195. amdgpu_benchmark_move(adev, common_modes[i],
  196. AMDGPU_GEM_DOMAIN_VRAM,
  197. AMDGPU_GEM_DOMAIN_GTT);
  198. break;
  199. case 8:
  200. /* VRAM to VRAM, buffer size sweep, common modes */
  201. for (i = 0; i < AMDGPU_BENCHMARK_COMMON_MODES_N; i++)
  202. amdgpu_benchmark_move(adev, common_modes[i],
  203. AMDGPU_GEM_DOMAIN_VRAM,
  204. AMDGPU_GEM_DOMAIN_VRAM);
  205. break;
  206. default:
  207. DRM_ERROR("Unknown benchmark\n");
  208. }
  209. }