Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Multiprocessing

Similar presentations


Presentation on theme: "Intro to Multiprocessing"— Presentation transcript:

1 Intro to Multiprocessing
CS/COE 0449 (term 2184) Jarrett Billingsley

2 Class announcements don't forget… project 3 is due next Wednesday night OMET completion is at 20% 15 responses out of 56 needed for cookies step up your game CS449 (2184)

3 Multiprocessing CS449 (2184)

4 Where'd it come from? computers used to be huge like.. physically
and therefore expensive like.. millions of dollars so many people had to be able to share one computer at once like.. thoth multiprocessing is: running multiple processes (programs) at the same time on one computer CS449 (2184)

5 And then they got small personal computers (PCs) weren't A Thing until the 1970s, and weren't really popular until well into the 1980s limited and basic at first, but… CS449 (2184)

6 Scheduling CS449 (2184)

7 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
All my children at any given time, there are dozens or hundreds of processes running Code Memory Process 1 my turn! my turn!!! I'm the ONLY process! that means I'm the BEST! Code Memory Process 173 Kernel AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Code Memory Process 9 Code Memory Process 92 I want all the CPU!! no I want all the CPU!! CS449 (2184)

8 we call these CPU-bound we call these IO-bound
Who's who some processes use LOTS OF CPU other just sit around most of the time, waiting for input or output (I/O) enter your choice: rock the computer chose rock. tie! enter your choice: paper the computer chose rock. you win! you: 1, computer: 0 enter your choice: _ g++ somefile.cpp Loading… we call these CPU-bound we call these IO-bound CS449 (2184)

9 I'm turning this car around
you've been playing for 3 hours… lemme just beat this boss okay??? if we give the CPU-bound processes priority… …then the IO-bound ones never get a turn. mommy has work to do, Billy if we give the IO-bound processes priority… cow!!!!!! …then the CPU-bound ones run really slowly. CS449 (2184)

10 Scheduling scheduling is how we make the processes take turns on the CPU this is an entire unit in CS1550 all the many ways of doing scheduling do the same basic thing: P1 P2 P5 P9 P1 P7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 time we're slicing up time and giving each slice to a different process. scheduling answers the question: "which process goes next?" CS449 (2184)

11 Collaborative scheduling
in this method, each process has to say "I'm done with my turn" before another process gets to run this is simple to implement and doesn't require any fancy OS or hardware features! …but we all know the problem with taking turns CS449 (2184)

12 What a hog while(true) {}
the problem with collaborative scheduling is… if a process never gives up the CPU, nothing else can run. not even the kernel. so it's unfortunately really, really easy to make a collaboratively scheduled OS freeze… while(true) {} aaaand now you have to restart the computer. CS449 (2184)

13 Preemptive scheduling
in this method, the OS can interrupt a process that's taking too long k, I'm done doo dee doo but.. but I wasn't… haha suckerrrr P1 P2 P5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 P2, your turn ok P2 that's enough… P5, go! Kernel CS449 (2184)

14 Interrupted by an interrupt
to make this work, we need special hardware in the CPU wheee!!! hey timer, wake me up in 100ms CPU P2 Kernel P2, gtfo RING RING!!!! the timer causes an interrupt – like a signal, but lower level only the kernel is allowed to respond to interrupts the quantum is how long a process has before it's preempted CS449 (2184)

15 The process lifecycle CS449 (2184)

16 The directed graph of life
processes can be in one of many states Running normal exit scheduled fork()! preempted Created Ready (sleeping) Dead (or yielded) blocking syscall abnormal termination – crashed or killed OS detects syscall can complete Blocked CS449 (2184)

17 Scheduling points whenever a process gives up the CPU to the kernel, the kernel has a chance to schedule another process ("who's next?") there are a few ways for it to give up the CPU it could get preempted it used up its whole quantum and the OS interrupted it it could yield it voluntarily gives up control – it's playing nice!! it could use a blocking syscall such as reading data from a file it could exit either on purpose or by crashing. CS449 (2184)

18 and then it can schedule a process from the ready set
Ready, set, blocked internally, the OS has these two (or more) sets of processes Blocked Ready P1 P4 P5 P9 P12 P7 yay!! when the kernel takes control, it can see if any of the blocked processes can be moved to the ready set and then it can schedule a process from the ready set CS449 (2184)

19 But context switches are haaaardddd
processes are pretty big things with many parts Stack Heap Globals Code open files internal OS data structures the kernel uses to keep tabs on the process 34 35 process 14 has been running for 8 years and shows no signs of stopping. what the hell is it doing all this crap sure would be nice to get some of the benefits of processes without all the overhead… CS449 (2184)


Download ppt "Intro to Multiprocessing"

Similar presentations


Ads by Google