38
06/15/22 COSC-4301-01, Lecture 5 1 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

Embed Size (px)

Citation preview

Page 1: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 1

Real-Time Systems, COSC-4301-01, Lecture 5

Stefan Andrei

Page 2: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 2

Reminder of the last lecture

Multiprocessor Scheduling Available scheduling tools Available real-time operating systems

Page 3: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 3

Overview of This Lecture

A Satisfiability Approach for the Scheduling Problem

Page 4: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 4

Introduction Most of the existing scheduling problems are

NP-hard. Researchers have been putting many efforts in

finding good heuristics for solving scheduling problem in polynomial time.

However, there still exist classes of task sets that are feasible and most traditional schedulers (e.g. RM, EDF, LL) fail to solve the scheduling problem.

Existing SAT encodings could not be adopted for the given scheduling problem.

Page 5: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 5

The main idea We present a new satisfiability (SAT) based

approach to the scheduling problem. We transform time constraints into a

satisfiability problem. The obtained clauses are converted to the

DIMACS format and passed as input to a SAT solver, such as Zchaff.

We conclude that our satisfiability-based approach is a promising technique for scheduling.

Page 6: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 6

Related work At first glance it seems to be an obvious

translation of scheduling problems into SAT: Create variables to represent the start times of the

operations and create clauses to represent the necessary inequalities.

However the search space in SAT problems so generated turns out to be much larger than necessary.

Previous SAT encodings approaches like those expressed in [Memik, Fallah; 2002] and [Crawford, Baker; 1994] could not be applied either because they do not consider the exact time relations [Crawford, Baker; 1994] or they are too large [Memik, Fallah; 2002].

Page 7: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 7

References

[Memik, Fallah; 2002] S.O.Memik, F.Fallah: “Accelerated SAT-based scheduling of control/data flow graphs”, Computer Design: VLSI in Computers and processors, 2002. Proceedings, 2002

[Crawford, Baker; 1994] J.M.Crawford, A.B.Baker: Experimental Results on the Application of Satisfiability Algorithms to Scheduling Problems, The 12th National Conference on Artificial Intelligence, 1994.

Page 8: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 8

Scheduling A task T is characterized by the following

parameters: S: start (also called release, ready, or arrival)

time. c: (maximum) computation time. d: relative deadline (deadline relative to the task's

start time) p: period (how often the tasks are supposed to be

executed) D: absolute deadline (wall clock time deadline)

e.g., D = S + d.

Page 9: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 9

The propositional satisfiability problem The SAT problem:

“Given a set of clauses C (disjunction of literals – also known as CNF: Conjunctive Normal Form) on a finite set U of variables, find a truth assignment for U that satisfies all the clauses in C”.

The SAT problem is solved by the SAT solvers.

Example: Given U = {A, B, C} the set of variables and F = (A B C) ( C) ( C a propositional formula, then a truth assignment for F is A = false, B = false, C = false.

Page 10: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 10

Encoding Scheduling problems as SAT problems

For each operation i executing between time t and t+1 there exists a boolean variable ei,t.

We have considered this encoding for solving many types of problems which are elaborated as follows, such as: Scheduling unit computation tasks in uniprocessor

environment Scheduling preemptive non-unit tasks for uniprocessor

environment Scheduling non-preemptive tasks in uniprocessor

environment

Page 11: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 11

Scheduling unit computation tasks in uniprocessor environment Consider T={T1, .., Tn} a task set with Ti = (Si, ci, di, pi). For simplicity, we assume pi=di. If task Ti can execute one time unit between times t, t+1, …,

t+ci, then the corresponding SAT clause is ei,t V ei,t+1 V... V ei,t+ci-2 V ei,t+ci-1.

Given tasks Ti and Tj for time between t and t+1, only either Ti or Tj is executing between t and t+1.

Hence, there exists a clause ei,t V ej,t (this is equivalent to: ei,t ej,t and ej,t ei,t).

The SAT encoding has to be done from 0 to LCM(p1, p2, …, pn).

Page 12: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

Scheduling unit computation tasks in uniprocessor environment. Example T1: s1 = 0, c1 = 1, d1 = p1 = 2

T2: s2 = 0, c2 = 1, d2 = p2 = 3 The SAT encoding has to be done by

LCM(d1, d2), that is, 6: e1,0 V e1,1

e1,2 V e1,3

e1,4 V e1,5

e2,0 V e2,1 V e2,2

e2,3 V e2,4 V e2,5

04/21/23 COSC-4301-01, Lecture 5 12

e1,0 V e2,0

e1,1 V e2,1

e1,2 V e2,2

e1,3 V e2,3

e1,4 V e2,4

e1,5 V e2,5

Page 13: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 13

Scheduling preemptive non-unit tasks for uniprocessor environment Solution:

Divide each non unit-time task into tasks with unit computation time, then apply the previous SAT encoding.

The starting time and deadline for the subsequent tasks are incremented.

Precedence constraints are introduces between the sub-tasks created.

Consider sub-task j with less precedence than sub-task i then at any time t, sub-task i will not occur after sub-task j is executing, that is, ej,t Vei,z where z > t.

Page 14: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

Scheduling preemptive non-unit tasks for uniprocessor environment. Example T1: s1 = 0, c1 = 2, d1 = p1 = 4

T2: s2 = 0, c2 = 2, d2 = p2 = 4 The task set is converted to unit computation

time: T1=T1,1: s1,1 = 0, c1,1 = 1, d1,1 = 3, p1,1 = 4

T2=T1,2: s1,2 = 1, c1,2 = 1, d1,2 = 4, p1,2 = 4

T3=T2,1: s2,1 = 0, c2,1 = 1, d2,1 = 3, p2,1 = 4

T4=T2,2: s2,2 = 1, c2,2 = 1, d2,2 = 4, p2,2 = 4

The precedence constraints: T1 T2, T3 T4

04/21/23 COSC-4301-01, Lecture 5 14

Page 15: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

Scheduling preemptive non-unit tasks for uniprocessor environment. Example e1,0 V e1,1 V e1,2

e2,1 V e2,2 V e2,3

e3,0 V e3,1 V e3,2

e4,1 V e4,2 V e4,3

e1,0 V e3,0

e1,1 V e2,1

e1,1 V e3,1

04/21/23 COSC-4301-01, Lecture 5 15

e1,1 V e4,1

e1,2 V e2,2

e1,2 V e3,2

e1,2 V e4,2

d1 = 3 e1,3

s2 = 1 e2,0

d3 = 3 e3,3

s4 = 1 e4,0

Page 16: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 16

The precedence constraints: e2,1 V e1,2

e4,1 V e3,2

Page 17: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 17

Scheduling non-preemptive tasks in uniprocessor environment A non-preemptable task is the one that once started

cannot be stopped by any other process or task. In practice tasks may contain critical sections that

cannot be interrupted. These critical sections are needed to access and

modify shared variables or use shared resources. The non-preemptable condition can be obtained by

grouping together executing constraints from starting time to deadline with size equal to that of computation time.

Page 18: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 18

Scheduling with non-preemption for uniprocessor environment - cont So, a non-preemptable task i is allowed to

execute for a computation time c starting at time t until deadline d.

Since a non-preemptive task T=(s, c, d, p) cannot not be interrupted, the conversion to the SAT problem should contain all possible solutions for task T to be scheduled in the intervals [s, c], [s + 1,c + 1], ..., [d - c, d].

Page 19: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 19

Example with two non-preemptive tasks T1: s1 = 0, c1 = 2, d1 = 4

T2: s2 = 0, c2 = 2, d2 = 4 The SAT encoding is:

T1: (e1,0 Λ e1,1 Λ e1,2 Λ e1,3) V

(e1,0 Λ e1,1 Λ e1,2 Λ e1,3) V

(e1,0 Λ e1,1 Λ e1,2 Λ e1,3)

T2: (e2,0 Λ e2,1 Λ e2,2 Λ e2,3) V

(e1,0 Λ e2,1 Λ e1,2 Λ e2,3) V

(e1,0 Λ e1,1 Λ e1,2 Λ e1,3)

Page 20: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 20

Example with two non-preemptive tasks The following are the clauses corresponding

to the fact that the processor is busy with at most one task at a given time: e1,0 V e2,0

e1,1 V e2,1

e1,2 V e2,2

e1,3 V e2,3

Problem: the sub-formula from previous slide is not expressed in CNF, but in DNF (Disjunctive Normal Form).

Page 21: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 21

DNF to CNF conversion

Some the above clauses are in Disjunctive Normal Form (DNF).

They have to be converted into Conjunctive Normal Form (CNF).

Once the whole formula is expressed in CNF, it has to be converted into DIMACS format as an input for SAT solvers.

Page 22: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

DNF to CNF conversion. Example New variables are introduced for each clause. Example: F = (A1 A2 A3 A4) (A5 A6 A7

A8) is converted to the following CNF formula (X1 and X2 are new propositional variables): (X1 A1) (X1 A2) (X1 A3) (X1 A4) (A1

A2 A3 A4 X1)

(X2 A5) (X2 A6) (X2 A7) (X2 A8) (A5 A6 A7 A8 X2)

X1 X2

04/21/23 COSC-4301-01, Lecture 5 22

Page 23: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

Complexity of this translation The traditional approach for converting a

general DNF formula needs an exponential space and time complexity: (A1,1 A1,2 … A1,n1) … (Ak,1 Ak,2 … Ak,nk)

leads to a propositional formula with n1 * … * nk CNF clauses.

The approach from previous slide needs only n1 + … + nk + k + 1 CNF clauses and k new propositional clauses.

04/21/23 COSC-4301-01, Lecture 5 23

Page 24: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

DNF to CNF conversion. Example Coming back to the example from slide 18:

T1: (e1,0 Λ e1,1 Λ e1,2 Λ e1,3) V

(e1,0 Λ e1,1 Λ e1,2 Λ e1,3) V

(e1,0 Λ e1,1 Λ e1,2 Λ e1,3)

we get the following CNF formula: (X1 e1,0) (X1 e1,1) (X1 e1,2) (X1 e1,3) (e1,0 e1,1

e1,2 e1,3 X1)

(X1 e1,0) (X1 e1,1) (X1 e1,2) (X1 e1,3) (e1,0 e1,1 e1,2 e1,3 X1)

(X1 e1,0) (X1 e1,1) (X1 e1,2) (X1 e1,3) (e1,0 e1,1 e1,2 e1,3 X1)

X1 X2 X3

04/21/23 COSC-4301-01, Lecture 5 24

Page 25: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 25

Some state-of-the-art SAT solvers Siege - http://www.cs.sfu.ca/research/groups/CL/software/siege/ zChaff - http://www.princeton.edu/~chaff/software.html Cachet - http://www.cs.rochester.edu/u/kautz/Cachet/index.htm SharpSAT -

http://www2.informatik.hu-berlin.de/~thurley/sharpSAT/index.html

Others: http://www.satlive.org/bytype.jsp?reftypefrom=-2 If the answer provided by this SAT solver or #SAT

solver is ‘Unsatisfiable’, then the corresponding propositional formula is unsatisfiable.

Page 26: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 26

The zChaff SAT Solver It is a state-of-the-art SAT solver designed for

robustness and efficiency. It features a highly optimized deduction engine. zChaff is designed with performance and capacity in

mind. zChaff has been tested on Solaris/Linux/Cygwin

machines with g++ as the compiler. It can also be compiled with Visual Studio Net under

Windows. zChaff can be compiled into a linkable library for

integration purpose so that the users do not need to export instance into intermediate files to use zChaff.

Page 27: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 27

DIMACS CNF Format In the format the number of variables and the number of

clauses is defined by the line “p cnf VARIABLES CLAUSES”.

The variables are assumed to be numbered from 1 up to VARIABLES.

It is not necessary that every variable appears in an instance.

Each clause will be represented by a sequence of integers, which are separated by a space, a tab, or a new line character.

The non-negated version of the variable i is represented by i; the negated version is represented by -i.

Each clause is terminated by a value 0.

Page 28: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 28

Example

The boolean formula F = (v1 V v3) Λ (v1 V v2 V v3) has the following DIMACS format:

p cnf 3 2

1 -3 0

2 3 -1 0

Page 29: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 29

Tool Description The input of our tool is the number of tasks which are

to be scheduled. For each of the tasks it asks for its starting time,

computation time and deadline. It develops various clauses using the SAT encoding

described in above part. Based on the encoding it passes the DIMACS CNF

format file to zChaff SAT Solver which gives whether it is either SAT solvable or not.

The output of zChaff also gives the variables which are true, using this variables we can schedule the tasks.

Page 30: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 30

Running the Code

Compile the zChaff code obtained from the Internet using the make command in C++ compiler and keep it inside a folder zchaff.

Inside the zchaff folder create a folder called Translate.

Add all the Java source code in this folder. Compile the java source code using javac

*.java in J2SE. Then run the Main class file from zchaff folder

using java Translate/Main

Page 31: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 31

Experimental Results

Page 32: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 32

The experimental results - comments The number of tasks in the original column are

converted into unit computation time tasks and thus increasing the number of tasks in the for preemption column.

The increase in the number of tasks increases the size of SAT and thus affects the performance of the SAT solver.

It can be seen from the above results that the performance is faster if there are fewer tasks.

Page 33: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 33

Conclusion We have explored the potential of satisfiability to be used

as a tool for modeling and solving scheduling problems. We have also researched on the earlier work and proven

that we need to consider computation time so as to make it suitable for real time systems.

We have presented experimental results on the performance of SAT solver zChaff.

The performance of the SAT decreases as the number of tasks increases.

We have demonstrated that a SAT solver presents a competitive alternative as a tool to find optimal solutions to the NP-complete time constrained scheduling problem.

Page 34: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 34

Future work We would like to consider the other categories of

tasks set constraints. Also adding resourses constraints would make the

system more suitable for real time systems. Minimize the number of preemptions (selects the

solution provided by the SAT solver that has the minimum number of preemptions).

Assuming there are new tasks added to the initial specification, design an incremental conversion to SAT without repeating the time spend for the initial tasks set).

Page 35: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 35

Summary

A Satisfiability Approach for the Scheduling Problem

Page 36: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 36

Reading suggestions Research papers

Ştefan Andrei: Schedulability Analysis

Page 37: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 37

Coming up next

An Efficient Power-Aware Scheduling Algorithm for the Multiprocessor Platform

Page 38: 10/9/2015COSC-4301-01, Lecture 51 Real-Time Systems, COSC-4301-01, Lecture 5 Stefan Andrei

04/21/23 COSC-4301-01, Lecture 5 38

Thank you for your attention!

Questions?