radeon_benchmark.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_object *dobj = NULL;
  32. struct radeon_object *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_object_create(rdev, NULL, size, true, sdomain, false, &sobj);
  43. if (r) {
  44. goto out_cleanup;
  45. }
  46. r = radeon_object_pin(sobj, sdomain, &saddr);
  47. if (r) {
  48. goto out_cleanup;
  49. }
  50. r = radeon_object_create(rdev, NULL, size, true, ddomain, false, &dobj);
  51. if (r) {
  52. goto out_cleanup;
  53. }
  54. r = radeon_object_pin(dobj, ddomain, &daddr);
  55. if (r) {
  56. goto out_cleanup;
  57. }
  58. start_jiffies = jiffies;
  59. for (i = 0; i < n; i++) {
  60. r = radeon_fence_create(rdev, &fence);
  61. if (r) {
  62. goto out_cleanup;
  63. }
  64. r = radeon_copy_dma(rdev, saddr, daddr, size >> 14, fence);
  65. if (r) {
  66. goto out_cleanup;
  67. }
  68. r = radeon_fence_wait(fence, false);
  69. if (r) {
  70. goto out_cleanup;
  71. }
  72. radeon_fence_unref(&fence);
  73. }
  74. end_jiffies = jiffies;
  75. time = end_jiffies - start_jiffies;
  76. time = jiffies_to_msecs(time);
  77. if (time > 0) {
  78. i = ((n * size) >> 10) / time;
  79. printk(KERN_INFO "radeon: dma %u bo moves of %ukb from %d to %d"
  80. " in %lums (%ukb/ms %ukb/s %uM/s)\n", n, size >> 10,
  81. sdomain, ddomain, time, i, i * 1000, (i * 1000) / 1024);
  82. }
  83. start_jiffies = jiffies;
  84. for (i = 0; i < n; i++) {
  85. r = radeon_fence_create(rdev, &fence);
  86. if (r) {
  87. goto out_cleanup;
  88. }
  89. r = radeon_copy_blit(rdev, saddr, daddr, size >> 14, fence);
  90. if (r) {
  91. goto out_cleanup;
  92. }
  93. r = radeon_fence_wait(fence, false);
  94. if (r) {
  95. goto out_cleanup;
  96. }
  97. radeon_fence_unref(&fence);
  98. }
  99. end_jiffies = jiffies;
  100. time = end_jiffies - start_jiffies;
  101. time = jiffies_to_msecs(time);
  102. if (time > 0) {
  103. i = ((n * size) >> 10) / time;
  104. printk(KERN_INFO "radeon: blit %u bo moves of %ukb from %d to %d"
  105. " in %lums (%ukb/ms %ukb/s %uM/s)\n", n, size >> 10,
  106. sdomain, ddomain, time, i, i * 1000, (i * 1000) / 1024);
  107. }
  108. out_cleanup:
  109. if (sobj) {
  110. radeon_object_unpin(sobj);
  111. radeon_object_unref(&sobj);
  112. }
  113. if (dobj) {
  114. radeon_object_unpin(dobj);
  115. radeon_object_unref(&dobj);
  116. }
  117. if (fence) {
  118. radeon_fence_unref(&fence);
  119. }
  120. if (r) {
  121. printk(KERN_WARNING "Error while benchmarking BO move.\n");
  122. }
  123. }
  124. void radeon_benchmark(struct radeon_device *rdev)
  125. {
  126. radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_GTT,
  127. RADEON_GEM_DOMAIN_VRAM);
  128. radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_VRAM,
  129. RADEON_GEM_DOMAIN_GTT);
  130. }