sl@0
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test/defrag/perf/t_perf.cpp
|
sl@0
|
15 |
// t_pagemove loads and opens the logical device driver ("D_PAGEMOVE.LDD").
|
sl@0
|
16 |
// Following this, it requests that the driver attempt to move various kinds of pages
|
sl@0
|
17 |
// directly amd notes time taken for each of the moves.
|
sl@0
|
18 |
// Platforms/Drives/Compatibility:
|
sl@0
|
19 |
// Hardware only. No defrag support on emulator.
|
sl@0
|
20 |
// 2 - Test the performance of moving user chunk pages
|
sl@0
|
21 |
// 3 - Test the performance of moving dll pages
|
sl@0
|
22 |
// 4 - Test the performance of moving kernel stack pages
|
sl@0
|
23 |
//
|
sl@0
|
24 |
//
|
sl@0
|
25 |
|
sl@0
|
26 |
//! @SYMTestCaseID KBASE-T_DEFRAGPERF-0601
|
sl@0
|
27 |
//! @SYMTestType CT
|
sl@0
|
28 |
//! @SYMPREQ PREQ308
|
sl@0
|
29 |
//! @SYMTestCaseDesc Testing performace of page moving
|
sl@0
|
30 |
//! @SYMTestActions 1 - Test the performance of moving code chunk pages
|
sl@0
|
31 |
//! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
|
sl@0
|
32 |
//! @SYMTestPriority High
|
sl@0
|
33 |
//! @SYMTestStatus Implemented
|
sl@0
|
34 |
//--------------------------------------------------------------------------------------------------
|
sl@0
|
35 |
#define __E32TEST_EXTENSION__
|
sl@0
|
36 |
#include <e32test.h>
|
sl@0
|
37 |
#include <e32std.h>
|
sl@0
|
38 |
#include <e32std_private.h>
|
sl@0
|
39 |
|
sl@0
|
40 |
#include "..\d_pagemove.h"
|
sl@0
|
41 |
#include "..\..\mmu\mmudetect.h"
|
sl@0
|
42 |
#include "t_perf.h"
|
sl@0
|
43 |
|
sl@0
|
44 |
|
sl@0
|
45 |
LOCAL_D RTest test(_L("T_DEFRAGPERF"));
|
sl@0
|
46 |
|
sl@0
|
47 |
const TPtrC KLddFileName=_L("D_PAGEMOVE.LDD");
|
sl@0
|
48 |
|
sl@0
|
49 |
const TUint KRepetitions=50;
|
sl@0
|
50 |
const TUint KPageMoves = 2000; // default to moving a page 2000 times
|
sl@0
|
51 |
|
sl@0
|
52 |
|
sl@0
|
53 |
TInt gPageSize;
|
sl@0
|
54 |
|
sl@0
|
55 |
#define DEFRAG_CHUNK_MAX (4 * 1024 * 1024)
|
sl@0
|
56 |
#define DEFRAG_CHUNK_MIN (1 * 1024 * 1024)
|
sl@0
|
57 |
|
sl@0
|
58 |
#define MIN_PROCS 10
|
sl@0
|
59 |
#define MAX_PROCS 50
|
sl@0
|
60 |
#define PROC_INCREMENTS 10
|
sl@0
|
61 |
|
sl@0
|
62 |
_LIT(BaseFileName, "t_defragtestperf");
|
sl@0
|
63 |
_LIT(BaseFileNameExt, ".exe");
|
sl@0
|
64 |
|
sl@0
|
65 |
LOCAL_C void TestUserDataMove(RPageMove& pagemove)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
RChunk chunk;
|
sl@0
|
68 |
TInt size;
|
sl@0
|
69 |
TInt r = KErrGeneral;
|
sl@0
|
70 |
|
sl@0
|
71 |
DefragLatency timer;
|
sl@0
|
72 |
timer.CalibrateTimer(test);
|
sl@0
|
73 |
|
sl@0
|
74 |
size = DEFRAG_CHUNK_MAX;
|
sl@0
|
75 |
|
sl@0
|
76 |
while (size > DEFRAG_CHUNK_MIN)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
/* Create a local chunk */
|
sl@0
|
79 |
r = chunk.CreateLocal(size,size);
|
sl@0
|
80 |
if (r == KErrNone)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TEST_PRINTF(_L("Created %dMB chunk\n"), size/(1024 * 1024));
|
sl@0
|
83 |
break;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
size = size / 2;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
test(r == KErrNone);
|
sl@0
|
89 |
|
sl@0
|
90 |
/* Initialise the Chunk */
|
sl@0
|
91 |
TUint8* base = (TUint8 *)chunk.Base();
|
sl@0
|
92 |
for (TUint i = 0; i < size/sizeof(*base); i++)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
base[i] = i;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
|
sl@0
|
98 |
TEST_PRINTF(_L("Starting to move chunk pages (%x %d) ...\n"), chunk.Base(), size);
|
sl@0
|
99 |
TUint j = 0;
|
sl@0
|
100 |
for (; j < KRepetitions; j++)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
TInt size2 = size;
|
sl@0
|
103 |
base = (TUint8 *)chunk.Base();
|
sl@0
|
104 |
timer.StartTimer();
|
sl@0
|
105 |
while (size2)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
test_KErrNone(pagemove.TryMovingUserPage(base));
|
sl@0
|
108 |
base += gPageSize;
|
sl@0
|
109 |
size2 -= gPageSize;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
test(timer.StopTimer(test) > 0);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
DTime_t average, max, min, delay;
|
sl@0
|
116 |
TEST_PRINTF(_L("Finished moving chunk pages\n"));
|
sl@0
|
117 |
average = timer.GetResult(max, min, delay);
|
sl@0
|
118 |
test.Printf(_L("Fast counter ticks to move %d chunk pages: Av %d Min %d Max %d (Overhead %d)\n"), size/gPageSize, average, min, max, delay);
|
sl@0
|
119 |
test.Printf(_L("Average of %d ticks to move one page\n\n"), average / (size/gPageSize));
|
sl@0
|
120 |
|
sl@0
|
121 |
base = (TUint8 *)chunk.Base();
|
sl@0
|
122 |
for (TUint i = 0; i < size/sizeof(*base); i++)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
test_Equal((TUint8)i, base[i]);
|
sl@0
|
125 |
}
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
TInt CreateProc(RProcess& aProcess, TInt aIndex)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
TFileName filename;
|
sl@0
|
131 |
TRequestStatus status;
|
sl@0
|
132 |
TBuf<64> command;
|
sl@0
|
133 |
|
sl@0
|
134 |
filename.Format(_L("%S%S"), &BaseFileName, &BaseFileNameExt);
|
sl@0
|
135 |
TInt r=aProcess.Create(filename, command);
|
sl@0
|
136 |
|
sl@0
|
137 |
if (r!=KErrNone)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
test.Printf(_L("Process %d could not be loaded!\n"), aIndex);
|
sl@0
|
140 |
return r;
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
aProcess.Rendezvous(status);
|
sl@0
|
144 |
aProcess.Resume();
|
sl@0
|
145 |
User::WaitForRequest(status);
|
sl@0
|
146 |
return KErrNone;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
void KillAllProcs(RProcess *aProcess, TInt aNum, TInt aError)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
TInt i;
|
sl@0
|
152 |
for (i = 0; i < aNum; i++)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
aProcess[i].Kill(aError);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
TInt TestDLL(int aNumProcess, RPageMove& aPageMove)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
RProcess *process;
|
sl@0
|
161 |
TInt retVal;
|
sl@0
|
162 |
|
sl@0
|
163 |
process = new RProcess[aNumProcess];
|
sl@0
|
164 |
|
sl@0
|
165 |
if (process == NULL)
|
sl@0
|
166 |
return KErrGeneral;
|
sl@0
|
167 |
|
sl@0
|
168 |
TEST_PRINTF(_L("Starting %d processes\n"), aNumProcess);
|
sl@0
|
169 |
for (TInt i = 0; i < aNumProcess; i++)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
retVal = CreateProc(process[i], i);
|
sl@0
|
172 |
if (retVal != KErrNone)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
// More Cleanup ?
|
sl@0
|
175 |
KillAllProcs(process, i, KErrNone);
|
sl@0
|
176 |
delete[] process;
|
sl@0
|
177 |
return retVal;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
/* Now Map the DLL to this process and Run the tests */
|
sl@0
|
182 |
DllDefrag dll;
|
sl@0
|
183 |
TEST_PRINTF(_L("Main Proc Loading The DLL ... \n"));
|
sl@0
|
184 |
retVal = dll.LoadTheLib(0, test);
|
sl@0
|
185 |
|
sl@0
|
186 |
if (retVal != KErrNone)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
KillAllProcs(process, aNumProcess, retVal);
|
sl@0
|
189 |
test.Printf(_L("Error (%d) Loading The DLLs!\n"), retVal);
|
sl@0
|
190 |
delete[] process;
|
sl@0
|
191 |
return KErrGeneral;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
retVal = dll.TestDLLPerformance(0, aPageMove, test);
|
sl@0
|
195 |
KillAllProcs(process, aNumProcess, KErrNone);
|
sl@0
|
196 |
delete[] process;
|
sl@0
|
197 |
|
sl@0
|
198 |
return retVal;
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
/*
|
sl@0
|
202 |
* Is this portable .. Hell No, so dont ask.
|
sl@0
|
203 |
*/
|
sl@0
|
204 |
#define isNum(a) ((a) >= '0' && (a) <= '9')
|
sl@0
|
205 |
|
sl@0
|
206 |
TInt atoi(const TBuf<64>& buf, TInt pos)
|
sl@0
|
207 |
{
|
sl@0
|
208 |
TInt i = pos;
|
sl@0
|
209 |
TInt num = 0;
|
sl@0
|
210 |
TInt len = User::CommandLineLength();
|
sl@0
|
211 |
while(i < len)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
TInt8 ch = buf[i++];
|
sl@0
|
214 |
if (!isNum(ch))
|
sl@0
|
215 |
{
|
sl@0
|
216 |
test.Printf(_L("Invalid Argument!\n"));
|
sl@0
|
217 |
return KErrGeneral;
|
sl@0
|
218 |
}
|
sl@0
|
219 |
num = (num * 10) + (ch - '0');
|
sl@0
|
220 |
}
|
sl@0
|
221 |
return num;
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
void TestCodeChunkMoving(RPageMove aPageMove)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
_LIT(ELOCL_DEFAULT, "");
|
sl@0
|
227 |
_LIT(ELOCLUS, "T_LOCLUS_RAM");
|
sl@0
|
228 |
|
sl@0
|
229 |
// Change locale and move the locale page repeatedly
|
sl@0
|
230 |
// On multiple memmodel this is the easiest way to move CodeChunk pages.
|
sl@0
|
231 |
|
sl@0
|
232 |
|
sl@0
|
233 |
// Setup the RAM loaded US Locale DLL
|
sl@0
|
234 |
test_KErrNone(UserSvr::ChangeLocale(ELOCLUS));
|
sl@0
|
235 |
TLocale locale;
|
sl@0
|
236 |
locale.Refresh();
|
sl@0
|
237 |
|
sl@0
|
238 |
|
sl@0
|
239 |
// Now get a pointer to some data in the DLL. This will be used to move a
|
sl@0
|
240 |
// page from the dll
|
sl@0
|
241 |
SLocaleLanguage localeLanguage;
|
sl@0
|
242 |
TPckg<SLocaleLanguage> localeLanguageBuf(localeLanguage);
|
sl@0
|
243 |
TInt r = RProperty::Get(KUidSystemCategory, KLocaleLanguageKey, localeLanguageBuf);
|
sl@0
|
244 |
test_KErrNone(r);
|
sl@0
|
245 |
TAny* localeAddr = (TAny *) localeLanguage.iDateSuffixTable;
|
sl@0
|
246 |
test(localeAddr != NULL);
|
sl@0
|
247 |
|
sl@0
|
248 |
|
sl@0
|
249 |
// Now we have a RAM loaded locale page determine the performance
|
sl@0
|
250 |
TEST_PRINTF(_L("Start moving a RAM loaded locale page\n"));
|
sl@0
|
251 |
// Setup the timer
|
sl@0
|
252 |
DefragLatency timer;
|
sl@0
|
253 |
timer.CalibrateTimer(test);
|
sl@0
|
254 |
TUint reps = 0;
|
sl@0
|
255 |
for (; reps < KRepetitions; reps++)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
timer.StartTimer();
|
sl@0
|
258 |
TUint i = 0;
|
sl@0
|
259 |
for (; i < KPageMoves; i++)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
test_KErrNone(aPageMove.TryMovingLocaleDll(localeAddr));
|
sl@0
|
262 |
}
|
sl@0
|
263 |
test_Compare(timer.StopTimer(test), >, 0);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
DTime_t max, min, delay;
|
sl@0
|
266 |
TUint average = timer.GetResult(max, min, delay);
|
sl@0
|
267 |
test.Printf(_L("Fast counter ticks to move code chunk page %d times: Av %d Min %d Max %d (Overhead %d)\n"), KPageMoves, average, min, max, delay);
|
sl@0
|
268 |
test.Printf(_L("Average of %d ticks to move one page\n\n"), average/ KPageMoves);
|
sl@0
|
269 |
|
sl@0
|
270 |
|
sl@0
|
271 |
// Reset the Locale to the default
|
sl@0
|
272 |
r=UserSvr::ChangeLocale(ELOCL_DEFAULT);
|
sl@0
|
273 |
test(r==KErrNone);
|
sl@0
|
274 |
locale.Refresh();
|
sl@0
|
275 |
}
|
sl@0
|
276 |
|
sl@0
|
277 |
GLDEF_C TInt E32Main()
|
sl@0
|
278 |
{
|
sl@0
|
279 |
test.Title();
|
sl@0
|
280 |
TInt procs = 1;
|
sl@0
|
281 |
_LIT(KStart,"-procs=");
|
sl@0
|
282 |
const TInt offset = KStart().Length();
|
sl@0
|
283 |
|
sl@0
|
284 |
TBuf<64> cmd;
|
sl@0
|
285 |
User::CommandLine(cmd);
|
sl@0
|
286 |
|
sl@0
|
287 |
if (!HaveMMU())
|
sl@0
|
288 |
{
|
sl@0
|
289 |
test.Printf(_L("This test requires an MMU\n"));
|
sl@0
|
290 |
return KErrNone;
|
sl@0
|
291 |
}
|
sl@0
|
292 |
test.Start(_L("Load test LDD"));
|
sl@0
|
293 |
TInt r=User::LoadLogicalDevice(KLddFileName);
|
sl@0
|
294 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
295 |
|
sl@0
|
296 |
r=UserHal::PageSizeInBytes(gPageSize);
|
sl@0
|
297 |
test_KErrNone(r);
|
sl@0
|
298 |
|
sl@0
|
299 |
RPageMove pagemove;
|
sl@0
|
300 |
test.Next(_L("Open test LDD"));
|
sl@0
|
301 |
r=pagemove.Open();
|
sl@0
|
302 |
test_KErrNone(r);
|
sl@0
|
303 |
|
sl@0
|
304 |
DefragLatency timer;
|
sl@0
|
305 |
timer.CalibrateTimer(test);
|
sl@0
|
306 |
test.Printf(_L("\nFast Counter Frequency = %dHz \n\n"), timer.iFastCounterFreq);
|
sl@0
|
307 |
|
sl@0
|
308 |
|
sl@0
|
309 |
test.Next(_L("Test performance of moving code chunk pages"));
|
sl@0
|
310 |
TestCodeChunkMoving(pagemove);
|
sl@0
|
311 |
|
sl@0
|
312 |
/*
|
sl@0
|
313 |
* Test User Data.
|
sl@0
|
314 |
* Create a large chunk ~ 4MB (> L2 Cache) and move pages from that chunk
|
sl@0
|
315 |
*/
|
sl@0
|
316 |
test.Next(_L("Test performance of moving user chunk pages"));
|
sl@0
|
317 |
TestUserDataMove(pagemove);
|
sl@0
|
318 |
|
sl@0
|
319 |
/* Test DLL Move */
|
sl@0
|
320 |
test.Next(_L("Test performance of moving dll pages"));
|
sl@0
|
321 |
TInt pos = cmd.FindF(KStart);
|
sl@0
|
322 |
if (pos >= 0)
|
sl@0
|
323 |
{
|
sl@0
|
324 |
pos += offset;
|
sl@0
|
325 |
procs = atoi(cmd, pos);
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
if (procs < MIN_PROCS)
|
sl@0
|
329 |
procs = MIN_PROCS;
|
sl@0
|
330 |
else if (procs > MAX_PROCS)
|
sl@0
|
331 |
procs = MAX_PROCS;
|
sl@0
|
332 |
|
sl@0
|
333 |
for (TInt i = 1; ; )
|
sl@0
|
334 |
{
|
sl@0
|
335 |
test.Printf(_L("Testing with %d Processes mapping a DLL\n"), i);
|
sl@0
|
336 |
TestDLL(i, pagemove);
|
sl@0
|
337 |
|
sl@0
|
338 |
if (i >= procs)
|
sl@0
|
339 |
break;
|
sl@0
|
340 |
|
sl@0
|
341 |
if (i + PROC_INCREMENTS >= procs)
|
sl@0
|
342 |
i = procs;
|
sl@0
|
343 |
else
|
sl@0
|
344 |
i += PROC_INCREMENTS;
|
sl@0
|
345 |
}
|
sl@0
|
346 |
|
sl@0
|
347 |
if ((MemModelAttributes()&EMemModelTypeMask) != EMemModelTypeFlexible)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
test.Next(_L("Test performance of moving kernel stack pages"));
|
sl@0
|
350 |
r = pagemove.TestKernelDataMovePerformance();
|
sl@0
|
351 |
test_KErrNone(r);
|
sl@0
|
352 |
}
|
sl@0
|
353 |
|
sl@0
|
354 |
test.Next(_L("Close test LDD"));
|
sl@0
|
355 |
|
sl@0
|
356 |
pagemove.Close();
|
sl@0
|
357 |
User::FreeLogicalDevice(KLddFileName);
|
sl@0
|
358 |
test.End();
|
sl@0
|
359 |
return(KErrNone);
|
sl@0
|
360 |
}
|