radeon_benchmark.c 6.8 KB

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