author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 21 Jun 2010 17:12:14 +0300 | |
branch | RCL_3 |
changeset 39 | 2bb754abd467 |
parent 0 | a41df078684a |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2002-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 |
// Overview: |
|
15 |
// Test and benchmark kernel-side utility operations |
|
16 |
// API Information: |
|
17 |
// RBusLogicalChannel |
|
18 |
// Details: |
|
19 |
// - Create a list of benchmark modules and start running them one by one; |
|
20 |
// each module contains a set of measurement units, each unit runs for a fixed |
|
21 |
// amount of time in a series of iterations; the results, minimum, maximum and |
|
22 |
// average times are displayed on the screen; |
|
23 |
// The tests use a high resolution timer implemented kernel side in a device |
|
24 |
// driver. |
|
25 |
// - The test contains the following benchmark modules: |
|
26 |
// - Real-time latency module measures: |
|
27 |
// - interrupt latency by calculating the time taken from when an |
|
28 |
// interrupt is generated until the ISR starts |
|
29 |
// - kernel thread latency by calculating the time taken from an ISR |
|
30 |
// scheduling a DFC to signal the kernel thread until the kernel thread |
|
31 |
// starts running |
|
32 |
// - kernel thread latency as above while a CPU intensive low priority |
|
33 |
// user thread runs at the same time |
|
34 |
// - user thread latency by calculating the time taken from an ISR |
|
35 |
// scheduling a DFC to signal the user thread until the user thread |
|
36 |
// starts running |
|
37 |
// - user thread latency as above while a CPU intensive low priority |
|
38 |
// user thread runs at the same time |
|
39 |
// - NTimer period jitter by calculating the actual period as the delta |
|
40 |
// between two consecutive NTimer callbacks that store the current time; |
|
41 |
// the jitter is the difference between the actual period and a theoretical |
|
42 |
// period. |
|
43 |
// - timer overhead by calculating the delta of time between two consecutive |
|
44 |
// timestamps requested from the high precision timer implemented in the |
|
45 |
// device driver; the calls are made from kernel side code |
|
46 |
// - Overhead module measures: |
|
47 |
// - timer overhead by calculating the delta of time between two consecutive |
|
48 |
// timestamps requested from the high precision timer implemented in the |
|
49 |
// device driver; the calls are made from user side code |
|
50 |
// - Synchronization module measures: |
|
51 |
// - mutex passing, local mutex contention, remote mutex contention, |
|
52 |
// local semaphore latency, remote semaphore latency, |
|
53 |
// local thread semaphore latency, remote thread semaphore latency. |
|
54 |
// - Client-server framework module measures: |
|
55 |
// - For local high priority, local low priority, remote high priority |
|
56 |
// and remote low priority: connection request latency, connection |
|
57 |
// reply latency, request latency, request response time, reply latency. |
|
58 |
// - Threads modules measures: |
|
59 |
// - Thread creation latency, thread creation suicide, thread suicide, |
|
60 |
// thread killing, setting per thread data, getting per thread data. |
|
61 |
// - Properties module measures: |
|
62 |
// - Local int notification latency, remote int notification latency, |
|
63 |
// local byte(1) notification latency, remote byte(1) notification latency, |
|
64 |
// local byte(8) notification latency, remote byte(8) notification latency, |
|
65 |
// local byte(512) notification latency, remote byte(512) notification latency, |
|
66 |
// int set overhead, byte(1) set overhead, byte(8) set overhead, byte(512) set |
|
67 |
// overhead, int get overhead, byte(1) get overhead, byte(8) get overhead, |
|
68 |
// byte(512) get overhead. |
|
69 |
// Platforms/Drives/Compatibility: |
|
70 |
// All. |
|
71 |
// Assumptions/Requirement/Pre-requisites: |
|
72 |
// Failures and causes: |
|
73 |
// Base Port information: |
|
74 |
// |
|
75 |
// |
|
76 |
||
77 |
#include "bm_suite.h" |
|
78 |
#include <e32svr.h> |
|
79 |
#include <u32hal.h> |
|
80 |
||
81 |
// |
|
82 |
// The default value of the time allocated for one benchmark program. |
|
83 |
// |
|
84 |
static TInt KBMSecondsPerProgram = 30; |
|
85 |
// |
|
86 |
// The initial number of iterations to estimate the acctual number of iteration. |
|
87 |
// |
|
88 |
static TInt KBMCalibrationIter = 64; |
|
89 |
||
90 |
// |
|
91 |
// Global handle to high-resolution timer. |
|
92 |
// |
|
93 |
RBMTimer bmTimer; |
|
94 |
// |
|
95 |
// The head of the benchmark programs' list |
|
96 |
// |
|
97 |
BMProgram* bmSuite; |
|
98 |
// |
|
99 |
// Global handle to the kernel side benchmark utilty API |
|
100 |
// |
|
101 |
static RBMDriver bmDriver; |
|
102 |
||
103 |
TBMResult::TBMResult(const TDesC& aName) : iName(aName) |
|
104 |
{ |
|
105 |
Reset(); |
|
106 |
} |
|
107 |
||
108 |
void TBMResult::Reset() |
|
109 |
{ |
|
110 |
::bmTimer.Period(&iMinTicks); |
|
111 |
iMaxTicks = 0; |
|
112 |
iCumulatedTicks = 0; |
|
113 |
iCumulatedIterations = 0; |
|
114 |
iIterations = 0; |
|
115 |
iMin = 0; |
|
116 |
iMax = 0; |
|
117 |
iAverage = 0; |
|
118 |
} |
|
119 |
||
120 |
void TBMResult::Reset(const TDesC& aName) |
|
121 |
{ |
|
122 |
Reset(); |
|
123 |
iName.Set(aName); |
|
124 |
} |
|
125 |
||
126 |
void TBMResult::Cumulate(TBMTicks aTicks) |
|
127 |
{ |
|
128 |
if (aTicks < iMinTicks) iMinTicks = aTicks; |
|
129 |
if (iMaxTicks < aTicks) iMaxTicks = aTicks; |
|
130 |
||
131 |
iCumulatedTicks += aTicks; |
|
132 |
if (iCumulatedIterations < KHeadSize) |
|
133 |
{ |
|
134 |
iHeadTicks[iCumulatedIterations] = aTicks; |
|
135 |
} |
|
136 |
// use the array as a circular buufer to store last KTailSize results |
|
137 |
// (would not really know which one was actually the last) |
|
138 |
iTailTicks[iCumulatedIterations % KTailSize] = aTicks; |
|
139 |
++iCumulatedIterations; |
|
140 |
||
141 |
} |
|
142 |
||
143 |
||
144 |
void TBMResult::Cumulate(TBMTicks aTicks, TBMUInt64 aIter) |
|
145 |
{ |
|
146 |
iCumulatedIterations += aIter; |
|
147 |
iCumulatedTicks += aTicks; |
|
148 |
} |
|
149 |
||
150 |
void TBMResult::Update() |
|
151 |
{ |
|
152 |
if (iCumulatedIterations == 0) return; |
|
153 |
iIterations = iCumulatedIterations; |
|
154 |
::bmTimer.TicksToNs(&iMinTicks, &iMin); |
|
155 |
::bmTimer.TicksToNs(&iMaxTicks, &iMax); |
|
156 |
TBMTicks averageTicks = iCumulatedTicks/TBMUInt64(iCumulatedIterations); |
|
157 |
::bmTimer.TicksToNs(&averageTicks, &iAverage); |
|
158 |
TInt i; |
|
159 |
for (i = 0; i < KHeadSize; ++i) |
|
160 |
{ |
|
161 |
::bmTimer.TicksToNs(&iHeadTicks[i], &iHead[i]); |
|
162 |
} |
|
163 |
for (i = 0; i < KTailSize; ++i) |
|
164 |
{ |
|
165 |
::bmTimer.TicksToNs(&iTailTicks[i], &iTail[i]); |
|
166 |
} |
|
167 |
} |
|
168 |
||
169 |
inline TBMNs TTimeIntervalMicroSecondsToTBMNs(TTimeIntervalMicroSeconds us) |
|
170 |
{ |
|
171 |
return BMUsToNs(*(TBMUInt64*)&us); |
|
172 |
} |
|
173 |
||
174 |
TBMNs TBMTimeInterval::iStampPeriodNs; |
|
175 |
TBMTicks TBMTimeInterval::iStampPeriod; |
|
176 |
||
177 |
void TBMTimeInterval::Init() |
|
178 |
{ |
|
179 |
::bmTimer.Period(&iStampPeriod); |
|
180 |
::bmTimer.TicksToNs(&iStampPeriod, &iStampPeriodNs); |
|
181 |
} |
|
182 |
||
183 |
void TBMTimeInterval::Begin() |
|
184 |
{ |
|
185 |
// |
|
186 |
// Order is important: read first low-precision timer, then the high-precision one. |
|
187 |
// Therefore, two high-precision timer reads will be accounted in the low-precision interval, |
|
188 |
// that's better than the opposite. |
|
189 |
// |
|
190 |
iTime.HomeTime(); |
|
191 |
::bmTimer.Stamp(&iStamp); |
|
192 |
} |
|
193 |
||
194 |
TBMNs TBMTimeInterval::EndNs() |
|
195 |
{ |
|
196 |
// |
|
197 |
// Now, in the reverse order |
|
198 |
// |
|
199 |
TBMTicks stamp; |
|
200 |
::bmTimer.Stamp(&stamp); |
|
201 |
TTime time; |
|
202 |
time.HomeTime(); |
|
203 |
TBMNs ns = TTimeIntervalMicroSecondsToTBMNs(time.MicroSecondsFrom(iTime)); |
|
204 |
// |
|
205 |
// If the interval fits in the high-precision timer period we can use it; |
|
206 |
// otherwise, use the low-precision timer. |
|
207 |
// |
|
208 |
if (ns < iStampPeriodNs) |
|
209 |
{ |
|
210 |
stamp = TBMTicksDelta(iStamp, stamp); |
|
211 |
::bmTimer.TicksToNs(&stamp, &ns); |
|
212 |
} |
|
213 |
return ns; |
|
214 |
} |
|
215 |
||
216 |
TBMTicks TBMTimeInterval::End() |
|
217 |
{ |
|
218 |
// |
|
219 |
// The same as the previous one but returns ticks |
|
220 |
// |
|
221 |
||
222 |
TBMTicks stamp; |
|
223 |
::bmTimer.Stamp(&stamp); |
|
224 |
TTime time; |
|
225 |
time.HomeTime(); |
|
226 |
TBMNs ns = TTimeIntervalMicroSecondsToTBMNs(time.MicroSecondsFrom(iTime)); |
|
227 |
if (ns < iStampPeriodNs) |
|
228 |
{ |
|
229 |
stamp = TBMTicksDelta(iStamp, stamp); |
|
230 |
} |
|
231 |
else |
|
232 |
{ |
|
233 |
// multiply first - privileging precision to improbable overflow. |
|
234 |
stamp = (ns * iStampPeriod) / iStampPeriodNs; |
|
235 |
} |
|
236 |
return stamp; |
|
237 |
} |
|
238 |
||
239 |
TInt BMProgram::SetAbsPriority(RThread aThread, TInt aNewPrio) |
|
240 |
{ |
|
241 |
TInt aOldPrio=0; |
|
242 |
TInt r = ::bmDriver.SetAbsPriority(aThread, aNewPrio, &aOldPrio); |
|
243 |
BM_ERROR(r, r == KErrNone); |
|
244 |
return aOldPrio; |
|
245 |
} |
|
246 |
||
247 |
const TInt TBMSpawnArgs::KMagic = 0xdeadbeef; |
|
248 |
||
249 |
TBMSpawnArgs::TBMSpawnArgs(TThreadFunction aChildFunc, TInt aChildPrio, TBool aRemote, TInt aSize) |
|
250 |
{ |
|
251 |
iMagic = KMagic; |
|
252 |
iParentId = RThread().Id(); |
|
253 |
// get a thread handle meaningful in the context of any other thread. |
|
254 |
// (RThread() doesn't work since contextual!) |
|
255 |
TInt r = iParent.Open(iParentId); |
|
256 |
BM_ERROR(r, r == KErrNone); |
|
257 |
iRemote = aRemote; |
|
258 |
iChildFunc = aChildFunc; |
|
259 |
iChildPrio = aChildPrio; |
|
260 |
iSize = aSize; |
|
261 |
} |
|
262 |
||
263 |
TBMSpawnArgs::~TBMSpawnArgs() |
|
264 |
{ |
|
265 |
iParent.Close(); |
|
266 |
} |
|
267 |
||
268 |
// |
|
269 |
// An object of CLocalChild class represents a "child" thread created by its "parent" thread |
|
270 |
// in the parent's process through BmProgram::SpawnChild() interface. |
|
271 |
// |
|
272 |
// CLocalChild class is typically used (invoked) by the parent's thread. |
|
273 |
// |
|
274 |
class CLocalChild : public CBase, public MBMChild |
|
275 |
{ |
|
276 |
private: |
|
277 |
BMProgram* iProg; |
|
278 |
public: |
|
279 |
RThread iChild; |
|
280 |
TRequestStatus iExitStatus; |
|
281 |
||
282 |
CLocalChild(BMProgram* aProg) |
|
283 |
{ |
|
284 |
iProg = aProg; |
|
285 |
} |
|
286 |
||
287 |
virtual void WaitChildExit(); |
|
288 |
virtual void Kill(); |
|
289 |
}; |
|
290 |
||
291 |
void CLocalChild::Kill() |
|
292 |
{ |
|
293 |
iChild.Kill(KErrCancel); |
|
294 |
} |
|
295 |
||
296 |
void CLocalChild::WaitChildExit() |
|
297 |
{ |
|
298 |
User::WaitForRequest(iExitStatus); |
|
299 |
CLOSE_AND_WAIT(iChild); |
|
300 |
// |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
// Lower the parent thread priority and then restore the current one |
0 | 302 |
// to make sure that the kernel-side thread destruction DFC had a chance to complete. |
303 |
// |
|
304 |
TInt prio = BMProgram::SetAbsPriority(RThread(), iProg->iOrigAbsPriority); |
|
305 |
BMProgram::SetAbsPriority(RThread(), prio); |
|
306 |
delete this; |
|
307 |
} |
|
308 |
||
309 |
// |
|
310 |
// Local (i.e. sharing the parent's process) child's entry point |
|
311 |
// |
|
312 |
TInt LocalChildEntry(void* ptr) |
|
313 |
{ |
|
314 |
TBMSpawnArgs* args = (TBMSpawnArgs*) ptr; |
|
315 |
args->iChildOrigPriority = BMProgram::SetAbsPriority(RThread(), args->iChildPrio); |
|
316 |
return args->iChildFunc(args); |
|
317 |
} |
|
318 |
||
319 |
MBMChild* BMProgram::SpawnLocalChild(TBMSpawnArgs* args) |
|
320 |
{ |
|
321 |
CLocalChild* child = new CLocalChild(this); |
|
322 |
BM_ERROR(KErrNoMemory, child); |
|
323 |
TInt r = child->iChild.Create(KNullDesC, ::LocalChildEntry, 0x2000, NULL, args); |
|
324 |
BM_ERROR(r, r == KErrNone); |
|
325 |
child->iChild.Logon(child->iExitStatus); |
|
326 |
child->iChild.Resume(); |
|
327 |
return child; |
|
328 |
} |
|
329 |
||
330 |
// |
|
331 |
// An object of CRemoteChild class represents a "child" thread created by its "parent" thread |
|
332 |
// as a separate process through BmProgram::SpawnChild() interface. |
|
333 |
// |
|
334 |
// CRemoteChild class is typically used (invoked) by the parent's thread. |
|
335 |
// |
|
336 |
class CRemoteChild : public CBase, public MBMChild |
|
337 |
{ |
|
338 |
private: |
|
339 |
BMProgram* iProg; |
|
340 |
public: |
|
341 |
RProcess iChild; |
|
342 |
TRequestStatus iExitStatus; |
|
343 |
||
344 |
CRemoteChild(BMProgram* aProg) |
|
345 |
{ |
|
346 |
iProg = aProg; |
|
347 |
} |
|
348 |
||
349 |
virtual void WaitChildExit(); |
|
350 |
virtual void Kill(); |
|
351 |
}; |
|
352 |
||
353 |
void CRemoteChild::Kill() |
|
354 |
{ |
|
355 |
iChild.Kill(KErrCancel); |
|
356 |
} |
|
357 |
||
358 |
void CRemoteChild::WaitChildExit() |
|
359 |
{ |
|
360 |
User::WaitForRequest(iExitStatus); |
|
361 |
CLOSE_AND_WAIT(iChild); |
|
362 |
// |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
// Lower the parent thread priority and then restore the current one |
0 | 364 |
// to make sure that the kernel-side thread destruction DFC had a chance to complete. |
365 |
// |
|
366 |
TInt prio = BMProgram::SetAbsPriority(RThread(), iProg->iOrigAbsPriority); |
|
367 |
BMProgram::SetAbsPriority(RThread(), prio); |
|
368 |
delete this; |
|
369 |
} |
|
370 |
||
371 |
// |
|
372 |
// Remote (i.e. running in its own process) child's entry point. |
|
373 |
// Note that the child's process entry point is still E32Main() process (see below) |
|
374 |
// |
|
375 |
TInt ChildMain(TBMSpawnArgs* args) |
|
376 |
{ |
|
377 |
args->iChildOrigPriority = BMProgram::SetAbsPriority(RThread(), args->iChildPrio); |
|
378 |
// get a handle to the parent's thread in the child's context. |
|
379 |
TInt r = args->iParent.Open(args->iParentId); |
|
380 |
BM_ERROR(r, r == KErrNone); |
|
381 |
return args->iChildFunc(args); |
|
382 |
} |
|
383 |
||
384 |
MBMChild* BMProgram::SpawnRemoteChild(TBMSpawnArgs* args) |
|
385 |
{ |
|
386 |
CRemoteChild* child = new CRemoteChild(this); |
|
387 |
BM_ERROR(KErrNoMemory, child); |
|
388 |
// |
|
389 |
// Create the child process and pass args as a UNICODE command line. |
|
390 |
// (we suppose that the args size is multiple of sizeof(TUint16)) |
|
391 |
// |
|
392 |
BM_ASSERT((args->iSize % sizeof(TUint16)) == 0); |
|
393 |
TInt r = child->iChild.Create(RProcess().FileName(), TPtrC((TUint16*) args, args->iSize/sizeof(TUint16))); |
|
394 |
BM_ERROR(r, (r == KErrNone) ); |
|
395 |
child->iChild.Logon(child->iExitStatus); |
|
396 |
child->iChild.Resume(); |
|
397 |
return child; |
|
398 |
} |
|
399 |
||
400 |
MBMChild* BMProgram::SpawnChild(TBMSpawnArgs* args) |
|
401 |
{ |
|
402 |
MBMChild* child; |
|
403 |
if (args->iRemote) |
|
404 |
{ |
|
405 |
child = SpawnRemoteChild(args); |
|
406 |
} |
|
407 |
else |
|
408 |
{ |
|
409 |
child = SpawnLocalChild(args); |
|
410 |
} |
|
411 |
return child; |
|
412 |
} |
|
413 |
||
414 |
// |
|
415 |
// The benchmark-suite entry point. |
|
416 |
// |
|
417 |
GLDEF_C TInt E32Main() |
|
418 |
{ |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
RTest test(_L("Benchmark Suite")); |
0 | 420 |
test.Title(); |
421 |
||
422 |
AddProperty(); |
|
423 |
AddThread(); |
|
424 |
AddIpc(); |
|
425 |
AddSync(); |
|
426 |
AddOverhead(); |
|
427 |
AddrtLatency(); |
|
428 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
TInt r = User::LoadPhysicalDevice(KBMPddFileName); |
0 | 430 |
BM_ERROR(r, (r == KErrNone) || (r == KErrAlreadyExists)); |
431 |
||
432 |
r = User::LoadLogicalDevice(KBMLddFileName); |
|
433 |
BM_ERROR(r, (r == KErrNone) || (r == KErrAlreadyExists)); |
|
434 |
||
435 |
r = ::bmTimer.Open(); |
|
436 |
BM_ERROR(r, (r == KErrNone)); |
|
437 |
||
438 |
r = ::bmDriver.Open(); |
|
439 |
BM_ERROR(r, (r == KErrNone)); |
|
440 |
||
441 |
TBMTimeInterval::Init(); |
|
442 |
||
443 |
TInt seconds = KBMSecondsPerProgram; |
|
444 |
||
445 |
TInt len = User::CommandLineLength(); |
|
446 |
if (len) |
|
447 |
{ |
|
448 |
// |
|
449 |
// Copy the command line in a buffer |
|
450 |
// |
|
451 |
TInt size = len * sizeof(TUint16); |
|
452 |
HBufC8* hb = HBufC8::NewMax(size); |
|
453 |
BM_ERROR(KErrNoMemory, hb); |
|
454 |
TPtr cmd((TUint16*) hb->Ptr(), len); |
|
455 |
User::CommandLine(cmd); |
|
456 |
// |
|
457 |
// Check for the TBMSpawnArgs magic number. |
|
458 |
// |
|
459 |
TBMSpawnArgs* args = (TBMSpawnArgs*) hb->Ptr(); |
|
460 |
if (args->iMagic == TBMSpawnArgs::KMagic) |
|
461 |
{ |
|
462 |
// |
|
463 |
// This is a child process - call it's entry point |
|
464 |
// |
|
465 |
return ::ChildMain(args); |
|
466 |
} |
|
467 |
else |
|
468 |
{ |
|
469 |
// |
|
470 |
// A real command line - the time (in seconds) for each benchmark program. |
|
471 |
// |
|
472 |
TLex l(cmd); |
|
473 |
r = l.Val(seconds); |
|
474 |
if (r != KErrNone) |
|
475 |
{ |
|
476 |
test.Printf(_L("Usage: bm_suite <seconds>\n")); |
|
477 |
BM_ERROR(r, 0); |
|
478 |
} |
|
479 |
} |
|
480 |
delete hb; |
|
481 |
} |
|
482 |
||
483 |
{ |
|
484 |
TBMTicks ticks = 1; |
|
485 |
TBMNs ns; |
|
486 |
::bmTimer.TicksToNs(&ticks, &ns); |
|
487 |
test.Printf(_L("High resolution timer tick %dns\n"), TInt(ns)); |
|
488 |
test.Printf(_L("High resolution timer period %dms\n"), BMNsToMs(TBMTimeInterval::iStampPeriodNs)); |
|
489 |
} |
|
490 |
||
491 |
test.Start(_L("Performance Benchmark Suite")); |
|
492 |
||
493 |
BMProgram* prog = ::bmSuite; |
|
494 |
while (prog) { |
|
495 |
// |
|
496 |
// For each program from the benchmark-suite's list |
|
497 |
// |
|
498 |
||
499 |
// |
|
500 |
// Remember the number of open handles. Just for a sanity check .... |
|
501 |
// |
|
502 |
TInt start_thc, start_phc; |
|
503 |
RThread().HandleCount(start_phc, start_thc); |
|
504 |
||
505 |
test.Printf(_L("%S\n"), &prog->Name()); |
|
506 |
||
507 |
// |
|
508 |
// A benchmark-suite's thread can run at any of three possible absolute priorities: |
|
509 |
// KBMPriorityLow, KBMPriorityMid and KBMPriorityHigh. |
|
510 |
// The main thread starts individual benchmark programs at KBMPriorityMid |
|
511 |
// |
|
512 |
prog->iOrigAbsPriority = BMProgram::SetAbsPriority(RThread(), KBMPriorityMid); |
|
513 |
||
514 |
// |
|
515 |
// First of all figure out how many iteration would be required to run this program |
|
516 |
// for the given number of seconds. |
|
517 |
// |
|
518 |
TInt count; |
|
519 |
TBMNs ns = 0; |
|
520 |
TBMUInt64 iter = KBMCalibrationIter; |
|
521 |
for (;;) |
|
522 |
{ |
|
523 |
TBMTimeInterval ti; |
|
524 |
ti.Begin(); |
|
525 |
prog->Run(iter, &count); |
|
526 |
ns = ti.EndNs(); |
|
527 |
// run at least 100ms (otherwise, could be too much impricise ...) |
|
528 |
if (ns > BMMsToNs(100)) break; |
|
529 |
iter *= 2; |
|
530 |
} |
|
531 |
test.Printf(_L("%d iterations in %dms\n"), TInt(iter), BMNsToMs(ns)); |
|
532 |
iter = (BMSecondsToNs(seconds) * iter) / ns; |
|
533 |
test.Printf(_L("Go for %d iterations ...\n"), TInt(iter)); |
|
534 |
||
535 |
// |
|
536 |
// Now the real run ... |
|
537 |
// |
|
538 |
TBMResult* results = prog->Run(iter, &count); |
|
539 |
||
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
540 |
// Restore the original priority |
0 | 541 |
BMProgram::SetAbsPriority(RThread(), prog->iOrigAbsPriority); |
542 |
||
543 |
// |
|
544 |
// Now print out the results |
|
545 |
// |
|
546 |
for (TInt i = 0; i < count; ++i) |
|
547 |
{ |
|
548 |
if (results[i].iMax) |
|
549 |
{ |
|
550 |
test.Printf(_L("%S. %d iterations; Avr: %dns; Min: %dns; Max: %dns\n"), |
|
551 |
&results[i].iName, TInt(results[i].iIterations), |
|
552 |
TInt(results[i].iAverage), TInt(results[i].iMin), TInt(results[i].iMax)); |
|
553 |
||
554 |
TInt j; |
|
555 |
BM_ASSERT((TBMResult::KHeadSize % 4) == 0); |
|
556 |
test.Printf(_L("Head:")); |
|
557 |
for (j = 0; j < TBMResult::KHeadSize; j += 4) |
|
558 |
{ |
|
559 |
test.Printf(_L(" %d %d %d %d "), |
|
560 |
TInt(results[i].iHead[j]), TInt(results[i].iHead[j+1]), |
|
561 |
TInt(results[i].iHead[j+2]), TInt(results[i].iHead[j+3])); |
|
562 |
} |
|
563 |
test.Printf(_L("\n")); |
|
564 |
||
565 |
BM_ASSERT((TBMResult::KTailSize % 4) == 0); |
|
566 |
test.Printf(_L("Tail:")); |
|
567 |
for (j = 0; j < TBMResult::KTailSize; j += 4) |
|
568 |
{ |
|
569 |
test.Printf(_L(" %d %d %d %d "), |
|
570 |
TInt(results[i].iTail[j]), TInt(results[i].iTail[j+1]), |
|
571 |
TInt(results[i].iTail[j+2]), TInt(results[i].iTail[j+3])); |
|
572 |
} |
|
573 |
test.Printf(_L("\n")); |
|
574 |
} |
|
575 |
else |
|
576 |
{ |
|
577 |
test.Printf(_L("%S. %d iterations; Avr: %dns\n"), |
|
578 |
&results[i].iName, TInt(results[i].iIterations), TInt(results[i].iAverage)); |
|
579 |
} |
|
580 |
||
581 |
} |
|
582 |
||
583 |
// |
|
584 |
// Sanity check for open handles |
|
585 |
// |
|
586 |
TInt end_thc, end_phc; |
|
587 |
RThread().HandleCount(end_phc, end_thc); |
|
588 |
BM_ASSERT(start_thc == end_thc); |
|
589 |
BM_ASSERT(start_phc == end_phc); |
|
590 |
// and also for pending requests ... |
|
591 |
BM_ASSERT(RThread().RequestCount() == 0); |
|
592 |
||
593 |
prog = prog->Next(); |
|
594 |
// |
|
595 |
// This can be used to run forever ... |
|
596 |
// |
|
597 |
// if (prog == NULL) |
|
598 |
// prog = ::bmSuite; |
|
599 |
// |
|
600 |
} |
|
601 |
||
602 |
test.End(); |
|
603 |
||
604 |
::bmDriver.Close(); |
|
605 |
::bmTimer.Close(); |
|
606 |
return 0; |
|
607 |
} |
|
608 |
||
609 |
||
610 |
void bm_assert_failed(char* aCond, char* aFile, TInt aLine) |
|
611 |
{ |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
612 |
RTest test(_L("Benchmark Suite Assert Failed")); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
613 |
test.Title(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
614 |
|
0 | 615 |
TPtrC8 fd((TUint8*)aFile); |
616 |
TPtrC8 cd((TUint8*)aCond); |
|
617 |
||
618 |
HBufC* fhb = HBufC::NewMax(fd.Length()); |
|
619 |
test(fhb != 0); |
|
620 |
HBufC* chb = HBufC::NewMax(cd.Length()); |
|
621 |
test(chb != 0); |
|
622 |
||
623 |
fhb->Des().Copy(fd); |
|
624 |
chb->Des().Copy(cd); |
|
625 |
||
626 |
test.Printf(_L("Assertion %S failed; File: %S; Line %d;\n"), chb, fhb, aLine); |
|
627 |
test(0); |
|
628 |
} |
|
629 |
||
630 |
void bm_error_detected(TInt aError, char* aCond, char* aFile, TInt aLine) |
|
631 |
{ |
|
39
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
632 |
RTest test(_L("Benchmark Suite Error Detected")); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
test.Title(); |
2bb754abd467
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
634 |
|
0 | 635 |
TPtrC8 fd((TUint8*)aFile); |
636 |
TPtrC8 cd((TUint8*)aCond); |
|
637 |
||
638 |
HBufC* fhb = HBufC::NewMax(fd.Length()); |
|
639 |
test(fhb != 0); |
|
640 |
HBufC* chb = HBufC::NewMax(cd.Length()); |
|
641 |
test(chb != 0); |
|
642 |
||
643 |
fhb->Des().Copy(fd); |
|
644 |
chb->Des().Copy(cd); |
|
645 |
||
646 |
test.Printf(_L("Error: %d; Cond: %S; File: %S; Line %d;\n"), aError, chb, fhb, aLine); |
|
647 |
test(0); |
|
648 |
} |