os/kernelhwsrv/kerneltest/e32test/bench/d_kernbm.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\bench\d_kernbm.h
    15 // Kernel side header containg internal definitions for d_kernasmbm ldd
    16 // 
    17 //
    18 
    19 #ifndef __D_KERNBM_H__
    20 #define __D_KERNBM_H__
    21 
    22 #include "d_kernasmbm.h"
    23 
    24 /// Base class for kernel benchmarks
    25 class TKernelBenchmark
    26 	{
    27 public:
    28 	const TBmInfo& Info() const;
    29 	virtual TInt Run(const TBmParams& aParams, TInt& aResult);
    30 protected:
    31 	TKernelBenchmark(const TDesC8& aName);
    32 	TKernelBenchmark(const TDesC8& aName, TInt aAlignStep);
    33 private:
    34 	virtual void DoRun(const TBmParams& aParams) = 0;
    35 private:
    36 	TBmInfo iInfo;
    37 	};
    38 
    39 #define CALL_10_TIMES(x) x; x; x; x; x; x; x; x; x; x
    40 
    41 /// Macro to define a benchmark
    42 #define DEFINE_BENCHMARK(name, pre, test, post)                  \
    43 _LIT(KName_##name, #name);                                       \
    44 class TGeneralBenchmark_##name : public TKernelBenchmark         \
    45 	{                                                            \
    46 	public:                                                      \
    47 	TGeneralBenchmark_##name():TKernelBenchmark(KName_##name){}  \
    48 	virtual void DoRun(const TBmParams& aParams)                 \
    49 		{                                                        \
    50 		TInt its = aParams.iIts;                                 \
    51 		pre;                                                     \
    52 		for (TInt j = 0 ; j < its ; ++j)                         \
    53 			{                                                    \
    54 			CALL_10_TIMES(test);                                 \
    55 			}                                                    \
    56 		post;                                                    \
    57 		}                                                        \
    58 	} Instance_##name
    59 
    60 /// Macro to define a memory benchmark
    61 #define DEFINE_MEMORY_BENCHMARK(name, step, srcBase, destBase, pre, test, post) \
    62 _LIT(KName_##name, #name);                                       \
    63 class TMemoryBenchmark_##name : public TKernelBenchmark          \
    64 	{                                                            \
    65 public:                                                          \
    66 	TMemoryBenchmark_##name():                                   \
    67 		TKernelBenchmark(KName_##name, step){}                   \
    68 	virtual void DoRun(const TBmParams& aParams)                 \
    69 		{                                                        \
    70 		TInt its = aParams.iIts;                                 \
    71 		const TUint8* src = srcBase + aParams.iSourceAlign;      \
    72 		TUint8* dest = destBase + aParams.iDestAlign;            \
    73 		pre;                                                     \
    74 		for (TInt j = 0 ; j < its ; ++j)                         \
    75 			{                                                    \
    76 			CALL_10_TIMES(test);                                 \
    77 			}                                                    \
    78 		post;                                                    \
    79 		}                                                        \
    80 	} Instance_##name
    81 
    82 /// Base class for benchmarks using a second thread
    83 class TThreadedBenchmark : public TKernelBenchmark
    84 	{
    85 public:
    86 	virtual TInt Run(const TBmParams& aParams, TInt& aResult);
    87 protected:
    88 	TThreadedBenchmark(const TDesC8& aName, TInt aRelPri);
    89 private:
    90 	static TInt Thread2Func(TAny *aPtr);
    91 	virtual void DoRun2(TInt aIts) = 0;
    92 protected:
    93 	DThread* iThread1;
    94 	DThread* iThread2;
    95 private:
    96 	TInt iRelPri;
    97 	TInt iIts;
    98 	};
    99 
   100 /// Macro to define a thread benchmark easily
   101 #define DEFINE_THREADED_BENCHMARK(name, relPri, pre, test1, test2, post) \
   102 _LIT(KName_##name, #name);                                               \
   103 class TKernelBenchmark_##name : public TThreadedBenchmark                \
   104 	{                                                                    \
   105 public:                                                                  \
   106 	TKernelBenchmark_##name():TThreadedBenchmark(KName_##name, relPri){} \
   107 	virtual void DoRun(const TBmParams& aParams)                         \
   108 		{                                                                \
   109 		TInt its = aParams.iIts;                                         \
   110 		pre;                                                             \
   111 		for (TInt j = 0 ; j < its*10 ; ++j)                              \
   112 			{                                                            \
   113 			test1;                                                       \
   114 			}                                                            \
   115 		post;                                                            \
   116 		}                                                                \
   117 	virtual void DoRun2(TInt aIts)                                       \
   118 		{                                                                \
   119 		for (TInt j = 0 ; j < aIts*10 ; ++j)                             \
   120 			{                                                            \
   121 			test2;                                                       \
   122 			}                                                            \
   123 		}                                                                \
   124 	} Instance_##name
   125 
   126 /// Initialise data used by benchmarks
   127 TInt InitData();
   128 
   129 /// Clean up data used by benchmarks
   130 void CloseData();
   131 
   132 /// Pointer to user-side buffer, needed by some tests
   133 extern TUint8* UserPtr;
   134 
   135 /// List of defined benchmarks
   136 extern RPointerArray<TKernelBenchmark> KernelBenchmarks;
   137 
   138 /// Macro to 32-byte align addresses
   139 #define ALIGN_ADDR(a) ((TAny*)((((TInt)a) & ~0x1f) + 0x20))
   140 
   141 #endif