sl@0
|
1 |
// Copyright (c) 2006-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\nkernsa\testipi.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <nktest/nkutils.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
#ifdef __SMP__
|
sl@0
|
21 |
|
sl@0
|
22 |
class TTestIPI : public TGenericIPI
|
sl@0
|
23 |
{
|
sl@0
|
24 |
public:
|
sl@0
|
25 |
TTestIPI();
|
sl@0
|
26 |
static TTestIPI* New();
|
sl@0
|
27 |
static void Isr(TGenericIPI*);
|
sl@0
|
28 |
void Inc(TInt aCpu, TInt aInc=1) {iExpected[aCpu] += aInc;}
|
sl@0
|
29 |
void IncM(TUint32 aMask);
|
sl@0
|
30 |
void Check();
|
sl@0
|
31 |
public:
|
sl@0
|
32 |
TInt iCount[KMaxCpus];
|
sl@0
|
33 |
TInt iExpected[KMaxCpus];
|
sl@0
|
34 |
};
|
sl@0
|
35 |
|
sl@0
|
36 |
TTestIPI::TTestIPI()
|
sl@0
|
37 |
{
|
sl@0
|
38 |
memclr(iCount, sizeof(iCount));
|
sl@0
|
39 |
memclr(iExpected, sizeof(iExpected));
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
TTestIPI* TTestIPI::New()
|
sl@0
|
43 |
{
|
sl@0
|
44 |
TTestIPI* p = new TTestIPI;
|
sl@0
|
45 |
TEST_OOM(p);
|
sl@0
|
46 |
return p;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
void TTestIPI::Isr(TGenericIPI* a)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
TTestIPI& ipi = *(TTestIPI*)a;
|
sl@0
|
52 |
TInt cpu = NKern::CurrentCpu();
|
sl@0
|
53 |
++ipi.iCount[cpu];
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void TTestIPI::IncM(TUint32 aMask)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
TInt i;
|
sl@0
|
59 |
for(i=0; i<KMaxCpus; ++i)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
if (aMask & (1<<i))
|
sl@0
|
62 |
++iExpected[i];
|
sl@0
|
63 |
}
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
void TTestIPI::Check()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
TInt i;
|
sl@0
|
69 |
for(i=0; i<KMaxCpus; ++i)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
TEST_RESULT3(iCount[i]==iExpected[i], "CPU %d Count %d Expected %d", i, iCount[i], iExpected[i]);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
void IPITestThread1(TAny*)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
TInt cpu;
|
sl@0
|
78 |
TUint32 all_cpus = ~(0xffffffffu << NKern::NumberOfCpus());
|
sl@0
|
79 |
|
sl@0
|
80 |
for_each_cpu(cpu)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TEST_PRINT("ipi1");
|
sl@0
|
83 |
TTestIPI ipi;
|
sl@0
|
84 |
ipi.Queue(&TTestIPI::Isr, 1u<<cpu);
|
sl@0
|
85 |
ipi.WaitCompletion();
|
sl@0
|
86 |
ipi.Inc(cpu);
|
sl@0
|
87 |
ipi.Check();
|
sl@0
|
88 |
|
sl@0
|
89 |
TEST_PRINT("ipi2");
|
sl@0
|
90 |
TTestIPI ipi2;
|
sl@0
|
91 |
TUint32 m = all_cpus & ~(1u<<cpu);
|
sl@0
|
92 |
ipi2.Queue(&TTestIPI::Isr, m);
|
sl@0
|
93 |
ipi2.WaitCompletion();
|
sl@0
|
94 |
ipi2.IncM(m);
|
sl@0
|
95 |
ipi2.Check();
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
TEST_PRINT("ipi3");
|
sl@0
|
99 |
TTestIPI ipi3;
|
sl@0
|
100 |
ipi3.QueueAll(&TTestIPI::Isr);
|
sl@0
|
101 |
ipi3.WaitCompletion();
|
sl@0
|
102 |
ipi3.IncM(all_cpus);
|
sl@0
|
103 |
ipi3.Check();
|
sl@0
|
104 |
|
sl@0
|
105 |
TEST_PRINT("ipi4");
|
sl@0
|
106 |
TTestIPI ipi4;
|
sl@0
|
107 |
ipi4.QueueAllOther(&TTestIPI::Isr);
|
sl@0
|
108 |
ipi4.WaitCompletion();
|
sl@0
|
109 |
ipi4.IncM(all_cpus & ~(1u<<NKern::CurrentCpu()) );
|
sl@0
|
110 |
ipi4.Check();
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
void DoIPITest1()
|
sl@0
|
114 |
{
|
sl@0
|
115 |
TInt cpu;
|
sl@0
|
116 |
for_each_cpu(cpu)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
CreateThreadAndWaitForExit("IPITest1", &IPITestThread1, 12, 0, 0, -1, cpu);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
|
sl@0
|
123 |
class TTestIPI2 : public TGenericIPI
|
sl@0
|
124 |
{
|
sl@0
|
125 |
public:
|
sl@0
|
126 |
TTestIPI2(TInt aId);
|
sl@0
|
127 |
static TTestIPI2* New(TInt aId);
|
sl@0
|
128 |
static void Isr(TGenericIPI*);
|
sl@0
|
129 |
static void Thread(TAny*);
|
sl@0
|
130 |
public:
|
sl@0
|
131 |
TInt iId;
|
sl@0
|
132 |
public:
|
sl@0
|
133 |
enum {EMaxIPI=32};
|
sl@0
|
134 |
enum {EBufSize=256};
|
sl@0
|
135 |
static volatile TInt NextPos;
|
sl@0
|
136 |
static volatile TUint32 Buffer[EBufSize];
|
sl@0
|
137 |
static volatile TUint32 PauseHere;
|
sl@0
|
138 |
};
|
sl@0
|
139 |
|
sl@0
|
140 |
volatile TInt TTestIPI2::NextPos;
|
sl@0
|
141 |
volatile TUint32 TTestIPI2::Buffer[TTestIPI2::EBufSize];
|
sl@0
|
142 |
volatile TUint32 TTestIPI2::PauseHere;
|
sl@0
|
143 |
|
sl@0
|
144 |
__ASSERT_COMPILE(TTestIPI2::EBufSize >= TTestIPI2::EMaxIPI*KMaxCpus);
|
sl@0
|
145 |
|
sl@0
|
146 |
TTestIPI2::TTestIPI2(TInt aId)
|
sl@0
|
147 |
: iId(aId)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
TTestIPI2* TTestIPI2::New(TInt aId)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
TTestIPI2* p = new TTestIPI2(aId);
|
sl@0
|
154 |
TEST_OOM(p);
|
sl@0
|
155 |
return p;
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
void TTestIPI2::Isr(TGenericIPI* a)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
TTestIPI2& ipi = *(TTestIPI2*)a;
|
sl@0
|
161 |
TUint32 cpu = NKern::CurrentCpu();
|
sl@0
|
162 |
TUint32 x = (cpu<<16) | ipi.iId;
|
sl@0
|
163 |
TInt pos = __e32_atomic_tas_ord32(&NextPos, EBufSize, 0, 1);
|
sl@0
|
164 |
if (pos < EBufSize)
|
sl@0
|
165 |
Buffer[pos] = x;
|
sl@0
|
166 |
while (PauseHere == x)
|
sl@0
|
167 |
{}
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
void TTestIPI2::Thread(TAny*)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
TTestIPI2* ipi[EMaxIPI];
|
sl@0
|
173 |
TUint32 all_cpus = ~(0xffffffffu << NKern::NumberOfCpus());
|
sl@0
|
174 |
TInt this_cpu = NKern::CurrentCpu();
|
sl@0
|
175 |
TInt pause_cpu = this_cpu + 1;
|
sl@0
|
176 |
if (pause_cpu >= NKern::NumberOfCpus())
|
sl@0
|
177 |
pause_cpu = 0;
|
sl@0
|
178 |
if (pause_cpu == this_cpu)
|
sl@0
|
179 |
pause_cpu = -1;
|
sl@0
|
180 |
TUint32 this_cpu_mask = 1u<<this_cpu;
|
sl@0
|
181 |
TUint32 pause_cpu_mask = (pause_cpu>=0) ? (1u<<pause_cpu) : 0;
|
sl@0
|
182 |
TUint32 other_cpus = all_cpus & ~(this_cpu_mask | pause_cpu_mask);
|
sl@0
|
183 |
TInt num_other_cpus = __e32_bit_count_32(other_cpus);
|
sl@0
|
184 |
TInt i;
|
sl@0
|
185 |
for(i=0; i<EMaxIPI; ++i)
|
sl@0
|
186 |
ipi[i] = New(i+1);
|
sl@0
|
187 |
|
sl@0
|
188 |
NextPos = 0;
|
sl@0
|
189 |
PauseHere = 0;
|
sl@0
|
190 |
if (pause_cpu >= 0)
|
sl@0
|
191 |
PauseHere = (pause_cpu<<16) | (EMaxIPI/2);
|
sl@0
|
192 |
|
sl@0
|
193 |
TEST_PRINT3("this_cpu=%d pause_cpu=%d PauseHere=%x", this_cpu, pause_cpu, PauseHere);
|
sl@0
|
194 |
|
sl@0
|
195 |
TInt irq = NKern::DisableAllInterrupts();
|
sl@0
|
196 |
for (i=0; i<EMaxIPI; ++i)
|
sl@0
|
197 |
ipi[i]->QueueAll(&Isr);
|
sl@0
|
198 |
|
sl@0
|
199 |
TInt expected1 = num_other_cpus*EMaxIPI + EMaxIPI/2;
|
sl@0
|
200 |
while (NextPos != expected1)
|
sl@0
|
201 |
{}
|
sl@0
|
202 |
|
sl@0
|
203 |
PauseHere = 0;
|
sl@0
|
204 |
TInt expected2 = num_other_cpus*EMaxIPI + EMaxIPI;
|
sl@0
|
205 |
while (NextPos != expected2)
|
sl@0
|
206 |
{}
|
sl@0
|
207 |
NKern::RestoreInterrupts(irq);
|
sl@0
|
208 |
ipi[EMaxIPI-1]->WaitCompletion();
|
sl@0
|
209 |
|
sl@0
|
210 |
for(i=0; i<NextPos; ++i)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
TEST_PRINT1("%08x", Buffer[i]);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
for(i=0; i<EMaxIPI; ++i)
|
sl@0
|
216 |
delete ipi[i];
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
void DoIPITest2()
|
sl@0
|
220 |
{
|
sl@0
|
221 |
TInt cpu;
|
sl@0
|
222 |
for_each_cpu(cpu)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
CreateThreadAndWaitForExit("IPITest2", &TTestIPI2::Thread, 12, 0, 0, -1, cpu);
|
sl@0
|
225 |
}
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
|
sl@0
|
229 |
void TestIPI()
|
sl@0
|
230 |
{
|
sl@0
|
231 |
TEST_PRINT("Testing generic IPIs...");
|
sl@0
|
232 |
|
sl@0
|
233 |
DoIPITest1();
|
sl@0
|
234 |
DoIPITest2();
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
#else // __SMP__
|
sl@0
|
238 |
void TestIPI()
|
sl@0
|
239 |
{
|
sl@0
|
240 |
}
|
sl@0
|
241 |
#endif // __SMP__
|