drm/radeon/kms: cleanup benchmark code
[deliverable/linux.git] / drivers / gpu / drm / radeon / radeon_benchmark.c
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
29 #define RADEON_BENCHMARK_COPY_BLIT 1
30 #define RADEON_BENCHMARK_COPY_DMA 0
31
32 #define RADEON_BENCHMARK_ITERATIONS 1024
33
34 static int radeon_benchmark_do_move(struct radeon_device *rdev, unsigned size,
35 uint64_t saddr, uint64_t daddr,
36 int flag, int n)
37 {
38 unsigned long start_jiffies;
39 unsigned long end_jiffies;
40 struct radeon_fence *fence = NULL;
41 int i, r;
42
43 start_jiffies = jiffies;
44 for (i = 0; i < n; i++) {
45 r = radeon_fence_create(rdev, &fence);
46 if (r)
47 return r;
48
49 switch (flag) {
50 case RADEON_BENCHMARK_COPY_DMA:
51 r = radeon_copy_dma(rdev, saddr, daddr,
52 size / RADEON_GPU_PAGE_SIZE,
53 fence);
54 break;
55 case RADEON_BENCHMARK_COPY_BLIT:
56 r = radeon_copy_blit(rdev, saddr, daddr,
57 size / RADEON_GPU_PAGE_SIZE,
58 fence);
59 break;
60 default:
61 DRM_ERROR("Unknown copy method\n");
62 r = -EINVAL;
63 }
64 if (r)
65 goto exit_do_move;
66 r = radeon_fence_wait(fence, false);
67 if (r)
68 goto exit_do_move;
69 radeon_fence_unref(&fence);
70 }
71 end_jiffies = jiffies;
72 r = jiffies_to_msecs(end_jiffies - start_jiffies);
73
74 exit_do_move:
75 if (fence)
76 radeon_fence_unref(&fence);
77 return r;
78 }
79
80
81 static void radeon_benchmark_log_results(int n, unsigned size,
82 unsigned int time,
83 unsigned sdomain, unsigned ddomain,
84 char *kind)
85 {
86 unsigned int throughput = (n * (size >> 10)) / time;
87 DRM_INFO("radeon: %s %u bo moves of %u kB from"
88 " %d to %d in %u ms, throughput: %u Mb/s or %u MB/s\n",
89 kind, n, size >> 10, sdomain, ddomain, time,
90 throughput * 8, throughput);
91 }
92
93 static void radeon_benchmark_move(struct radeon_device *rdev, unsigned size,
94 unsigned sdomain, unsigned ddomain)
95 {
96 struct radeon_bo *dobj = NULL;
97 struct radeon_bo *sobj = NULL;
98 uint64_t saddr, daddr;
99 int r, n;
100 unsigned int time;
101
102 n = RADEON_BENCHMARK_ITERATIONS;
103 r = radeon_bo_create(rdev, size, PAGE_SIZE, true, sdomain, &sobj);
104 if (r) {
105 goto out_cleanup;
106 }
107 r = radeon_bo_reserve(sobj, false);
108 if (unlikely(r != 0))
109 goto out_cleanup;
110 r = radeon_bo_pin(sobj, sdomain, &saddr);
111 radeon_bo_unreserve(sobj);
112 if (r) {
113 goto out_cleanup;
114 }
115 r = radeon_bo_create(rdev, size, PAGE_SIZE, true, ddomain, &dobj);
116 if (r) {
117 goto out_cleanup;
118 }
119 r = radeon_bo_reserve(dobj, false);
120 if (unlikely(r != 0))
121 goto out_cleanup;
122 r = radeon_bo_pin(dobj, ddomain, &daddr);
123 radeon_bo_unreserve(dobj);
124 if (r) {
125 goto out_cleanup;
126 }
127
128 /* r100 doesn't have dma engine so skip the test */
129 if (rdev->asic->copy_dma) {
130 time = radeon_benchmark_do_move(rdev, size, saddr, daddr,
131 RADEON_BENCHMARK_COPY_DMA, n);
132 if (time < 0)
133 goto out_cleanup;
134 if (time > 0)
135 radeon_benchmark_log_results(n, size, time,
136 sdomain, ddomain, "dma");
137 }
138
139 time = radeon_benchmark_do_move(rdev, size, saddr, daddr,
140 RADEON_BENCHMARK_COPY_BLIT, n);
141 if (time < 0)
142 goto out_cleanup;
143 if (time > 0)
144 radeon_benchmark_log_results(n, size, time,
145 sdomain, ddomain, "blit");
146
147 out_cleanup:
148 if (sobj) {
149 r = radeon_bo_reserve(sobj, false);
150 if (likely(r == 0)) {
151 radeon_bo_unpin(sobj);
152 radeon_bo_unreserve(sobj);
153 }
154 radeon_bo_unref(&sobj);
155 }
156 if (dobj) {
157 r = radeon_bo_reserve(dobj, false);
158 if (likely(r == 0)) {
159 radeon_bo_unpin(dobj);
160 radeon_bo_unreserve(dobj);
161 }
162 radeon_bo_unref(&dobj);
163 }
164
165 if (r) {
166 DRM_ERROR("Error while benchmarking BO move.\n");
167 }
168 }
169
170 void radeon_benchmark(struct radeon_device *rdev)
171 {
172 radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_GTT,
173 RADEON_GEM_DOMAIN_VRAM);
174 radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_VRAM,
175 RADEON_GEM_DOMAIN_GTT);
176 }
This page took 0.035172 seconds and 5 git commands to generate.