Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 class RTLatency : public BMProgram
25 RBMChannel::TMode iMode;
29 Measurement(RBMChannel::TMode aMode, const TDesC& aName, TBool aForcePSwitch = EFalse) :
30 iMode(aMode), iName(aName), iForcePSwitch(aForcePSwitch) {}
34 RTLatency() : BMProgram(_L("Real-Time Latency"))
36 virtual TBMResult* Run(TBMUInt64 aIter, TInt* aCount);
38 static TBMResult iResults[];
39 static Measurement iMeasurements[];
41 void Perform(RBMChannel::TMode, TBMResult*, TBMUInt64 aIter, TBool aForcePSwitch);
42 static TInt Child(TAny*);
45 RTLatency::Measurement RTLatency::iMeasurements[] =
47 Measurement(RBMChannel::EInterruptLatency, _L("Interrupt Latency")),
48 Measurement(RBMChannel::EKernelPreemptionLatency, _L("Kernel Thread Preemption Latency (Idle)")),
49 Measurement(RBMChannel::EKernelPreemptionLatency, _L("Kernel Thread Preemption Latency(Busy)"), ETrue),
50 Measurement(RBMChannel::EUserPreemptionLatency, _L("User Thread Preemption Latency (Idle)")),
51 Measurement(RBMChannel::EUserPreemptionLatency, _L("User Thread Preemption Latency (Busy)"), ETrue),
52 Measurement(RBMChannel::ENTimerJitter, _L("NTimer Jitter")),
53 Measurement(RBMChannel::ETimerStampOverhead, _L("Getting Time Stamp Overhead"))
55 TBMResult RTLatency::iResults[sizeof(RTLatency::iMeasurements)/sizeof(RTLatency::iMeasurements[0])];
57 static RTLatency rtLatency;
59 struct ChildArgs : public TBMSpawnArgs
62 ChildArgs () : TBMSpawnArgs(RTLatency::Child, KBMPriorityLow, ETrue, sizeof(*this))
66 { //"Bm_SuiteSemaphore" is created/deleted a number of times during the test.
67 if (r) //If kernel did not clean up the previous instance, wait a sec and retry.
69 r = iSem.CreateGlobal(_L("Bm_SuiteSemaphore"), 0);
71 while(KErrAlreadyExists == r);
73 BM_ERROR(r, r == KErrNone);
77 iSem.Duplicate(iParent);
86 // Child process entry point.
88 TInt RTLatency::Child(TAny* ptr)
90 ChildArgs* ca = (ChildArgs*) ptr;
91 // get handles to all objects shared with the parent
93 // signal the parent that the child is ready
99 void RTLatency::Perform(RBMChannel::TMode aMode, TBMResult* aResult, TBMUInt64 aIter, TBool aForcePSwitch)
102 MBMChild* child = NULL;
105 // spawn a busy running low-pririty child process
106 child = rtLatency.SpawnChild(&ca);
111 TInt r = ch.Open(aMode);
113 return; // Assume that resources are being used for other forms of latency testing
114 BM_ERROR(r, r == KErrNone);
117 // request an interrupt
118 ch.RequestInterrupt();
120 // wait for the result. At this point the child becomes running.
122 aResult->Cumulate(ticks);
129 child->WaitChildExit();
134 TBMResult* RTLatency::Run(TBMUInt64 aIter, TInt* aCount)
136 TInt count = sizeof(iResults)/sizeof(iResults[0]);
138 for (TInt i = 0; i < count; ++i)
140 iResults[i].Reset(iMeasurements[i].iName);
141 Perform(iMeasurements[i].iMode, &iResults[i], aIter, iMeasurements[i].iForcePSwitch);
142 iResults[i].Update();
151 BMProgram* next = bmSuite;
152 bmSuite=(BMProgram*)&rtLatency;
153 bmSuite->Next()=next;