sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\demandpaging\d_ramsterss.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <kernel/kern_priv.h>
|
sl@0
|
19 |
#include <kernel/cache.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
#include "t_ramstress.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
//
|
sl@0
|
24 |
// Class definitions
|
sl@0
|
25 |
//
|
sl@0
|
26 |
|
sl@0
|
27 |
class DRamStressTestFactory : public DLogicalDevice
|
sl@0
|
28 |
{
|
sl@0
|
29 |
public:
|
sl@0
|
30 |
~DRamStressTestFactory();
|
sl@0
|
31 |
virtual TInt Install();
|
sl@0
|
32 |
virtual void GetCaps(TDes8& aDes) const;
|
sl@0
|
33 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
sl@0
|
34 |
};
|
sl@0
|
35 |
|
sl@0
|
36 |
class DRamStressTestChannel : public DLogicalChannelBase
|
sl@0
|
37 |
{
|
sl@0
|
38 |
public:
|
sl@0
|
39 |
DRamStressTestChannel();
|
sl@0
|
40 |
~DRamStressTestChannel();
|
sl@0
|
41 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
sl@0
|
42 |
virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
|
sl@0
|
43 |
|
sl@0
|
44 |
TInt FreeRam();
|
sl@0
|
45 |
TInt DoSetDebugFlag(TInt aState);
|
sl@0
|
46 |
TInt DoSetEndFlag(TInt aState);
|
sl@0
|
47 |
public:
|
sl@0
|
48 |
DRamStressTestFactory* iFactory;
|
sl@0
|
49 |
|
sl@0
|
50 |
private:
|
sl@0
|
51 |
TInt DoMovePagesInZone(TUint aZoneIndex);
|
sl@0
|
52 |
TInt DoPageMove(TLinAddr aAddr);
|
sl@0
|
53 |
TInt DoAllocPagesInZone(TUint aZoneIndex);
|
sl@0
|
54 |
|
sl@0
|
55 |
private:
|
sl@0
|
56 |
TInt iDebug;
|
sl@0
|
57 |
TInt iFinish;
|
sl@0
|
58 |
TInt iThreadCounter;
|
sl@0
|
59 |
TInt iPageSize;
|
sl@0
|
60 |
};
|
sl@0
|
61 |
|
sl@0
|
62 |
//
|
sl@0
|
63 |
// DRamStressTestFactory
|
sl@0
|
64 |
//
|
sl@0
|
65 |
|
sl@0
|
66 |
TInt DRamStressTestFactory::Install()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
return SetName(&KRamStressTestLddName);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
DRamStressTestFactory::~DRamStressTestFactory()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
void DRamStressTestFactory::GetCaps(TDes8& /*aDes*/) const
|
sl@0
|
76 |
{
|
sl@0
|
77 |
// Not used but required as DLogicalDevice::GetCaps is pure virtual
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
TInt DRamStressTestFactory::Create(DLogicalChannelBase*& aChannel)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
aChannel = NULL;
|
sl@0
|
83 |
DRamStressTestChannel* channel=new DRamStressTestChannel;
|
sl@0
|
84 |
if(!channel)
|
sl@0
|
85 |
return KErrNoMemory;
|
sl@0
|
86 |
channel->iFactory = this;
|
sl@0
|
87 |
aChannel = channel;
|
sl@0
|
88 |
return KErrNone;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
DECLARE_STANDARD_LDD()
|
sl@0
|
92 |
{
|
sl@0
|
93 |
return new DRamStressTestFactory;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
//
|
sl@0
|
97 |
// DRamStressTestChannel
|
sl@0
|
98 |
//
|
sl@0
|
99 |
|
sl@0
|
100 |
TInt DRamStressTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
return KErrNone;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
//
|
sl@0
|
106 |
// DRamStressTestChannel::DRamStressTestChannel()
|
sl@0
|
107 |
//
|
sl@0
|
108 |
|
sl@0
|
109 |
DRamStressTestChannel::DRamStressTestChannel()
|
sl@0
|
110 |
: iDebug(0), iFinish(0), iThreadCounter(1), iPageSize(0)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TInt pageSize = 0;
|
sl@0
|
113 |
if (Kern::HalFunction(EHalGroupKernel,EKernelHalPageSizeInBytes,&pageSize,0) == KErrNone)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
iPageSize = pageSize;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
//
|
sl@0
|
120 |
// DRamStressTestChannel::~DRamStressTestChannel()
|
sl@0
|
121 |
//
|
sl@0
|
122 |
|
sl@0
|
123 |
DRamStressTestChannel::~DRamStressTestChannel()
|
sl@0
|
124 |
{
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
//
|
sl@0
|
128 |
// DRamStressTestChannel::Request
|
sl@0
|
129 |
//
|
sl@0
|
130 |
TInt DRamStressTestChannel::Request(TInt aFunction, TAny* a1, TAny* a2)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
TInt threadCount = __e32_atomic_tas_ord32(&iThreadCounter, 1, 1, 0);
|
sl@0
|
133 |
if (threadCount >= 2)
|
sl@0
|
134 |
if (iDebug)
|
sl@0
|
135 |
Kern::Printf("DRamStressTestChannel::Request threadCount = %d\n", threadCount);
|
sl@0
|
136 |
NKern::ThreadEnterCS();
|
sl@0
|
137 |
TInt retVal = KErrNotSupported;
|
sl@0
|
138 |
switch(aFunction)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
case RRamStressTestLdd::EDoMovePagesInZone:
|
sl@0
|
141 |
{
|
sl@0
|
142 |
retVal = DoMovePagesInZone((TUint)a1);
|
sl@0
|
143 |
}
|
sl@0
|
144 |
break;
|
sl@0
|
145 |
|
sl@0
|
146 |
case RRamStressTestLdd::EDoSetDebugFlag:
|
sl@0
|
147 |
{
|
sl@0
|
148 |
retVal = DoSetDebugFlag((TInt) a1);
|
sl@0
|
149 |
}
|
sl@0
|
150 |
break;
|
sl@0
|
151 |
|
sl@0
|
152 |
case RRamStressTestLdd::EDoSetEndFlag:
|
sl@0
|
153 |
{
|
sl@0
|
154 |
retVal = DoSetEndFlag((TInt) a1);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
break;
|
sl@0
|
157 |
|
sl@0
|
158 |
default: break;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
NKern::ThreadLeaveCS();
|
sl@0
|
161 |
__e32_atomic_tas_ord32(&iThreadCounter, 1, -1, 0);
|
sl@0
|
162 |
return retVal;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
TInt DRamStressTestChannel::DoAllocPagesInZone(TUint aZoneIndex)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
TInt retVal = KErrNone;
|
sl@0
|
168 |
|
sl@0
|
169 |
|
sl@0
|
170 |
|
sl@0
|
171 |
return retVal;
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
//
|
sl@0
|
175 |
// DRamStressTestChannel::DoMovePagesInZone
|
sl@0
|
176 |
//
|
sl@0
|
177 |
|
sl@0
|
178 |
TInt DRamStressTestChannel::DoMovePagesInZone(TUint aZoneIndex)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
if (iDebug)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d)", aZoneIndex);
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
// first get info on the 2 zones....
|
sl@0
|
186 |
struct SRamZoneConfig zoneConfig;
|
sl@0
|
187 |
TInt retVal;
|
sl@0
|
188 |
if (KErrNone != Kern::HalFunction(EHalGroupRam,ERamHalGetZoneConfig,(TAny*)aZoneIndex, (TAny*)&zoneConfig))
|
sl@0
|
189 |
{
|
sl@0
|
190 |
Kern::Printf("Error ::: DoMovePagesInZone : bad zone %d", aZoneIndex);
|
sl@0
|
191 |
retVal = KErrArgument;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
else
|
sl@0
|
194 |
{
|
sl@0
|
195 |
//Kern::Printf("DoMovePagesInZone : zone %d", aZoneIndex);
|
sl@0
|
196 |
TPhysAddr addr = zoneConfig.iPhysBase;
|
sl@0
|
197 |
TUint moved = 0;
|
sl@0
|
198 |
TUint failed = 0;
|
sl@0
|
199 |
TUint unused = 0;
|
sl@0
|
200 |
TUint bad = 0;
|
sl@0
|
201 |
TUint nosupport = 0;
|
sl@0
|
202 |
retVal = KErrNone;
|
sl@0
|
203 |
while (addr < zoneConfig.iPhysEnd)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
//Kern::Printf("DoMovePagesInZone(%d) moving 0x%08x", aZoneIndex, addr);
|
sl@0
|
206 |
retVal = DoPageMove(addr);
|
sl@0
|
207 |
if (retVal == KErrNone)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
moved ++;
|
sl@0
|
210 |
}
|
sl@0
|
211 |
else
|
sl@0
|
212 |
{
|
sl@0
|
213 |
switch (retVal)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
case KErrArgument:
|
sl@0
|
216 |
bad ++;
|
sl@0
|
217 |
break;
|
sl@0
|
218 |
|
sl@0
|
219 |
case KErrNotFound:
|
sl@0
|
220 |
unused ++;
|
sl@0
|
221 |
break;
|
sl@0
|
222 |
|
sl@0
|
223 |
case KErrNotSupported:
|
sl@0
|
224 |
nosupport ++;
|
sl@0
|
225 |
break;
|
sl@0
|
226 |
|
sl@0
|
227 |
case KErrGeneral:
|
sl@0
|
228 |
default:
|
sl@0
|
229 |
failed ++;
|
sl@0
|
230 |
if (iDebug)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) failed 0x%08x err=%d", aZoneIndex, addr, retVal);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
break;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
}
|
sl@0
|
237 |
addr += iPageSize;
|
sl@0
|
238 |
NKern::Sleep(1);
|
sl@0
|
239 |
if (iFinish)
|
sl@0
|
240 |
{
|
sl@0
|
241 |
Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) Finishing", aZoneIndex);
|
sl@0
|
242 |
break;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
}
|
sl@0
|
245 |
if (iDebug)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
Kern::Printf("DRamStressTestChannel::DoMovePagesInZone(%d) moved %u failed %u bad %u unused %u nosupport %u", aZoneIndex, moved, failed, bad, unused, nosupport);
|
sl@0
|
248 |
}
|
sl@0
|
249 |
retVal = (failed==0) ? KErrNone : KErrGeneral;
|
sl@0
|
250 |
}
|
sl@0
|
251 |
return retVal;
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
//
|
sl@0
|
255 |
// DRamStressTestChannel::DoPageMove
|
sl@0
|
256 |
//
|
sl@0
|
257 |
|
sl@0
|
258 |
TInt DRamStressTestChannel::DoPageMove(TPhysAddr aAddr)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
aAddr = _ALIGN_DOWN(aAddr, iPageSize);
|
sl@0
|
261 |
|
sl@0
|
262 |
TInt r;
|
sl@0
|
263 |
TPhysAddr aNew;
|
sl@0
|
264 |
r=Epoc::MovePhysicalPage(aAddr, aNew);
|
sl@0
|
265 |
if ((r==KErrNone) && (aNew == aAddr))
|
sl@0
|
266 |
{
|
sl@0
|
267 |
Kern::Printf("DRamStressTestChannel::DoPageMove moved bad 0x%08x now 0x%08x ", aAddr, aNew);
|
sl@0
|
268 |
r=KErrGeneral;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
return r;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
|
sl@0
|
274 |
TInt DRamStressTestChannel::FreeRam()
|
sl@0
|
275 |
{
|
sl@0
|
276 |
return Kern::FreeRamInBytes();
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
TInt DRamStressTestChannel::DoSetDebugFlag(TInt aState)
|
sl@0
|
280 |
{
|
sl@0
|
281 |
iDebug = aState;
|
sl@0
|
282 |
return KErrNone;
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
TInt DRamStressTestChannel::DoSetEndFlag(TInt aState)
|
sl@0
|
286 |
{
|
sl@0
|
287 |
iFinish = aState;
|
sl@0
|
288 |
return KErrNone;
|
sl@0
|
289 |
}
|