Update contrib.
1 // Copyright (c) 1999-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.
16 #if !defined(__BM_BM_LDD_H__)
17 #define __BM_BM_LDD_H__
23 * The filename of the benchmark-suite logical device driver DLL
25 _LIT(KBMLddFileName, "bm_ldd");
27 * The name of the benchmark-suite logical device.
29 _LIT(KBMLdName, "bm_dev");
32 * The filename of the benchmark-suite physical device driver DLL
34 _LIT(KBMPddFileName, "bm_pdd");
36 * The name of the benchmark-suite physical device.
38 _LIT(KBMPdName, "bm_dev.pdd");
40 typedef Uint64 TBMUInt64;
41 typedef Int64 TBMInt64;
44 * Integer type for high-resolution RBMTimer ticks.
46 typedef TBMUInt64 TBMTicks;
48 * Integer type for nano-second
50 typedef TBMUInt64 TBMNs;
53 * Translates seconds to nano-seconds
55 inline TBMNs BMSecondsToNs(TInt aSeconds)
57 return TBMNs(aSeconds) * 1000 * 1000 * 1000;
60 * Translates milliseconds to nanoseconds
62 inline TBMNs BMMsToNs(TInt aMs)
64 return TBMNs(aMs) * 1000 * 1000;
67 * Translates microseconds to nanoseconds
69 inline TBMNs BMUsToNs(TBMUInt64 aUs)
71 return TBMNs(aUs) * 1000;
74 * Translates nanoseconds to seconds
76 inline TInt BMNsToSeconds(TBMNs aNs)
78 return TInt(aNs/(1000 * 1000 * 1000));
81 * Translates nanoseconds to milliseconds
83 inline TInt BMNsToMs(TBMNs aNs)
85 return TInt(aNs/(1000 * 1000));
88 * Translates nanoseconds to microseconds
90 inline TBMUInt64 BMNsToUs(TBMNs aNs)
96 * RBMChannel class defines the user-side API to the kernel-side half of the benchmark-suite.
98 * The kernel-side half is implmented as <code>KBMLdName</code> logical and <code>KBMPdName</code> physical
99 * devices by <code>KBMLddFileName</code> logical and <code>KBMPddFileName</code> physical device driver DLLs
102 * The API enables to measure some kernel-side performace parameters such as interrupt and preemption latences.
104 class RBMChannel : public RBusLogicalChannel
109 * Measured performace parameters.
114 * Interrupt Latency is the elapsed time from the occurrence of an external event to the execution of
115 * the first instruction of the corresponding interrupt service routine (ISR).
119 * Kernel Preemption Latency is the elapsed time from the end of the ISR to the execution of the first
120 * instruction of a kernel thread activated by the ISR.
122 EKernelPreemptionLatency,
124 * User Preemption Latency is the elapsed time from the end of the ISR to the execution of the first
125 * instruction of a user thread activated by the ISR
127 EUserPreemptionLatency,
129 * NTimer callback invocations' jitter.
133 * The kernel-side overhead of one high-precision timer read.
139 * The benchmark-suite logical device controls.
141 * There is three groups of controls: (1) measurement of a performance parameter which is accessible through
142 * RBMChannel, (2) high-resolution timer interface which is accessible through RBMTimer and (3) misc controls
143 * accessible through RBMDriver.
148 * Prepare to perform a sequence of measurements of a specific performance parameter.
152 * Perform one measurement.
156 * Get the result of the last measurement.
161 * Get the current high-resolution time.
165 * Get the high-resolution timer period.
169 * Translate a time value from high-resolution timer ticks to nanoseconds.
173 * Translate a time value from nanoseconds to high-resolution timer ticks.
178 * Change the absolute priority of a thread.
183 #ifndef __KERNEL_MODE__
185 * Open the channel for measurements of one specific performance parameter.
187 * @param aMode specifies the performance parameter.
189 * @return <code>KErrNone</code> on success; otherwise an error code.
191 TInt Open(TMode aMode)
193 TInt r = DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
196 r = DoControl(EStart, (TAny*) aMode);
205 * Perform one measurement.
207 void RequestInterrupt()
209 DoControl(ERequestInterrupt);
212 * Get the result of the last measurement.
214 * @retval aTicks the result of the last measurement in RBMTimer's ticks
216 void Result(TBMTicks* aTicks)
218 User::WaitForAnyRequest();
219 DoControl(EResult, aTicks);
225 * RBMDriver class defines the user-side API to kernel-side utility operations.
227 * The operations are implmented as <code>KBMLdName</code> logical device by <code>KBMLddFileName</code>
228 * logical device driver DLL.
230 * The API enables to change the absolute prioirty of a thread.
232 class RBMDriver : public RBusLogicalChannel
235 #ifndef __KERNEL_MODE__
239 * @return <code>KErrNone</code> on success; otherwise an error code
243 return DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
246 * Change the absolute prioirty of a thread.
248 * @param aThread a handle to the target thread
249 * @param aNewPrio a new absolute priority for the target thread
251 * @retval aOldPrio the old absolute priority of the target thread
253 * @return <code>KErrNone</code> on success; otherwise an error code
255 TInt SetAbsPriority(RThread aThread, TInt aNewPrio, TInt* aOldPrio)
257 TInt aPrio = aNewPrio;
258 TInt r = DoControl(RBMChannel::ESetAbsPriority, (TAny*) aThread.Handle(), (TAny*) &aPrio);
269 * RBMTimer class defines the user-side API to the high-precision timer.
271 * The timer is implmented as <code>KBMLdName</code> logical and <code>KBMPdName</code> physical
272 * devices by <code>KBMLddFileName</code> logical and <code>KBMPddFileName</code> physical device driver DLLs
275 class RBMTimer : public RBusLogicalChannel
279 #ifndef __KERNEL_MODE__
281 * Opens the channel to the high-precision timer.
283 * @return <code>KErrNone</code> on success; otherwise an error code
287 return DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
290 * Gets the current time in ticks.
292 * @retval aTicks the current time in <code>TBMTicks</code>
294 void Stamp(TBMTicks* aTicks)
296 DoControl(RBMChannel::ETimerStamp, aTicks);
299 * Gets the timer period in ticks.
301 * @retval aPriod the timer period in <code>TBMTicks</code>
303 void Period(TBMTicks* aPeriod)
305 DoControl(RBMChannel::ETimerPeriod, aPeriod);
308 * Translates ticks to nano-seconds.
310 * @param aTciks a pointer to the <code>TBMTicks</code> value to be translated.
312 * @retval aNs the resulting time value in nanoseconds.
314 void TicksToNs(TBMTicks* aTicks, TBMNs* aNs)
316 DoControl(RBMChannel::ETimerTicksToNs, aTicks, aNs);
319 * Translates nanoseconds to ticks.
321 * @param aNs a pointer to the time value in nanoseconds to be translated.
323 * @retval aTicks the resulting time in <code>TBMTicks</code>.
325 void NsToTicks(TBMNs* aNs, TBMTicks* aTicks)
327 DoControl(RBMChannel::ETimerTicksToNs, aNs, aTicks);