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\demandpaging\d_ramsterss.cpp
18 #include <kernel/kern_priv.h>
19 #include <kernel/cache.h>
21 #include "t_ramstress.h"
27 class DRamStressTestFactory : public DLogicalDevice
30 ~DRamStressTestFactory();
31 virtual TInt Install();
32 virtual void GetCaps(TDes8& aDes) const;
33 virtual TInt Create(DLogicalChannelBase*& aChannel);
36 class DRamStressTestChannel : public DLogicalChannelBase
39 DRamStressTestChannel();
40 ~DRamStressTestChannel();
41 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
42 virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
45 TInt DoSetDebugFlag(TInt aState);
46 TInt DoSetEndFlag(TInt aState);
48 DRamStressTestFactory* iFactory;
51 TInt DoMovePagesInZone(TUint aZoneIndex);
52 TInt DoPageMove(TLinAddr aAddr);
53 TInt DoAllocPagesInZone(TUint aZoneIndex);
63 // DRamStressTestFactory
66 TInt DRamStressTestFactory::Install()
68 return SetName(&KRamStressTestLddName);
71 DRamStressTestFactory::~DRamStressTestFactory()
75 void DRamStressTestFactory::GetCaps(TDes8& /*aDes*/) const
77 // Not used but required as DLogicalDevice::GetCaps is pure virtual
80 TInt DRamStressTestFactory::Create(DLogicalChannelBase*& aChannel)
83 DRamStressTestChannel* channel=new DRamStressTestChannel;
86 channel->iFactory = this;
91 DECLARE_STANDARD_LDD()
93 return new DRamStressTestFactory;
97 // DRamStressTestChannel
100 TInt DRamStressTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
106 // DRamStressTestChannel::DRamStressTestChannel()
109 DRamStressTestChannel::DRamStressTestChannel()
110 : iDebug(0), iFinish(0), iThreadCounter(1), iPageSize(0)
113 if (Kern::HalFunction(EHalGroupKernel,EKernelHalPageSizeInBytes,&pageSize,0) == KErrNone)
115 iPageSize = pageSize;
120 // DRamStressTestChannel::~DRamStressTestChannel()
123 DRamStressTestChannel::~DRamStressTestChannel()
128 // DRamStressTestChannel::Request
130 TInt DRamStressTestChannel::Request(TInt aFunction, TAny* a1, TAny* a2)
132 TInt threadCount = __e32_atomic_tas_ord32(&iThreadCounter, 1, 1, 0);
133 if (threadCount >= 2)
135 Kern::Printf("DRamStressTestChannel::Request threadCount = %d\n", threadCount);
136 NKern::ThreadEnterCS();
137 TInt retVal = KErrNotSupported;
140 case RRamStressTestLdd::EDoMovePagesInZone:
142 retVal = DoMovePagesInZone((TUint)a1);
146 case RRamStressTestLdd::EDoSetDebugFlag:
148 retVal = DoSetDebugFlag((TInt) a1);
152 case RRamStressTestLdd::EDoSetEndFlag:
154 retVal = DoSetEndFlag((TInt) a1);
160 NKern::ThreadLeaveCS();
161 __e32_atomic_tas_ord32(&iThreadCounter, 1, -1, 0);
165 TInt DRamStressTestChannel::DoAllocPagesInZone(TUint aZoneIndex)
167 TInt retVal = KErrNone;
175 // DRamStressTestChannel::DoMovePagesInZone
178 TInt DRamStressTestChannel::DoMovePagesInZone(TUint aZoneIndex)
182 Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d)", aZoneIndex);
185 // first get info on the 2 zones....
186 struct SRamZoneConfig zoneConfig;
188 if (KErrNone != Kern::HalFunction(EHalGroupRam,ERamHalGetZoneConfig,(TAny*)aZoneIndex, (TAny*)&zoneConfig))
190 Kern::Printf("Error ::: DoMovePagesInZone : bad zone %d", aZoneIndex);
191 retVal = KErrArgument;
195 //Kern::Printf("DoMovePagesInZone : zone %d", aZoneIndex);
196 TPhysAddr addr = zoneConfig.iPhysBase;
203 while (addr < zoneConfig.iPhysEnd)
205 //Kern::Printf("DoMovePagesInZone(%d) moving 0x%08x", aZoneIndex, addr);
206 retVal = DoPageMove(addr);
207 if (retVal == KErrNone)
223 case KErrNotSupported:
232 Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) failed 0x%08x err=%d", aZoneIndex, addr, retVal);
241 Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) Finishing", aZoneIndex);
247 Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) moved %u failed %u bad %u unused %u nosupport %u", aZoneIndex, moved, failed, bad, unused, nosupport);
249 retVal = (failed==0) ? KErrNone : KErrGeneral;
255 // DRamStressTestChannel::DoPageMove
258 TInt DRamStressTestChannel::DoPageMove(TPhysAddr aAddr)
260 aAddr = _ALIGN_DOWN(aAddr, iPageSize);
264 r=Epoc::MovePhysicalPage(aAddr, aNew);
265 if ((r==KErrNone) && (aNew == aAddr))
267 Kern::Printf("DRamStressTestChannel::DoPageMove moved bad 0x%08x now 0x%08x ", aAddr, aNew);
274 TInt DRamStressTestChannel::FreeRam()
276 return Kern::FreeRamInBytes();
279 TInt DRamStressTestChannel::DoSetDebugFlag(TInt aState)
285 TInt DRamStressTestChannel::DoSetEndFlag(TInt aState)