First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\nkernsmp\x86\ncsched.cpp
18 // NThreadBase member data
19 #define __INCLUDE_NTHREADBASE_DEFINES__
25 // Called by a thread which has been forced to exit
26 // Kernel locked on entry
27 extern "C" void __fastcall do_forced_exit(NThreadBase* aT)
29 __NK_ASSERT_ALWAYS(aT->iFastMutexDefer != 1);
30 aT->iFastMutexDefer = 0;
34 extern "C" NThreadBase* __fastcall select_next_thread(TSubScheduler* aS)
36 return aS->SelectNextThread();
39 extern "C" void __fastcall queue_dfcs(TSubScheduler* aS)
44 extern "C" void NewThreadTrace(NThread* a)
46 __ACQUIRE_BTRACE_LOCK();
47 BTraceData.iHandler(BTRACE_HEADER_C(4,BTrace::ECpuUsage,BTrace::ENewThreadContext),0,(TUint32)a,0,0,0,0,0);
48 __RELEASE_BTRACE_LOCK();
51 extern "C" void __fastcall send_ipi(TUint32);
52 extern "C" void __fastcall do_send_resched_ipis(TUint32);
54 extern "C" void send_resched_ipi(TInt aCpu)
56 TSubScheduler& ss = TheSubSchedulers[aCpu];
57 __KTRACE_OPT(KSCHED2,DEBUGPRINT("@%d",aCpu));
58 send_ipi((TUint32)ss.i_APICID);
61 extern "C" void send_resched_ipis(TUint32 aMask)
63 __KTRACE_OPT(KSCHED2,DEBUGPRINT("@%02x",aMask));
64 #ifdef __USE_LOGICAL_DEST_MODE__
65 do_send_resched_ipis(aMask);
78 extern "C" void send_resched_ipi_and_wait(TInt aCpu)
80 TSubScheduler& ss = TheSubSchedulers[aCpu];
81 __KTRACE_OPT(KSCHED2,DEBUGPRINT("@@%d",aCpu));
82 volatile TUint32& irqc = (volatile TUint32&)ss.i_IrqCount;
83 volatile TInt& irqn = (volatile TInt&)ss.i_IrqNestCount;
86 send_ipi((TUint32)ss.i_APICID);
88 while (!ss.iRescheduleNeededFlag || (irqn<0 && irqc==irqc0))
92 mb(); // guaranteed to observe final thread state after this
95 void TSubScheduler::SaveTimesliceTimer(NThreadBase* aT)
97 if (aT->iTime>0 && !aT->i_NThread_Initial)
99 TUint32 remain32 = read_apic_reg(CURRCNT);
101 x *= TUint32(i_TimerMultI);
106 write_apic_reg(INITCNT, 0);
110 /* Update aOld's execution time and set up the timer for aNew
111 Update this CPU's timestamp value
113 if (!aOld) aOld=iInitialThread
114 if (!aNew) aNew=iInitialThread
115 if new thread has a timeslice, start the timeslice timer
116 update the last reschedule time
117 update the run time for the old thread
118 update the reschedule count for the new thread and the current CPU
120 void TSubScheduler::UpdateThreadTimes(NThreadBase* aOld, NThreadBase* aNew)
123 aOld = iInitialThread;
125 aNew = iInitialThread;
128 TUint32 remain32 = (TUint32)aNew->iTime;
130 x *= TUint32(i_TimerMultF);
133 write_apic_reg(LVTTMR, TIMESLICE_VECTOR);
134 write_apic_reg(INITCNT, (TUint32)x);
138 TUint64 now = NKern::Timestamp();
139 aOld->iTotalCpuTime64 += (now - iLastTimestamp64);
140 iLastTimestamp64 = now;