Subversion Repositories Kolibri OS

Rev

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