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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\bench\d_kernasmbm.cpp
15 // Device driver providing benchmarking for assmblerised kernel routines
19 #include <kernel/kern_priv.h>
20 #include <kernel/cache.h>
21 #include "d_kernasmbm.h"
24 RPointerArray<TKernelBenchmark> KernelBenchmarks;
26 // TKernelBenchmark ////////////////////////////////////////////////////////////
28 TKernelBenchmark::TKernelBenchmark(const TDesC8& aName)
31 iInfo.iCategories = KCategoryGeneral;
33 KernelBenchmarks.Append(this); // Ignores rc
36 TKernelBenchmark::TKernelBenchmark(const TDesC8& aName, TInt aAlignStep)
39 iInfo.iCategories = KCategoryGeneral | KCategoryMemory;
40 iInfo.iAlignStep = aAlignStep;
41 KernelBenchmarks.Append(this); // Ignores rc
44 const TBmInfo& TKernelBenchmark::Info() const
49 TInt TKernelBenchmark::Run(const TBmParams& aParams, TInt& aResult)
52 init = NKern::FastCounter();
54 final = NKern::FastCounter();
55 aResult = final - init;
59 // TThreadedBenchmark //////////////////////////////////////////////////////////
61 TThreadedBenchmark::TThreadedBenchmark(const TDesC8& aName, TInt aRelPri) :
62 TKernelBenchmark(aName), iRelPri(aRelPri)
66 TInt TThreadedBenchmark::Run(const TBmParams& aParams, TInt& aResult)
69 iThread1 = &Kern::CurrentThread();
71 SThreadCreateInfo info;
72 info.iType=EThreadSupervisor;
73 info.iFunction=Thread2Func;
75 info.iSupervisorStack=NULL;
76 info.iSupervisorStackSize=0; // zero means use default value
77 info.iInitialThreadPriority=iThread1->iNThread.iPriority + iRelPri;
78 info.iName.Set(_L("bmthread"));
79 info.iTotalSize = sizeof(info);
81 NKern::ThreadEnterCS();
82 TInt r = Kern::ThreadCreate(info);
83 NKern::ThreadLeaveCS();
87 iThread2 = (DThread*)info.iHandle;
89 return TKernelBenchmark::Run(aParams, aResult);
92 TInt TThreadedBenchmark::Thread2Func(TAny* aPtr)
94 TThreadedBenchmark* self = (TThreadedBenchmark*)aPtr;
95 self->DoRun2(self->iIts);
99 // Device driver implementation ////////////////////////////////////////////////
101 class DKernAsmBmFactory : public DLogicalDevice
104 virtual TInt Install(); //overriding pure virtual
105 virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
106 virtual TInt Create(DLogicalChannelBase*& aChannel);
109 class DKernAsmBm : public DLogicalChannel
112 virtual ~DKernAsmBm();
113 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
114 virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
115 virtual void HandleMsg(TMessageBase *aMsg);
118 TInt DKernAsmBmFactory::Install()
120 return(SetName(&KKernAsmBmLddName));
123 void DKernAsmBmFactory::GetCaps(TDes8& /*aDes*/) const
127 TInt DKernAsmBmFactory::Create(DLogicalChannelBase*& aChannel)
129 aChannel = new DKernAsmBm;
135 DECLARE_STANDARD_LDD()
137 return new DKernAsmBmFactory;
140 DKernAsmBm::~DKernAsmBm()
145 TInt DKernAsmBm::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
150 TInt DKernAsmBm::Request(TInt aFunction, TAny* a1, TAny* a2)
152 TInt index = aFunction >> 8;
155 if (aFunction != RKernAsmBmLdd::ECount && (index < 0 || index >= KernelBenchmarks.Count()))
160 case RKernAsmBmLdd::ECount:
161 return KernelBenchmarks.Count();
163 case RKernAsmBmLdd::EInfo:
165 TPckgC<TBmInfo> info(KernelBenchmarks[index]->Info());
166 return Kern::ThreadDesWrite(&Kern::CurrentThread(), a1, info, 0, 0, NULL);
169 case RKernAsmBmLdd::ERun:
171 TPckgBuf<TBmParams> params;
172 Kern::ThreadDesRead(&Kern::CurrentThread(), a1, params, 0, 0);
173 UserPtr = (TUint8*)ALIGN_ADDR(a2);
176 TInt r = KernelBenchmarks[index]->Run(params(), delta);
178 r = Kern::ThreadRawWrite(&Kern::CurrentThread(), a2, &delta, sizeof(TInt));
187 void DKernAsmBm::HandleMsg(TMessageBase* /*aMsg*/)