tivdm2vdm-rt scheduling1 vdm-rt scheduling in overture kenneth lausdahl and peter gorm larsen

16
TIVDM2 VDM-RT Scheduling 1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

Upload: franklin-jeremy-hensley

Post on 17-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 1

VDM-RT Scheduling in Overture

Kenneth Lausdahl and Peter Gorm Larsen

Page 2: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 22

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

Page 3: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 33

Resources

• There is only one master scheduler• Master scheduler is able to advance wall time

Page 4: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 4

A Small Example

4

system S

instance variables

cpu1 : CPU := new CPU(<FCFS>, 1E9);cpu2 : CPU := new CPU(<FCFS>, 1E9);static public a : A := new A();static public b : B := new B();

operations

public S: () ==> SS() == (cpu1.deploy(a); cpu2.deploy(b)) end S class Test

operations

public Run:() ==> nat * natRun() == (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: () ==> natGetA() == duration (10) (return a); sync

per GetA => #fin(IncA) >= 1;mutex(IncA,GetA);

thread

for i = 1 to 3 do IncA()

end A

Page 5: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 5

Architecture

5

Resources

CPU1

Threads

A

CPU2

Threads

B

vCPU Threads…

Page 6: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 6TIVDM2 VDM-RT Scheduling 6

Thread life cycle

6

CREATEDRUNABLE

RUNNING

TIMESTEPRUNABLE•Commit values from last run

RUNNING

COMPLETED

Swap in/outSwap in/out

Swap in/outSwap in/out

Thread Policy controls SwapThread Policy controls SwapSwap out, killSwap

out, kill

Page 7: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 7

Schedule resource

7

CPU1

Threads

A

CPU2

Threads

B

vCPU Threads…

1. Reschedule resource2. Get thread through

policy3. Thread run time slice

1. RUNNING2. If duration

TIMESTEP3. Else

RUNABLE

Reschedule

Reschedule

Page 8: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 8

Cpu2

• Time step size decided per thread in RUNNING stage• Resource Scheduler uses smallest time step

calculated over all resources.

Cpu1

Time step size

Page 9: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 9

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• COMPLETE

D

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

Page 10: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 10

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• COMPLETE

D

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

Page 11: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 11

• When the debug thread completes the execution is terminated.

• If all resources (CPUs and BUSes) are idle the model has deadlocked.

Scheduling Resources

11

Page 12: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 12

• 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...);

elseRTLogger.log("ThreadSwapIn...);

}running = best;running.runslice(policy.getTimeslice());

if (running.getRunState() == RunState.COMPLETE){

RTLogger.log("ThreadSwapOut...);RTLogger.log("ThreadKill...);running = null;

}…

Page 13: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 13

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

@Overridepublic void run(){

reschedule();body();setState(COMPLETE);resource.unregister(this);synchronized (allThreads){

allThreads.remove(this);}

}abstract protected void body();

Page 14: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 14

• 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 timeduration(Properties.rt_duration_default);

}else

SystemClock.advance(Properties.rt_duration_default);

if (++steps >= timeslice){

reschedule();steps = 0;

}}

Page 15: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 15

Async Operation Calls becomesThreads

• 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

Page 16: TIVDM2VDM-RT Scheduling1 VDM-RT Scheduling in Overture Kenneth Lausdahl and Peter Gorm Larsen

TIVDM2 VDM-RT Scheduling 16

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