sl@0: // Copyright (c) 2005-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: // e32test\bench\d_kernbm.h sl@0: // Kernel side header containg internal definitions for d_kernasmbm ldd sl@0: // sl@0: // sl@0: sl@0: #ifndef __D_KERNBM_H__ sl@0: #define __D_KERNBM_H__ sl@0: sl@0: #include "d_kernasmbm.h" sl@0: sl@0: /// Base class for kernel benchmarks sl@0: class TKernelBenchmark sl@0: { sl@0: public: sl@0: const TBmInfo& Info() const; sl@0: virtual TInt Run(const TBmParams& aParams, TInt& aResult); sl@0: protected: sl@0: TKernelBenchmark(const TDesC8& aName); sl@0: TKernelBenchmark(const TDesC8& aName, TInt aAlignStep); sl@0: private: sl@0: virtual void DoRun(const TBmParams& aParams) = 0; sl@0: private: sl@0: TBmInfo iInfo; sl@0: }; sl@0: sl@0: #define CALL_10_TIMES(x) x; x; x; x; x; x; x; x; x; x sl@0: sl@0: /// Macro to define a benchmark sl@0: #define DEFINE_BENCHMARK(name, pre, test, post) \ sl@0: _LIT(KName_##name, #name); \ sl@0: class TGeneralBenchmark_##name : public TKernelBenchmark \ sl@0: { \ sl@0: public: \ sl@0: TGeneralBenchmark_##name():TKernelBenchmark(KName_##name){} \ sl@0: virtual void DoRun(const TBmParams& aParams) \ sl@0: { \ sl@0: TInt its = aParams.iIts; \ sl@0: pre; \ sl@0: for (TInt j = 0 ; j < its ; ++j) \ sl@0: { \ sl@0: CALL_10_TIMES(test); \ sl@0: } \ sl@0: post; \ sl@0: } \ sl@0: } Instance_##name sl@0: sl@0: /// Macro to define a memory benchmark sl@0: #define DEFINE_MEMORY_BENCHMARK(name, step, srcBase, destBase, pre, test, post) \ sl@0: _LIT(KName_##name, #name); \ sl@0: class TMemoryBenchmark_##name : public TKernelBenchmark \ sl@0: { \ sl@0: public: \ sl@0: TMemoryBenchmark_##name(): \ sl@0: TKernelBenchmark(KName_##name, step){} \ sl@0: virtual void DoRun(const TBmParams& aParams) \ sl@0: { \ sl@0: TInt its = aParams.iIts; \ sl@0: const TUint8* src = srcBase + aParams.iSourceAlign; \ sl@0: TUint8* dest = destBase + aParams.iDestAlign; \ sl@0: pre; \ sl@0: for (TInt j = 0 ; j < its ; ++j) \ sl@0: { \ sl@0: CALL_10_TIMES(test); \ sl@0: } \ sl@0: post; \ sl@0: } \ sl@0: } Instance_##name sl@0: sl@0: /// Base class for benchmarks using a second thread sl@0: class TThreadedBenchmark : public TKernelBenchmark sl@0: { sl@0: public: sl@0: virtual TInt Run(const TBmParams& aParams, TInt& aResult); sl@0: protected: sl@0: TThreadedBenchmark(const TDesC8& aName, TInt aRelPri); sl@0: private: sl@0: static TInt Thread2Func(TAny *aPtr); sl@0: virtual void DoRun2(TInt aIts) = 0; sl@0: protected: sl@0: DThread* iThread1; sl@0: DThread* iThread2; sl@0: private: sl@0: TInt iRelPri; sl@0: TInt iIts; sl@0: }; sl@0: sl@0: /// Macro to define a thread benchmark easily sl@0: #define DEFINE_THREADED_BENCHMARK(name, relPri, pre, test1, test2, post) \ sl@0: _LIT(KName_##name, #name); \ sl@0: class TKernelBenchmark_##name : public TThreadedBenchmark \ sl@0: { \ sl@0: public: \ sl@0: TKernelBenchmark_##name():TThreadedBenchmark(KName_##name, relPri){} \ sl@0: virtual void DoRun(const TBmParams& aParams) \ sl@0: { \ sl@0: TInt its = aParams.iIts; \ sl@0: pre; \ sl@0: for (TInt j = 0 ; j < its*10 ; ++j) \ sl@0: { \ sl@0: test1; \ sl@0: } \ sl@0: post; \ sl@0: } \ sl@0: virtual void DoRun2(TInt aIts) \ sl@0: { \ sl@0: for (TInt j = 0 ; j < aIts*10 ; ++j) \ sl@0: { \ sl@0: test2; \ sl@0: } \ sl@0: } \ sl@0: } Instance_##name sl@0: sl@0: /// Initialise data used by benchmarks sl@0: TInt InitData(); sl@0: sl@0: /// Clean up data used by benchmarks sl@0: void CloseData(); sl@0: sl@0: /// Pointer to user-side buffer, needed by some tests sl@0: extern TUint8* UserPtr; sl@0: sl@0: /// List of defined benchmarks sl@0: extern RPointerArray KernelBenchmarks; sl@0: sl@0: /// Macro to 32-byte align addresses sl@0: #define ALIGN_ADDR(a) ((TAny*)((((TInt)a) & ~0x1f) + 0x20)) sl@0: sl@0: #endif