Subversion Repositories Kolibri OS

Rev

Rev 2007 | Go to most recent revision | Details | 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
 
29
unsigned int inline jiffies_to_msecs(const unsigned long j)
30
{
31
    return (10 * j);
32
};
33
 
34
 
35
void radeon_benchmark_move(struct radeon_device *rdev, unsigned bsize,
36
			   unsigned sdomain, unsigned ddomain)
37
{
38
	struct radeon_bo *dobj = NULL;
39
	struct radeon_bo *sobj = NULL;
40
	struct radeon_fence *fence = NULL;
41
	uint64_t saddr, daddr;
42
	unsigned long start_jiffies;
43
	unsigned long end_jiffies;
44
	unsigned long time;
45
	unsigned i, n, size;
46
	int r;
47
 
48
    ENTER();
49
 
50
	size = bsize;
51
    n = 2; //1024;
52
 
53
    dbgprintf("source domain %x\n", sdomain);
54
 
55
	r = radeon_bo_create(rdev, size, PAGE_SIZE, true, sdomain, &sobj);
56
	if (r) {
57
		goto out_cleanup;
58
	}
59
	r = radeon_bo_reserve(sobj, false);
60
	if (unlikely(r != 0))
61
		goto out_cleanup;
62
	r = radeon_bo_pin(sobj, sdomain, &saddr);
63
//   radeon_bo_unreserve(sobj);
64
	if (r) {
65
		goto out_cleanup;
66
	}
67
 
68
    dbgprintf("destination domain %x\n", ddomain);
69
 
70
	r = radeon_bo_create(rdev, size, PAGE_SIZE, true, ddomain, &dobj);
71
	if (r) {
72
		goto out_cleanup;
73
	}
74
	r = radeon_bo_reserve(dobj, false);
75
	if (unlikely(r != 0))
76
		goto out_cleanup;
77
	r = radeon_bo_pin(dobj, ddomain, &daddr);
78
//   radeon_bo_unreserve(dobj);
79
	if (r) {
80
		goto out_cleanup;
81
	}
82
    dbgprintf("done\n");
83
 
84
	/* r100 doesn't have dma engine so skip the test */
85
	if (rdev->asic->copy_dma) {
86
 
87
        dbgprintf("copy dma\n");
88
 
89
        start_jiffies = GetTimerTicks();
90
		for (i = 0; i < n; i++) {
91
			r = radeon_fence_create(rdev, &fence);
92
			if (r) {
93
				goto out_cleanup;
94
			}
95
 
96
			r = radeon_copy_dma(rdev, saddr, daddr,
97
					size / RADEON_GPU_PAGE_SIZE, fence);
98
 
99
			if (r) {
100
				goto out_cleanup;
101
			}
102
			r = radeon_fence_wait(fence, false);
103
			if (r) {
104
				goto out_cleanup;
105
			}
106
			radeon_fence_unref(&fence);
107
		}
108
        end_jiffies = GetTimerTicks();
109
		time = end_jiffies - start_jiffies;
110
		time = jiffies_to_msecs(time);
111
		if (time > 0) {
112
			i = ((n * size) >> 10) / time;
113
			printk(KERN_INFO "radeon: dma %u bo moves of %ukb from"
114
					" %d to %d in %lums (%ukb/ms %ukb/s %uM/s)\n",
115
					n, size >> 10,
116
					sdomain, ddomain, time,
117
					i, i * 1000, (i * 1000) / 1024);
118
		}
119
	}
120
 
121
    start_jiffies = GetTimerTicks();
122
	for (i = 0; i < n; i++) {
123
		r = radeon_fence_create(rdev, &fence);
124
		if (r) {
125
			goto out_cleanup;
126
		}
127
		r = radeon_copy_blit(rdev, saddr, daddr, size / RADEON_GPU_PAGE_SIZE, fence);
128
		if (r) {
129
			goto out_cleanup;
130
		}
131
		r = radeon_fence_wait(fence, false);
132
		if (r) {
133
			goto out_cleanup;
134
		}
135
		radeon_fence_unref(&fence);
136
	}
137
    end_jiffies = GetTimerTicks();
138
	time = end_jiffies - start_jiffies;
139
	time = jiffies_to_msecs(time);
140
	if (time > 0) {
141
		i = ((n * size) >> 10) / time;
142
		printk(KERN_INFO "radeon: blit %u bo moves of %ukb from %d to %d"
143
		       " in %lums (%ukb/ms %ukb/s %uM/s)\n", n, size >> 10,
144
		       sdomain, ddomain, time, i, i * 1000, (i * 1000) / 1024);
145
	}
146
out_cleanup:
147
 
148
    dbgprintf("cleanup\n");
149
 
150
	if (sobj) {
151
		r = radeon_bo_reserve(sobj, false);
152
		if (likely(r == 0)) {
153
			radeon_bo_unpin(sobj);
154
			radeon_bo_unreserve(sobj);
155
		}
156
		radeon_bo_unref(&sobj);
157
	}
158
	if (dobj) {
159
		r = radeon_bo_reserve(dobj, false);
160
		if (likely(r == 0)) {
161
			radeon_bo_unpin(dobj);
162
			radeon_bo_unreserve(dobj);
163
		}
164
		radeon_bo_unref(&dobj);
165
	}
166
	if (fence) {
167
		radeon_fence_unref(&fence);
168
	}
169
	if (r) {
170
		printk(KERN_WARNING "Error while benchmarking BO move.\n");
171
	}
172
 
173
    LEAVE();
174
 
175
}
176
 
177
void radeon_benchmark(struct radeon_device *rdev)
178
{
179
   radeon_benchmark_move(rdev, 8192*4096, RADEON_GEM_DOMAIN_GTT,
180
                 RADEON_GEM_DOMAIN_VRAM);
181
   radeon_benchmark_move(rdev, 8192*4096, RADEON_GEM_DOMAIN_VRAM,
182
                 RADEON_GEM_DOMAIN_GTT);
183
   radeon_benchmark_move(rdev, 8192*4096, RADEON_GEM_DOMAIN_VRAM,
184
                 RADEON_GEM_DOMAIN_VRAM);
185
}