1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/demandpaging/d_ramstress.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,289 @@
1.4 +// Copyright (c) 2005-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 +// e32test\demandpaging\d_ramsterss.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <kernel/kern_priv.h>
1.22 +#include <kernel/cache.h>
1.23 +
1.24 +#include "t_ramstress.h"
1.25 +
1.26 +//
1.27 +// Class definitions
1.28 +//
1.29 +
1.30 +class DRamStressTestFactory : public DLogicalDevice
1.31 + {
1.32 +public:
1.33 + ~DRamStressTestFactory();
1.34 + virtual TInt Install();
1.35 + virtual void GetCaps(TDes8& aDes) const;
1.36 + virtual TInt Create(DLogicalChannelBase*& aChannel);
1.37 + };
1.38 +
1.39 +class DRamStressTestChannel : public DLogicalChannelBase
1.40 + {
1.41 +public:
1.42 + DRamStressTestChannel();
1.43 + ~DRamStressTestChannel();
1.44 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.45 + virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
1.46 +
1.47 + TInt FreeRam();
1.48 + TInt DoSetDebugFlag(TInt aState);
1.49 + TInt DoSetEndFlag(TInt aState);
1.50 +public:
1.51 + DRamStressTestFactory* iFactory;
1.52 +
1.53 +private:
1.54 + TInt DoMovePagesInZone(TUint aZoneIndex);
1.55 + TInt DoPageMove(TLinAddr aAddr);
1.56 + TInt DoAllocPagesInZone(TUint aZoneIndex);
1.57 +
1.58 +private:
1.59 + TInt iDebug;
1.60 + TInt iFinish;
1.61 + TInt iThreadCounter;
1.62 + TInt iPageSize;
1.63 + };
1.64 +
1.65 +//
1.66 +// DRamStressTestFactory
1.67 +//
1.68 +
1.69 +TInt DRamStressTestFactory::Install()
1.70 + {
1.71 + return SetName(&KRamStressTestLddName);
1.72 + }
1.73 +
1.74 +DRamStressTestFactory::~DRamStressTestFactory()
1.75 + {
1.76 + }
1.77 +
1.78 +void DRamStressTestFactory::GetCaps(TDes8& /*aDes*/) const
1.79 + {
1.80 + // Not used but required as DLogicalDevice::GetCaps is pure virtual
1.81 + }
1.82 +
1.83 +TInt DRamStressTestFactory::Create(DLogicalChannelBase*& aChannel)
1.84 + {
1.85 + aChannel = NULL;
1.86 + DRamStressTestChannel* channel=new DRamStressTestChannel;
1.87 + if(!channel)
1.88 + return KErrNoMemory;
1.89 + channel->iFactory = this;
1.90 + aChannel = channel;
1.91 + return KErrNone;
1.92 + }
1.93 +
1.94 +DECLARE_STANDARD_LDD()
1.95 + {
1.96 + return new DRamStressTestFactory;
1.97 + }
1.98 +
1.99 +//
1.100 +// DRamStressTestChannel
1.101 +//
1.102 +
1.103 +TInt DRamStressTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
1.104 + {
1.105 + return KErrNone;
1.106 + }
1.107 +
1.108 +//
1.109 +// DRamStressTestChannel::DRamStressTestChannel()
1.110 +//
1.111 +
1.112 +DRamStressTestChannel::DRamStressTestChannel()
1.113 + : iDebug(0), iFinish(0), iThreadCounter(1), iPageSize(0)
1.114 + {
1.115 + TInt pageSize = 0;
1.116 + if (Kern::HalFunction(EHalGroupKernel,EKernelHalPageSizeInBytes,&pageSize,0) == KErrNone)
1.117 + {
1.118 + iPageSize = pageSize;
1.119 + }
1.120 + }
1.121 +
1.122 +//
1.123 +// DRamStressTestChannel::~DRamStressTestChannel()
1.124 +//
1.125 +
1.126 +DRamStressTestChannel::~DRamStressTestChannel()
1.127 + {
1.128 + }
1.129 +
1.130 +//
1.131 +// DRamStressTestChannel::Request
1.132 +//
1.133 +TInt DRamStressTestChannel::Request(TInt aFunction, TAny* a1, TAny* a2)
1.134 + {
1.135 + TInt threadCount = __e32_atomic_tas_ord32(&iThreadCounter, 1, 1, 0);
1.136 + if (threadCount >= 2)
1.137 + if (iDebug)
1.138 + Kern::Printf("DRamStressTestChannel::Request threadCount = %d\n", threadCount);
1.139 + NKern::ThreadEnterCS();
1.140 + TInt retVal = KErrNotSupported;
1.141 + switch(aFunction)
1.142 + {
1.143 + case RRamStressTestLdd::EDoMovePagesInZone:
1.144 + {
1.145 + retVal = DoMovePagesInZone((TUint)a1);
1.146 + }
1.147 + break;
1.148 +
1.149 + case RRamStressTestLdd::EDoSetDebugFlag:
1.150 + {
1.151 + retVal = DoSetDebugFlag((TInt) a1);
1.152 + }
1.153 + break;
1.154 +
1.155 + case RRamStressTestLdd::EDoSetEndFlag:
1.156 + {
1.157 + retVal = DoSetEndFlag((TInt) a1);
1.158 + }
1.159 + break;
1.160 +
1.161 + default: break;
1.162 + }
1.163 + NKern::ThreadLeaveCS();
1.164 + __e32_atomic_tas_ord32(&iThreadCounter, 1, -1, 0);
1.165 + return retVal;
1.166 + }
1.167 +
1.168 +TInt DRamStressTestChannel::DoAllocPagesInZone(TUint aZoneIndex)
1.169 + {
1.170 + TInt retVal = KErrNone;
1.171 +
1.172 +
1.173 +
1.174 + return retVal;
1.175 + }
1.176 +
1.177 +//
1.178 +// DRamStressTestChannel::DoMovePagesInZone
1.179 +//
1.180 +
1.181 +TInt DRamStressTestChannel::DoMovePagesInZone(TUint aZoneIndex)
1.182 + {
1.183 + if (iDebug)
1.184 + {
1.185 + Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d)", aZoneIndex);
1.186 + }
1.187 +
1.188 + // first get info on the 2 zones....
1.189 + struct SRamZoneConfig zoneConfig;
1.190 + TInt retVal;
1.191 + if (KErrNone != Kern::HalFunction(EHalGroupRam,ERamHalGetZoneConfig,(TAny*)aZoneIndex, (TAny*)&zoneConfig))
1.192 + {
1.193 + Kern::Printf("Error ::: DoMovePagesInZone : bad zone %d", aZoneIndex);
1.194 + retVal = KErrArgument;
1.195 + }
1.196 + else
1.197 + {
1.198 + //Kern::Printf("DoMovePagesInZone : zone %d", aZoneIndex);
1.199 + TPhysAddr addr = zoneConfig.iPhysBase;
1.200 + TUint moved = 0;
1.201 + TUint failed = 0;
1.202 + TUint unused = 0;
1.203 + TUint bad = 0;
1.204 + TUint nosupport = 0;
1.205 + retVal = KErrNone;
1.206 + while (addr < zoneConfig.iPhysEnd)
1.207 + {
1.208 + //Kern::Printf("DoMovePagesInZone(%d) moving 0x%08x", aZoneIndex, addr);
1.209 + retVal = DoPageMove(addr);
1.210 + if (retVal == KErrNone)
1.211 + {
1.212 + moved ++;
1.213 + }
1.214 + else
1.215 + {
1.216 + switch (retVal)
1.217 + {
1.218 + case KErrArgument:
1.219 + bad ++;
1.220 + break;
1.221 +
1.222 + case KErrNotFound:
1.223 + unused ++;
1.224 + break;
1.225 +
1.226 + case KErrNotSupported:
1.227 + nosupport ++;
1.228 + break;
1.229 +
1.230 + case KErrGeneral:
1.231 + default:
1.232 + failed ++;
1.233 + if (iDebug)
1.234 + {
1.235 + Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) failed 0x%08x err=%d", aZoneIndex, addr, retVal);
1.236 + }
1.237 + break;
1.238 + }
1.239 + }
1.240 + addr += iPageSize;
1.241 + NKern::Sleep(1);
1.242 + if (iFinish)
1.243 + {
1.244 + Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) Finishing", aZoneIndex);
1.245 + break;
1.246 + }
1.247 + }
1.248 + if (iDebug)
1.249 + {
1.250 + Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) moved %u failed %u bad %u unused %u nosupport %u", aZoneIndex, moved, failed, bad, unused, nosupport);
1.251 + }
1.252 + retVal = (failed==0) ? KErrNone : KErrGeneral;
1.253 + }
1.254 + return retVal;
1.255 + }
1.256 +
1.257 +//
1.258 +// DRamStressTestChannel::DoPageMove
1.259 +//
1.260 +
1.261 +TInt DRamStressTestChannel::DoPageMove(TPhysAddr aAddr)
1.262 + {
1.263 + aAddr = _ALIGN_DOWN(aAddr, iPageSize);
1.264 +
1.265 + TInt r;
1.266 + TPhysAddr aNew;
1.267 + r=Epoc::MovePhysicalPage(aAddr, aNew);
1.268 + if ((r==KErrNone) && (aNew == aAddr))
1.269 + {
1.270 + Kern::Printf("DRamStressTestChannel::DoPageMove moved bad 0x%08x now 0x%08x ", aAddr, aNew);
1.271 + r=KErrGeneral;
1.272 + }
1.273 + return r;
1.274 + }
1.275 +
1.276 +
1.277 +TInt DRamStressTestChannel::FreeRam()
1.278 + {
1.279 + return Kern::FreeRamInBytes();
1.280 + }
1.281 +
1.282 +TInt DRamStressTestChannel::DoSetDebugFlag(TInt aState)
1.283 + {
1.284 + iDebug = aState;
1.285 + return KErrNone;
1.286 + }
1.287 +
1.288 +TInt DRamStressTestChannel::DoSetEndFlag(TInt aState)
1.289 + {
1.290 + iFinish = aState;
1.291 + return KErrNone;
1.292 + }