sl@0: // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #if !defined(__BM_BM_LDD_H__) sl@0: #define __BM_BM_LDD_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: /** sl@0: * The filename of the benchmark-suite logical device driver DLL sl@0: */ sl@0: _LIT(KBMLddFileName, "bm_ldd"); sl@0: /** sl@0: * The name of the benchmark-suite logical device. sl@0: */ sl@0: _LIT(KBMLdName, "bm_dev"); sl@0: sl@0: /** sl@0: * The filename of the benchmark-suite physical device driver DLL sl@0: */ sl@0: _LIT(KBMPddFileName, "bm_pdd"); sl@0: /** sl@0: * The name of the benchmark-suite physical device. sl@0: */ sl@0: _LIT(KBMPdName, "bm_dev.pdd"); sl@0: sl@0: typedef Uint64 TBMUInt64; sl@0: typedef Int64 TBMInt64; sl@0: sl@0: /** sl@0: * Integer type for high-resolution RBMTimer ticks. sl@0: */ sl@0: typedef TBMUInt64 TBMTicks; sl@0: /** sl@0: * Integer type for nano-second sl@0: */ sl@0: typedef TBMUInt64 TBMNs; sl@0: sl@0: /** sl@0: * Translates seconds to nano-seconds sl@0: */ sl@0: inline TBMNs BMSecondsToNs(TInt aSeconds) sl@0: { sl@0: return TBMNs(aSeconds) * 1000 * 1000 * 1000; sl@0: } sl@0: /** sl@0: * Translates milliseconds to nanoseconds sl@0: */ sl@0: inline TBMNs BMMsToNs(TInt aMs) sl@0: { sl@0: return TBMNs(aMs) * 1000 * 1000; sl@0: } sl@0: /** sl@0: * Translates microseconds to nanoseconds sl@0: */ sl@0: inline TBMNs BMUsToNs(TBMUInt64 aUs) sl@0: { sl@0: return TBMNs(aUs) * 1000; sl@0: } sl@0: /** sl@0: * Translates nanoseconds to seconds sl@0: */ sl@0: inline TInt BMNsToSeconds(TBMNs aNs) sl@0: { sl@0: return TInt(aNs/(1000 * 1000 * 1000)); sl@0: } sl@0: /** sl@0: * Translates nanoseconds to milliseconds sl@0: */ sl@0: inline TInt BMNsToMs(TBMNs aNs) sl@0: { sl@0: return TInt(aNs/(1000 * 1000)); sl@0: } sl@0: /** sl@0: * Translates nanoseconds to microseconds sl@0: */ sl@0: inline TBMUInt64 BMNsToUs(TBMNs aNs) sl@0: { sl@0: return aNs/(1000); sl@0: } sl@0: sl@0: /** sl@0: * RBMChannel class defines the user-side API to the kernel-side half of the benchmark-suite. sl@0: * sl@0: * The kernel-side half is implmented as KBMLdName logical and KBMPdName physical sl@0: * devices by KBMLddFileName logical and KBMPddFileName physical device driver DLLs sl@0: * respectively. sl@0: * sl@0: * The API enables to measure some kernel-side performace parameters such as interrupt and preemption latences. sl@0: */ sl@0: class RBMChannel : public RBusLogicalChannel sl@0: { sl@0: public: sl@0: sl@0: /** sl@0: * Measured performace parameters. sl@0: */ sl@0: enum TMode sl@0: { sl@0: /** sl@0: * Interrupt Latency is the elapsed time from the occurrence of an external event to the execution of sl@0: * the first instruction of the corresponding interrupt service routine (ISR). sl@0: */ sl@0: EInterruptLatency, sl@0: /** sl@0: * Kernel Preemption Latency is the elapsed time from the end of the ISR to the execution of the first sl@0: * instruction of a kernel thread activated by the ISR. sl@0: */ sl@0: EKernelPreemptionLatency, sl@0: /** sl@0: * User Preemption Latency is the elapsed time from the end of the ISR to the execution of the first sl@0: * instruction of a user thread activated by the ISR sl@0: */ sl@0: EUserPreemptionLatency, sl@0: /** sl@0: * NTimer callback invocations' jitter. sl@0: */ sl@0: ENTimerJitter, sl@0: /** sl@0: * The kernel-side overhead of one high-precision timer read. sl@0: */ sl@0: ETimerStampOverhead sl@0: }; sl@0: sl@0: /** sl@0: * The benchmark-suite logical device controls. sl@0: * sl@0: * There is three groups of controls: (1) measurement of a performance parameter which is accessible through sl@0: * RBMChannel, (2) high-resolution timer interface which is accessible through RBMTimer and (3) misc controls sl@0: * accessible through RBMDriver. sl@0: */ sl@0: enum TControl sl@0: { sl@0: /** sl@0: * Prepare to perform a sequence of measurements of a specific performance parameter. sl@0: */ sl@0: EStart, sl@0: /** sl@0: * Perform one measurement. sl@0: */ sl@0: ERequestInterrupt, sl@0: /** sl@0: * Get the result of the last measurement. sl@0: */ sl@0: EResult, sl@0: sl@0: /** sl@0: * Get the current high-resolution time. sl@0: */ sl@0: ETimerStamp, sl@0: /** sl@0: * Get the high-resolution timer period. sl@0: */ sl@0: ETimerPeriod, sl@0: /** sl@0: * Translate a time value from high-resolution timer ticks to nanoseconds. sl@0: */ sl@0: ETimerTicksToNs, sl@0: /** sl@0: * Translate a time value from nanoseconds to high-resolution timer ticks. sl@0: */ sl@0: ETimerNsToTicks, sl@0: sl@0: /** sl@0: * Change the absolute priority of a thread. sl@0: */ sl@0: ESetAbsPriority sl@0: }; sl@0: sl@0: #ifndef __KERNEL_MODE__ sl@0: /** sl@0: * Open the channel for measurements of one specific performance parameter. sl@0: * sl@0: * @param aMode specifies the performance parameter. sl@0: * sl@0: * @return KErrNone on success; otherwise an error code. sl@0: */ sl@0: TInt Open(TMode aMode) sl@0: { sl@0: TInt r = DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL); sl@0: if (r == KErrNone) sl@0: { sl@0: r = DoControl(EStart, (TAny*) aMode); sl@0: if (r != KErrNone) sl@0: { sl@0: Close(); sl@0: } sl@0: } sl@0: return r; sl@0: } sl@0: /** sl@0: * Perform one measurement. sl@0: */ sl@0: void RequestInterrupt() sl@0: { sl@0: DoControl(ERequestInterrupt); sl@0: } sl@0: /** sl@0: * Get the result of the last measurement. sl@0: * sl@0: * @retval aTicks the result of the last measurement in RBMTimer's ticks sl@0: */ sl@0: void Result(TBMTicks* aTicks) sl@0: { sl@0: User::WaitForAnyRequest(); sl@0: DoControl(EResult, aTicks); sl@0: } sl@0: #endif sl@0: }; sl@0: sl@0: /** sl@0: * RBMDriver class defines the user-side API to kernel-side utility operations. sl@0: * sl@0: * The operations are implmented as KBMLdName logical device by KBMLddFileName sl@0: * logical device driver DLL. sl@0: * sl@0: * The API enables to change the absolute prioirty of a thread. sl@0: */ sl@0: class RBMDriver : public RBusLogicalChannel sl@0: { sl@0: public: sl@0: #ifndef __KERNEL_MODE__ sl@0: /** sl@0: * Opens the channel sl@0: * sl@0: * @return KErrNone on success; otherwise an error code sl@0: */ sl@0: TInt Open() sl@0: { sl@0: return DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL); sl@0: } sl@0: /** sl@0: * Change the absolute prioirty of a thread. sl@0: * sl@0: * @param aThread a handle to the target thread sl@0: * @param aNewPrio a new absolute priority for the target thread sl@0: * sl@0: * @retval aOldPrio the old absolute priority of the target thread sl@0: * sl@0: * @return KErrNone on success; otherwise an error code sl@0: */ sl@0: TInt SetAbsPriority(RThread aThread, TInt aNewPrio, TInt* aOldPrio) sl@0: { sl@0: TInt aPrio = aNewPrio; sl@0: TInt r = DoControl(RBMChannel::ESetAbsPriority, (TAny*) aThread.Handle(), (TAny*) &aPrio); sl@0: if (r == KErrNone) sl@0: { sl@0: *aOldPrio = aPrio; sl@0: } sl@0: return r; sl@0: } sl@0: #endif sl@0: }; sl@0: sl@0: /** sl@0: * RBMTimer class defines the user-side API to the high-precision timer. sl@0: * sl@0: * The timer is implmented as KBMLdName logical and KBMPdName physical sl@0: * devices by KBMLddFileName logical and KBMPddFileName physical device driver DLLs sl@0: * respectively. sl@0: */ sl@0: class RBMTimer : public RBusLogicalChannel sl@0: { sl@0: public: sl@0: sl@0: #ifndef __KERNEL_MODE__ sl@0: /** sl@0: * Opens the channel to the high-precision timer. sl@0: * sl@0: * @return KErrNone on success; otherwise an error code sl@0: */ sl@0: TInt Open() sl@0: { sl@0: return DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL); sl@0: } sl@0: /** sl@0: * Gets the current time in ticks. sl@0: * sl@0: * @retval aTicks the current time in TBMTicks sl@0: */ sl@0: void Stamp(TBMTicks* aTicks) sl@0: { sl@0: DoControl(RBMChannel::ETimerStamp, aTicks); sl@0: } sl@0: /** sl@0: * Gets the timer period in ticks. sl@0: * sl@0: * @retval aPriod the timer period in TBMTicks sl@0: */ sl@0: void Period(TBMTicks* aPeriod) sl@0: { sl@0: DoControl(RBMChannel::ETimerPeriod, aPeriod); sl@0: } sl@0: /** sl@0: * Translates ticks to nano-seconds. sl@0: * sl@0: * @param aTciks a pointer to the TBMTicks value to be translated. sl@0: * sl@0: * @retval aNs the resulting time value in nanoseconds. sl@0: */ sl@0: void TicksToNs(TBMTicks* aTicks, TBMNs* aNs) sl@0: { sl@0: DoControl(RBMChannel::ETimerTicksToNs, aTicks, aNs); sl@0: } sl@0: /** sl@0: * Translates nanoseconds to ticks. sl@0: * sl@0: * @param aNs a pointer to the time value in nanoseconds to be translated. sl@0: * sl@0: * @retval aTicks the resulting time in TBMTicks. sl@0: */ sl@0: void NsToTicks(TBMNs* aNs, TBMTicks* aTicks) sl@0: { sl@0: DoControl(RBMChannel::ETimerTicksToNs, aNs, aTicks); sl@0: } sl@0: #endif sl@0: }; sl@0: sl@0: #endif