Download presentation
Presentation is loading. Please wait.
Published byFranklin Jeremy Hensley Modified over 9 years ago
1
TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen
2
TIVDM2VDM-RT Scheduling22 Scheduling Controls the available resources CPUs BUSses Deployment of instances of classes to cpus Inter-cpu communication implicitly over busses Schedule resources Advances time in time slices Always determines minimum time slice to advance
3
TIVDM2VDM-RT Scheduling33 Resources There is only one master scheduler Master scheduler is able to advance wall time Resource Scheduler CPU Resource Scheduling Policy FCFS FP Threads BUS Resource Scheduling Policy..
4
TIVDM2VDM-RT Scheduling4 A Small Example 4 system S instance variables cpu1 : CPU := new CPU(, 1E9); cpu2 : CPU := new CPU(, 1E9); static public a : A := new A(); static public b : B := new B(); operations public S: () ==> S S() == (cpu1.deploy(a); cpu2.deploy(b)) end S class Test operations public Run:() ==> nat * nat Run() == (start(S`a); start(S`b); return mk_(S`a.GetA(), S`b.GetB())) end Test class A instance variables a: nat := 0 operations public IncA: () ==> () IncA() == duration(6) a := a + 1; public GetA: () ==> nat GetA() == duration (10) (return a); sync per GetA => #fin(IncA) >= 1; mutex(IncA,GetA); thread for i = 1 to 3 do IncA() end A
5
TIVDM2VDM-RT Scheduling5 Architecture 5 BUS Resources CPU1 Policy Threads A CPU2 Policy Threads B vCPU Policy Threads …
6
TIVDM2VDM-RT Scheduling6 TIVDM2 VDM-RT Scheduling6 Thread life cycle 6 CREATED RUNABLE RUNNINGTIMESTEP RUNABLE Commit values from last run RUNNINGCOMPLETED Swap in/out Thread Policy controls Swap Swap out, kill
7
TIVDM2VDM-RT Scheduling7 Schedule resource 7 Resource Scheduler CPU1 Policy Threads A CPU2 Policy Threads B vCPU Policy Threads … 1.Reschedule resource 2.Get thread through policy 3.Thread run time slice 1.RUNNING 2.If duration TIMESTEP 3.Else RUNABLE Reschedule
8
TIVDM2VDM-RT Scheduling8 Cpu2 Time step size decided per thread in RUNNING stage Resource Scheduler uses smallest time step calculated over all resources. Cpu1 Time step size Thread 1 duration(2) … Thread 2 duration(6) … Min time step = 2
9
TIVDM2VDM-RT Scheduling9 Thread schedule on different cpus Scheduler A i = 0 RUNABLE A i = 0 RUNNING A i = 0 TIMESTEP(6) A i = 0 TIMESTEP(4) A i = 0 TIMESTEP(2) A i = 0 -> i = 1 Committing last transaction RUNNING … B i = 0 RUNABLE B i = 0 RUNNING B i = 0 TIMESTEP(2) B i = 0 -> i = 1 Committing last transaction RUNNING B i = 1 TIMESTEP(2) B i = 0 -> i = 2 Committing last transaction RUNNING B i = 2 TIMESTEP(2) B i = 0 -> i = 3 Committing last transaction RUNNING B i = 3 COMPLETED Reschedule Time Step = 0 Reschedule Advance wall time. Time Step = min(2 ; 6) = 2 Reschedule Advance wall time. Time Step = min(2 ; 4) = 2 Reschedule Advance wall time. Time Step = min(2 ; 2) = 2 … CPU1 CPU2
10
TIVDM2VDM-RT Scheduling10 Thread schedule on the same cpu Scheduler A i = 0 RUNABLE A i = 0 RUNNING A i = 0 TIMESTEP(6) A i = 0 -> i = 1 Committing last transaction RUNNING … B i = 0 RUNABLE B i = 1 RUNNING B i = 1 TIMESTEP(2) B i = 1 -> i = 2 Committing last transaction RUNNING B i = 2 TIMESTEP(2) B i = 2-> i = 3 Committing last transaction RUNNING B i = 3 TIMESTEP(2) B i = 3 -> i = 4 Committing last transaction RUNNING B i = 4 COMPLETED Reschedule Time Step = 0 Compute thread in A Advance wall time. Swap time Advance wall time. Time Step = 6 Reschedule … Swap in thread A Swap out thread A Advance wall time. Swap time Swap in thread B Advance wall time. Swap time Compute thread in B Advance wall time. Time Step = 8 Compute thread in B Advance wall time. Time Step = 10 Compute thread in B Advance wall time. Time Step = 12 Both on CPU1
11
TIVDM2VDM-RT Scheduling11 When the debug thread completes the execution is terminated. If all resources (CPUs and BUSes) are idle the model has deadlocked. Scheduling Resources 11
12
TIVDM2VDM-RT Scheduling12 Reschedule of a CPU VDM-RT Log ThreadCreate ThreadSwapIn DelayedThreadSwapIn ThreadSwapOut ThreadKill… Request Activation Completion Of ops + messages Reschedule CPUResource 12 if (policy.reschedule()){ SchedulableThread best = policy.getThread(); if (running != best) // We swapped { If (running != null) RTLogger.log("ThreadSwapOut...); if (delayed) RTLogger.log("DelayedThreadSwapIn...); else RTLogger.log("ThreadSwapIn...); } running = best; running.runslice(policy.getTimeslice()); if (running.getRunState() == RunState.COMPLETE) { RTLogger.log("ThreadSwapOut...); RTLogger.log("ThreadKill...); running = null; } …
13
TIVDM2VDM-RT Scheduling13 Threads One virtual thread (the debug thread) exists where duration is skipped. All threads are implemented on top of Java threads The abstract body will handle the actual execution of the thread. 13 @Override public void run() { reschedule(); body(); setState(COMPLETE); resource.unregister(this); synchronized (allThreads) { allThreads.remove(this); } abstract protected void body();
14
TIVDM2VDM-RT Scheduling14 When executing a computation step is taken before a time penalty is taken All Expressions and Statements have a default duration Can be overruled by cycle- and duration- statements Computation Step 14 public void step() { if (dialect is VDM_RT) { if (!virtual) // vCPUs don't take any time duration(Properties.rt_duration_default); } else SystemClock.advance(Properties.rt_duration_default); if (++steps >= timeslice) { reschedule(); steps = 0; }
15
TIVDM2VDM-RT Scheduling15 Async Operation Calls becomes Threads Async operation calls on a different CPU goes over a BUS Threads gets the parameter values through a message queue. Gets parameter values as MessageRequest from BUS Normal operation returns results as MessageResponse in the same BUS 15
16
TIVDM2VDM-RT Scheduling16 BUS Operation calls through a BUS MessageRequest – ready to communicate MessaggeActivate – Send the parameter values MessageFinish – Take size of message into account in time penalty MessageResponse – get the result Data holder + ControlQueue ControlQueue A queue where threads can wait to get access Block calls the waiting method of SchedulableThread –Get cannot complete before a reschedule When guard potentially changes all threads are notified to recheck their blocked guards are now satisfied. 16
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.