author | hgs |
Wed, 23 Jun 2010 12:58:21 +0100 | |
changeset 177 | a232af6b0b1f |
parent 90 | 947f0dc9f7a8 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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 |
// e32\nkernsmp\arm\ncsched.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
// NThreadBase member data |
|
19 |
#define __INCLUDE_NTHREADBASE_DEFINES__ |
|
20 |
||
21 |
#include <arm.h> |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
22 |
#include <arm_tmr.h> |
0 | 23 |
|
24 |
extern "C" void NewThreadTrace(NThread* a) |
|
25 |
{ |
|
26 |
__ACQUIRE_BTRACE_LOCK(); |
|
27 |
BTraceData.iHandler(BTRACE_HEADER_C(4,BTrace::ECpuUsage,BTrace::ENewThreadContext),0,(TUint32)a,0,0,0,0,0); |
|
28 |
__RELEASE_BTRACE_LOCK(); |
|
29 |
} |
|
30 |
||
31 |
extern "C" void __DebugMsgSendReschedIPI(int a) |
|
32 |
{ |
|
33 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("@%d",a)); |
|
34 |
} |
|
35 |
||
36 |
extern "C" void __DebugMsgSendReschedIPIs(int a) |
|
37 |
{ |
|
38 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("@%02x",a)); |
|
39 |
} |
|
40 |
||
41 |
extern "C" void __DebugMsgSendReschedIPIAndWait(int a) |
|
42 |
{ |
|
43 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("@@%d",a)); |
|
44 |
} |
|
45 |
||
46 |
#ifdef __FAST_SEM_MACHINE_CODED__ |
|
47 |
extern "C" void PanicFastSemaphoreWait() |
|
48 |
{ |
|
49 |
FAULT(); |
|
50 |
} |
|
51 |
#endif |
|
52 |
||
53 |
#ifdef BTRACE_CPU_USAGE |
|
54 |
extern "C" void btrace_irq_entry(TInt aVector) |
|
55 |
{ |
|
56 |
BTrace4(BTrace::ECpuUsage, BTrace::EIrqStart, aVector); |
|
57 |
} |
|
58 |
||
59 |
extern "C" void btrace_fiq_entry() |
|
60 |
{ |
|
61 |
BTrace0(BTrace::ECpuUsage, BTrace::EFiqStart); |
|
62 |
} |
|
63 |
||
64 |
extern "C" void btrace_irq_exit() |
|
65 |
{ |
|
66 |
BTrace0(BTrace::ECpuUsage, BTrace::EIrqEnd); |
|
67 |
} |
|
68 |
||
69 |
extern "C" void btrace_fiq_exit() |
|
70 |
{ |
|
71 |
BTrace0(BTrace::ECpuUsage, BTrace::EFiqEnd); |
|
72 |
} |
|
73 |
#endif |
|
74 |
||
75 |
extern "C" void __DebugMsgIrq(TUint a) |
|
76 |
{ |
|
77 |
if ((a & 0x3ffu) >= 0x20u) |
|
78 |
return; |
|
79 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("!%x",a)); |
|
80 |
} |
|
81 |
||
82 |
||
83 |
#ifdef _DEBUG |
|
84 |
extern "C" void __DebugMsgFSWait(NFastSemaphore* a) |
|
85 |
{ |
|
86 |
CHECK_PRECONDITIONS(MASK_KERNEL_LOCKED|MASK_NO_FAST_MUTEX,"NFastSemaphore::Wait"); |
|
87 |
NThreadBase* pC = NCurrentThreadL(); |
|
88 |
__ASSERT_WITH_MESSAGE_ALWAYS(pC==a->iOwningThread,"The calling thread must own the semaphore","NFastSemaphore::Wait"); |
|
89 |
} |
|
90 |
||
91 |
extern "C" void __DebugMsgNKFSWait(NFastSemaphore* a) |
|
92 |
{ |
|
93 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("NFSW %m",a)); |
|
94 |
NThreadBase* pC = NCurrentThread(); |
|
95 |
__ASSERT_WITH_MESSAGE_ALWAYS(pC==a->iOwningThread,"The calling thread must own the semaphore","NKern::FSWait"); |
|
96 |
} |
|
97 |
||
98 |
extern "C" void __DebugMsgWFAR() |
|
99 |
{ |
|
100 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"NKern::WaitForAnyRequest"); |
|
101 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("WfAR")); |
|
102 |
} |
|
103 |
||
104 |
extern "C" void __DebugMsgFSSignal(NFastSemaphore* /*a*/) |
|
105 |
{ |
|
106 |
CHECK_PRECONDITIONS(MASK_KERNEL_LOCKED|MASK_NOT_ISR,"NFastSemaphore::Signal"); |
|
107 |
} |
|
108 |
||
109 |
extern "C" void __DebugMsgFSSignalN(NFastSemaphore* /*a*/, TInt aCount) |
|
110 |
{ |
|
111 |
CHECK_PRECONDITIONS(MASK_KERNEL_LOCKED|MASK_NOT_ISR,"NFastSemaphore::SignalN"); |
|
112 |
__NK_ASSERT_DEBUG(aCount>=0); |
|
113 |
} |
|
114 |
||
115 |
extern "C" void __DebugMsgNKThreadRequestSignalN(NThread* /*aThread*/, TInt aCount) |
|
116 |
{ |
|
117 |
__ASSERT_WITH_MESSAGE_DEBUG(aCount>=0, "aCount>=0", "NKern::ThreadRequestSignal"); |
|
118 |
} |
|
119 |
||
120 |
extern "C" void __DebugMsgNKThreadRequestSignal(NThread* /*aThread*/) |
|
121 |
{ |
|
122 |
} |
|
123 |
||
124 |
extern "C" void __DebugMsgNKFSSignal(NFastSemaphore* a) |
|
125 |
{ |
|
126 |
CHECK_PRECONDITIONS(MASK_INTERRUPTS_ENABLED|MASK_NOT_ISR,"NKern::FSSignal(NFastSemaphore*)"); |
|
127 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("NFSS %m",a)); |
|
128 |
} |
|
129 |
||
130 |
extern "C" void __DebugMsgNKFSSignalN(NFastSemaphore* a, TInt aCount) |
|
131 |
{ |
|
132 |
CHECK_PRECONDITIONS(MASK_INTERRUPTS_ENABLED|MASK_NOT_ISR,"NKern::FSSignalN(NFastSemaphore*, TInt)"); |
|
133 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("NFSSN %m %d",a,aCount)); |
|
134 |
__NK_ASSERT_DEBUG(aCount>=0); |
|
135 |
} |
|
136 |
||
137 |
extern "C" void __DebugMsgFMSignal(NFastMutex* /*a*/) |
|
138 |
{ |
|
139 |
CHECK_PRECONDITIONS(MASK_KERNEL_LOCKED,"NFastMutex::Signal"); |
|
140 |
} |
|
141 |
||
142 |
extern "C" void __DebugMsgNKFMWait(NFastMutex* a) |
|
143 |
{ |
|
144 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("NFMW %M", a)); |
|
145 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"NKern::FMWait"); |
|
146 |
} |
|
147 |
||
148 |
extern "C" void __DebugMsgNKFMSignal(NFastMutex* a) |
|
149 |
{ |
|
150 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("NFMS %M", a)); |
|
151 |
CHECK_PRECONDITIONS(MASK_KERNEL_UNLOCKED | MASK_INTERRUPTS_ENABLED | MASK_NOT_ISR | MASK_NOT_IDFC, "NKern::FMSignal"); |
|
152 |
__ASSERT_WITH_MESSAGE_DEBUG(a->HeldByCurrentThread(),"The calling thread holds the mutex","NKern::FMSignal"); |
|
153 |
} |
|
154 |
||
155 |
extern "C" void __DebugMsgNKFMFlash(NFastMutex* a) |
|
156 |
{ |
|
157 |
CHECK_PRECONDITIONS(MASK_KERNEL_UNLOCKED | MASK_INTERRUPTS_ENABLED | MASK_NOT_ISR | MASK_NOT_IDFC, "NKern::FMFlash"); |
|
158 |
__ASSERT_WITH_MESSAGE_DEBUG(a->HeldByCurrentThread(),"The calling thread holds the mutex","NKern::FMFlash"); |
|
159 |
} |
|
160 |
||
161 |
#endif |
|
162 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
#if !defined(__UTT_MACHINE_CODED__) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
void TSubScheduler::UpdateThreadTimes(NThreadBase* aOld, NThreadBase* aNew) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
{ |
177 | 166 |
/* If necessary update local timer frequency (DVFS) */ |
167 |
SRatioInv* pNCF = iSSX.iNewCpuFreqRI; |
|
168 |
if (pNCF) |
|
169 |
{ |
|
170 |
iSSX.iCpuFreqRI = *pNCF; |
|
171 |
__e32_atomic_store_rel_ptr(&iSSX.iNewCpuFreqRI, 0); |
|
172 |
} |
|
173 |
SRatioInv* pNTF = iSSX.iNewTimerFreqRI; |
|
174 |
if (pNTF) |
|
175 |
{ |
|
176 |
iSSX.iTimerFreqRI = *pNTF; |
|
177 |
__e32_atomic_store_rel_ptr(&iSSX.iNewTimerFreqRI, 0); |
|
178 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
if (!aOld) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
aOld = iInitialThread; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
if (!aNew) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
aNew = iInitialThread; |
177 | 183 |
if (aNew!=aOld || aNew->iTime<=0 || pNTF) |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
TUint32 tmrval = 0x7fffffffu; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
if (aNew->iTime > 0) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
{ |
177 | 188 |
tmrval = aNew->iTime; // this will have been computed based on the old timer frequency |
189 |
iSSX.iTimerFreqRI.iR.Mult(tmrval); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
} |
177 | 191 |
// iSSX.iLastTimerSet = tmrval; |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
iSSX.iLocalTimerAddr->iTimerCount = tmrval; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
if (aNew!=aOld) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
TUint64 now = NKern::Timestamp(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
TUint64 delta = now - iLastTimestamp.i64; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
iLastTimestamp.i64 = now; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
aOld->iLastRunTime.i64 = now; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
aOld->iTotalCpuTime.i64 += delta; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
++iReschedCount.i64; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
++aNew->iRunCount.i64; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
if (!aOld->iActiveState) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
aOld->iTotalActiveTime.i64 += (now - aOld->iLastActivationTime.i64); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
205 |
NSchedulable* parent = aOld->iParent; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
if (parent != aOld) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
208 |
parent->iLastRunTime.i64 = now; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
if (!parent->iActiveState) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
parent->iTotalActiveTime.i64 += (now - parent->iLastActivationTime.i64); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
if (parent != aNew->iParent) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
parent->iTotalCpuTime.i64 += (now - parent->iLastStartTime.i64); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
NSchedulable* np = aNew->iParent; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
if (np!=aNew && np!=parent) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
np->iLastStartTime.i64 = now; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
#endif |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |