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