-
Notifications
You must be signed in to change notification settings - Fork 2
/
bltTest.cpp
229 lines (195 loc) · 5.89 KB
/
bltTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* Program bltTest.cpp
*
* This test program will copy data to and from the screen
* as rapidly as possible, counting the number of iterations
* in 2 seconds.
*
*
* Change History :
*
* $Log: bltTest.cpp,v $
* Revision 1.1 2006-06-14 13:54:38 ericn
* -Initial import
*
*
* Copyright Boundary Devices, Inc. 2006
*/
#include "fbDev.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include "tickMs.h"
static bool volatile done = false ;
static void handler( int sig )
{
done = true ;
}
static void blt( void *dest, void *src, unsigned rows, unsigned bytesPerRow )
{
unsigned long const *srcLongs = (unsigned long const *)src ;
unsigned long *destLongs = (unsigned long *)dest ;
unsigned long const cacheLinesPerRow = bytesPerRow / 32 ;
__asm__ volatile (
" pld [%0, #0]\n"
" pld [%0, #32]\n"
" pld [%1, #0]\n"
" pld [%1, #32]\n"
" pld [%0, #64]\n"
" pld [%0, #96]\n"
" pld [%1, #64]\n"
" pld [%1, #96]\n"
:
: "r" (destLongs), "r" (srcLongs)
);
for( unsigned y = 0 ; y < rows ; y++ )
{
for( unsigned x = 0 ; x < cacheLinesPerRow ; x++ )
{
*destLongs++ = *srcLongs++ ;
*destLongs++ = *srcLongs++ ;
*destLongs++ = *srcLongs++ ;
*destLongs++ = *srcLongs++ ;
*destLongs++ = *srcLongs++ ;
*destLongs++ = *srcLongs++ ;
*destLongs++ = *srcLongs++ ;
*destLongs++ = *srcLongs++ ;
__asm__ volatile (
" pld [%0, #96]\n"
" pld [%1, #96]\n"
:
: "r" (destLongs), "r" (srcLongs)
);
}
}
}
int main( int argc, char const * const argv[] )
{
fbDevice_t &fb = getFB();
void *const dataMem = malloc(fb.getMemSize());
void *const dataMem2 = malloc(fb.getMemSize());
signal (SIGALRM, handler);
/*
* Set the timer up to be non repeating, so that once it expires, it
* doesn't start another cycle. What you do depends on what you need
* in a particular application.
*/
struct itimerval itimer;
int interval = 2; /* 1 second interval */
itimer . it_interval . tv_sec = 0;
itimer . it_interval . tv_usec = 0;
/*
* Set the time to expiration to interval seconds.
* The timer resolution is milliseconds.
*/
itimer . it_value . tv_sec = interval;
itimer . it_value . tv_usec = 0;
unsigned readCount = 0 ;
unsigned writeCount = 0 ;
unsigned long readTime = 0 ;
unsigned long writeTime = 0 ;
done = false ; setitimer (ITIMER_REAL, &itimer, NULL);
while( !done )
{
long long start = tickMs();
memcpy( dataMem, fb.getMem(), fb.getMemSize() );
readTime += (unsigned long)(tickMs()-start);
readCount++ ;
// printf( "r" ); fflush(stdout);
if( !done )
{
start = tickMs();
memcpy( fb.getMem(), dataMem, fb.getMemSize() );
writeTime += (unsigned long)(tickMs()-start);
writeCount++ ;
// printf( "w" ); fflush(stdout);
}
}
printf( "\n%u/%u iterations in %u seconds system<->fb (memcpy)\n", readCount, writeCount, interval );
printf( " %lu ms read\n", readTime );
printf( " %lu ms write\n", writeTime );
memcpy( dataMem2, dataMem, fb.getMemSize() );
readCount = 0 ;
writeCount = 0 ;
readTime = 0 ;
writeTime = 0 ;
done = false ; setitimer (ITIMER_REAL, &itimer, NULL);
while( !done )
{
long long start = tickMs();
memcpy( dataMem, dataMem2, fb.getMemSize() );
readTime += (unsigned long)(tickMs()-start);
readCount++ ;
// printf( "r" ); fflush(stdout);
if( !done )
{
start = tickMs();
memcpy( dataMem2, dataMem, fb.getMemSize() );
writeTime += (unsigned long)(tickMs()-start);
writeCount++ ;
// printf( "w" ); fflush(stdout);
}
}
printf( "\n%u/%u iterations in %u seconds system<->system (memcpy)\n", readCount, writeCount, interval );
printf( " %lu ms read\n", readTime );
printf( " %lu ms write\n", writeTime );
/*
* hand-crafted blt
*
*/
unsigned const stride = fb.getStride();
readCount = 0 ;
writeCount = 0 ;
readTime = 0 ;
writeTime = 0 ;
done = false ; setitimer (ITIMER_REAL, &itimer, NULL);
while( !done )
{
long long start = tickMs();
blt( dataMem, fb.getMem(), fb.getHeight(), stride );
readTime += (unsigned long)(tickMs()-start);
readCount++ ;
// printf( "r" ); fflush(stdout);
if( !done )
{
start = tickMs();
blt( fb.getMem(), dataMem, fb.getHeight(), stride );
writeTime += (unsigned long)(tickMs()-start);
writeCount++ ;
// printf( "w" ); fflush(stdout);
}
}
printf( "\n%u/%u iterations in %u seconds system<->fb (blt)\n", readCount, writeCount, interval );
printf( " %lu ms read\n", readTime );
printf( " %lu ms write\n", writeTime );
readCount = 0 ;
writeCount = 0 ;
readTime = 0 ;
writeTime = 0 ;
done = false ; setitimer (ITIMER_REAL, &itimer, NULL);
while( !done )
{
long long start = tickMs();
blt( dataMem, dataMem2, fb.getHeight(), stride );
readTime += (unsigned long)(tickMs()-start);
readCount++ ;
// printf( "r" ); fflush(stdout);
if( !done )
{
start = tickMs();
blt( dataMem2, dataMem, fb.getHeight(), stride );
writeTime += (unsigned long)(tickMs()-start);
writeCount++ ;
// printf( "w" ); fflush(stdout);
}
}
printf( "\n%u/%u iterations in %u seconds system<->system (blt)\n", readCount, writeCount, interval );
printf( " %lu ms read\n", readTime );
printf( " %lu ms write\n", writeTime );
return 0 ;
}