|
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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 |
|
18 #include "bm_suite.h" |
|
19 |
|
20 class RTLatency : public BMProgram |
|
21 { |
|
22 |
|
23 struct Measurement |
|
24 { |
|
25 RBMChannel::TMode iMode; |
|
26 TPtrC iName; |
|
27 TBool iForcePSwitch; |
|
28 |
|
29 Measurement(RBMChannel::TMode aMode, const TDesC& aName, TBool aForcePSwitch = EFalse) : |
|
30 iMode(aMode), iName(aName), iForcePSwitch(aForcePSwitch) {} |
|
31 }; |
|
32 |
|
33 public : |
|
34 RTLatency() : BMProgram(_L("Real-Time Latency")) |
|
35 {} |
|
36 virtual TBMResult* Run(TBMUInt64 aIter, TInt* aCount); |
|
37 |
|
38 static TBMResult iResults[]; |
|
39 static Measurement iMeasurements[]; |
|
40 |
|
41 void Perform(RBMChannel::TMode, TBMResult*, TBMUInt64 aIter, TBool aForcePSwitch); |
|
42 static TInt Child(TAny*); |
|
43 }; |
|
44 |
|
45 RTLatency::Measurement RTLatency::iMeasurements[] = |
|
46 { |
|
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")) |
|
54 }; |
|
55 TBMResult RTLatency::iResults[sizeof(RTLatency::iMeasurements)/sizeof(RTLatency::iMeasurements[0])]; |
|
56 |
|
57 static RTLatency rtLatency; |
|
58 |
|
59 struct ChildArgs : public TBMSpawnArgs |
|
60 { |
|
61 RSemaphore iSem; |
|
62 ChildArgs () : TBMSpawnArgs(RTLatency::Child, KBMPriorityLow, ETrue, sizeof(*this)) |
|
63 { |
|
64 TInt r = KErrNone; |
|
65 do |
|
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. |
|
68 User::After(1000000); |
|
69 r = iSem.CreateGlobal(_L("Bm_SuiteSemaphore"), 0); |
|
70 } |
|
71 while(KErrAlreadyExists == r); |
|
72 |
|
73 BM_ERROR(r, r == KErrNone); |
|
74 } |
|
75 void ChildOpen() |
|
76 { |
|
77 iSem.Duplicate(iParent); |
|
78 } |
|
79 ~ChildArgs () |
|
80 { |
|
81 iSem.Close(); |
|
82 } |
|
83 }; |
|
84 |
|
85 // |
|
86 // Child process entry point. |
|
87 // |
|
88 TInt RTLatency::Child(TAny* ptr) |
|
89 { |
|
90 ChildArgs* ca = (ChildArgs*) ptr; |
|
91 // get handles to all objects shared with the parent |
|
92 ca->ChildOpen(); |
|
93 // signal the parent that the child is ready |
|
94 ca->iSem.Signal(); |
|
95 // loop forever |
|
96 for(;;) {} |
|
97 } |
|
98 |
|
99 void RTLatency::Perform(RBMChannel::TMode aMode, TBMResult* aResult, TBMUInt64 aIter, TBool aForcePSwitch) |
|
100 { |
|
101 ChildArgs ca; |
|
102 MBMChild* child = NULL; |
|
103 if (aForcePSwitch) |
|
104 { |
|
105 // spawn a busy running low-pririty child process |
|
106 child = rtLatency.SpawnChild(&ca); |
|
107 ca.iSem.Wait(); |
|
108 } |
|
109 |
|
110 RBMChannel ch; |
|
111 TInt r = ch.Open(aMode); |
|
112 if(r==KErrInUse) |
|
113 return; // Assume that resources are being used for other forms of latency testing |
|
114 BM_ERROR(r, r == KErrNone); |
|
115 while(aIter--) |
|
116 { |
|
117 // request an interrupt |
|
118 ch.RequestInterrupt(); |
|
119 TBMTicks ticks; |
|
120 // wait for the result. At this point the child becomes running. |
|
121 ch.Result(&ticks); |
|
122 aResult->Cumulate(ticks); |
|
123 } |
|
124 ch.Close(); |
|
125 |
|
126 if (aForcePSwitch) |
|
127 { |
|
128 child->Kill(); |
|
129 child->WaitChildExit(); |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 TBMResult* RTLatency::Run(TBMUInt64 aIter, TInt* aCount) |
|
135 { |
|
136 TInt count = sizeof(iResults)/sizeof(iResults[0]); |
|
137 |
|
138 for (TInt i = 0; i < count; ++i) |
|
139 { |
|
140 iResults[i].Reset(iMeasurements[i].iName); |
|
141 Perform(iMeasurements[i].iMode, &iResults[i], aIter, iMeasurements[i].iForcePSwitch); |
|
142 iResults[i].Update(); |
|
143 } |
|
144 |
|
145 *aCount = count; |
|
146 return iResults; |
|
147 } |
|
148 |
|
149 void AddrtLatency() |
|
150 { |
|
151 BMProgram* next = bmSuite; |
|
152 bmSuite=(BMProgram*)&rtLatency; |
|
153 bmSuite->Next()=next; |
|
154 } |