0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\bench\t_membm.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <e32std_private.h>
|
|
20 |
#include <e32base.h>
|
|
21 |
#include <e32base_private.h>
|
|
22 |
#include <e32test.h>
|
|
23 |
#include <e32svr.h>
|
|
24 |
|
|
25 |
#define ALIGN_UP(x, y) (TInt8*)(_ALIGN_UP((TInt)(x), (y)))
|
|
26 |
#define ALIGN_DOWN(x, y) (TInt8*)(_ALIGN_DOWN((TInt)(x), (y)))
|
|
27 |
|
|
28 |
const TInt KHeapSize=720*1024;
|
|
29 |
const TInt KAverageOverInMilliseconds=500;
|
|
30 |
const TInt Len64K = 64*1024;
|
|
31 |
|
|
32 |
volatile TInt count;
|
|
33 |
volatile TInt iters;
|
|
34 |
|
|
35 |
TInt8* trg;
|
|
36 |
TInt8* src;
|
|
37 |
TInt8* dummy;
|
|
38 |
TInt8 trgoffset;
|
|
39 |
TInt8 srcoffset;
|
|
40 |
TInt len=64*1024;
|
|
41 |
TInt64 result;
|
|
42 |
|
|
43 |
RTest test(_L("T_MEMBM"));
|
|
44 |
|
|
45 |
GLREF_C TInt MemBaseline(TAny*);
|
|
46 |
GLREF_C TInt MemCopy(TAny*);
|
|
47 |
GLREF_C TInt MemMove(TAny*);
|
|
48 |
GLREF_C TInt MemFill(TAny*);
|
|
49 |
GLREF_C TInt MemSwap(TAny*);
|
|
50 |
GLREF_C TInt WordMove(TAny*);
|
|
51 |
GLREF_C TInt MemCopyUncached(TAny*);
|
|
52 |
GLREF_C TInt WordMoveUncached(TAny*);
|
|
53 |
GLREF_C TInt MemFillUncached(TAny*);
|
|
54 |
GLREF_C TInt PurgeCache();
|
|
55 |
|
|
56 |
TInt nextLen(TInt aTestLength)
|
|
57 |
{
|
|
58 |
if (len == Len64K)
|
|
59 |
return 0;
|
|
60 |
if (!aTestLength)
|
|
61 |
return Len64K;
|
|
62 |
|
|
63 |
TInt inc = aTestLength;
|
|
64 |
for (TInt i = len >> 5 ; i ; i >>= 1)
|
|
65 |
inc <<= 1;
|
|
66 |
|
|
67 |
return len + inc;
|
|
68 |
}
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Run benchmarks on the supplied function.
|
|
72 |
*
|
|
73 |
* @param aFunction The function to benchmark
|
|
74 |
* @param aTestBackwards Run copy tests with overlapping areas to test backwards copy
|
|
75 |
* @param aTestSrcAlign Run tests for source alignments 0 - 31
|
|
76 |
* @param aTestDestAlign Run tests for destination alignments 0 - 31
|
|
77 |
* @param aTestLength If non-zero, run tests for different lengths starting at aTestLength
|
|
78 |
*/
|
|
79 |
TInt64 runTest(TThreadFunction aFunction,const TDesC& aTitle, TBool aTestBackwards, TBool aTestSrcAlign, TBool aTestDestAlign, TInt aTestLength)
|
|
80 |
{
|
|
81 |
TInt8* buffer = (TInt8*)User::Alloc(640 * 1024 + 32);
|
|
82 |
test(buffer != 0);
|
|
83 |
|
|
84 |
test(!(aTestLength && aTestBackwards)); // not supported
|
|
85 |
|
|
86 |
TBool goingforward=ETrue;
|
|
87 |
|
|
88 |
FOREVER
|
|
89 |
{
|
|
90 |
if (aTestLength)
|
|
91 |
test.Printf(_L("Running length experiment on %S. Results follow:\n"), &aTitle);
|
|
92 |
|
|
93 |
len = 0;
|
|
94 |
while(len = nextLen(aTestLength), len)
|
|
95 |
{
|
|
96 |
src = ALIGN_UP(buffer, 32);
|
|
97 |
if (goingforward)
|
|
98 |
trg = src + 512 * 1024; // blow half a meg
|
|
99 |
else
|
|
100 |
trg = ALIGN_DOWN(src + len - 1, 32); // ensure overlapping, doesn't work for length < 32
|
|
101 |
|
|
102 |
if (aTestLength)
|
|
103 |
test.Printf(_L("%d, "), len);
|
|
104 |
else
|
|
105 |
test.Printf(_L("Test array bases trg=0x%08x, src=0x%08x. Running experiment on %S. Results follow:\n"), trg, src, &aTitle);
|
|
106 |
|
|
107 |
const TInt xsquare = aTestDestAlign ? 32 : 1;
|
|
108 |
const TInt ysquare = aTestSrcAlign ? 32 : 1;
|
|
109 |
|
|
110 |
for (srcoffset = 0 ; srcoffset < ysquare ; srcoffset++)
|
|
111 |
{
|
|
112 |
for (trgoffset = 0 ; trgoffset < xsquare ; trgoffset++)
|
|
113 |
{
|
|
114 |
RThread thread;
|
|
115 |
TInt r=thread.Create(aTitle,aFunction,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
|
|
116 |
if(r!=KErrNone)
|
|
117 |
{
|
|
118 |
test.Printf(_L("Failed to create thread with error %d\n"),r);
|
|
119 |
return(r);
|
|
120 |
}
|
|
121 |
thread.SetPriority(EPriorityLess);
|
|
122 |
thread.Resume();
|
|
123 |
User::After(50000); // 50 msec is more than enough in EKA2
|
|
124 |
count=0;
|
|
125 |
User::After(5000); // even if the second reset fails, max inaccuracy is 5000 usecs
|
|
126 |
count=0; // try and reduce the probability of failing to reset
|
|
127 |
User::After(KAverageOverInMilliseconds*1000);
|
|
128 |
result=count;
|
|
129 |
thread.Kill(0);
|
|
130 |
CLOSE_AND_WAIT(thread);
|
|
131 |
PurgeCache();
|
|
132 |
|
|
133 |
result *= 1000;
|
|
134 |
result /= KAverageOverInMilliseconds;
|
|
135 |
|
|
136 |
TInt s = I64INT(result);
|
|
137 |
test.Printf(_L("%d, "),s);
|
|
138 |
}
|
|
139 |
test.Printf(_L("\n"));
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
if (aTestBackwards && goingforward)
|
|
144 |
goingforward = EFalse;
|
|
145 |
else
|
|
146 |
break;
|
|
147 |
}
|
|
148 |
|
|
149 |
User::Free(buffer);
|
|
150 |
|
|
151 |
return(result);
|
|
152 |
}
|
|
153 |
|
|
154 |
enum TTestType
|
|
155 |
{
|
|
156 |
ENormalTests,
|
|
157 |
EFullTests,
|
|
158 |
ELengthTests,
|
|
159 |
};
|
|
160 |
|
|
161 |
// Return whether we should run the full alignment benchmarks
|
|
162 |
TTestType ParseCommandLine()
|
|
163 |
{
|
|
164 |
TBuf<32> args;
|
|
165 |
User::CommandLine(args);
|
|
166 |
|
|
167 |
if (args == _L("-f"))
|
|
168 |
return EFullTests;
|
|
169 |
else if (args == _L("-l"))
|
|
170 |
return ELengthTests;
|
|
171 |
else if (args != KNullDesC)
|
|
172 |
{
|
|
173 |
test.Printf(_L("usage: t_membm [OPTIONS]\n"));
|
|
174 |
test.Printf(_L(" -f Run full alignment benchmarks\n"));
|
|
175 |
test.Printf(_L(" -l Run memcpy length benchmarks\n"));
|
|
176 |
test(EFalse);
|
|
177 |
}
|
|
178 |
|
|
179 |
return ENormalTests;
|
|
180 |
}
|
|
181 |
|
|
182 |
TInt E32Main()
|
|
183 |
//
|
|
184 |
// Benchmark for Mem functions
|
|
185 |
//
|
|
186 |
{
|
|
187 |
|
|
188 |
test.Title();
|
|
189 |
test.Start(_L("Benchmarks for Mem functions"));
|
|
190 |
|
|
191 |
TTestType testType = ParseCommandLine();
|
|
192 |
|
|
193 |
switch (testType)
|
|
194 |
{
|
|
195 |
case ENormalTests:
|
|
196 |
case EFullTests:
|
|
197 |
{
|
|
198 |
TBool srcAlign = testType == EFullTests;
|
|
199 |
|
|
200 |
if (srcAlign)
|
|
201 |
test.Printf(_L("Running full alignment benchmarks (may take a long time)\n"));
|
|
202 |
else
|
|
203 |
test.Printf(_L("Not testing source alignment (run with -f if you want this)\n"));
|
|
204 |
|
|
205 |
runTest(MemBaseline, _L("Processor baseline"), EFalse, EFalse, EFalse, 0);
|
|
206 |
runTest(MemFill, _L("Memory fill"), EFalse, EFalse, ETrue, 0);
|
|
207 |
runTest(MemCopy, _L("Memory copy"), ETrue, srcAlign, ETrue, 0);
|
|
208 |
runTest(MemSwap, _L("Memory swap"), ETrue, srcAlign, ETrue, 0);
|
|
209 |
}
|
|
210 |
break;
|
|
211 |
case ELengthTests:
|
|
212 |
test.Printf(_L("Running length benchmarks (may take a long time)\n"));
|
|
213 |
runTest(MemFill, _L("Fill length cached"), EFalse, EFalse, EFalse, 1);
|
|
214 |
runTest(MemFillUncached, _L("Fill length uncached"), EFalse, EFalse, EFalse, 1);
|
|
215 |
runTest(MemCopy, _L("Copy length cached"), EFalse, EFalse, EFalse, 1);
|
|
216 |
runTest(MemCopyUncached, _L("Copy length uncached"), EFalse, EFalse, EFalse, 1);
|
|
217 |
runTest(WordMove, _L("Word move length cached"), EFalse, EFalse, EFalse, 4);
|
|
218 |
runTest(WordMoveUncached,_L("Word move length uncached"), EFalse, EFalse, EFalse, 4);
|
|
219 |
break;
|
|
220 |
default:
|
|
221 |
test(EFalse);
|
|
222 |
break;
|
|
223 |
}
|
|
224 |
|
|
225 |
test.End();
|
|
226 |
return(KErrNone);
|
|
227 |
}
|