• No results found

Midterm Review (2021 Spring)

N/A
N/A
Protected

Academic year: 2021

Share "Midterm Review (2021 Spring)"

Copied!
29
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

University of Massachusetts Amherst 2

Homework2

Kevin Zheng

Tongping Liu

ECE 570: System Software Design

2 March 2021

Homework 2

1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3

P2: CPU 5, I/O 8, CPU 7

1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35

P1 R R R R R R R w w w r r R R R

P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35

P1 r r r r r R R R R R R R w w w r r r r r R R R

P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35

P1 r r r r r R R R R R R R w w w R R R

P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35

P1 R R r r R R r r R R r R w w w R R R

P2 r r R R r r R R r r R w w w w w w w w R R R R R R R

Algorithm

P1 WT

P2 WT

Avg WT

P1 FT

P1 FT

Schd Len

CPU Ut

FCFS

2

7

4.5

15

27

27

81.48%

SJF

10

0

5

23

20

23

95.65%

PSJF

5

3

4

18

23

23

95.65%

RR 2

5

6

5.5

18

26

26

84.62%

2. agree/disagree

a. disagree – shortest job first scheduling runs the job with the shortest CPU

burst first, not the shortest total execution time

b. agree – a quantum that is greater than or equal to the longest CPU burst

will make RR behave like FCFS.

P1: CPU-7, IO-3, CPU-3

P2: CPU-5, IO-8, CPU-7

Kevin Zheng Tongping Liu

ECE 570: System Software Design 2 March 2021

Homework 2 1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3 P2: CPU 5, I/O 8, CPU 7 1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35 P1 R R R R R R R w w w r r R R R P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w r r r r r R R R P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w R R R P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35 P1 R R r r R R r r R R r R w w w R R R P2 r r R R r r R R r r R w w w w w w w w R R R R R R R

Algorithm P1 WT P2 WT Avg WT P1 FT P1 FT Schd Len CPU Ut FCFS 2 7 4.5 15 27 27 81.48% SJF 10 0 5 23 20 23 95.65% PSJF 5 3 4 18 23 23 95.65% RR 2 5 6 5.5 18 26 26 84.62%

2. agree/disagree

a. disagree – shortest job first scheduling runs the job with the shortest CPU burst first, not the shortest total execution time

b. agree – a quantum that is greater than or equal to the longest CPU burst will make RR behave like FCFS.

Kevin Zheng

Tongping Liu

ECE 570: System Software Design

2 March 2021

Homework 2

1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3

P2: CPU 5, I/O 8, CPU 7

1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35 P1 R R R R R R R w w w r r R R R P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w r r r r r R R R P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w R R R P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35 P1 R R r r R R r r R R r R w w w R R R P2 r r R R r r R R r r R w w w w w w w w R R R R R R R

Algorithm P1 WT P2 WT Avg WT P1 FT P1 FT Schd Len CPU Ut

FCFS 2 7 4.5 15 27 27 81.48%

SJF 10 0 5 23 20 23 95.65%

PSJF 5 3 4 18 23 23 95.65%

RR 2 5 6 5.5 18 26 26 84.62%

2. agree/disagree

a. disagree – shortest job first scheduling runs the job with the shortest CPU

burst first, not the shortest total execution time

b. agree – a quantum that is greater than or equal to the longest CPU burst

will make RR behave like FCFS.

Kevin Zheng

Tongping Liu

ECE 570: System Software Design

2 March 2021

Homework 2

1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3

P2: CPU 5, I/O 8, CPU 7

1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35 P1 R R R R R R R w w w r r R R R P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w r r r r r R R R P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w R R R P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35 P1 R R r r R R r r R R r R w w w R R R P2 r r R R r r R R r r R w w w w w w w w R R R R R R R

Algorithm P1 WT P2 WT Avg WT P1 FT P1 FT Schd Len CPU Ut

FCFS 2 7 4.5 15 27 27 81.48%

SJF 10 0 5 23 20 23 95.65%

PSJF 5 3 4 18 23 23 95.65%

RR 2 5 6 5.5 18 26 26 84.62%

2. agree/disagree

a. disagree – shortest job first scheduling runs the job with the shortest CPU

burst first, not the shortest total execution time

(3)

University of Massachusetts Amherst 3

Homework2

P1: CPU-7, IO-3, CPU-3

P2: CPU-5, IO-8, CPU-7

Kevin Zheng

Tongping Liu

ECE 570: System Software Design

2 March 2021

Homework 2

1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3

P2: CPU 5, I/O 8, CPU 7

1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35

P1 R R R R R R R w w w r r R R R

P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35

P1 r r r r r R R R R R R R w w w r r r r r R R R

P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35

P1 r r r r r R R R R R R R w w w R R R

P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35

P1 R R r r R R r r R R r R w w w R R R

P2 r r R R r r R R r r R w w w w w w w w R R R R R R R

Algorithm

P1 WT

P2 WT

Avg WT

P1 FT

P1 FT

Schd Len

CPU Ut

FCFS

2

7

4.5

15

27

27

81.48%

SJF

10

0

5

23

20

23

95.65%

PSJF

5

3

4

18

23

23

95.65%

RR 2

5

6

5.5

18

26

26

84.62%

2. agree/disagree

Kevin Zheng

Tongping Liu

ECE 570: System Software Design

2 March 2021

Homework 2

1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3

P2: CPU 5, I/O 8, CPU 7

1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35 P1 R R R R R R R w w w r r R R R P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w r r r r r R R R P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w R R R P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35 P1 R R r r R R r r R R r R w w w R R R P2 r r R R r r R R r r R w w w w w w w w R R R R R R R

Algorithm P1 WT P2 WT Avg WT P1 FT P1 FT Schd Len CPU Ut

FCFS 2 7 4.5 15 27 27 81.48%

SJF 10 0 5 23 20 23 95.65%

PSJF 5 3 4 18 23 23 95.65%

RR 2 5 6 5.5 18 26 26 84.62%

2. agree/disagree

a. disagree – shortest job first scheduling runs the job with the shortest CPU

burst first, not the shortest total execution time

b. agree – a quantum that is greater than or equal to the longest CPU burst

will make RR behave like FCFS.

Kevin Zheng

Tongping Liu

ECE 570: System Software Design

2 March 2021

Homework 2

1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3

P2: CPU 5, I/O 8, CPU 7

1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35 P1 R R R R R R R w w w r r R R R P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w r r r r r R R R P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w R R R P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35 P1 R R r r R R r r R R r R w w w R R R P2 r r R R r r R R r r R w w w w w w w w R R R R R R R

Algorithm P1 WT P2 WT Avg WT P1 FT P1 FT Schd Len CPU Ut

FCFS 2 7 4.5 15 27 27 81.48%

SJF 10 0 5 23 20 23 95.65%

PSJF 5 3 4 18 23 23 95.65%

RR 2 5 6 5.5 18 26 26 84.62%

2. agree/disagree

a. disagree – shortest job first scheduling runs the job with the shortest CPU

burst first, not the shortest total execution time

b. agree – a quantum that is greater than or equal to the longest CPU burst

will make RR behave like FCFS.

Kevin Zheng

Tongping Liu

ECE 570: System Software Design

2 March 2021

Homework 2

1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3

P2: CPU 5, I/O 8, CPU 7

1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35 P1 R R R R R R R w w w r r R R R P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w r r r r r R R R P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w R R R P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35 P1 R R r r R R r r R R r R w w w R R R P2 r r R R r r R R r r R w w w w w w w w R R R R R R R Algorithm P1 WT P2 WT Avg WT P1 FT P1 FT Schd Len CPU Ut FCFS 2 7 4.5 15 27 27 81.48% SJF 10 0 5 23 20 23 95.65% PSJF 5 3 4 18 23 23 95.65% RR 2 5 6 5.5 18 26 26 84.62%

2. agree/disagree

a. disagree – shortest job first scheduling runs the job with the shortest CPU

burst first, not the shortest total execution time

b. agree – a quantum that is greater than or equal to the longest CPU burst

will make RR behave like FCFS.

Kevin Zheng Tongping Liu

ECE 570: System Software Design 2 March 2021

Homework 2 1. CPU scheduling

P1: CPU 7, I/O 3, CPU 3 P2: CPU 5, I/O 8, CPU 7 1 just before 2

a. First-come/first-served

0 5 10 15 20 25 30 35 P1 R R R R R R R w w w r r R R R P2 r r r r r r r R R R R R w w w w w w w w R R R R R R R

b. Shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w r r r r r R R R P2 R R R R R w w w w w w w w R R R R R R R

c. Preemptive shortest job first

5 10 15 20 25 30 35 P1 r r r r r R R R R R R R w w w R R R P2 R R R R R w w w w w w w w R R r r r R R R R R

d. Round robin with a quantum of 2

5 10 15 20 25 30 35 P1 R R r r R R r r R R r R w w w R R R P2 r r R R r r R R r r R w w w w w w w w R R R R R R R Algorithm P1 WT P2 WT Avg WT P1 FT P1 FT Schd Len CPU Ut FCFS 2 7 4.5 15 27 27 81.48% SJF 10 0 5 23 20 23 95.65% PSJF 5 3 4 18 23 23 95.65% RR 2 5 6 5.5 18 26 26 84.62%

2. agree/disagree

a. disagree – shortest job first scheduling runs the job with the shortest CPU burst first, not the shortest total execution time

(4)

University of Massachusetts Amherst 4

Homework2

• Q2:

– Disagree. In SJF scheduling, the task

with the next

shortest cpu burst

,

not total execution time

, will be

scheduled first.

– Agree. There is a quantum value in RR to make it

(5)

Homework2

void initLock(bool * lock) {

*lock = false;

}

void lock(bool * lock) {

bool key = true;

while (key == true) {

swap(&key, lock);

}

void unlock(bool * lock) {

*lock = false;

(6)

University of Massachusetts Amherst 6

Homework2

• Pros:

– Easy to implement

– No priority inversion.

– Deletion safety

• Cons:

(7)

Midterm

• Time:

– March 17: 8pm~10PM (EST)

• Zoom Link (lectures link):

(8)

University of Massachusetts Amherst 8

Midterm Exam Format

• 2-hour exam over the zoom (open the video)

• Ask questions in a separate room

• Close notes but with one cheat sheet

(back-and-forth)

(9)

Lecture-1: Overview

• Evolution of Computer Systems and OS

Concepts

• Different Types of OS

– Parallel/Distributed/Real-time/Embedded OS

• OS Services

• OS Structures and Basic Components

(10)

University of Massachusetts Amherst 10

Important Concepts

(11)

Lecture-2: Process

• Programs and Processes

• Process (program image) in memory

• PCB: Process Control Block

(12)

University of Massachusetts Amherst 12

Important Concepts

• Difference between a program with a process

• Program states and state transition

(13)

Lecture-3: Threads

• Motivation and thread basics

– Resource requirements: thread vs. process

• Thread implementations

– User threads: e.g., Pthreads and Java threads

– Kernel threads: e.g., Linux tasks

– Map user- and kernel-level threads

– Lightweight process and scheduler activation

• Other issues with threads:

– process creation and signals etc.

– Memory sharing model

(14)

University of Massachusetts Amherst 14

Important Concepts

• Difference and similarities between threads and

processes

• Pros and cons of thread models: 1-to-1, n-to-1, and

m-to-n

(15)

Lecture-5

• Shared data access

– Race condition and critical section

– General structure for enforce critical section

• Synchronization mechanism

– Hardware supported instructions

– Software solution

• Classical Synchronization Problems

(16)

University of Massachusetts Amherst 16

Important Concepts

• Critical section

• General structure for ensuring safety of critical

section

• swap() and testAndset()

• Semaphore vs. Mutex

• Monitor

(17)

Lecture-6

• Implementing Multithreaded Programs

– Synchronization Errors:

• Deadlock, race condition, order violation, atomicity violation

– Performance Issues:

• Hardware related: false/true sharing

• Software related: lock issues

(18)

University of Massachusetts Amherst 18

Important Concepts

• Four common synchronization errors

• False/true sharing performance issues

• Lock performance issues

(19)

Question #1

What is the difference between a process and a

thread?

(20)

University of Massachusetts Amherst 20

20

Question #2

What process states for a running process is not

stored in the address space?

(21)

Question #3

What is the problem with defining large critical

sections in multi-threaded code?

Results in a lot of waiting by the threads. You

want to release the lock as much as possible.

(22)

University of Massachusetts Amherst 22

22

Question #4

• When might you use signal() instead of

broadcast() with condition variables?

(23)

Question #5

• Does the order of the signal() calls matter with

semaphores in terms of causing/preventing

deadlock? Does the order of the wait() calls

matter?

(24)

University of Massachusetts Amherst 24

24

Question #6

Name three internal events a thread may

execute to return control back to the OS?

(25)

Question #7

Name the most common external event that

transfers control back to the OS from a

running thread?

(26)

University of Massachusetts Amherst 26

26

Question #8

What are the basic steps involved with creating

a new thread?

Allocate and initialize a new TCB, allocate a new

(27)

Question #9

Why is it ok for the OS to disable interrupts,

but not application programs?

(28)

University of Massachusetts Amherst 28

28

Question #10

How does the testAndset(X) function work?

Implement a simple busy-waiting lock for

multi-processors using the testAndset(X)

function.

lock () { while (testAndset(value) == 1) {;}

(29)

Question #11

What are the options for ensuring atomicity on

a uniprocessor within the OS?

Disabling interrupts, atomic load-store,

References

Related documents

In order to understand the role of statistical self-similar topol- ogy observed in real river networks on spatial scaling statis- tics of hydrographs, we created Monte Carlo

The TCAM-based deep packet inspection algorithm developed in this paper uses a jumping window scheme, which is supported by position-aware sub-patterns and the state transition

One of the first systems management applications a customer with a distributed information technology (IT) environment should consider is software distribution, followed by an

of burst time divided by time quantum (avgburst/tq) value, then CPU again allocated to the currently running job for remaining CPU burst time. Behera [4] proposes a

She does not provide the extensive introduc- tion to the techniques of canning found in the other guides in this section, nor does she provide the traditional recipes found in

Conclusão: A versão em Português europeu do the Alcohol, Smoking and Substance Involvement Screening Test (‘Tabaco’, ‘Bebidas Alcoólicas’ e ‘ Cannabis ’)

SJF Algorithm Difficult to understand and code CPU is allocated to the process with least CPU burst time Lesser than FCFS Suitable for Batch system Priority

Specifically, in these types of scenarios where a DSO needs to keep the energy grid balanced, a district-level granularity for charging events is sufficient to verify that the