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