author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 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 |
// e32\nkernsmp\sched.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
// NThreadBase member data |
|
19 |
#define __INCLUDE_NTHREADBASE_DEFINES__ |
|
20 |
||
21 |
// TDfc member data |
|
22 |
#define __INCLUDE_TDFC_DEFINES__ |
|
23 |
||
24 |
#include "nk_priv.h" |
|
25 |
#include <nk_irq.h> |
|
26 |
||
27 |
TSpinLock NEventHandler::TiedLock(TSpinLock::EOrderEventHandlerTied); |
|
28 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
29 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
30 |
const TUint8 KClassFromPriority[KNumPriorities] = |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
32 |
0, 0, 0, 0, 0, 0, 0, 0, // priorities 0-7 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
33 |
0, 0, 0, 0, 1, 1, 1, 1, // priorities 8-15 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
34 |
2, 2, 2, 2, 2, 2, 2, 2, // priorities 16-23 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
35 |
2, 2, 2, 3, 3, 3, 3, 3, // priorities 24-31 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
36 |
3, 3, 3, 3, 3, 3, 3, 3, // priorities 32-39 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
37 |
3, 3, 3, 3, 3, 3, 3, 3, // priorities 40-47 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
38 |
3, 3, 3, 3, 3, 3, 3, 3, // priorities 48-55 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
39 |
3, 3, 3, 3, 3, 3, 3, 3 // priorities 56-63 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
}; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
41 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
42 |
|
0 | 43 |
/****************************************************************************** |
44 |
* TScheduler |
|
45 |
******************************************************************************/ |
|
46 |
||
47 |
// TScheduler resides in .bss so other fields are zero-initialised |
|
48 |
TScheduler::TScheduler() |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
: iThreadAcceptCpus(1), // only boot CPU for now |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
iIpiAcceptCpus(1), // only boot CPU for now |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
iGenIPILock(TSpinLock::EOrderGenericIPIList), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
iIdleBalanceLock(TSpinLock::EOrderEnumerate), |
0 | 53 |
iIdleSpinLock(TSpinLock::EOrderIdleDFCList), |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
iCpusNotIdle(1), // only boot CPU for now |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
iEnumerateLock(TSpinLock::EOrderEnumerate), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
iBalanceListLock(TSpinLock::EOrderReadyList), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
iBalanceTimer(&BalanceTimerExpired, this, 1), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
iCCSyncIDFC(&CCSyncDone, 0), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
iCCReactivateDfc(&CCReactivateDfcFn, this, 3), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
iCCRequestLevel(1), // only boot CPU for now |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
iCCRequestDfc(&CCRequestDfcFn, this, 2), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
iCCPowerDownDfc(&CCIndirectPowerDown, this, 0), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
iCCIpiReactIDFC(&CCIpiReactivateFn, this), |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
iFreqChgDfc(&DoFrequencyChanged, this, 6) |
0 | 65 |
{ |
66 |
TInt i; |
|
67 |
for (i=0; i<KMaxCpus; ++i) |
|
68 |
{ |
|
69 |
TSubScheduler* s = TheSubSchedulers + i; |
|
70 |
iSub[i] = s; |
|
71 |
s->iScheduler = this; |
|
72 |
s->iCpuNum = TUint32(i); |
|
73 |
s->iCpuMask = 1u<<i; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
s->iLbCounter = TUint8(NSchedulable::ELbState_PerCpu + i); |
0 | 75 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
iLbCounter = (TUint8)NSchedulable::ELbState_Global; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
iNeedBal = 1; // stop anyone trying to kick rebalancer before it has been created |
0 | 78 |
} |
79 |
||
80 |
||
81 |
/** Return a pointer to the scheduler |
|
82 |
Intended for use by the crash debugger, not for general device driver use. |
|
83 |
||
84 |
@return Pointer to the scheduler object |
|
85 |
@internalTechnology |
|
86 |
*/ |
|
87 |
EXPORT_C TScheduler* TScheduler::Ptr() |
|
88 |
{ |
|
89 |
return &TheScheduler; |
|
90 |
} |
|
91 |
||
92 |
||
93 |
/****************************************************************************** |
|
94 |
* TSubScheduler |
|
95 |
******************************************************************************/ |
|
96 |
||
97 |
// TSubScheduler resides in .bss so other fields are zero-initialised |
|
98 |
TSubScheduler::TSubScheduler() |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
: iExIDfcLock(TSpinLock::EOrderExIDfcQ), |
0 | 100 |
iReadyListLock(TSpinLock::EOrderReadyList), |
101 |
iKernLockCount(1), |
|
102 |
iEventHandlerLock(TSpinLock::EOrderEventHandlerList) |
|
103 |
{ |
|
104 |
} |
|
105 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
void TSubScheduler::SSAddEntry(NSchedulable* aEntry) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
if (aEntry->iParent!=aEntry || !((NThreadBase*)aEntry)->i_NThread_Initial) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
TInt c = KClassFromPriority[aEntry->iPriority]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
++iPriClassThreadCount[c]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
112 |
++iRdyThreadCount; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
iSSList.Add(aEntry); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
void TSubScheduler::SSAddEntryHead(NSchedulable* aEntry) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
if (aEntry->iParent!=aEntry || !((NThreadBase*)aEntry)->i_NThread_Initial) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
TInt c = KClassFromPriority[aEntry->iPriority]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
++iPriClassThreadCount[c]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
++iRdyThreadCount; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
iSSList.AddHead(aEntry); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
void TSubScheduler::SSRemoveEntry(NSchedulable* aEntry) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
if (aEntry->iParent!=aEntry || !((NThreadBase*)aEntry)->i_NThread_Initial) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
TInt c = KClassFromPriority[aEntry->iPriority]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
--iPriClassThreadCount[c]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
--iRdyThreadCount; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
iSSList.Remove(aEntry); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
void TSubScheduler::SSChgEntryP(NSchedulable* aEntry, TInt aNewPriority) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
if (aEntry->iParent!=aEntry || !((NThreadBase*)aEntry)->i_NThread_Initial) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
TInt c0 = KClassFromPriority[aEntry->iPriority]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
TInt c1 = KClassFromPriority[aNewPriority]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
if (c0 != c1) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
--iPriClassThreadCount[c0]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
++iPriClassThreadCount[c1]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
iSSList.ChangePriority(aEntry, aNewPriority); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
|
0 | 154 |
|
155 |
/****************************************************************************** |
|
156 |
* NSchedulable |
|
157 |
******************************************************************************/ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
TUint32 NSchedulable::PreprocessCpuAffinity(TUint32 aAffinity) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
if (!(aAffinity & NTHREADBASE_CPU_AFFINITY_MASK)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
return aAffinity; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
TUint32 x = aAffinity & ~NTHREADBASE_CPU_AFFINITY_MASK; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
if (x & (x-1)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
return aAffinity; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
return __e32_find_ls1_32(x); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
166 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
|
0 | 168 |
void NSchedulable::AcqSLock() |
169 |
{ |
|
170 |
iSSpinLock.LockOnly(); |
|
171 |
if (iParent!=this && iParent) |
|
172 |
iParent->AcqSLock(); |
|
173 |
} |
|
174 |
||
175 |
void NSchedulable::RelSLock() |
|
176 |
{ |
|
177 |
if (iParent!=this && iParent) |
|
178 |
iParent->RelSLock(); |
|
179 |
iSSpinLock.UnlockOnly(); |
|
180 |
} |
|
181 |
||
182 |
void NSchedulable::LAcqSLock() |
|
183 |
{ |
|
184 |
NKern::Lock(); |
|
185 |
AcqSLock(); |
|
186 |
} |
|
187 |
||
188 |
void NSchedulable::RelSLockU() |
|
189 |
{ |
|
190 |
RelSLock(); |
|
191 |
NKern::Unlock(); |
|
192 |
} |
|
193 |
||
194 |
void NSchedulable::UnPauseT() |
|
195 |
{ |
|
196 |
CHECK_PRECONDITIONS(MASK_KERNEL_LOCKED|MASK_NOT_ISR,"NSchedulable::UnPauseT"); |
|
197 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%T nUnPauseT",this)); |
|
198 |
__NK_ASSERT_DEBUG(iPauseCount); |
|
199 |
if (--iPauseCount || iReady || iSuspended || (iParent && ((NThread*)this)->iWaitState.ThreadIsBlocked())) |
|
200 |
return; |
|
201 |
ReadyT(EUnPause); |
|
202 |
} |
|
203 |
||
204 |
void NSchedulable::DeferredReadyIDfcFn(TAny* aPtr) |
|
205 |
{ |
|
206 |
NSchedulable* a = (NSchedulable*)aPtr; |
|
207 |
a->AcqSLock(); |
|
208 |
TUint32 evs = __e32_atomic_and_acq32(&a->iEventState, ~EDeferredReady); |
|
209 |
if (evs & EDeferredReady) |
|
210 |
{ |
|
211 |
if (a->iParent) |
|
212 |
{ |
|
213 |
// thread |
|
214 |
a->UnPauseT(); |
|
215 |
} |
|
216 |
else |
|
217 |
{ |
|
218 |
// thread group |
|
219 |
NThreadGroup* g = (NThreadGroup*)a; |
|
220 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%G nDeferredReady",g)); |
|
221 |
__NK_ASSERT_DEBUG(g->iPauseCount); |
|
222 |
if (--g->iPauseCount && g->iNThreadList.NonEmpty()) |
|
223 |
g->ReadyT(EUnPause); |
|
224 |
} |
|
225 |
} |
|
226 |
a->RelSLock(); |
|
227 |
} |
|
228 |
||
229 |
TInt NSchedulable::AddTiedEvent(NEventHandler* aEvent) |
|
230 |
{ |
|
231 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%T AddEv %08x",this,aEvent)); |
|
232 |
TInt r = KErrGeneral; |
|
233 |
NEventHandler::TiedLock.LockOnly(); |
|
234 |
AcqSLock(); |
|
235 |
if (iStopping) |
|
236 |
r = KErrDied; |
|
237 |
else if (!aEvent->iTied) |
|
238 |
{ |
|
239 |
aEvent->iTied = this; |
|
240 |
iEvents.Add(&aEvent->iTiedLink); |
|
241 |
r = KErrNone; |
|
242 |
} |
|
243 |
RelSLock(); |
|
244 |
NEventHandler::TiedLock.UnlockOnly(); |
|
245 |
return r; |
|
246 |
} |
|
247 |
||
248 |
void ipi_dummy(TGenericIPI*) |
|
249 |
{ |
|
250 |
} |
|
251 |
||
252 |
/** Detach and cancel any tied events attached to this thread/group |
|
253 |
||
254 |
Call in a thread context with interrupts and preemption enabled. |
|
255 |
Calling thread in critical section. |
|
256 |
||
257 |
@internalComponent |
|
258 |
*/ |
|
259 |
void NSchedulable::DetachTiedEvents() |
|
260 |
{ |
|
261 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%T DetTiedEv",this)); |
|
262 |
NKern::Lock(); |
|
263 |
NEventHandler::TiedLock.LockOnly(); |
|
264 |
AcqSLock(); |
|
265 |
iStopping = TRUE; |
|
266 |
if (!iParent) |
|
267 |
{ |
|
268 |
// can't destroy a group until all threads have detached from it |
|
269 |
NThreadGroup* g = (NThreadGroup*)this; |
|
270 |
__NK_ASSERT_ALWAYS(g->iThreadCount==0 && g->iNThreadList.IsEmpty()); |
|
271 |
} |
|
272 |
RelSLock(); |
|
273 |
NEventHandler::TiedLock.UnlockOnly(); |
|
274 |
||
275 |
// send IPI to all processors to synchronise |
|
276 |
// after this, any tied IDFCs can only proceed to completion |
|
277 |
// they can't be queued again |
|
278 |
TGenericIPI ipi; |
|
279 |
ipi.QueueAllOther(&ipi_dummy); |
|
280 |
NKern::Unlock(); |
|
281 |
ipi.WaitCompletion(); |
|
282 |
||
283 |
FOREVER |
|
284 |
{ |
|
285 |
NKern::Lock(); |
|
286 |
NEventHandler::TiedLock.LockOnly(); |
|
287 |
AcqSLock(); |
|
288 |
NEventHandler* h = 0; |
|
289 |
TInt type = -1; |
|
290 |
if (!iEvents.IsEmpty()) |
|
291 |
{ |
|
292 |
h = _LOFF(iEvents.First()->Deque(), NEventHandler, iTiedLink); |
|
293 |
h->iTiedLink.iNext = 0; |
|
294 |
type = h->iHType; |
|
295 |
} |
|
296 |
RelSLock(); |
|
297 |
if (type == NEventHandler::EEventHandlerNTimer) |
|
298 |
{ |
|
299 |
// everything's easy for a timer since we can just cancel it here |
|
300 |
NTimer* tmr = (NTimer*)h; |
|
301 |
tmr->DoCancel(NTimer::ECancelDestroy); |
|
302 |
tmr->iTied = 0; |
|
303 |
} |
|
304 |
else if (type == NEventHandler::EEventHandlerIDFC) |
|
305 |
{ |
|
306 |
// can just cancel the IDFC with TiedLock held |
|
307 |
// EndTiedEvent() may be delayed, but we wait for that further down |
|
308 |
// iTied will have been captured before the IDFC state is reset |
|
309 |
// Cancel() waits for the state to be reset |
|
310 |
TDfc* d = (TDfc*)h; |
|
311 |
d->Cancel(); |
|
312 |
d->iHType = (TUint8)NEventHandler::EEventHandlerDummy; |
|
313 |
d->iTied = 0; |
|
314 |
} |
|
315 |
NEventHandler::TiedLock.UnlockOnly(); |
|
316 |
NKern::Unlock(); |
|
317 |
if (!h) |
|
318 |
break; |
|
319 |
switch (type) |
|
320 |
{ |
|
321 |
case NEventHandler::EEventHandlerIrq: |
|
322 |
{ |
|
323 |
NIrqHandler* pH = (NIrqHandler*)h; |
|
324 |
// pH can't have been freed since we dequeued it but left iTied set |
|
325 |
pH->Unbind(pH->iHandle, this); |
|
326 |
break; |
|
327 |
} |
|
328 |
case NEventHandler::EEventHandlerNTimer: |
|
329 |
case NEventHandler::EEventHandlerIDFC: |
|
330 |
case NEventHandler::EEventHandlerDummy: |
|
331 |
// nothing left to do |
|
332 |
break; |
|
333 |
default: |
|
334 |
__NK_ASSERT_ALWAYS(0); |
|
335 |
break; |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
// Wait for any remaining tied event handlers to complete |
|
340 |
while (iEventState & EEventCountMask) |
|
341 |
{ |
|
342 |
__chill(); |
|
343 |
} |
|
344 |
} |
|
345 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
/** Return the total CPU time so far used by the specified thread. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
349 |
@return The total CPU time in units of 1/NKern::CpuTimeMeasFreq(). |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
*/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
EXPORT_C TUint64 NKern::ThreadCpuTime(NThread* aThread) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
NSchedulable::SCpuStats stats; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
NKern::Lock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
355 |
aThread->GetCpuStats(NSchedulable::E_RunTime, stats); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
NKern::Unlock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
return stats.iRunTime; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
359 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
360 |
void NSchedulable::GetCpuStats(TUint aMask, NSchedulable::SCpuStats& aOut) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
361 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
AcqSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
GetCpuStatsT(aMask, aOut); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
RelSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
void NSchedulable::GetCpuStatsT(TUint aMask, NSchedulable::SCpuStats& aOut) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
TSubScheduler* ss = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
NThread* t = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
TBool initial = FALSE; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
372 |
if (!IsGroup()) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
t = (NThread*)this; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
if (t && t->i_NThread_Initial) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
ss = &TheSubSchedulers[iLastCpu], initial = TRUE; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
376 |
else if (iReady) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
377 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
if (IsGroup()) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
ss = &TheSubSchedulers[iReady & NSchedulable::EReadyCpuMask]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
380 |
else if (iParent->iReady) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
ss = &TheSubSchedulers[iParent->iReady & NSchedulable::EReadyCpuMask]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
if (ss) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
ss->iReadyListLock.LockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
TUint64 now = NKern::Timestamp(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
if (aMask & (E_RunTime|E_RunTimeDelta)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
aOut.iRunTime = iTotalCpuTime.i64; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
if (iCurrent || (initial && !ss->iCurrentThread)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
aOut.iRunTime += (now - ss->iLastTimestamp.i64); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
if (aMask & E_RunTimeDelta) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
aOut.iRunTimeDelta = aOut.iRunTime - iSavedCpuTime.i64; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
iSavedCpuTime.i64 = aOut.iRunTime; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
if (aMask & (E_ActiveTime|E_ActiveTimeDelta)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
aOut.iActiveTime = iTotalActiveTime.i64; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
if (iActiveState) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
aOut.iActiveTime += (now - iLastActivationTime.i64); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
if (aMask & E_ActiveTimeDelta) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
aOut.iActiveTimeDelta = aOut.iActiveTime - iSavedActiveTime.i64; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
iSavedActiveTime.i64 = aOut.iActiveTime; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
if (aMask & E_LastRunTime) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
if (iCurrent) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
aOut.iLastRunTime = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
else |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
aOut.iLastRunTime = now - iLastRunTime.i64; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
if (aMask & E_LastActiveTime) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
if (iActiveState) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
418 |
aOut.iLastActiveTime = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
else |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
aOut.iLastActiveTime = now - iLastRunTime.i64; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
if (ss) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
ss->iReadyListLock.UnlockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
425 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
|
0 | 427 |
/****************************************************************************** |
428 |
* NThreadGroup |
|
429 |
******************************************************************************/ |
|
430 |
||
431 |
||
432 |
/****************************************************************************** |
|
433 |
* NThreadBase |
|
434 |
******************************************************************************/ |
|
435 |
||
436 |
/** Makes a nanothread ready. |
|
437 |
||
438 |
For use by RTOS personality layers. |
|
439 |
||
440 |
@pre Kernel must be locked. |
|
441 |
@pre Call either in a thread or an IDFC context. |
|
442 |
@pre The thread being made ready must not be explicitly suspended |
|
443 |
||
444 |
@post Kernel is locked. |
|
445 |
*/ |
|
446 |
void NSchedulable::ReadyT(TUint aMode) |
|
447 |
{ |
|
448 |
CHECK_PRECONDITIONS(MASK_KERNEL_LOCKED|MASK_NOT_ISR,"NSchedulable::ReadyT"); |
|
449 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%T nReadyT(%x)",this,aMode)); |
|
450 |
NThreadBase* t = (NThreadBase*)this; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
if (iParent && !iActiveState) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
452 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
453 |
iActiveState=1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
454 |
iLastActivationTime.i64 = NKern::Timestamp(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
455 |
if (iParent!=this && ++iParent->iActiveState==1) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
456 |
iParent->iLastActivationTime.i64 = iLastActivationTime.i64; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
457 |
} |
0 | 458 |
#ifdef _DEBUG |
459 |
if (!iParent) |
|
460 |
t = (NThreadBase*)0xface0fff; |
|
461 |
#endif |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
462 |
__NK_ASSERT_DEBUG(!iReady && (!iParent || (!t->iWaitState.iWtC.iWtStFlags && !t->iSuspended))); |
0 | 463 |
TSubScheduler& ss0 = SubScheduler(); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
464 |
TScheduler& s = TheScheduler; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
TBool reactivate = FALSE; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
466 |
TBool no_ipi = FALSE; |
0 | 467 |
NSchedulable* g = this; |
468 |
if (iParent != this && iParent) |
|
469 |
{ |
|
470 |
NThreadGroup* tg = (NThreadGroup*)iParent; |
|
471 |
iReady = EReadyGroup; |
|
472 |
if (tg->iReady) |
|
473 |
{ |
|
474 |
// extra thread added to group - change priority if necessary |
|
475 |
tg->iNThreadList.Add(this); |
|
476 |
TInt gp = tg->iPriority; |
|
477 |
TSubScheduler& ss = TheSubSchedulers[tg->iReady & EReadyCpuMask]; |
|
478 |
ss.iReadyListLock.LockOnly(); |
|
479 |
TInt hp = ss.HighestPriority(); |
|
480 |
if (iPriority>gp) |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
481 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
ss.SSChgEntryP(tg, iPriority); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
} |
0 | 484 |
if (iPriority>hp || (iPriority==hp && ss.iCurrentThread && ss.iCurrentThread->iTime==0)) |
485 |
{ |
|
486 |
if (&ss == &ss0) |
|
487 |
RescheduleNeeded(); // reschedule on this processor |
|
488 |
else |
|
489 |
ss0.iReschedIPIs |= ss.iCpuMask; // will kick the other CPU when this CPU reenables preemption |
|
490 |
} |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
491 |
if ((aMode & ENewTimeslice) && t->iTime==0 && (iNext!=this || ss.EntryAtPriority(iPriority)) ) |
0 | 492 |
t->iTime = t->iTimeslice; |
493 |
ss.iReadyListLock.UnlockOnly(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
ss0.iMadeReadyCounter++; |
0 | 496 |
return; |
497 |
} |
|
498 |
tg->iNThreadList.Add(this); |
|
499 |
tg->iPriority = iPriority; // first in group |
|
500 |
g = tg; // fall through to add group to subscheduler |
|
501 |
} |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
502 |
TInt priClass = -1; |
0 | 503 |
TInt cpu = -1; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
504 |
TUint32 active = TheScheduler.iThreadAcceptCpus; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
505 |
if (g!=t || !t->i_NThread_Initial) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
506 |
priClass = KClassFromPriority[g->iPriority]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
507 |
if (g->iForcedCpu) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
508 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
509 |
cpu = iForcedCpu & EReadyCpuMask; // handles core cycling case (No.1 below) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
510 |
if (active & (1u<<cpu)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
511 |
goto cpu_ok; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
512 |
else |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
513 |
goto single_cpu_reactivate; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
514 |
} |
0 | 515 |
if (aMode & EUnPause) |
516 |
{ |
|
517 |
cpu = (g->iEventState & EThreadCpuMask)>>EThreadCpuShift; |
|
518 |
if (CheckCpuAgainstAffinity(cpu, g->iCpuAffinity)) |
|
519 |
goto cpu_ok; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
520 |
cpu = -1; |
0 | 521 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
522 |
if (g->iFreezeCpu) |
0 | 523 |
{ |
524 |
cpu = g->iLastCpu; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
525 |
goto cpu_ok; |
0 | 526 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
527 |
if (!(g->iCpuAffinity & NTHREADBASE_CPU_AFFINITY_MASK)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
528 |
{ |
0 | 529 |
cpu = g->iCpuAffinity; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
530 |
if (!(active & (1u<<cpu))) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
531 |
goto single_cpu_reactivate; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
532 |
goto cpu_ok; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
533 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
534 |
if ((aMode & EPreferSameCpu) && CheckCpuAgainstAffinity(ss0.iCpuNum, g->iCpuAffinity, active)) |
0 | 535 |
cpu = ss0.iCpuNum; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
536 |
else if (iTransientCpu && CheckCpuAgainstAffinity(iTransientCpu & EReadyCpuMask, g->iCpuAffinity)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
cpu = iTransientCpu & EReadyCpuMask; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
538 |
else if (iPreferredCpu && CheckCpuAgainstAffinity(iPreferredCpu & EReadyCpuMask, g->iCpuAffinity, active)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
cpu = iPreferredCpu & EReadyCpuMask; |
0 | 540 |
if (cpu < 0) |
541 |
{ |
|
542 |
// pick a cpu |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
543 |
TUint32 m = g->iCpuAffinity & active; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
544 |
TInt lastCpu = g->iLastCpu; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
545 |
TInt i = lastCpu; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
546 |
TInt lcp = KMaxTInt; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
547 |
TInt lco = KMaxTInt; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
548 |
TInt cpunp = -1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
549 |
TInt idle_cpu = -1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
do { |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
if (m & (1u<<i)) |
0 | 552 |
{ |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
553 |
TSubScheduler& ss = *s.iSub[i]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
554 |
TInt nInC = ss.iPriClassThreadCount[priClass]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
if (nInC < lco) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
556 |
lco=nInC, cpunp=i; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
557 |
TInt hp = ss.HighestPriority(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
if (idle_cpu<0 && hp<=0) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
idle_cpu = i; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
if (hp < iPriority) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
if (i == lastCpu) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
564 |
cpu = i; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
565 |
if (hp <= 0) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
566 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
567 |
lcp = -1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
568 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
569 |
if (nInC < lcp) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
570 |
lcp=nInC, cpu=i; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
571 |
} |
0 | 572 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
573 |
if (++i == s.iNumCpus) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
574 |
i = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
575 |
} while (i != lastCpu); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
576 |
if (idle_cpu>=0 && cpu!=idle_cpu) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
577 |
cpu = idle_cpu; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
578 |
else if (cpu<0) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
579 |
cpu = cpunp; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
580 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
581 |
if (cpu<0) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
582 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
583 |
single_cpu_reactivate: |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
584 |
/* CORE_CONTROL |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
585 |
Might have no CPU at this point due to all CPUs specified by |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
586 |
iCpuAffinity being off or in the process of shutting down. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
587 |
There are three possibilities: |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
588 |
1. This thread is 'core cycling'. In that case it will be |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
589 |
allowed to move to a 'shutting down' CPU. The CPU will |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
590 |
not be permitted to shut down entirely until all core cycling |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
591 |
has completed. This is already handled above. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
592 |
2. There are one or more CPUs which this thread could run on which |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
593 |
are shutting down. In that case, pick one, abort the shutdown |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
594 |
process and put this thread on it. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
595 |
3. All CPUs which this thread can run on are off. In that case, |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
596 |
assign the thread to one of them and initiate power up of that core. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
597 |
*/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
598 |
TUint32 affm = AffinityToMask(g->iCpuAffinity); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
599 |
TInt irq = s.iGenIPILock.LockIrqSave(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
600 |
if (cpu < 0) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
601 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
602 |
if (affm & s.iCCReactivateCpus) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
603 |
cpu = __e32_find_ls1_32(affm & s.iCCReactivateCpus); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
604 |
else if (affm & s.iIpiAcceptCpus) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
605 |
cpu = __e32_find_ls1_32(affm & s.iIpiAcceptCpus); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
606 |
else |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
607 |
cpu = __e32_find_ls1_32(affm), no_ipi = TRUE; |
0 | 608 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
TUint32 cm = 1u<<cpu; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
610 |
if (!((s.iCCReactivateCpus|s.iThreadAcceptCpus) & cm)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
611 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
612 |
s.iCCReactivateCpus |= (1u<<cpu); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
613 |
reactivate = TRUE; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
614 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
615 |
s.iGenIPILock.UnlockIrqRestore(irq); |
0 | 616 |
} |
617 |
cpu_ok: |
|
618 |
__NK_ASSERT_ALWAYS(cpu>=0); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
619 |
if (g->iFreezeCpu && !CheckCpuAgainstAffinity(cpu, g->iCpuAffinity)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
620 |
g->iCpuChange = TRUE; |
0 | 621 |
if (g->TiedEventReadyInterlock(cpu)) |
622 |
{ |
|
623 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("ReadyT->CPU %dD",cpu)); |
|
624 |
++g->iPauseCount; |
|
625 |
} |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
626 |
else |
0 | 627 |
{ |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
628 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("ReadyT->CPU %d",cpu)); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
629 |
TSubScheduler& ss = TheSubSchedulers[cpu]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
630 |
ss.iReadyListLock.LockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
631 |
TInt hp = ss.HighestPriority(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
632 |
if (g->iPriority>hp || (g->iPriority==hp && ss.iCurrentThread && ss.iCurrentThread->iTime==0)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
634 |
if (&ss == &ss0) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
635 |
RescheduleNeeded(); // reschedule on this processor |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
636 |
else if (!no_ipi) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
637 |
ss0.iReschedIPIs |= ss.iCpuMask; // will kick the other CPU when this CPU reenables preemption |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
638 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
639 |
ss.SSAddEntry(g); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
640 |
g->iReady = TUint8(cpu | EReadyOffset); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
641 |
if ((aMode & ENewTimeslice) && iParent && t->iTime==0 && g->iNext!=g) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
642 |
t->iTime = t->iTimeslice; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
643 |
if (!g->iLbLink.iNext && !(g->iParent && t->i_NThread_Initial)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
644 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
645 |
ss.iLbQ.Add(&g->iLbLink); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
646 |
g->iLbState = ss.iLbCounter; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
647 |
if (!s.iNeedBal && (!g->iParent || !(t->iRebalanceAttr & 1))) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
649 |
s.iNeedBal = 1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
650 |
reactivate = TRUE; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
651 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
652 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
653 |
if (g->iForcedCpu == g->iReady) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
654 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
655 |
g->iLastCpu = (TUint8)cpu; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
656 |
g->iForcedCpu = 0; // iForcedCpu has done its job - iFreezeCpu will keep the thread on the right CPU |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
657 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
658 |
ss.iReadyListLock.UnlockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
659 |
ss0.iMadeReadyCounter++; |
0 | 660 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
661 |
if (reactivate) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
662 |
s.iCCReactivateDfc.Add(); |
0 | 663 |
} |
664 |
||
665 |
||
666 |
NThread* TSubScheduler::SelectNextThread() |
|
667 |
{ |
|
668 |
NThread* ot = iCurrentThread; |
|
669 |
NThread* t = 0; |
|
670 |
TBool migrate = FALSE; |
|
671 |
TBool gmigrate = FALSE; |
|
672 |
TBool fmd_done = FALSE; |
|
673 |
TBool fmd_res = FALSE; |
|
674 |
if (!ot) |
|
675 |
{ |
|
676 |
iReadyListLock.LockOnly(); |
|
677 |
iRescheduleNeededFlag = FALSE; |
|
678 |
goto no_ot; |
|
679 |
} |
|
680 |
ot->AcqSLock(); |
|
681 |
if (ot->iNewParent) |
|
682 |
ot->iNewParent->AcqSLock(); |
|
683 |
SaveTimesliceTimer(ot); // remember how much of current thread's timeslice remains |
|
684 |
if (ot->iCsFunction==NThreadBase::ECSDivertPending && ot->iWaitState.iWtC.iWtStFlags) |
|
685 |
{ |
|
686 |
// thread about to exit so cancel outstanding wait |
|
687 |
ot->DoReleaseT(KErrDied,0); |
|
688 |
} |
|
689 |
if (ot->iWaitState.iWtC.iWtStFlags==0) |
|
690 |
{ |
|
691 |
// ASSUMPTION: If iNewParent set, ot can't hold a fast mutex (assertion in JoinGroup) |
|
692 |
TBool pfmd = (ot->iParent!=ot && !ot->iFastMutexDefer); |
|
693 |
if (ot->iTime==0 || pfmd) |
|
694 |
{ |
|
695 |
// ot's timeslice has expired |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
696 |
ot->iParent->iTransientCpu = 0; |
0 | 697 |
fmd_res = ot->CheckFastMutexDefer(); |
698 |
fmd_done = TRUE; |
|
699 |
if (fmd_res) |
|
700 |
{ |
|
701 |
if (ot->iTime == 0) |
|
702 |
ot->iTime = 0x80000000; // mark deferred timeslice expiry |
|
703 |
if (pfmd) |
|
704 |
{ |
|
705 |
ot->iFastMutexDefer = 1; |
|
706 |
++ot->iParent->iFreezeCpu; |
|
707 |
} |
|
708 |
} |
|
709 |
} |
|
710 |
} |
|
711 |
iReadyListLock.LockOnly(); |
|
712 |
iRescheduleNeededFlag = FALSE; |
|
713 |
||
714 |
// process outstanding suspend/kill/CPU change on ot |
|
715 |
||
716 |
__NK_ASSERT_DEBUG(!(ot->iWaitState.iWtC.iWtStFlags & NThreadWaitState::EWtStWaitActive)); |
|
717 |
if (ot->iWaitState.iWtC.iWtStFlags || ot->iPauseCount || ot->iSuspended) |
|
718 |
{ |
|
719 |
// ot is no longer ready to run |
|
720 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("Rschd<-%T WS: %02x %02x (%08x) P:%02x S:%1x", ot, |
|
721 |
ot->iWaitState.iWtC.iWtStFlags, ot->iWaitState.iWtC.iWtObjType, ot->iWaitState.iWtC.iWtObj, ot->iPauseCount, ot->iSuspended)); |
|
722 |
TInt wtst = ot->iWaitState.DoWait(); |
|
723 |
if (wtst>=0 && wtst!=NThread::EWaitFastMutex) |
|
724 |
ot->iTime = ot->iTimeslice; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
725 |
if (wtst==KErrDied || ot->iSuspended || (!(ot->iWaitState.iWtC.iWtStFlags & NThreadWaitState::EWtStObstructed) && wtst>=0) ) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
ot->iActiveState = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
728 |
ot->iParent->iTransientCpu = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
if (ot->iParent != ot) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
730 |
--ot->iParent->iActiveState; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
731 |
} |
0 | 732 |
ot->UnReadyT(); |
733 |
if (ot->iNewParent) |
|
734 |
{ |
|
735 |
ot->iParent = ot->iNewParent, ++((NThreadGroup*)ot->iParent)->iThreadCount; |
|
736 |
wmb(); // must make sure iParent is updated before iNewParent is cleared |
|
737 |
ot->iNewParent = 0; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
738 |
if (ot->iActiveState && ++ot->iParent->iActiveState==1) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
739 |
ot->iParent->iLastActivationTime.i64 = NKern::Timestamp(); |
0 | 740 |
} |
741 |
ot->iCpuChange = FALSE; |
|
742 |
} |
|
743 |
else if (ot->iNewParent) |
|
744 |
{ |
|
745 |
__NK_ASSERT_ALWAYS(ot->iParent==ot && !ot->iHeldFastMutex && !ot->iFreezeCpu); |
|
746 |
ot->UnReadyT(); |
|
747 |
migrate = TRUE; |
|
748 |
ot->iParent = ot->iNewParent; |
|
749 |
ot->iCpuChange = FALSE; |
|
750 |
++((NThreadGroup*)ot->iParent)->iThreadCount; |
|
751 |
wmb(); // must make sure iParent is updated before iNewParent is cleared |
|
752 |
ot->iNewParent = 0; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
TUint64 now = NKern::Timestamp(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
754 |
if (!ot->iParent->iCurrent) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
ot->iParent->iLastStartTime.i64 = now; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
if (++ot->iParent->iActiveState==1) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
ot->iParent->iLastActivationTime.i64 = now; |
0 | 758 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
759 |
else if (ot->iParent->iCpuChange) |
0 | 760 |
{ |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
if (ot->iForcedCpu) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
migrate = TRUE; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
else if (!ot->iParent->iFreezeCpu) |
0 | 764 |
{ |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
if (ot->iParent->ShouldMigrate(iCpuNum)) |
0 | 766 |
{ |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
if (ot->iParent==ot) |
0 | 768 |
{ |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
if (!fmd_done) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
fmd_res = ot->CheckFastMutexDefer(), fmd_done = TRUE; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
if (!fmd_res) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
migrate = TRUE; |
0 | 773 |
} |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
else |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
gmigrate = TRUE; |
0 | 776 |
} |
777 |
else |
|
778 |
{ |
|
779 |
ot->iCpuChange = FALSE; |
|
780 |
ot->iParent->iCpuChange = FALSE; |
|
781 |
} |
|
782 |
} |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
783 |
if (migrate) |
0 | 784 |
{ |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
785 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("Rschd<-%T A:%08x",ot,ot->iParent->iCpuAffinity)); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
786 |
ot->UnReadyT(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
787 |
ot->iCpuChange = FALSE; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
788 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
789 |
else if (gmigrate) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
790 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
791 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("Rschd<-%T GA:%08x",ot,ot->iParent->iCpuAffinity)); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
792 |
SSRemoveEntry(ot->iParent); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
793 |
ot->iParent->iReady = 0; |
0 | 794 |
ot->iCpuChange = FALSE; |
795 |
ot->iParent->iCpuChange = FALSE; |
|
796 |
} |
|
797 |
} |
|
798 |
no_ot: |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
799 |
NSchedulable* g = (NSchedulable*)iSSList.First(); |
0 | 800 |
TBool rrcg = FALSE; |
801 |
if (g && g->IsGroup()) |
|
802 |
{ |
|
803 |
t = (NThread*)((NThreadGroup*)g)->iNThreadList.First(); |
|
804 |
if (g->iNext!=g) |
|
805 |
rrcg = TRUE; |
|
806 |
} |
|
807 |
else |
|
808 |
t = (NThread*)g; |
|
809 |
TBool rrct = (t && t->iNext!=t); |
|
810 |
if (t && t->iTime==0 && (rrcg || rrct)) |
|
811 |
{ |
|
812 |
// candidate thread's timeslice has expired and there is another at the same priority |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
813 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
814 |
iTimeSliceExpireCounter++; // update metric |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
815 |
|
0 | 816 |
if (t==ot) |
817 |
{ |
|
818 |
if (ot->iParent!=ot) |
|
819 |
{ |
|
820 |
((NThreadGroup*)ot->iParent)->iNThreadList.iQueue[ot->iPriority] = ot->iNext; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
821 |
iSSList.iQueue[ot->iParent->iPriority] = ot->iParent->iNext; |
0 | 822 |
} |
823 |
else |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
824 |
iSSList.iQueue[ot->iPriority] = ot->iNext; |
0 | 825 |
ot->iTime = ot->iTimeslice; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
826 |
NSchedulable* g2 = (NSchedulable*)iSSList.First(); |
0 | 827 |
if (g2->IsGroup()) |
828 |
t = (NThread*)((NThreadGroup*)g2)->iNThreadList.First(); |
|
829 |
else |
|
830 |
t = (NThread*)g2; |
|
831 |
if (t->iTime==0) |
|
832 |
{ |
|
833 |
// loop again since we need to lock t before round robining it |
|
834 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("Rschd<-%T RRL",ot)); |
|
835 |
iRescheduleNeededFlag = TRUE; |
|
836 |
} |
|
837 |
else |
|
838 |
{ |
|
839 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("Rschd<-%T RR",ot)); |
|
840 |
} |
|
841 |
} |
|
842 |
else // loop again since we need to lock t before round robining it |
|
843 |
{ |
|
844 |
__KTRACE_OPT(KSCHED2,DEBUGPRINT("Rschd<-%T LL",ot)); |
|
845 |
iRescheduleNeededFlag = TRUE; |
|
846 |
} |
|
847 |
} |
|
848 |
if (t != ot) |
|
849 |
{ |
|
850 |
if (ot) |
|
851 |
{ |
|
852 |
ot->iCurrent = 0; |
|
853 |
ot->iParent->iCurrent = 0; |
|
854 |
ot->CompleteContextSave(); |
|
855 |
} |
|
856 |
if (t) |
|
857 |
{ |
|
858 |
t->iLastCpu = iCpuNum; |
|
859 |
t->iParent->iLastCpu = iCpuNum; |
|
860 |
t->iCurrent = TUint8(iCpuNum | NSchedulable::EReadyOffset); |
|
861 |
t->iParent->iCurrent = t->iCurrent; |
|
862 |
} |
|
863 |
iCurrentThread = t; |
|
864 |
} |
|
865 |
UpdateThreadTimes(ot,t); // update ot's run time and set up the timeslice timer for t |
|
866 |
iReadyListLock.UnlockOnly(); |
|
867 |
if (migrate) |
|
868 |
ot->ReadyT(NThreadBase::ENewTimeslice); // new timeslice if it's queued behind another thread at same priority |
|
869 |
if (gmigrate) |
|
870 |
ot->iParent->ReadyT(0); // new timeslice if it's queued behind another thread at same priority |
|
871 |
if (ot) |
|
872 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
873 |
TBool dead = ot->iWaitState.ThreadIsDead(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
874 |
if (dead && ot->iLbLink.iNext) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
875 |
ot->LbUnlink(); |
0 | 876 |
ot->RelSLock(); |
877 |
||
878 |
// DFC to signal thread is now dead |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
879 |
if (dead && ot->iWaitState.iWtC.iKillDfc && __e32_atomic_tau_ord8(&ot->iACount, 1, 0xff, 0)==1) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
880 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
881 |
ot->RemoveFromEnumerateList(); |
0 | 882 |
ot->iWaitState.iWtC.iKillDfc->DoEnque(); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
883 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
884 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
885 |
if (iCCSyncPending) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
886 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
887 |
iCCSyncPending = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
888 |
iReschedIPIs |= 0x80000000u; // update iCCSyncCpus when kernel is finally unlocked |
0 | 889 |
} |
890 |
__KTRACE_OPT(KSCHED,DEBUGPRINT("Rschd->%T",t)); |
|
891 |
__NK_ASSERT_ALWAYS(!t || t->iParent); // must be a thread not a group |
|
892 |
return t; // could return NULL |
|
893 |
} |
|
894 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
895 |
void NSchedulable::LbUnlink() |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
896 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
897 |
if (iLbState & ELbState_PerCpu) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
898 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
899 |
TSubScheduler* ss = &TheSubSchedulers[iLbState & ELbState_CpuMask]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
900 |
ss->iReadyListLock.LockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
901 |
if (iLbState == ss->iLbCounter) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
902 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
903 |
iLbLink.Deque(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
904 |
iLbLink.iNext = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
905 |
iLbState = ELbState_Inactive; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
906 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
907 |
ss->iReadyListLock.UnlockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
908 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
909 |
else if ((iLbState & ELbState_CpuMask) == ELbState_Global) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
910 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
911 |
TScheduler& s = TheScheduler; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
912 |
s.iBalanceListLock.LockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
913 |
if (iLbState == s.iLbCounter) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
914 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
915 |
iLbLink.Deque(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
916 |
iLbLink.iNext = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
917 |
iLbState = ELbState_Inactive; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
918 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
919 |
s.iBalanceListLock.UnlockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
920 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
921 |
if (iLbState != ELbState_Inactive) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
922 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
923 |
// load balancer is running so we can't dequeue the thread |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
924 |
iLbState |= ELbState_ExtraRef; // indicates extra ref has been taken |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
925 |
__e32_atomic_tau_ord8(&iACount, 1, 1, 0); // extra ref will be removed by load balancer |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
926 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
927 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
928 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
929 |
TBool NSchedulable::TakeRef() |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
930 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
931 |
return __e32_atomic_tau_ord8(&iACount, 1, 1, 0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
932 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
933 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
934 |
TBool NSchedulable::DropRef() |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
935 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
936 |
if (__e32_atomic_tau_ord8(&iACount, 1, 0xff, 0)!=1) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
937 |
return EFalse; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
938 |
TDfc* d = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
939 |
AcqSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
940 |
if (iParent) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
941 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
942 |
// it's a thread |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
943 |
NThreadBase* t = (NThreadBase*)this; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
944 |
if (t->iWaitState.ThreadIsDead() && t->iWaitState.iWtC.iKillDfc) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
945 |
d = t->iWaitState.iWtC.iKillDfc; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
946 |
RelSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
947 |
t->RemoveFromEnumerateList(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
948 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
949 |
else |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
950 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
951 |
NThreadGroup* g = (NThreadGroup*)this; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
952 |
d = g->iDestructionDfc; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
953 |
RelSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
954 |
g->RemoveFromEnumerateList(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
955 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
956 |
if (d) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
957 |
d->DoEnque(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
958 |
return ETrue; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
959 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
960 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
961 |
void NSchedulable::RemoveFromEnumerateList() |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
962 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
963 |
TScheduler& s = TheScheduler; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
964 |
s.iEnumerateLock.LockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
965 |
if (iEnumerateLink.Next()) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
966 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
967 |
iEnumerateLink.Deque(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
968 |
iEnumerateLink.SetNext(0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
969 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
970 |
s.iEnumerateLock.UnlockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
971 |
} |
0 | 972 |
|
973 |
void NThreadBase::UnReadyT() |
|
974 |
{ |
|
975 |
if (iParent!=this) |
|
976 |
{ |
|
977 |
NThreadGroup& g = *(NThreadGroup*)iParent; |
|
978 |
TPriListBase& l = g.iNThreadList; |
|
979 |
l.Remove(this); |
|
980 |
if (g.iReady) |
|
981 |
{ |
|
982 |
TSubScheduler& ss = TheSubSchedulers[g.iReady & EReadyCpuMask]; |
|
983 |
if (l.IsEmpty()) |
|
984 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
985 |
ss.SSRemoveEntry(&g); |
0 | 986 |
g.iReady = 0; |
987 |
g.iPriority = 0; |
|
988 |
} |
|
989 |
else |
|
990 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
991 |
TInt np = l.HighestPriority(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
992 |
ss.SSChgEntryP(&g, np); |
0 | 993 |
} |
994 |
} |
|
995 |
} |
|
996 |
else |
|
997 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
998 |
TSubScheduler& ss = TheSubSchedulers[iReady & EReadyCpuMask]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
999 |
ss.SSRemoveEntry(this); |
0 | 1000 |
} |
1001 |
iReady = 0; |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1002 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1003 |
SubScheduler().iMadeUnReadyCounter++; |
0 | 1004 |
} |
1005 |
||
1006 |
||
1007 |
void NThreadBase::ChangeReadyThreadPriority() |
|
1008 |
{ |
|
1009 |
TInt newp = iMutexPri>iBasePri ? iMutexPri : iBasePri; |
|
1010 |
TInt oldp = iPriority; |
|
1011 |
TSubScheduler* ss0 = &SubScheduler(); |
|
1012 |
TSubScheduler* ss = 0; |
|
1013 |
if (iParent->iReady) |
|
1014 |
{ |
|
1015 |
ss = TheSubSchedulers + (iParent->iReady & EReadyCpuMask); |
|
1016 |
ss->iReadyListLock.LockOnly(); |
|
1017 |
} |
|
1018 |
TBool resched = FALSE; |
|
1019 |
NSchedulable* g = iParent; |
|
1020 |
if (g!=this) |
|
1021 |
{ |
|
1022 |
NThreadGroup* tg = (NThreadGroup*)g; |
|
1023 |
tg->iNThreadList.ChangePriority(this, newp); |
|
1024 |
if (ss) |
|
1025 |
{ |
|
1026 |
TInt ngp = tg->iNThreadList.HighestPriority(); |
|
1027 |
if (ngp!=tg->iPriority) |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1028 |
ss->SSChgEntryP(tg, ngp); |
0 | 1029 |
} |
1030 |
} |
|
1031 |
else |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1032 |
ss->SSChgEntryP(this, newp); |
0 | 1033 |
if (iCurrent) // can't be current if parent not ready |
1034 |
{ |
|
1035 |
TInt nhp = ss->HighestPriority(); |
|
1036 |
if (newp<oldp && (newp<nhp || (newp==nhp && iTime==0))) |
|
1037 |
resched = TRUE; |
|
1038 |
} |
|
1039 |
else if (ss) |
|
1040 |
{ |
|
1041 |
NThreadBase* ct = ss->iCurrentThread; |
|
1042 |
TInt cp = ct ? ct->iPriority : -1; |
|
1043 |
if (newp>cp || (newp==cp && ct->iTime==0)) |
|
1044 |
resched = TRUE; |
|
1045 |
} |
|
1046 |
if (resched) |
|
1047 |
{ |
|
1048 |
if (ss == ss0) |
|
1049 |
RescheduleNeeded(); |
|
1050 |
else |
|
1051 |
ss0->iReschedIPIs |= ss->iCpuMask; // will kick the other CPU when this CPU reenables preemption |
|
1052 |
} |
|
1053 |
if (ss) |
|
1054 |
ss->iReadyListLock.UnlockOnly(); |
|
1055 |
} |
|
1056 |
||
1057 |
||
1058 |
/** Changes the priority of a nanokernel thread. |
|
1059 |
||
1060 |
For use by RTOS personality layers. |
|
1061 |
Do not use this function directly on a Symbian OS thread. |
|
1062 |
||
1063 |
The thread's unknown state handler will be invoked with function EChangePriority |
|
1064 |
and parameter newp if the current NState is not recognised and the new priority |
|
1065 |
is not equal to the original priority. |
|
1066 |
||
1067 |
@param newp The new nanokernel priority (0 <= newp < KNumPriorities). |
|
1068 |
||
1069 |
@pre Kernel must be locked. |
|
1070 |
@pre Call in a thread context. |
|
1071 |
||
1072 |
@post Kernel is locked. |
|
1073 |
*/ |
|
1074 |
EXPORT_C void NThreadBase::SetPriority(TInt newp) |
|
1075 |
{ |
|
1076 |
CHECK_PRECONDITIONS(MASK_KERNEL_LOCKED|MASK_NOT_IDFC|MASK_NOT_ISR,"NThreadBase::SetPriority"); |
|
1077 |
AcqSLock(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1078 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%T nSetPri(%d) PBNM[%d,%d,%d,%d]",this,newp,iPriority,iBasePri,iNominalPri,iMutexPri)); |
0 | 1079 |
iBasePri = TUint8(newp); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1080 |
if (iMutexPri > newp) |
0 | 1081 |
newp = iMutexPri; |
1082 |
TInt oldp = iPriority; |
|
1083 |
if (newp == oldp) |
|
1084 |
{ |
|
1085 |
RelSLock(); |
|
1086 |
return; |
|
1087 |
} |
|
1088 |
NFastMutex* wfm = 0; |
|
1089 |
if (iLinkedObj && iLinkedObjType==EWaitFastMutex) |
|
1090 |
wfm = (NFastMutex*)iLinkedObj; |
|
1091 |
if (wfm) |
|
1092 |
{ |
|
1093 |
// if thread is attached to/waiting on a fast mutex, need to acquire mutex lock |
|
1094 |
++iPauseCount; |
|
1095 |
RelSLock(); |
|
1096 |
wfm->iMutexLock.LockOnly(); |
|
1097 |
AcqSLock(); |
|
1098 |
UnPauseT(); |
|
1099 |
wfm->iWaitQ.ChangePriority(&iWaitLink, newp); // change position of this thread on mutex wait queue |
|
1100 |
} |
|
1101 |
if (iReady) |
|
1102 |
{ |
|
1103 |
ChangeReadyThreadPriority(); |
|
1104 |
RelSLock(); |
|
1105 |
if (wfm && newp<=wfm->iWaitQ.HighestPriority()) |
|
1106 |
{ |
|
1107 |
// this thread was contending for the mutex but they may be other waiting threads |
|
1108 |
// with higher or equal priority, so wake up the first thread on the list. |
|
1109 |
NThreadBase* pT = _LOFF(wfm->iWaitQ.First(), NThreadBase, iWaitLink); |
|
1110 |
pT->AcqSLock(); |
|
1111 |
||
1112 |
// if thread is still blocked on this fast mutex, release it but leave it on the wait queue |
|
1113 |
// NOTE: it can't be suspended |
|
1114 |
pT->iWaitState.UnBlockT(NThreadBase::EWaitFastMutex, wfm, KErrNone); |
|
1115 |
pT->RelSLock(); |
|
1116 |
} |
|
1117 |
} |
|
1118 |
else |
|
1119 |
{ |
|
1120 |
iPriority = (TUint8)newp; |
|
1121 |
if (wfm && newp>oldp) |
|
1122 |
{ |
|
1123 |
NThreadBase* pT = _LOFF(wfm->iWaitQ.First(), NThreadBase, iWaitLink); // highest priority waiting thread |
|
1124 |
if (pT==this) |
|
1125 |
{ |
|
1126 |
// this is now highest priority waiting thread so wake it up |
|
1127 |
iWaitState.UnBlockT(NThreadBase::EWaitFastMutex, wfm, KErrNone); |
|
1128 |
} |
|
1129 |
} |
|
1130 |
RelSLock(); |
|
1131 |
} |
|
1132 |
if (wfm) |
|
1133 |
{ |
|
1134 |
NThreadBase* t = (NThreadBase*)(TLinAddr(wfm->iHoldingThread)&~3); |
|
1135 |
if (t) |
|
1136 |
t->SetMutexPriority(wfm); |
|
1137 |
wfm->iMutexLock.UnlockOnly(); |
|
1138 |
} |
|
1139 |
} |
|
1140 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1141 |
void NThreadBase::SetNominalPriority(TInt newp) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1142 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1143 |
CHECK_PRECONDITIONS(MASK_KERNEL_LOCKED|MASK_NOT_IDFC|MASK_NOT_ISR,"NThreadBase::SetNominalPriority"); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1144 |
AcqSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1145 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%T nSetNPr(%d) PBNM[%d,%d,%d,%d]",this,newp,iPriority,iBasePri,iNominalPri,iMutexPri)); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1146 |
iNominalPri = TUint8(newp); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1147 |
NominalPriorityChanged(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1148 |
RelSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1149 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1150 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1151 |
|
0 | 1152 |
|
1153 |
/** Set the inherited priority of a nanokernel thread. |
|
1154 |
||
1155 |
@pre Kernel must be locked. |
|
1156 |
@pre Call in a thread context. |
|
1157 |
@pre The thread holds a fast mutex |
|
1158 |
||
1159 |
@post Kernel is locked. |
|
1160 |
*/ |
|
1161 |
void NThreadBase::SetMutexPriority(NFastMutex* aM) |
|
1162 |
{ |
|
1163 |
TInt newp = aM->iWaitQ.HighestPriority(); |
|
1164 |
if (newp<0) |
|
1165 |
newp = 0; |
|
1166 |
AcqSLock(); |
|
1167 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%T nSetMPri %d->%d Base %d (mutex %08x)",this,iMutexPri,newp,iBasePri,aM)); |
|
1168 |
iMutexPri = TUint8(newp); |
|
1169 |
if (iMutexPri < iBasePri) |
|
1170 |
newp = iBasePri; |
|
1171 |
TInt oldp = iPriority; |
|
1172 |
if (newp == oldp) |
|
1173 |
{ |
|
1174 |
RelSLock(); |
|
1175 |
return; |
|
1176 |
} |
|
1177 |
if (iReady) |
|
1178 |
ChangeReadyThreadPriority(); |
|
1179 |
else |
|
1180 |
iPriority = (TUint8)newp; |
|
1181 |
RelSLock(); |
|
1182 |
} |
|
1183 |
||
1184 |
||
1185 |
void NThreadBase::LoseInheritedPriorityT() |
|
1186 |
{ |
|
1187 |
__KTRACE_OPT(KNKERN,DEBUGPRINT("%T nLoseInhPri %d->%d",this,iPriority,iBasePri)); |
|
1188 |
TSubScheduler* ss = &SubScheduler(); |
|
1189 |
TInt newp = iBasePri; |
|
1190 |
NSchedulable* g = iParent; |
|
1191 |
ss->iReadyListLock.LockOnly(); |
|
1192 |
if (g!=this) |
|
1193 |
{ |
|
1194 |
NThreadGroup* tg = (NThreadGroup*)g; |
|
1195 |
tg->iNThreadList.ChangePriority(this, newp); |
|
1196 |
TInt hp = tg->iNThreadList.HighestPriority(); |
|
1197 |
if (hp == tg->iPriority) |
|
1198 |
{ |
|
1199 |
if (newp <= hp) |
|
1200 |
RescheduleNeeded(); |
|
1201 |
goto out; |
|
1202 |
} |
|
1203 |
newp = hp; |
|
1204 |
g = tg; |
|
1205 |
} |
|
1206 |
if (newp <= ss->HighestPriority()) |
|
1207 |
RescheduleNeeded(); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1208 |
ss->SSChgEntryP(g, newp); |
0 | 1209 |
out: |
1210 |
ss->iReadyListLock.UnlockOnly(); |
|
1211 |
} |
|
1212 |
||
1213 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1214 |
/****************************************************************************** |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1215 |
* Pull threads on idle |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1216 |
******************************************************************************/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1217 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1218 |
const TInt KMaxTries = 4; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1219 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1220 |
struct SIdlePullThread |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1221 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1222 |
SIdlePullThread(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1223 |
void Finish(TBool aDone); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1224 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1225 |
NSchedulable* iS; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1226 |
TInt iPri; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1227 |
NSchedulable* iOld[KMaxCpus]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1228 |
}; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1229 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1230 |
SIdlePullThread::SIdlePullThread() |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1231 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1232 |
iS = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1233 |
iPri = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1234 |
TInt i; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1235 |
for (i=0; i<KMaxCpus; ++i) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1236 |
iOld[i] = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1237 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1238 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1239 |
void SIdlePullThread::Finish(TBool aComplete) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1240 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1241 |
if (aComplete && iS) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1242 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1243 |
iS->AcqSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1244 |
iS->SetCpuAffinityT(NKern::CurrentCpu() | KCpuAffinityTransient); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1245 |
iS->RelSLock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1246 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1247 |
if (iS) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1248 |
iS->DropRef(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1249 |
TInt i; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1250 |
for (i=0; i<KMaxCpus; ++i) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1251 |
if (iOld[i]) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1252 |
iOld[i]->DropRef(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1253 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1254 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1255 |
void TSubScheduler::IdlePullSearch(SIdlePullThread& a, TSubScheduler* aDest) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1256 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1257 |
NSchedulable* orig = a.iS; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1258 |
TInt dcpu = aDest->iCpuNum; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1259 |
volatile TUint32& flags = *(volatile TUint32*)&aDest->iRescheduleNeededFlag; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1260 |
iReadyListLock.LockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1261 |
if (iRdyThreadCount>1) // if there's only 1 it'll be running so leave it alone |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1262 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1263 |
TUint64 pres = iSSList.iPresent64; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1264 |
TInt tries = iRdyThreadCount; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1265 |
if (tries > KMaxTries) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1266 |
tries = KMaxTries; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1267 |
NSchedulable* q = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1268 |
NSchedulable* p = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1269 |
TInt pri = -1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1270 |
for (; tries>0 && !flags; --tries) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1271 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1272 |
if (p) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1273 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1274 |
p = (NSchedulable*)(p->iNext); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1275 |
if (p == q) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1276 |
pri = -1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1277 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1278 |
if (pri<0) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1279 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1280 |
pri = __e32_find_ms1_64(pres); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1281 |
if (pri < 0) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1282 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1283 |
pres &= ~(TUint64(1)<<pri); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1284 |
q = (NSchedulable*)iSSList.iQueue[pri]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1285 |
p = q; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1286 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1287 |
NThreadBase* t = 0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1288 |
if (p->iParent) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1289 |
t = (NThreadBase*)p; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1290 |
if (p->iCurrent) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1291 |
continue; // running on other CPU so leave it alone |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1292 |
if (p->iFreezeCpu) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1293 |
continue; // can't run on this CPU - frozen to current CPU |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1294 |
if (t && t->iCoreCycling) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1295 |
continue; // currently cycling through cores so leave alone |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1296 |
if (t && t->iHeldFastMutex && t->iLinkedObjType==NThreadBase::EWaitNone) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1297 |
continue; // can't run on this CPU - fast mutex held |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1298 |
if (p->iCpuChange) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1299 |
continue; // already being migrated so leave it alone |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1300 |
if (!CheckCpuAgainstAffinity(dcpu, p->iCpuAffinity)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1301 |
continue; // can't run on this CPU - hard affinity |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1302 |
if (p->iPreferredCpu & NSchedulable::EReadyCpuSticky) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1303 |
continue; // don't want to move it on idle, only on periodic balance |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1304 |
if (pri > a.iPri) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1305 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1306 |
if (p->TakeRef()) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1307 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1308 |
a.iS = p; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1309 |
a.iPri = pri; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1310 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1311 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1312 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1313 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1314 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1315 |
iReadyListLock.UnlockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1316 |
if (orig && orig!=a.iS) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1317 |
a.iOld[iCpuNum] = orig; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1318 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1319 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1320 |
void NKern::Idle() |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1321 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1322 |
TScheduler& s = TheScheduler; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1323 |
TSubScheduler& ss0 = SubScheduler(); // OK since idle thread locked to CPU |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1324 |
ss0.iCurrentThread->iSavedSP = 0; // will become nonzero if a reschedule occurs |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1325 |
TUint32 m0 = ss0.iCpuMask; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1326 |
volatile TUint32& flags = *(volatile TUint32*)&ss0.iRescheduleNeededFlag; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1327 |
if (s.iThreadAcceptCpus & m0) // if this CPU is shutting down, don't try to pull threads |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1328 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1329 |
SIdlePullThread ipt; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1330 |
NKern::Lock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1331 |
s.iIdleBalanceLock.LockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1332 |
TUint32 active = s.iThreadAcceptCpus; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1333 |
TUint32 srchm = active &~ m0; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1334 |
if (srchm && srchm!=active) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1335 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1336 |
TUint32 randomizer = *(volatile TUint32*)&s.iIdleBalanceLock; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1337 |
TInt nact = __e32_bit_count_32(srchm); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
while (srchm) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1339 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1340 |
TUint32 srchm2 = srchm; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1341 |
if (nact > 1) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1342 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1343 |
randomizer = 69069*randomizer+41; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1344 |
TUint32 lose = randomizer % TUint32(nact); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1345 |
for (; lose; --lose) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1346 |
srchm2 = srchm2 & (srchm2-1); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1347 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1348 |
TInt cpu = __e32_find_ls1_32(srchm2); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1349 |
TSubScheduler* ss = &TheSubSchedulers[cpu]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1350 |
ss->IdlePullSearch(ipt, &ss0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1351 |
if (flags) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1352 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1353 |
srchm &= ~(1u<<cpu); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1354 |
--nact; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1355 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1356 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1357 |
s.iIdleBalanceLock.UnlockOnly(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1358 |
ipt.Finish(!srchm); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1359 |
NKern::Unlock(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1360 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1361 |
DoIdle(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1362 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1363 |