1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/benchmark/d32bm.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,332 @@
1.4 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#if !defined(__BM_BM_LDD_H__)
1.20 +#define __BM_BM_LDD_H__
1.21 +
1.22 +#include <e32def.h>
1.23 +#include <e32cmn.h>
1.24 +
1.25 +/**
1.26 + * The filename of the benchmark-suite logical device driver DLL
1.27 + */
1.28 +_LIT(KBMLddFileName, "bm_ldd");
1.29 +/**
1.30 + * The name of the benchmark-suite logical device.
1.31 + */
1.32 +_LIT(KBMLdName, "bm_dev");
1.33 +
1.34 +/**
1.35 + * The filename of the benchmark-suite physical device driver DLL
1.36 + */
1.37 +_LIT(KBMPddFileName, "bm_pdd");
1.38 +/**
1.39 + * The name of the benchmark-suite physical device.
1.40 + */
1.41 +_LIT(KBMPdName, "bm_dev.pdd");
1.42 +
1.43 +typedef Uint64 TBMUInt64;
1.44 +typedef Int64 TBMInt64;
1.45 +
1.46 +/**
1.47 + * Integer type for high-resolution RBMTimer ticks.
1.48 + */
1.49 +typedef TBMUInt64 TBMTicks;
1.50 +/**
1.51 + * Integer type for nano-second
1.52 + */
1.53 +typedef TBMUInt64 TBMNs;
1.54 +
1.55 +/**
1.56 + * Translates seconds to nano-seconds
1.57 + */
1.58 + inline TBMNs BMSecondsToNs(TInt aSeconds)
1.59 + {
1.60 + return TBMNs(aSeconds) * 1000 * 1000 * 1000;
1.61 + }
1.62 +/**
1.63 + * Translates milliseconds to nanoseconds
1.64 + */
1.65 + inline TBMNs BMMsToNs(TInt aMs)
1.66 + {
1.67 + return TBMNs(aMs) * 1000 * 1000;
1.68 + }
1.69 +/**
1.70 + * Translates microseconds to nanoseconds
1.71 + */
1.72 + inline TBMNs BMUsToNs(TBMUInt64 aUs)
1.73 + {
1.74 + return TBMNs(aUs) * 1000;
1.75 + }
1.76 +/**
1.77 + * Translates nanoseconds to seconds
1.78 + */
1.79 +inline TInt BMNsToSeconds(TBMNs aNs)
1.80 + {
1.81 + return TInt(aNs/(1000 * 1000 * 1000));
1.82 + }
1.83 +/**
1.84 + * Translates nanoseconds to milliseconds
1.85 + */
1.86 +inline TInt BMNsToMs(TBMNs aNs)
1.87 + {
1.88 + return TInt(aNs/(1000 * 1000));
1.89 + }
1.90 +/**
1.91 + * Translates nanoseconds to microseconds
1.92 + */
1.93 +inline TBMUInt64 BMNsToUs(TBMNs aNs)
1.94 + {
1.95 + return aNs/(1000);
1.96 + }
1.97 +
1.98 +/**
1.99 + * RBMChannel class defines the user-side API to the kernel-side half of the benchmark-suite.
1.100 + *
1.101 + * The kernel-side half is implmented as <code>KBMLdName</code> logical and <code>KBMPdName</code> physical
1.102 + * devices by <code>KBMLddFileName</code> logical and <code>KBMPddFileName</code> physical device driver DLLs
1.103 + * respectively.
1.104 + *
1.105 + * The API enables to measure some kernel-side performace parameters such as interrupt and preemption latences.
1.106 + */
1.107 +class RBMChannel : public RBusLogicalChannel
1.108 + {
1.109 +public:
1.110 +
1.111 + /**
1.112 + * Measured performace parameters.
1.113 + */
1.114 + enum TMode
1.115 + {
1.116 + /**
1.117 + * Interrupt Latency is the elapsed time from the occurrence of an external event to the execution of
1.118 + * the first instruction of the corresponding interrupt service routine (ISR).
1.119 + */
1.120 + EInterruptLatency,
1.121 + /**
1.122 + * Kernel Preemption Latency is the elapsed time from the end of the ISR to the execution of the first
1.123 + * instruction of a kernel thread activated by the ISR.
1.124 + */
1.125 + EKernelPreemptionLatency,
1.126 + /**
1.127 + * User Preemption Latency is the elapsed time from the end of the ISR to the execution of the first
1.128 + * instruction of a user thread activated by the ISR
1.129 + */
1.130 + EUserPreemptionLatency,
1.131 + /**
1.132 + * NTimer callback invocations' jitter.
1.133 + */
1.134 + ENTimerJitter,
1.135 + /**
1.136 + * The kernel-side overhead of one high-precision timer read.
1.137 + */
1.138 + ETimerStampOverhead
1.139 + };
1.140 +
1.141 + /**
1.142 + * The benchmark-suite logical device controls.
1.143 + *
1.144 + * There is three groups of controls: (1) measurement of a performance parameter which is accessible through
1.145 + * RBMChannel, (2) high-resolution timer interface which is accessible through RBMTimer and (3) misc controls
1.146 + * accessible through RBMDriver.
1.147 + */
1.148 + enum TControl
1.149 + {
1.150 + /**
1.151 + * Prepare to perform a sequence of measurements of a specific performance parameter.
1.152 + */
1.153 + EStart,
1.154 + /**
1.155 + * Perform one measurement.
1.156 + */
1.157 + ERequestInterrupt,
1.158 + /**
1.159 + * Get the result of the last measurement.
1.160 + */
1.161 + EResult,
1.162 +
1.163 + /**
1.164 + * Get the current high-resolution time.
1.165 + */
1.166 + ETimerStamp,
1.167 + /**
1.168 + * Get the high-resolution timer period.
1.169 + */
1.170 + ETimerPeriod,
1.171 + /**
1.172 + * Translate a time value from high-resolution timer ticks to nanoseconds.
1.173 + */
1.174 + ETimerTicksToNs,
1.175 + /**
1.176 + * Translate a time value from nanoseconds to high-resolution timer ticks.
1.177 + */
1.178 + ETimerNsToTicks,
1.179 +
1.180 + /**
1.181 + * Change the absolute priority of a thread.
1.182 + */
1.183 + ESetAbsPriority
1.184 + };
1.185 +
1.186 +#ifndef __KERNEL_MODE__
1.187 + /**
1.188 + * Open the channel for measurements of one specific performance parameter.
1.189 + *
1.190 + * @param aMode specifies the performance parameter.
1.191 + *
1.192 + * @return <code>KErrNone</code> on success; otherwise an error code.
1.193 + */
1.194 + TInt Open(TMode aMode)
1.195 + {
1.196 + TInt r = DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
1.197 + if (r == KErrNone)
1.198 + {
1.199 + r = DoControl(EStart, (TAny*) aMode);
1.200 + if (r != KErrNone)
1.201 + {
1.202 + Close();
1.203 + }
1.204 + }
1.205 + return r;
1.206 + }
1.207 + /**
1.208 + * Perform one measurement.
1.209 + */
1.210 + void RequestInterrupt()
1.211 + {
1.212 + DoControl(ERequestInterrupt);
1.213 + }
1.214 + /**
1.215 + * Get the result of the last measurement.
1.216 + *
1.217 + * @retval aTicks the result of the last measurement in RBMTimer's ticks
1.218 + */
1.219 + void Result(TBMTicks* aTicks)
1.220 + {
1.221 + User::WaitForAnyRequest();
1.222 + DoControl(EResult, aTicks);
1.223 + }
1.224 +#endif
1.225 + };
1.226 +
1.227 +/**
1.228 + * RBMDriver class defines the user-side API to kernel-side utility operations.
1.229 + *
1.230 + * The operations are implmented as <code>KBMLdName</code> logical device by <code>KBMLddFileName</code>
1.231 + * logical device driver DLL.
1.232 + *
1.233 + * The API enables to change the absolute prioirty of a thread.
1.234 + */
1.235 +class RBMDriver : public RBusLogicalChannel
1.236 + {
1.237 +public:
1.238 +#ifndef __KERNEL_MODE__
1.239 + /**
1.240 + * Opens the channel
1.241 + *
1.242 + * @return <code>KErrNone</code> on success; otherwise an error code
1.243 + */
1.244 + TInt Open()
1.245 + {
1.246 + return DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
1.247 + }
1.248 + /**
1.249 + * Change the absolute prioirty of a thread.
1.250 + *
1.251 + * @param aThread a handle to the target thread
1.252 + * @param aNewPrio a new absolute priority for the target thread
1.253 + *
1.254 + * @retval aOldPrio the old absolute priority of the target thread
1.255 + *
1.256 + * @return <code>KErrNone</code> on success; otherwise an error code
1.257 + */
1.258 + TInt SetAbsPriority(RThread aThread, TInt aNewPrio, TInt* aOldPrio)
1.259 + {
1.260 + TInt aPrio = aNewPrio;
1.261 + TInt r = DoControl(RBMChannel::ESetAbsPriority, (TAny*) aThread.Handle(), (TAny*) &aPrio);
1.262 + if (r == KErrNone)
1.263 + {
1.264 + *aOldPrio = aPrio;
1.265 + }
1.266 + return r;
1.267 + }
1.268 +#endif
1.269 + };
1.270 +
1.271 +/**
1.272 + * RBMTimer class defines the user-side API to the high-precision timer.
1.273 + *
1.274 + * The timer is implmented as <code>KBMLdName</code> logical and <code>KBMPdName</code> physical
1.275 + * devices by <code>KBMLddFileName</code> logical and <code>KBMPddFileName</code> physical device driver DLLs
1.276 + * respectively.
1.277 + */
1.278 +class RBMTimer : public RBusLogicalChannel
1.279 + {
1.280 +public:
1.281 +
1.282 +#ifndef __KERNEL_MODE__
1.283 + /**
1.284 + * Opens the channel to the high-precision timer.
1.285 + *
1.286 + * @return <code>KErrNone</code> on success; otherwise an error code
1.287 + */
1.288 + TInt Open()
1.289 + {
1.290 + return DoCreate(KBMLdName, TVersion(1,0,1), KNullUnit, &KBMPdName, NULL);
1.291 + }
1.292 + /**
1.293 + * Gets the current time in ticks.
1.294 + *
1.295 + * @retval aTicks the current time in <code>TBMTicks</code>
1.296 + */
1.297 + void Stamp(TBMTicks* aTicks)
1.298 + {
1.299 + DoControl(RBMChannel::ETimerStamp, aTicks);
1.300 + }
1.301 + /**
1.302 + * Gets the timer period in ticks.
1.303 + *
1.304 + * @retval aPriod the timer period in <code>TBMTicks</code>
1.305 + */
1.306 + void Period(TBMTicks* aPeriod)
1.307 + {
1.308 + DoControl(RBMChannel::ETimerPeriod, aPeriod);
1.309 + }
1.310 + /**
1.311 + * Translates ticks to nano-seconds.
1.312 + *
1.313 + * @param aTciks a pointer to the <code>TBMTicks</code> value to be translated.
1.314 + *
1.315 + * @retval aNs the resulting time value in nanoseconds.
1.316 + */
1.317 + void TicksToNs(TBMTicks* aTicks, TBMNs* aNs)
1.318 + {
1.319 + DoControl(RBMChannel::ETimerTicksToNs, aTicks, aNs);
1.320 + }
1.321 + /**
1.322 + * Translates nanoseconds to ticks.
1.323 + *
1.324 + * @param aNs a pointer to the time value in nanoseconds to be translated.
1.325 + *
1.326 + * @retval aTicks the resulting time in <code>TBMTicks</code>.
1.327 + */
1.328 + void NsToTicks(TBMNs* aNs, TBMTicks* aTicks)
1.329 + {
1.330 + DoControl(RBMChannel::ETimerTicksToNs, aNs, aTicks);
1.331 + }
1.332 +#endif
1.333 + };
1.334 +
1.335 +#endif