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 |
// e32\nkernsmp\nkerns.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
// NThreadBase member data
|
sl@0
|
19 |
#define __INCLUDE_NTHREADBASE_DEFINES__
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <e32cmn.h>
|
sl@0
|
22 |
#include <e32cmn_private.h>
|
sl@0
|
23 |
#include "nk_priv.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
extern "C" void ExcFault(TAny*);
|
sl@0
|
26 |
|
sl@0
|
27 |
/******************************************************************************
|
sl@0
|
28 |
* Fast mutex
|
sl@0
|
29 |
******************************************************************************/
|
sl@0
|
30 |
/** Create a fast mutex
|
sl@0
|
31 |
|
sl@0
|
32 |
@publishedPartner
|
sl@0
|
33 |
@released
|
sl@0
|
34 |
*/
|
sl@0
|
35 |
EXPORT_C NFastMutex::NFastMutex()
|
sl@0
|
36 |
: iHoldingThread(0), iMutexLock(TSpinLock::EOrderFastMutex)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
/******************************************************************************
|
sl@0
|
41 |
* NSchedulable
|
sl@0
|
42 |
******************************************************************************/
|
sl@0
|
43 |
NSchedulable::NSchedulable()
|
sl@0
|
44 |
: iSSpinLock(TSpinLock::EOrderThread)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
iPriority = 0;
|
sl@0
|
47 |
iReady = 0;
|
sl@0
|
48 |
iCurrent = 0;
|
sl@0
|
49 |
iLastCpu = 0;
|
sl@0
|
50 |
iNSchedulableSpare1 = 0;
|
sl@0
|
51 |
iPauseCount = 0;
|
sl@0
|
52 |
iSuspended = 0;
|
sl@0
|
53 |
iNSchedulableSpare2 = 0;
|
sl@0
|
54 |
iCpuChange = 0;
|
sl@0
|
55 |
iStopping = 0;
|
sl@0
|
56 |
iFreezeCpu = 0;
|
sl@0
|
57 |
iParent = (NSchedulable*)0xdeadbeef;
|
sl@0
|
58 |
iCpuAffinity = 0;
|
sl@0
|
59 |
new (i_IDfcMem) TDfc(&DeferredReadyIDfcFn, this);
|
sl@0
|
60 |
iEventState = 0;
|
sl@0
|
61 |
iTotalCpuTime64 = 0;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
/******************************************************************************
|
sl@0
|
65 |
* NThreadGroup
|
sl@0
|
66 |
******************************************************************************/
|
sl@0
|
67 |
NThreadGroup::NThreadGroup()
|
sl@0
|
68 |
{
|
sl@0
|
69 |
iParent = 0;
|
sl@0
|
70 |
iThreadCount = 0;
|
sl@0
|
71 |
new (&iSSpinLock) TSpinLock(TSpinLock::EOrderThreadGroup);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
/** Create a thread group
|
sl@0
|
75 |
|
sl@0
|
76 |
@publishedPartner
|
sl@0
|
77 |
@prototype
|
sl@0
|
78 |
*/
|
sl@0
|
79 |
EXPORT_C TInt NKern::GroupCreate(NThreadGroup* aGroup, SNThreadGroupCreateInfo& aInfo)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
new (aGroup) NThreadGroup();
|
sl@0
|
82 |
aGroup->iCpuAffinity = aInfo.iCpuAffinity;
|
sl@0
|
83 |
return KErrNone;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
|
sl@0
|
87 |
/** Destroy a thread group
|
sl@0
|
88 |
|
sl@0
|
89 |
@pre Call in thread context, interrupts enabled, preemption enabled
|
sl@0
|
90 |
@pre No fast mutex held
|
sl@0
|
91 |
@pre Calling thread in critical section
|
sl@0
|
92 |
@pre All threads have left the group
|
sl@0
|
93 |
|
sl@0
|
94 |
@publishedPartner
|
sl@0
|
95 |
@prototype
|
sl@0
|
96 |
*/
|
sl@0
|
97 |
EXPORT_C void NKern::GroupDestroy(NThreadGroup* aGroup)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
NKern::ThreadEnterCS();
|
sl@0
|
100 |
aGroup->DetachTiedEvents();
|
sl@0
|
101 |
NKern::ThreadLeaveCS();
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
|
sl@0
|
105 |
/******************************************************************************
|
sl@0
|
106 |
* Thread
|
sl@0
|
107 |
******************************************************************************/
|
sl@0
|
108 |
void InvalidExec()
|
sl@0
|
109 |
{
|
sl@0
|
110 |
FAULT();
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
static const SFastExecTable DefaultFastExecTable={0,{0}};
|
sl@0
|
114 |
static const SSlowExecTable DefaultSlowExecTable={0,(TLinAddr)InvalidExec,0,{{0,0}}};
|
sl@0
|
115 |
|
sl@0
|
116 |
const SNThreadHandlers NThread_Default_Handlers =
|
sl@0
|
117 |
{
|
sl@0
|
118 |
NTHREAD_DEFAULT_EXIT_HANDLER,
|
sl@0
|
119 |
NTHREAD_DEFAULT_STATE_HANDLER,
|
sl@0
|
120 |
NTHREAD_DEFAULT_EXCEPTION_HANDLER,
|
sl@0
|
121 |
NTHREAD_DEFAULT_TIMEOUT_HANDLER
|
sl@0
|
122 |
};
|
sl@0
|
123 |
|
sl@0
|
124 |
NThreadWaitState::NThreadWaitState()
|
sl@0
|
125 |
: iTimer(&TimerExpired, this)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
iWtSt64 = 0;
|
sl@0
|
128 |
iTimer.iTriggerTime = 0;
|
sl@0
|
129 |
iTimer.iNTimerSpare1 = 0;
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
NThreadBase::NThreadBase()
|
sl@0
|
133 |
: iRequestSemaphore(), iWaitState()
|
sl@0
|
134 |
{
|
sl@0
|
135 |
iParent = this;
|
sl@0
|
136 |
iWaitLink.iPriority = 0;
|
sl@0
|
137 |
iBasePri = 0;
|
sl@0
|
138 |
iMutexPri = 0;
|
sl@0
|
139 |
i_NThread_Initial = 0;
|
sl@0
|
140 |
iLinkedObjType = EWaitNone;
|
sl@0
|
141 |
i_ThrdAttr = 0;
|
sl@0
|
142 |
iNThreadBaseSpare10 = 0;
|
sl@0
|
143 |
iFastMutexDefer = 0;
|
sl@0
|
144 |
iRequestSemaphore.iOwningThread = (NThreadBase*)this;
|
sl@0
|
145 |
iTime = 0;
|
sl@0
|
146 |
iTimeslice = 0;
|
sl@0
|
147 |
iSavedSP = 0;
|
sl@0
|
148 |
iAddressSpace = 0;
|
sl@0
|
149 |
iHeldFastMutex = 0;
|
sl@0
|
150 |
iUserModeCallbacks = 0;
|
sl@0
|
151 |
iLinkedObj = 0;
|
sl@0
|
152 |
iNewParent = 0;
|
sl@0
|
153 |
iFastExecTable = 0;
|
sl@0
|
154 |
iSlowExecTable = 0;
|
sl@0
|
155 |
iCsCount = 0;
|
sl@0
|
156 |
iCsFunction = 0;
|
sl@0
|
157 |
iHandlers = 0;
|
sl@0
|
158 |
iSuspendCount = 0;
|
sl@0
|
159 |
iStackBase = 0;
|
sl@0
|
160 |
iStackSize = 0;
|
sl@0
|
161 |
iExtraContext = 0;
|
sl@0
|
162 |
iExtraContextSize = 0;
|
sl@0
|
163 |
iNThreadBaseSpare6 = 0;
|
sl@0
|
164 |
iNThreadBaseSpare7 = 0;
|
sl@0
|
165 |
iNThreadBaseSpare8 = 0;
|
sl@0
|
166 |
iNThreadBaseSpare9 = 0;
|
sl@0
|
167 |
|
sl@0
|
168 |
// KILL
|
sl@0
|
169 |
iTag = 0;
|
sl@0
|
170 |
iVemsData = 0;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
TInt NThreadBase::Create(SNThreadCreateInfo& aInfo, TBool aInitial)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
__KTRACE_OPT(KNKERN,DEBUGPRINT(">NThreadBase::Create %08x(%08x,%d)", this, &aInfo, aInitial));
|
sl@0
|
176 |
if (aInfo.iPriority<0 || aInfo.iPriority>63)
|
sl@0
|
177 |
return KErrArgument;
|
sl@0
|
178 |
if (aInfo.iPriority==0 && !aInitial)
|
sl@0
|
179 |
return KErrArgument;
|
sl@0
|
180 |
// if (aInfo.iCpu!=KCpuAny && aInfo.iCpu>=TheScheduler.iNumCpus)
|
sl@0
|
181 |
// return KErrArgument;
|
sl@0
|
182 |
iStackBase=(TLinAddr)aInfo.iStackBase;
|
sl@0
|
183 |
iStackSize=aInfo.iStackSize;
|
sl@0
|
184 |
iTimeslice=(aInfo.iTimeslice>0)?aInfo.iTimeslice:-1;
|
sl@0
|
185 |
iTime=iTimeslice;
|
sl@0
|
186 |
iPriority=TUint8(aInfo.iPriority);
|
sl@0
|
187 |
iBasePri=TUint8(aInfo.iPriority);
|
sl@0
|
188 |
iCpuAffinity = aInfo.iCpuAffinity;
|
sl@0
|
189 |
iHandlers = aInfo.iHandlers ? aInfo.iHandlers : &NThread_Default_Handlers;
|
sl@0
|
190 |
iFastExecTable=aInfo.iFastExecTable?aInfo.iFastExecTable:&DefaultFastExecTable;
|
sl@0
|
191 |
iSlowExecTable=(aInfo.iSlowExecTable?aInfo.iSlowExecTable:&DefaultSlowExecTable)->iEntries;
|
sl@0
|
192 |
i_ThrdAttr=(TUint8)aInfo.iAttributes;
|
sl@0
|
193 |
if (aInitial)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
TSubScheduler& ss = SubScheduler();
|
sl@0
|
196 |
iLastCpu = (TUint8)ss.iCpuNum;
|
sl@0
|
197 |
iReady = (TUint8)(iLastCpu | EReadyOffset);
|
sl@0
|
198 |
iCurrent = iReady;
|
sl@0
|
199 |
iCpuAffinity = iLastCpu;
|
sl@0
|
200 |
iEventState = (iLastCpu<<EEventCpuShift) | (iLastCpu<<EThreadCpuShift);
|
sl@0
|
201 |
ss.Add(this);
|
sl@0
|
202 |
i_NThread_Initial = TRUE;
|
sl@0
|
203 |
ss.iInitialThread = (NThread*)this;
|
sl@0
|
204 |
NKern::Unlock(); // now that current thread is defined
|
sl@0
|
205 |
}
|
sl@0
|
206 |
else
|
sl@0
|
207 |
{
|
sl@0
|
208 |
iSuspendCount = 1;
|
sl@0
|
209 |
iSuspended = 1;
|
sl@0
|
210 |
TInt ecpu;
|
sl@0
|
211 |
if (iCpuAffinity & NTHREADBASE_CPU_AFFINITY_MASK)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
ecpu = __e32_find_ls1_32(iCpuAffinity);
|
sl@0
|
214 |
if (ecpu >= TheScheduler.iNumCpus)
|
sl@0
|
215 |
ecpu = 0; // FIXME: Inactive CPU?
|
sl@0
|
216 |
}
|
sl@0
|
217 |
else
|
sl@0
|
218 |
ecpu = iCpuAffinity;
|
sl@0
|
219 |
iEventState = (ecpu<<EEventCpuShift) | (ecpu<<EThreadCpuShift);
|
sl@0
|
220 |
if (aInfo.iGroup)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
NKern::Lock();
|
sl@0
|
223 |
AcqSLock();
|
sl@0
|
224 |
aInfo.iGroup->AcqSLock();
|
sl@0
|
225 |
iParent = (NSchedulable*)aInfo.iGroup;
|
sl@0
|
226 |
++aInfo.iGroup->iThreadCount;
|
sl@0
|
227 |
iEventState |= EEventParent;
|
sl@0
|
228 |
RelSLock();
|
sl@0
|
229 |
NKern::Unlock();
|
sl@0
|
230 |
}
|
sl@0
|
231 |
}
|
sl@0
|
232 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("<NThreadBase::Create OK"));
|
sl@0
|
233 |
return KErrNone;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
void NThread_Default_State_Handler(NThread* __DEBUG_ONLY(aThread), TInt __DEBUG_ONLY(aOperation), TInt __DEBUG_ONLY(aParameter))
|
sl@0
|
237 |
{
|
sl@0
|
238 |
// __KTRACE_OPT(KPANIC,DEBUGPRINT("Unknown NState %d: thread %T op %08x par %08x",aThread,aThread->iNState,aOperation,aParameter));
|
sl@0
|
239 |
#ifdef _DEBUG
|
sl@0
|
240 |
DEBUGPRINT("UnknownState: thread %T op %08x par %08x",aThread,aOperation,aParameter);
|
sl@0
|
241 |
#endif
|
sl@0
|
242 |
FAULT();
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
void NThread_Default_Exception_Handler(TAny* aContext, NThread*)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
ExcFault(aContext);
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
|
sl@0
|
251 |
/** Create a nanothread.
|
sl@0
|
252 |
|
sl@0
|
253 |
This function is intended to be used by the EPOC kernel and by personality
|
sl@0
|
254 |
layers. A nanothread may not use most of the functions available to normal
|
sl@0
|
255 |
Symbian OS threads. Use Kern::ThreadCreate() to create a Symbian OS thread.
|
sl@0
|
256 |
|
sl@0
|
257 |
@param aThread Pointer to control block for thread to create.
|
sl@0
|
258 |
@param aInfo Information needed for creating the thread.
|
sl@0
|
259 |
|
sl@0
|
260 |
@see SNThreadCreateInfo
|
sl@0
|
261 |
@see Kern::ThreadCreate
|
sl@0
|
262 |
|
sl@0
|
263 |
@pre Call in a thread context.
|
sl@0
|
264 |
@pre Interrupts must be enabled.
|
sl@0
|
265 |
@pre Kernel must be unlocked.
|
sl@0
|
266 |
*/
|
sl@0
|
267 |
EXPORT_C TInt NKern::ThreadCreate(NThread* aThread, SNThreadCreateInfo& aInfo)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
CHECK_PRECONDITIONS(MASK_KERNEL_UNLOCKED|MASK_INTERRUPTS_ENABLED|MASK_NOT_ISR|MASK_NOT_IDFC,"NKern::ThreadCreate");
|
sl@0
|
270 |
return aThread->Create(aInfo,FALSE);
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
// User-mode callbacks
|
sl@0
|
274 |
|
sl@0
|
275 |
TUserModeCallback::TUserModeCallback(TUserModeCallbackFunc aFunc)
|
sl@0
|
276 |
: iNext(KUserModeCallbackUnqueued),
|
sl@0
|
277 |
iFunc(aFunc)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
TUserModeCallback::~TUserModeCallback()
|
sl@0
|
282 |
{
|
sl@0
|
283 |
__NK_ASSERT_DEBUG(iNext == KUserModeCallbackUnqueued);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
void NKern::CancelUserModeCallbacks()
|
sl@0
|
287 |
{
|
sl@0
|
288 |
// Call any queued callbacks with the EUserModeCallbackCancel reason code, in the current
|
sl@0
|
289 |
// thread.
|
sl@0
|
290 |
|
sl@0
|
291 |
TUserModeCallback* listHead =
|
sl@0
|
292 |
(TUserModeCallback*)__e32_atomic_swp_ord_ptr(&NCurrentThread()->iUserModeCallbacks, NULL);
|
sl@0
|
293 |
while (listHead)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
TUserModeCallback* callback = listHead;
|
sl@0
|
296 |
listHead = listHead->iNext;
|
sl@0
|
297 |
callback->iNext = KUserModeCallbackUnqueued;
|
sl@0
|
298 |
__e32_memory_barrier();
|
sl@0
|
299 |
callback->iFunc(callback, EUserModeCallbackCancel);
|
sl@0
|
300 |
}
|
sl@0
|
301 |
}
|
sl@0
|
302 |
|
sl@0
|
303 |
void NKern::MoveUserModeCallbacks(NThreadBase* aDestThread, NThreadBase* aSrcThread)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
// Move all queued user-mode callbacks from the source thread to the destination thread, and
|
sl@0
|
306 |
// prevent any more from being queued. Used by the kernel thread code so that callbacks get
|
sl@0
|
307 |
// cancelled in another thread if the thread they were originally queued on dies.
|
sl@0
|
308 |
|
sl@0
|
309 |
// Atomically remove list of callbacks and set pointer to 1
|
sl@0
|
310 |
// The latter ensures any subsequent attempts to add callbacks fail
|
sl@0
|
311 |
TUserModeCallback* sourceListStart =
|
sl@0
|
312 |
(TUserModeCallback*)__e32_atomic_swp_ord_ptr(&aSrcThread->iUserModeCallbacks, (TAny*)1);
|
sl@0
|
313 |
__NK_ASSERT_DEBUG(((TUint)sourceListStart & 3) == 0); // check this only gets called once per thread
|
sl@0
|
314 |
|
sl@0
|
315 |
if (sourceListStart == NULL)
|
sl@0
|
316 |
return;
|
sl@0
|
317 |
|
sl@0
|
318 |
TUserModeCallback* sourceListEnd = sourceListStart;
|
sl@0
|
319 |
while (sourceListEnd->iNext != NULL)
|
sl@0
|
320 |
sourceListEnd = sourceListEnd->iNext;
|
sl@0
|
321 |
|
sl@0
|
322 |
NKern::Lock();
|
sl@0
|
323 |
TUserModeCallback* destListStart = aDestThread->iUserModeCallbacks;
|
sl@0
|
324 |
do
|
sl@0
|
325 |
{
|
sl@0
|
326 |
__NK_ASSERT_DEBUG(((TUint)destListStart & 3) == 0); // dest thread must not die
|
sl@0
|
327 |
sourceListEnd->iNext = destListStart;
|
sl@0
|
328 |
} while (!__e32_atomic_cas_ord_ptr(&aDestThread->iUserModeCallbacks, &destListStart, sourceListStart));
|
sl@0
|
329 |
NKern::Unlock();
|
sl@0
|
330 |
}
|
sl@0
|
331 |
|
sl@0
|
332 |
/** Initialise the null thread
|
sl@0
|
333 |
@internalComponent
|
sl@0
|
334 |
*/
|
sl@0
|
335 |
void NKern::Init(NThread* aThread, SNThreadCreateInfo& aInfo)
|
sl@0
|
336 |
{
|
sl@0
|
337 |
aInfo.iFunction=NULL; // irrelevant
|
sl@0
|
338 |
aInfo.iPriority=0; // null thread has lowest priority
|
sl@0
|
339 |
aInfo.iTimeslice=0; // null thread not timesliced
|
sl@0
|
340 |
aInfo.iAttributes=0; // null thread does not require implicit locks
|
sl@0
|
341 |
aThread->Create(aInfo,TRUE); // create the null thread
|
sl@0
|
342 |
}
|
sl@0
|
343 |
|
sl@0
|
344 |
/** @internalTechnology */
|
sl@0
|
345 |
EXPORT_C void NKern::RecordIntLatency(TInt /*aLatency*/, TInt /*aIntMask*/)
|
sl@0
|
346 |
{
|
sl@0
|
347 |
}
|
sl@0
|
348 |
|
sl@0
|
349 |
|
sl@0
|
350 |
/** @internalTechnology */
|
sl@0
|
351 |
EXPORT_C void NKern::RecordThreadLatency(TInt /*aLatency*/)
|
sl@0
|
352 |
{
|
sl@0
|
353 |
}
|
sl@0
|
354 |
|
sl@0
|
355 |
/********************************************
|
sl@0
|
356 |
* Deterministic Priority List Implementation
|
sl@0
|
357 |
********************************************/
|
sl@0
|
358 |
|
sl@0
|
359 |
|
sl@0
|
360 |
/** Construct a priority list with the specified number of priorities
|
sl@0
|
361 |
|
sl@0
|
362 |
@param aNumPriorities The number of priorities (must be 1-64).
|
sl@0
|
363 |
*/
|
sl@0
|
364 |
EXPORT_C TPriListBase::TPriListBase(TInt aNumPriorities)
|
sl@0
|
365 |
{
|
sl@0
|
366 |
memclr(this, sizeof(TPriListBase)+(aNumPriorities-1)*sizeof(SDblQueLink*) );
|
sl@0
|
367 |
}
|
sl@0
|
368 |
|
sl@0
|
369 |
|
sl@0
|
370 |
/********************************************
|
sl@0
|
371 |
* Miscellaneous
|
sl@0
|
372 |
********************************************/
|
sl@0
|
373 |
|
sl@0
|
374 |
/** Get the current value of the high performance counter.
|
sl@0
|
375 |
|
sl@0
|
376 |
If a high performance counter is not available, this uses the millisecond
|
sl@0
|
377 |
tick count instead.
|
sl@0
|
378 |
*/
|
sl@0
|
379 |
EXPORT_C TUint32 NKern::FastCounter()
|
sl@0
|
380 |
{
|
sl@0
|
381 |
return (TUint32)Timestamp();
|
sl@0
|
382 |
}
|
sl@0
|
383 |
|
sl@0
|
384 |
|
sl@0
|
385 |
/** Get the frequency of counter queried by NKern::FastCounter().
|
sl@0
|
386 |
*/
|
sl@0
|
387 |
EXPORT_C TInt NKern::FastCounterFrequency()
|
sl@0
|
388 |
{
|
sl@0
|
389 |
return (TInt)TimestampFrequency();
|
sl@0
|
390 |
}
|
sl@0
|
391 |
|
sl@0
|
392 |
|
sl@0
|
393 |
extern "C" {
|
sl@0
|
394 |
TUint32 CrashState;
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
EXPORT_C TBool NKern::Crashed()
|
sl@0
|
398 |
{
|
sl@0
|
399 |
return CrashState!=0;
|
sl@0
|
400 |
}
|
sl@0
|
401 |
|
sl@0
|
402 |
|
sl@0
|
403 |
/** Returns number of nanokernel timer ticks since system started.
|
sl@0
|
404 |
@return tick count
|
sl@0
|
405 |
@pre any context
|
sl@0
|
406 |
*/
|
sl@0
|
407 |
EXPORT_C TUint32 NKern::TickCount()
|
sl@0
|
408 |
{
|
sl@0
|
409 |
return NTickCount();
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
|
sl@0
|
413 |
TUint32 BTrace::BigTraceId = 0;
|
sl@0
|
414 |
|
sl@0
|
415 |
TBool BTrace::DoOutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize, TUint32 aContext, TUint32 aPc)
|
sl@0
|
416 |
{
|
sl@0
|
417 |
SBTraceData& traceData = BTraceData;
|
sl@0
|
418 |
|
sl@0
|
419 |
// see if trace is small enough to fit in single record...
|
sl@0
|
420 |
if(TUint(aDataSize)<=TUint(KMaxBTraceDataArray+4))
|
sl@0
|
421 |
{
|
sl@0
|
422 |
a0 += aDataSize;
|
sl@0
|
423 |
TUint32 a2 = 0;
|
sl@0
|
424 |
TUint32 a3 = 0;
|
sl@0
|
425 |
if(aDataSize)
|
sl@0
|
426 |
{
|
sl@0
|
427 |
a2 = *((TUint32*&)aData)++; // first 4 bytes into a2
|
sl@0
|
428 |
if(aDataSize>=4 && aDataSize<=8)
|
sl@0
|
429 |
a3 = *(TUint32*)aData; // only 4 more bytes, so pass by value, not pointer
|
sl@0
|
430 |
else
|
sl@0
|
431 |
a3 = (TUint32)aData;
|
sl@0
|
432 |
}
|
sl@0
|
433 |
__ACQUIRE_BTRACE_LOCK();
|
sl@0
|
434 |
TBool r = traceData.iHandler(a0,0,aContext,a1,a2,a3,0,aPc);
|
sl@0
|
435 |
__RELEASE_BTRACE_LOCK();
|
sl@0
|
436 |
return r;
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
// adjust for header2, extra, and size word...
|
sl@0
|
440 |
a0 |= BTrace::EHeader2Present<<(BTrace::EFlagsIndex*8)|BTrace::EExtraPresent<<(BTrace::EFlagsIndex*8);
|
sl@0
|
441 |
a0 += 12;
|
sl@0
|
442 |
|
sl@0
|
443 |
TUint32 traceId = __e32_atomic_add_ord32(&BigTraceId, 1);
|
sl@0
|
444 |
TUint32 header2 = BTrace::EMultipartFirst;
|
sl@0
|
445 |
TInt offset = 0;
|
sl@0
|
446 |
do
|
sl@0
|
447 |
{
|
sl@0
|
448 |
TUint32 size = aDataSize-offset;
|
sl@0
|
449 |
if(size>KMaxBTraceDataArray)
|
sl@0
|
450 |
size = KMaxBTraceDataArray;
|
sl@0
|
451 |
else
|
sl@0
|
452 |
header2 = BTrace::EMultipartLast;
|
sl@0
|
453 |
if(size<=4)
|
sl@0
|
454 |
*(TUint32*)&aData = *(TUint32*)aData; // 4 bytes or less are passed by value, not pointer
|
sl@0
|
455 |
|
sl@0
|
456 |
__ACQUIRE_BTRACE_LOCK();
|
sl@0
|
457 |
TBool result = traceData.iHandler(a0+size,header2,aContext,aDataSize,a1,(TUint32)aData,traceId,aPc);
|
sl@0
|
458 |
__RELEASE_BTRACE_LOCK();
|
sl@0
|
459 |
if (!result)
|
sl@0
|
460 |
return result;
|
sl@0
|
461 |
|
sl@0
|
462 |
offset += size;
|
sl@0
|
463 |
*(TUint8**)&aData += size;
|
sl@0
|
464 |
|
sl@0
|
465 |
header2 = BTrace::EMultipartMiddle;
|
sl@0
|
466 |
a1 = offset;
|
sl@0
|
467 |
}
|
sl@0
|
468 |
while(offset<aDataSize);
|
sl@0
|
469 |
|
sl@0
|
470 |
return TRUE;
|
sl@0
|
471 |
}
|
sl@0
|
472 |
|
sl@0
|
473 |
EXPORT_C TSpinLock* BTrace::LockPtr()
|
sl@0
|
474 |
{
|
sl@0
|
475 |
#ifdef __USE_BTRACE_LOCK__
|
sl@0
|
476 |
return &BTraceLock;
|
sl@0
|
477 |
#else
|
sl@0
|
478 |
return 0;
|
sl@0
|
479 |
#endif
|
sl@0
|
480 |
}
|