- patches.suse/slab-handle-memoryless-nodes-v2a.patch: Refresh.
[linux-flexiantxendom0-3.2.10.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 void radeon_benchmark_move(struct radeon_device *rdev, unsigned bsize,
30                            unsigned sdomain, unsigned ddomain)
31 {
32         struct radeon_bo *dobj = NULL;
33         struct radeon_bo *sobj = NULL;
34         struct radeon_fence *fence = NULL;
35         uint64_t saddr, daddr;
36         unsigned long start_jiffies;
37         unsigned long end_jiffies;
38         unsigned long time;
39         unsigned i, n, size;
40         int r;
41
42         size = bsize;
43         n = 1024;
44         r = radeon_bo_create(rdev, NULL, size, true, sdomain, &sobj);
45         if (r) {
46                 goto out_cleanup;
47         }
48         r = radeon_bo_reserve(sobj, false);
49         if (unlikely(r != 0))
50                 goto out_cleanup;
51         r = radeon_bo_pin(sobj, sdomain, &saddr);
52         radeon_bo_unreserve(sobj);
53         if (r) {
54                 goto out_cleanup;
55         }
56         r = radeon_bo_create(rdev, NULL, size, true, ddomain, &dobj);
57         if (r) {
58                 goto out_cleanup;
59         }
60         r = radeon_bo_reserve(dobj, false);
61         if (unlikely(r != 0))
62                 goto out_cleanup;
63         r = radeon_bo_pin(dobj, ddomain, &daddr);
64         radeon_bo_unreserve(dobj);
65         if (r) {
66                 goto out_cleanup;
67         }
68         start_jiffies = jiffies;
69         for (i = 0; i < n; i++) {
70                 r = radeon_fence_create(rdev, &fence);
71                 if (r) {
72                         goto out_cleanup;
73                 }
74                 r = radeon_copy_dma(rdev, saddr, daddr, size / RADEON_GPU_PAGE_SIZE, fence);
75                 if (r) {
76                         goto out_cleanup;
77                 }
78                 r = radeon_fence_wait(fence, false);
79                 if (r) {
80                         goto out_cleanup;
81                 }
82                 radeon_fence_unref(&fence);
83         }
84         end_jiffies = jiffies;
85         time = end_jiffies - start_jiffies;
86         time = jiffies_to_msecs(time);
87         if (time > 0) {
88                 i = ((n * size) >> 10) / time;
89                 printk(KERN_INFO "radeon: dma %u bo moves of %ukb from %d to %d"
90                        " in %lums (%ukb/ms %ukb/s %uM/s)\n", n, size >> 10,
91                        sdomain, ddomain, time, i, i * 1000, (i * 1000) / 1024);
92         }
93         start_jiffies = jiffies;
94         for (i = 0; i < n; i++) {
95                 r = radeon_fence_create(rdev, &fence);
96                 if (r) {
97                         goto out_cleanup;
98                 }
99                 r = radeon_copy_blit(rdev, saddr, daddr, size / RADEON_GPU_PAGE_SIZE, fence);
100                 if (r) {
101                         goto out_cleanup;
102                 }
103                 r = radeon_fence_wait(fence, false);
104                 if (r) {
105                         goto out_cleanup;
106                 }
107                 radeon_fence_unref(&fence);
108         }
109         end_jiffies = jiffies;
110         time = end_jiffies - start_jiffies;
111         time = jiffies_to_msecs(time);
112         if (time > 0) {
113                 i = ((n * size) >> 10) / time;
114                 printk(KERN_INFO "radeon: blit %u bo moves of %ukb from %d to %d"
115                        " in %lums (%ukb/ms %ukb/s %uM/s)\n", n, size >> 10,
116                        sdomain, ddomain, time, i, i * 1000, (i * 1000) / 1024);
117         }
118 out_cleanup:
119         if (sobj) {
120                 r = radeon_bo_reserve(sobj, false);
121                 if (likely(r == 0)) {
122                         radeon_bo_unpin(sobj);
123                         radeon_bo_unreserve(sobj);
124                 }
125                 radeon_bo_unref(&sobj);
126         }
127         if (dobj) {
128                 r = radeon_bo_reserve(dobj, false);
129                 if (likely(r == 0)) {
130                         radeon_bo_unpin(dobj);
131                         radeon_bo_unreserve(dobj);
132                 }
133                 radeon_bo_unref(&dobj);
134         }
135         if (fence) {
136                 radeon_fence_unref(&fence);
137         }
138         if (r) {
139                 printk(KERN_WARNING "Error while benchmarking BO move.\n");
140         }
141 }
142
143 void radeon_benchmark(struct radeon_device *rdev)
144 {
145         radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_GTT,
146                               RADEON_GEM_DOMAIN_VRAM);
147         radeon_benchmark_move(rdev, 1024*1024, RADEON_GEM_DOMAIN_VRAM,
148                               RADEON_GEM_DOMAIN_GTT);
149 }