Subversion Repositories Kolibri OS

Rev

Rev 2007 | Rev 3031 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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