radeon_benchmark.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. void radeon_benchmark_move(struct radeon_device *rdev, unsigned bsize,
  29. unsigned sdomain, unsigned ddomain)
  30. {
  31. struct radeon_bo *dobj = NULL;
  32. struct radeon_bo *sobj = NULL;
  33. struct radeon_fence *fence = NULL;
  34. uint64_t saddr, daddr;
  35. unsigned long start_jiffies;
  36. unsigned long end_jiffies;
  37. unsigned long time;
  38. unsigned i, n, size;
  39. int r;
  40. size = bsize;
  41. n = 1024;
  42. r = radeon_bo_create(rdev, NULL, size, true, sdomain, &sobj);
  43. if (r) {
  44. goto out_cleanup;
  45. }
  46. r = radeon_bo_reserve(sobj, false);
  47. if (unlikely(r != 0))
  48. goto out_cleanup;
  49. r = radeon_bo_pin(sobj, sdomain, &saddr);
  50. radeon_bo_unreserve(sobj);
  51. if (r) {
  52. goto out_cleanup;
  53. }
  54. r = radeon_bo_create(rdev, NULL, size, true, ddomain, &dobj);
  55. if (r) {
  56. goto out_cleanup;
  57. }
  58. r = radeon_bo_reserve(dobj, false);
  59. if (unlikely(r != 0))
  60. goto out_cleanup;
  61. r = radeon_bo_pin(dobj, ddomain, &daddr);
  62. radeon_bo_unreserve(dobj);
  63. if (r) {
  64. goto out_cleanup;
  65. }
  66. start_jiffies = jiffies;
  67. for (i = 0; i < n; i++) {
  68. r = radeon_fence_create(rdev, &fence);
  69. if (r) {
  70. goto out_cleanup;
  71. }
  72. r = radeon_copy_dma(rdev, saddr, daddr, size / RADEON_GPU_PAGE_SIZE, fence);
  73. if (r) {
  74. goto out_cleanup;
  75. }
  76. r = radeon_fence_wait(fence, false);
  77. if (r) {
  78. goto out_cleanup;
  79. }
  80. radeon_fence_unref(&fence);
  81. }
  82. end_jiffies = jiffies;
  83. time = end_jiffies - start_jiffies;
  84. time = jiffies_to_msecs(time);
  85. if (time > 0) {
  86. i = ((n * size) >> 10) / time;
  87. printk(KERN_INFO "radeon: dma %u bo moves of %ukb from %d to %d"
  88. " in %lums (%ukb/ms %ukb/s %uM/s)\n", n, size >> 10,
  89. sdomain, ddomain, time, i, i * 1000, (i * 1000) / 1024);
  90. }
  91. start_jiffies = jiffies;
  92. for (i = 0; i < n; i++) {
  93. r = radeon_fence_create(rdev, &fence);
  94. if (r) {
  95. goto out_cleanup;
  96. }
  97. r = radeon_copy_blit(rdev, saddr, daddr, size / RADEON_GPU_PAGE_SIZE, fence);
  98. if (r) {
  99. goto out_cleanup;
  100. }
  101. r = radeon_fence_wait(fence, false);
  102. if (r) {
  103. goto out_cleanup;
  104. }
  105. radeon_fence_unref(&fence);
  106. }
  107. end_jiffies = jiffies;
  108. time = end_jiffies - start_jiffies;
  109. time = jiffies_to_msecs(time);
  110. if (time > 0) {
  111. i = ((n * size) >> 10) / time;
  112. printk(KERN_INFO "radeon: blit %u bo moves of %ukb from %d to %d"
  113. " in %lums (%ukb/ms %ukb/s %uM/s)\n", n, size >> 10,
  114. sdomain, ddomain, time, i, i * 1000, (i * 1000) / 1024);
  115. }
  116. out_cleanup:
  117. if (sobj) {
  118. r = radeon_bo_reserve(sobj, false);
  119. if (likely(r == 0)) {
  120. radeon_bo_unpin(sobj);
  121. radeon_bo_unreserve(sobj);
  122. }
  123. radeon_bo_unref(&sobj);
  124. }
  125. if (dobj) {
  126. r = radeon_bo_reserve(dobj, false);
  127. if (likely(r == 0)) {
  128. radeon_bo_unpin(dobj);
  129. radeon_bo_unreserve(dobj);
  130. }
  131. radeon_bo_unref(&dobj);
  132. }
  133. if (fence) {
  134. radeon_fence_unref(&fence);
  135. }
  136. if (r) {
  137. printk(KERN_WARNING "Error while benchmarking BO move.\n");
  138. }
  139. }
  140. void radeon_benchmark(struct radeon_device *rdev)
  141. {
  142. radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_GTT,
  143. RADEON_GEM_DOMAIN_VRAM);
  144. radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_VRAM,
  145. RADEON_GEM_DOMAIN_GTT);
  146. }