here - Computer Engineering Department

advertisement
EASTERN MEDITERRANEAN UNIVERSITY
DEPARTMENT OF COMPUTER ENGINEERING
CMPE 443
Real-Time Systems Design
Quiz 2
2012/13 Spring Semester
January 4, 2013
Name-Surname : ___________________
Student Number : ___________________
Instructor:
Assoc. Prof. Dr. Alexander CHEFRANOV
Time: 100 minutes
MOBILES ARE NOT ALLOWED
YOU CAN BRING ONE A4 SIZED SHEET OF HAND-WRITTEN NOTES TO THE
EXAM. PHOTOCOPIES ARE NOT ALLOWED AND WILL BE COLLECTED.
READ THE INSTRUCTIONS FOR EACH SECTION CAREFULLY.
Grade
1
Task 1. (15 points) Build a Rate-Monotonic schedule for tasks:
Task# E
P
1
1
12
2
3
8
3
1
3
What are the utilization and hyperperiod for this set of tasks? Are the deadlines
met by the RM schedule? Explain why they are met (not met)?
U=1/12+3/8+1/3=(2+9+8)/24=19/24, H=24
Time 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
Task 3 2 2 3 2 1 3 2 2 3 2
3 1
3 2 2 3 2
3
The task releases, deadlines, and completion times are as follows
Task
Release Deadline Completion
time
time
3
0
3
1
3
6
4
6
9
7
9
12
10
12
15
13
15
18
16
18
21
19
21
24
22
2
0
8
5
8
16
11
16
24
10
1
0
12
6
12
24
14
We see that all completion times do not exceed respective deadlines, hence all deadlines
are met in the RM schedule above
Task 2. (15 points) Build an Earliest-Deadline-First schedule for the set of tasks:
Task# E
P
1
1
8
2
3
6
3
1
3
Are the deadlines met by the EDF schedule? Explain why they are met (not met)?
U=1/8+3/6+1/3=(3+12+8)=23/24, H=24
Time 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
Task 3 2 2 2 3 1 3 2 2 2 3 1 3 2 2 2 3 1 3 2 2 2 3
The task releases, deadlines, and completion times are as follows
Task
Release Deadline Completion
time
time
3
0
3
1
3
6
5
6
9
7
2
9
12
11
12
15
13
15
18
17
18
21
19
21
24
23
2
0
6
4
6
12
10
12
18
16
18
24
22
1
0
8
6
8
16
12
16
24
18
We see that all completion times do not exceed respective deadlines, hence all deadlines
are met in the EDF schedule above
3
Task 3. (20 points) Assume, two parallel processes, A and B, run concurrently. Process
A gets a portion of information from an external device, processes it, and places result in
the buffer BUF for B. Process B, on placing results in BUF by A, takes them, processes,
and displays results of its processing. Processes, A, and B, mutually exclude each other
when accessing the buffer. Writing into a buffer is allowed if there is an empty slot; a slot
is emptied only after the process B has read it. Reading from the buffer is allowed, if
there is information in it for a reading process. If conditions for reading/writing are not
met, the processes shall sleep. The suspended processes shall be awakened when the
event they are waiting for (buffer is not empty for a reader, and has free slots for a
writer), happens. Write a pseudo-code using binary semaphores to provide necessary
synchronization of the processes A, and B. Define necessary data structures assuming the
buffer has one slot. Show initial settings of the semaphores you use.
Sema mutex=1 /*open*/, suspend=0/*closed*/
Int slots=N, freeslots=N;//total number of slots initially all are empty
Int suspended=0;//number of suspended processes is 0 initially
Process A{
While(1){
Read(dev, info);//read info from external device
Proc(info);// process info
1: P(mutex);//enter critical section
If (free_slots>0){
Write(buffer, info); free_slots--;//write in buffer, decrement free slots counter
If(suspended>0){
suspended--;V(suspend);
}
V(mutex);//release mutex
}
Else{
suspended++; V(mutex); P(suspend); //increment suspended, release mutex and
//suspend itself
goto 1;
}
}//while
}//end A
Process B{
While(1){
P(mutex);
Read(dev, info);//read info from external device
Proc(info);// process info
P(mutex);//enter critical section
If (free_slots<N){
Read(buffer, info); free_slots++;//read from buffer, increment free slots counter
If(suspended>0){
suspended--;V(suspend);
}
4
V(mutex);//release mutex
}
Else{
suspended++; V(mutex); P(suspend);//increment suspended, release mutex and
//suspend itself
}
}//while
}//end B
Task 4. (15 points) Assume that a system has 5 processes and resources of one type:
memory (total available number is 10). Processes’ resources granted and required are as
follows:
Process
Memory granted
Memory required
1
1
4
2
3
7
3
1
2
4
2
5
5
2
5
Draw a resource graph for the processes. Use the process reduction procedure to decide
on the existence of deadlocks in this resource state. Show all the steps of the procedure
you make to come to your
decision.
P1
P2
4
P3
3 7 1
1
P4
2
2
5
P5
2
5
10
Memory available is m=10-(1+3+1+2+2)=1.
P1 needs 4 memory units and m=1 is available, hence it can’t be satisfied
P2 needs 7 memory units and m=1 is available, hence it can’t be satisfied
P3 needs 2 memory units and m=1 is available, hence it can’t be satisfied
P4 needs 5 memory units and m=1 is available, hence it can’t be satisfied
P5 needs 5 memory units and m=1 is available, hence it can’t be satisfied
No one edge can be reduced, hence, the system in the deadlock
5
Task 5. (15 points) Assume, we have a priority preemptive system (without time sharing
for same priority tasks) and the following system of processes:
Process
Priority
Execution
Release time
sequence
A
3
VVQEVVE
2
B
4 (highest)
EQVEQQ
1
C
1 (lowest)
QQVQ
0
D
2
EEVQQE
1
Show time diagrams of execution for each process, if Original Ceiling Priority Protocol is
used. Calculate response time for each process A, B, C, D. Specify dynamic priority for
each task and each time unit when it runs.
6
D
C
B
A
Q
P
B
P
P
P
P
P
P
P
P
P
P
P
P
E
E
V
Q
Q
E
P
Q
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
P
E
B
Q
V
E
Q
Q
B
P
P
P
P
P
V
V
Q
E
V
V
E
V
Q
`
Response time for task A is 13 time units, for task B is 7, for task C is 23, for task D is 20
Dynamic priority of Task C during time unit 3 is 4 as it blocks this time task B of priority 4. All the rest time dynamic priority of each
task is equal to the static priority.
7
Task 6. (20 points) Build a Finite State Automaton modeling a microwave oven. After
pressing the button Micro, it waits for setting Timer using buttons “1 sec”, “10 sec”.
After pressing “Start”, it starts operating if the door is closed with light switched on until
Timer expires. When Timer expires, light is switched off and operating stops; after the
door has been opened and then closed, the oven is again ready for operation. When the
door is open, lighting is switched on and operating stops. When the door is closed and the
oven is not operating, light is switched off.
1 sec, 10 sec
Wait
for
micro
Door
closed/light
switched on
Door
open/light
switched
on
Wait
for door
closed
Micro
Door
open/light
switched
on
Door
open/light
switched on
Wait
for
timer
Door
open/light
switched on
Start/light
switched on
operatin
g
Timer
expired/light
switched off
Wait
for door
open
8
Download