radeon_benchmark.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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/radeon_drm.h>
  26. #include "radeon_reg.h"
  27. #include "radeon.h"
  28. #define RADEON_BENCHMARK_COPY_BLIT 1
  29. #define RADEON_BENCHMARK_COPY_DMA 0
  30. #define RADEON_BENCHMARK_ITERATIONS 1024
  31. #define RADEON_BENCHMARK_COMMON_MODES_N 17
  32. static int radeon_benchmark_do_move(struct radeon_device *rdev, unsigned size,
  33. uint64_t saddr, uint64_t daddr,
  34. int flag, int n)
  35. {
  36. unsigned long start_jiffies;
  37. unsigned long end_jiffies;
  38. struct radeon_fence *fence = NULL;
  39. int i, r;
  40. start_jiffies = jiffies;
  41. for (i = 0; i < n; i++) {
  42. switch (flag) {
  43. case RADEON_BENCHMARK_COPY_DMA:
  44. r = radeon_fence_create(rdev, &fence, radeon_copy_dma_ring_index(rdev));
  45. if (r)
  46. return r;
  47. r = radeon_copy_dma(rdev, saddr, daddr,
  48. size / RADEON_GPU_PAGE_SIZE,
  49. fence);
  50. break;
  51. case RADEON_BENCHMARK_COPY_BLIT:
  52. r = radeon_fence_create(rdev, &fence, radeon_copy_blit_ring_index(rdev));
  53. if (r)
  54. return r;
  55. r = radeon_copy_blit(rdev, saddr, daddr,
  56. size / RADEON_GPU_PAGE_SIZE,
  57. fence);
  58. break;
  59. default:
  60. DRM_ERROR("Unknown copy method\n");
  61. r = -EINVAL;
  62. }
  63. if (r)
  64. goto exit_do_move;
  65. r = radeon_fence_wait(fence, false);
  66. if (r)
  67. goto exit_do_move;
  68. radeon_fence_unref(&fence);
  69. }
  70. end_jiffies = jiffies;
  71. r = jiffies_to_msecs(end_jiffies - start_jiffies);
  72. exit_do_move:
  73. if (fence)
  74. radeon_fence_unref(&fence);
  75. return r;
  76. }
  77. static void radeon_benchmark_log_results(int n, unsigned size,
  78. unsigned int time,
  79. unsigned sdomain, unsigned ddomain,
  80. char *kind)
  81. {
  82. unsigned int throughput = (n * (size >> 10)) / time;
  83. DRM_INFO("radeon: %s %u bo moves of %u kB from"
  84. " %d to %d in %u ms, throughput: %u Mb/s or %u MB/s\n",
  85. kind, n, size >> 10, sdomain, ddomain, time,
  86. throughput * 8, throughput);
  87. }
  88. static void radeon_benchmark_move(struct radeon_device *rdev, unsigned size,
  89. unsigned sdomain, unsigned ddomain)
  90. {
  91. struct radeon_bo *dobj = NULL;
  92. struct radeon_bo *sobj = NULL;
  93. uint64_t saddr, daddr;
  94. int r, n;
  95. int time;
  96. n = RADEON_BENCHMARK_ITERATIONS;
  97. r = radeon_bo_create(rdev, size, PAGE_SIZE, true, sdomain, &sobj);
  98. if (r) {
  99. goto out_cleanup;
  100. }
  101. r = radeon_bo_reserve(sobj, false);
  102. if (unlikely(r != 0))
  103. goto out_cleanup;
  104. r = radeon_bo_pin(sobj, sdomain, &saddr);
  105. radeon_bo_unreserve(sobj);
  106. if (r) {
  107. goto out_cleanup;
  108. }
  109. r = radeon_bo_create(rdev, size, PAGE_SIZE, true, ddomain, &dobj);
  110. if (r) {
  111. goto out_cleanup;
  112. }
  113. r = radeon_bo_reserve(dobj, false);
  114. if (unlikely(r != 0))
  115. goto out_cleanup;
  116. r = radeon_bo_pin(dobj, ddomain, &daddr);
  117. radeon_bo_unreserve(dobj);
  118. if (r) {
  119. goto out_cleanup;
  120. }
  121. /* r100 doesn't have dma engine so skip the test */
  122. /* also, VRAM-to-VRAM test doesn't make much sense for DMA */
  123. /* skip it as well if domains are the same */
  124. if ((rdev->asic->copy.dma) && (sdomain != ddomain)) {
  125. time = radeon_benchmark_do_move(rdev, size, saddr, daddr,
  126. RADEON_BENCHMARK_COPY_DMA, n);
  127. if (time < 0)
  128. goto out_cleanup;
  129. if (time > 0)
  130. radeon_benchmark_log_results(n, size, time,
  131. sdomain, ddomain, "dma");
  132. }
  133. if (rdev->asic->copy.blit) {
  134. time = radeon_benchmark_do_move(rdev, size, saddr, daddr,
  135. RADEON_BENCHMARK_COPY_BLIT, n);
  136. if (time < 0)
  137. goto out_cleanup;
  138. if (time > 0)
  139. radeon_benchmark_log_results(n, size, time,
  140. sdomain, ddomain, "blit");
  141. }
  142. out_cleanup:
  143. if (sobj) {
  144. r = radeon_bo_reserve(sobj, false);
  145. if (likely(r == 0)) {
  146. radeon_bo_unpin(sobj);
  147. radeon_bo_unreserve(sobj);
  148. }
  149. radeon_bo_unref(&sobj);
  150. }
  151. if (dobj) {
  152. r = radeon_bo_reserve(dobj, false);
  153. if (likely(r == 0)) {
  154. radeon_bo_unpin(dobj);
  155. radeon_bo_unreserve(dobj);
  156. }
  157. radeon_bo_unref(&dobj);
  158. }
  159. if (r) {
  160. DRM_ERROR("Error while benchmarking BO move.\n");
  161. }
  162. }
  163. void radeon_benchmark(struct radeon_device *rdev, int test_number)
  164. {
  165. int i;
  166. int common_modes[RADEON_BENCHMARK_COMMON_MODES_N] = {
  167. 640 * 480 * 4,
  168. 720 * 480 * 4,
  169. 800 * 600 * 4,
  170. 848 * 480 * 4,
  171. 1024 * 768 * 4,
  172. 1152 * 768 * 4,
  173. 1280 * 720 * 4,
  174. 1280 * 800 * 4,
  175. 1280 * 854 * 4,
  176. 1280 * 960 * 4,
  177. 1280 * 1024 * 4,
  178. 1440 * 900 * 4,
  179. 1400 * 1050 * 4,
  180. 1680 * 1050 * 4,
  181. 1600 * 1200 * 4,
  182. 1920 * 1080 * 4,
  183. 1920 * 1200 * 4
  184. };
  185. switch (test_number) {
  186. case 1:
  187. /* simple test, VRAM to GTT and GTT to VRAM */
  188. radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_GTT,
  189. RADEON_GEM_DOMAIN_VRAM);
  190. radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_VRAM,
  191. RADEON_GEM_DOMAIN_GTT);
  192. break;
  193. case 2:
  194. /* simple test, VRAM to VRAM */
  195. radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_VRAM,
  196. RADEON_GEM_DOMAIN_VRAM);
  197. break;
  198. case 3:
  199. /* GTT to VRAM, buffer size sweep, powers of 2 */
  200. for (i = 1; i <= 16384; i <<= 1)
  201. radeon_benchmark_move(rdev, i * RADEON_GPU_PAGE_SIZE,
  202. RADEON_GEM_DOMAIN_GTT,
  203. RADEON_GEM_DOMAIN_VRAM);
  204. break;
  205. case 4:
  206. /* VRAM to GTT, buffer size sweep, powers of 2 */
  207. for (i = 1; i <= 16384; i <<= 1)
  208. radeon_benchmark_move(rdev, i * RADEON_GPU_PAGE_SIZE,
  209. RADEON_GEM_DOMAIN_VRAM,
  210. RADEON_GEM_DOMAIN_GTT);
  211. break;
  212. case 5:
  213. /* VRAM to VRAM, buffer size sweep, powers of 2 */
  214. for (i = 1; i <= 16384; i <<= 1)
  215. radeon_benchmark_move(rdev, i * RADEON_GPU_PAGE_SIZE,
  216. RADEON_GEM_DOMAIN_VRAM,
  217. RADEON_GEM_DOMAIN_VRAM);
  218. break;
  219. case 6:
  220. /* GTT to VRAM, buffer size sweep, common modes */
  221. for (i = 0; i < RADEON_BENCHMARK_COMMON_MODES_N; i++)
  222. radeon_benchmark_move(rdev, common_modes[i],
  223. RADEON_GEM_DOMAIN_GTT,
  224. RADEON_GEM_DOMAIN_VRAM);
  225. break;
  226. case 7:
  227. /* VRAM to GTT, buffer size sweep, common modes */
  228. for (i = 0; i < RADEON_BENCHMARK_COMMON_MODES_N; i++)
  229. radeon_benchmark_move(rdev, common_modes[i],
  230. RADEON_GEM_DOMAIN_VRAM,
  231. RADEON_GEM_DOMAIN_GTT);
  232. break;
  233. case 8:
  234. /* VRAM to VRAM, buffer size sweep, common modes */
  235. for (i = 0; i < RADEON_BENCHMARK_COMMON_MODES_N; i++)
  236. radeon_benchmark_move(rdev, common_modes[i],
  237. RADEON_GEM_DOMAIN_VRAM,
  238. RADEON_GEM_DOMAIN_VRAM);
  239. break;
  240. default:
  241. DRM_ERROR("Unknown benchmark\n");
  242. }
  243. }