sl@0
|
1 |
// Copyright (c) 1999-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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#if !defined(__BM_BM_LDD_H__)
|
sl@0
|
17 |
#define __BM_BM_LDD_H__
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32def.h>
|
sl@0
|
20 |
#include <e32cmn.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
/**
|
sl@0
|
23 |
* The filename of the benchmark-suite logical device driver DLL
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
_LIT(KBMLddFileName, "bm_ldd");
|
sl@0
|
26 |
/**
|
sl@0
|
27 |
* The name of the benchmark-suite logical device.
|
sl@0
|
28 |
*/
|
sl@0
|
29 |
_LIT(KBMLdName, "bm_dev");
|
sl@0
|
30 |
|
sl@0
|
31 |
/**
|
sl@0
|
32 |
* The filename of the benchmark-suite physical device driver DLL
|
sl@0
|
33 |
*/
|
sl@0
|
34 |
_LIT(KBMPddFileName, "bm_pdd");
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
* The name of the benchmark-suite physical device.
|
sl@0
|
37 |
*/
|
sl@0
|
38 |
_LIT(KBMPdName, "bm_dev.pdd");
|
sl@0
|
39 |
|
sl@0
|
40 |
typedef Uint64 TBMUInt64;
|
sl@0
|
41 |
typedef Int64 TBMInt64;
|
sl@0
|
42 |
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
* Integer type for high-resolution RBMTimer ticks.
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
typedef TBMUInt64 TBMTicks;
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
* Integer type for nano-second
|
sl@0
|
49 |
*/
|
sl@0
|
50 |
typedef TBMUInt64 TBMNs;
|
sl@0
|
51 |
|
sl@0
|
52 |
/**
|
sl@0
|
53 |
* Translates seconds to nano-seconds
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
inline TBMNs BMSecondsToNs(TInt aSeconds)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
return TBMNs(aSeconds) * 1000 * 1000 * 1000;
|
sl@0
|
58 |
}
|
sl@0
|
59 |
/**
|
sl@0
|
60 |
* Translates milliseconds to nanoseconds
|
sl@0
|
61 |
*/
|
sl@0
|
62 |
inline TBMNs BMMsToNs(TInt aMs)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
return TBMNs(aMs) * 1000 * 1000;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
/**
|
sl@0
|
67 |
* Translates microseconds to nanoseconds
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
inline TBMNs BMUsToNs(TBMUInt64 aUs)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
return TBMNs(aUs) * 1000;
|
sl@0
|
72 |
}
|
sl@0
|
73 |
/**
|
sl@0
|
74 |
* Translates nanoseconds to seconds
|
sl@0
|
75 |
*/
|
sl@0
|
76 |
inline TInt BMNsToSeconds(TBMNs aNs)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
return TInt(aNs/(1000 * 1000 * 1000));
|
sl@0
|
79 |
}
|
sl@0
|
80 |
/**
|
sl@0
|
81 |
* Translates nanoseconds to milliseconds
|
sl@0
|
82 |
*/
|
sl@0
|
83 |
inline TInt BMNsToMs(TBMNs aNs)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
return TInt(aNs/(1000 * 1000));
|
sl@0
|
86 |
}
|
sl@0
|
87 |
/**
|
sl@0
|
88 |
* Translates nanoseconds to microseconds
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
inline TBMUInt64 BMNsToUs(TBMNs aNs)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
return aNs/(1000);
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
/**
|
sl@0
|
96 |
* RBMChannel class defines the user-side API to the kernel-side half of the benchmark-suite.
|
sl@0
|
97 |
*
|
sl@0
|
98 |
* The kernel-side half is implmented as <code>KBMLdName</code> logical and <code>KBMPdName</code> physical
|
sl@0
|
99 |
* devices by <code>KBMLddFileName</code> logical and <code>KBMPddFileName</code> physical device driver DLLs
|
sl@0
|
100 |
* respectively.
|
sl@0
|
101 |
*
|
sl@0
|
102 |
* The API enables to measure some kernel-side performace parameters such as interrupt and preemption latences.
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
class RBMChannel : public RBusLogicalChannel
|
sl@0
|
105 |
{
|
sl@0
|
106 |
public:
|
sl@0
|
107 |
|
sl@0
|
108 |
/**
|
sl@0
|
109 |
* Measured performace parameters.
|
sl@0
|
110 |
*/
|
sl@0
|
111 |
enum TMode
|
sl@0
|
112 |
{
|
sl@0
|
113 |
/**
|
sl@0
|
114 |
* Interrupt Latency is the elapsed time from the occurrence of an external event to the execution of
|
sl@0
|
115 |
* the first instruction of the corresponding interrupt service routine (ISR).
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
EInterruptLatency,
|
sl@0
|
118 |
/**
|
sl@0
|
119 |
* Kernel Preemption Latency is the elapsed time from the end of the ISR to the execution of the first
|
sl@0
|
120 |
* instruction of a kernel thread activated by the ISR.
|
sl@0
|
121 |
*/
|
sl@0
|
122 |
EKernelPreemptionLatency,
|
sl@0
|
123 |
/**
|
sl@0
|
124 |
* User Preemption Latency is the elapsed time from the end of the ISR to the execution of the first
|
sl@0
|
125 |
* instruction of a user thread activated by the ISR
|
sl@0
|
126 |
*/
|
sl@0
|
127 |
EUserPreemptionLatency,
|
sl@0
|
128 |
/**
|
sl@0
|
129 |
* NTimer callback invocations' jitter.
|
sl@0
|
130 |
*/
|
sl@0
|
131 |
ENTimerJitter,
|
sl@0
|
132 |
/**
|
sl@0
|
133 |
* The kernel-side overhead of one high-precision timer read.
|
sl@0
|
134 |
*/
|
sl@0
|
135 |
ETimerStampOverhead
|
sl@0
|
136 |
};
|
sl@0
|
137 |
|
sl@0
|
138 |
/**
|
sl@0
|
139 |
* The benchmark-suite logical device controls.
|
sl@0
|
140 |
*
|
sl@0
|
141 |
* There is three groups of controls: (1) measurement of a performance parameter which is accessible through
|
sl@0
|
142 |
* RBMChannel, (2) high-resolution timer interface which is accessible through RBMTimer and (3) misc controls
|
sl@0
|
143 |
* accessible through RBMDriver.
|
sl@0
|
144 |
*/
|
sl@0
|
145 |
enum TControl
|
sl@0
|
146 |
{
|
sl@0
|
147 |
/**
|
sl@0
|
148 |
* Prepare to perform a sequence of measurements of a specific performance parameter.
|
sl@0
|
149 |
*/
|
sl@0
|
150 |
EStart,
|
sl@0
|
151 |
/**
|
sl@0
|
152 |
* Perform one measurement.
|
sl@0
|
153 |
*/
|
sl@0
|
154 |
ERequestInterrupt,
|
sl@0
|
155 |
/**
|
sl@0
|
156 |
* Get the result of the last measurement.
|
sl@0
|
157 |
*/
|
sl@0
|
158 |
EResult,
|
sl@0
|
159 |
|
sl@0
|
160 |
/**
|
sl@0
|
161 |
* Get the current high-resolution time.
|
sl@0
|
162 |
*/
|
sl@0
|
163 |
ETimerStamp,
|
sl@0
|
164 |
/**
|
sl@0
|
165 |
* Get the high-resolution timer period.
|
sl@0
|
166 |
*/
|
sl@0
|
167 |
ETimerPeriod,
|
sl@0
|
168 |
/**
|
sl@0
|
169 |
* Translate a time value from high-resolution timer ticks to nanoseconds.
|
sl@0
|
170 |
*/
|
sl@0
|
171 |
ETimerTicksToNs,
|
sl@0
|
172 |
/**
|
sl@0
|
173 |
* Translate a time value from nanoseconds to high-resolution timer ticks.
|
sl@0
|
174 |
*/
|
sl@0
|
175 |
ETimerNsToTicks,
|
sl@0
|
176 |
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
* Change the absolute priority of a thread.
|
sl@0
|
179 |
*/
|
sl@0
|
180 |
ESetAbsPriority
|
sl@0
|
181 |
};
|
sl@0
|
182 |
|
sl@0
|
183 |
#ifndef __KERNEL_MODE__
|
sl@0
|
184 |
/**
|
sl@0
|
185 |
* Open the channel for measurements of one specific performance parameter.
|
sl@0
|
186 |
*
|
sl@0
|
187 |
* @param aMode specifies the performance parameter.
|
sl@0
|
188 |
*
|
sl@0
|
189 |
* @return <code>KErrNone</code> on success; otherwise an error code.
|
sl@0
|
190 |
*/
|
sl@0
|
191 |
TInt Open(TMode aMode)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
TInt r = DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
|
sl@0
|
194 |
if (r == KErrNone)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
r = DoControl(EStart, (TAny*) aMode);
|
sl@0
|
197 |
if (r != KErrNone)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
Close();
|
sl@0
|
200 |
}
|
sl@0
|
201 |
}
|
sl@0
|
202 |
return r;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
/**
|
sl@0
|
205 |
* Perform one measurement.
|
sl@0
|
206 |
*/
|
sl@0
|
207 |
void RequestInterrupt()
|
sl@0
|
208 |
{
|
sl@0
|
209 |
DoControl(ERequestInterrupt);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
/**
|
sl@0
|
212 |
* Get the result of the last measurement.
|
sl@0
|
213 |
*
|
sl@0
|
214 |
* @retval aTicks the result of the last measurement in RBMTimer's ticks
|
sl@0
|
215 |
*/
|
sl@0
|
216 |
void Result(TBMTicks* aTicks)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
User::WaitForAnyRequest();
|
sl@0
|
219 |
DoControl(EResult, aTicks);
|
sl@0
|
220 |
}
|
sl@0
|
221 |
#endif
|
sl@0
|
222 |
};
|
sl@0
|
223 |
|
sl@0
|
224 |
/**
|
sl@0
|
225 |
* RBMDriver class defines the user-side API to kernel-side utility operations.
|
sl@0
|
226 |
*
|
sl@0
|
227 |
* The operations are implmented as <code>KBMLdName</code> logical device by <code>KBMLddFileName</code>
|
sl@0
|
228 |
* logical device driver DLL.
|
sl@0
|
229 |
*
|
sl@0
|
230 |
* The API enables to change the absolute prioirty of a thread.
|
sl@0
|
231 |
*/
|
sl@0
|
232 |
class RBMDriver : public RBusLogicalChannel
|
sl@0
|
233 |
{
|
sl@0
|
234 |
public:
|
sl@0
|
235 |
#ifndef __KERNEL_MODE__
|
sl@0
|
236 |
/**
|
sl@0
|
237 |
* Opens the channel
|
sl@0
|
238 |
*
|
sl@0
|
239 |
* @return <code>KErrNone</code> on success; otherwise an error code
|
sl@0
|
240 |
*/
|
sl@0
|
241 |
TInt Open()
|
sl@0
|
242 |
{
|
sl@0
|
243 |
return DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
|
sl@0
|
244 |
}
|
sl@0
|
245 |
/**
|
sl@0
|
246 |
* Change the absolute prioirty of a thread.
|
sl@0
|
247 |
*
|
sl@0
|
248 |
* @param aThread a handle to the target thread
|
sl@0
|
249 |
* @param aNewPrio a new absolute priority for the target thread
|
sl@0
|
250 |
*
|
sl@0
|
251 |
* @retval aOldPrio the old absolute priority of the target thread
|
sl@0
|
252 |
*
|
sl@0
|
253 |
* @return <code>KErrNone</code> on success; otherwise an error code
|
sl@0
|
254 |
*/
|
sl@0
|
255 |
TInt SetAbsPriority(RThread aThread, TInt aNewPrio, TInt* aOldPrio)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
TInt aPrio = aNewPrio;
|
sl@0
|
258 |
TInt r = DoControl(RBMChannel::ESetAbsPriority, (TAny*) aThread.Handle(), (TAny*) &aPrio);
|
sl@0
|
259 |
if (r == KErrNone)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
*aOldPrio = aPrio;
|
sl@0
|
262 |
}
|
sl@0
|
263 |
return r;
|
sl@0
|
264 |
}
|
sl@0
|
265 |
#endif
|
sl@0
|
266 |
};
|
sl@0
|
267 |
|
sl@0
|
268 |
/**
|
sl@0
|
269 |
* RBMTimer class defines the user-side API to the high-precision timer.
|
sl@0
|
270 |
*
|
sl@0
|
271 |
* The timer is implmented as <code>KBMLdName</code> logical and <code>KBMPdName</code> physical
|
sl@0
|
272 |
* devices by <code>KBMLddFileName</code> logical and <code>KBMPddFileName</code> physical device driver DLLs
|
sl@0
|
273 |
* respectively.
|
sl@0
|
274 |
*/
|
sl@0
|
275 |
class RBMTimer : public RBusLogicalChannel
|
sl@0
|
276 |
{
|
sl@0
|
277 |
public:
|
sl@0
|
278 |
|
sl@0
|
279 |
#ifndef __KERNEL_MODE__
|
sl@0
|
280 |
/**
|
sl@0
|
281 |
* Opens the channel to the high-precision timer.
|
sl@0
|
282 |
*
|
sl@0
|
283 |
* @return <code>KErrNone</code> on success; otherwise an error code
|
sl@0
|
284 |
*/
|
sl@0
|
285 |
TInt Open()
|
sl@0
|
286 |
{
|
sl@0
|
287 |
return DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
|
sl@0
|
288 |
}
|
sl@0
|
289 |
/**
|
sl@0
|
290 |
* Gets the current time in ticks.
|
sl@0
|
291 |
*
|
sl@0
|
292 |
* @retval aTicks the current time in <code>TBMTicks</code>
|
sl@0
|
293 |
*/
|
sl@0
|
294 |
void Stamp(TBMTicks* aTicks)
|
sl@0
|
295 |
{
|
sl@0
|
296 |
DoControl(RBMChannel::ETimerStamp, aTicks);
|
sl@0
|
297 |
}
|
sl@0
|
298 |
/**
|
sl@0
|
299 |
* Gets the timer period in ticks.
|
sl@0
|
300 |
*
|
sl@0
|
301 |
* @retval aPriod the timer period in <code>TBMTicks</code>
|
sl@0
|
302 |
*/
|
sl@0
|
303 |
void Period(TBMTicks* aPeriod)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
DoControl(RBMChannel::ETimerPeriod, aPeriod);
|
sl@0
|
306 |
}
|
sl@0
|
307 |
/**
|
sl@0
|
308 |
* Translates ticks to nano-seconds.
|
sl@0
|
309 |
*
|
sl@0
|
310 |
* @param aTciks a pointer to the <code>TBMTicks</code> value to be translated.
|
sl@0
|
311 |
*
|
sl@0
|
312 |
* @retval aNs the resulting time value in nanoseconds.
|
sl@0
|
313 |
*/
|
sl@0
|
314 |
void TicksToNs(TBMTicks* aTicks, TBMNs* aNs)
|
sl@0
|
315 |
{
|
sl@0
|
316 |
DoControl(RBMChannel::ETimerTicksToNs, aTicks, aNs);
|
sl@0
|
317 |
}
|
sl@0
|
318 |
/**
|
sl@0
|
319 |
* Translates nanoseconds to ticks.
|
sl@0
|
320 |
*
|
sl@0
|
321 |
* @param aNs a pointer to the time value in nanoseconds to be translated.
|
sl@0
|
322 |
*
|
sl@0
|
323 |
* @retval aTicks the resulting time in <code>TBMTicks</code>.
|
sl@0
|
324 |
*/
|
sl@0
|
325 |
void NsToTicks(TBMNs* aNs, TBMTicks* aTicks)
|
sl@0
|
326 |
{
|
sl@0
|
327 |
DoControl(RBMChannel::ETimerTicksToNs, aNs, aTicks);
|
sl@0
|
328 |
}
|
sl@0
|
329 |
#endif
|
sl@0
|
330 |
};
|
sl@0
|
331 |
|
sl@0
|
332 |
#endif
|