Eventdriven programming n Eventdriven programming is a programming

  • Slides: 40
Download presentation
Event-driven programming n Event-driven programming is a programming paradigm in which the flow of

Event-driven programming n Event-driven programming is a programming paradigm in which the flow of the program is determined by n n n Application has a main loop n n n sensor outputs, user actions (mouse clicks, key presses), or messages from other programs or threads. interrupts Event selection (scheduler). Event handling (dispatcher). Events are external to a task n Signals are asynchronous events n n Occur anytime, handled by call-back functions Semaphores are synchronous events. n BYU CS 345 Occur anytime, handled by semaphores Chapter 2: OS Overview 1

Project 1 File Summary… n Files needing attention: n n n os 345 tasks.

Project 1 File Summary… n Files needing attention: n n n os 345 tasks. c – create. Task, sys. Kill. Task os 345 interrupts. c – keyboard_isr os 345 signals. c – signals, sig. Action, sig. Signal, default. Sigxx. Handler, create. Task. Sig. Handlers os 345 p 1. c – P 1_shell. Task, P 1_help … os 345. h – your equates Signal Event Handlers n n n int signals(void); int sig. Action(void (*sig. Handler)(void), int sig); int sig. Signal(int task. Id, int sig); void default. Sigxxx. Handler(void); void create. Task. Sig. Handlers(int tid) BYU CS 345 Chapter 2: OS Overview 2

1. 4 Signals A signal is an asynchronous notification of an event that is

1. 4 Signals A signal is an asynchronous notification of an event that is sent to a process before it is rescheduled for execution. n Blocked processes are not un-blocked by a signal, but rather the signal remains pending until such time as the process is un-blocked and scheduled for execution. 4. Before a task is scheduled by the function dispatcher (os 345. c), the function signals (os 345 signals. c) is called: n n n Modify the function signals (os 345 signals. c) to call pending task signal handlers. Modify the function create. Task. Sig. Handlers (os 345 signals. c) such that a child task inherits all its parent signal handlers. Modify the function sig. Action (os 345 signals. c) to register new task signal handlers. Add default signal handlers as needed. Implement all signals and signal handlers such that: n Cntrl-X terminates (kills) all tasks except task 0 (shell). n Cntrl-W pauses the execution of all tasks. n Cntrl-R continues the execution of all tasks after a pause. BYU CS 345 Chapter 2: OS Overview 3

Signals 1. 4 Signals Example Dispatcher calls signal handlers before rescheduling task: void my.

Signals 1. 4 Signals Example Dispatcher calls signal handlers before rescheduling task: void my. SIGINTHandler(void) { sig. Signal(-1, SIGTERM); return; } keyboard_isr() detects a cntrl-X and sends a SIGINT signal to the shell: Task registers call-back signal handler functions with the OS: sig. Signal(0, SIGINT); sig. Action(my. SIGINTHandler , SIGINT); sig. Action(my. SIGTERMHandler , SIGTERM); dispatch() create. Task() New void my. SIGTERMHandler(void ) { kill. Task(cur. Task); return; } Ready sys. Kill. Task() Running Exit SWAP create. Task calls create. Task. Sig. Handlers() to setup default / parent signal handlers: void create. Task. Sig. Handlers(int tid ) tcb[tid]. sig. Int. Handler = default. Sig. Int. Handler; tcb[tid]. sig. Term. Handler = default. Sig. Term. Handler; return; { } BYU CS 345 Chapter 2: OS Overview 4

Signals Signal Handling BYU CS 345 Chapter 2: OS Overview 5

Signals Signal Handling BYU CS 345 Chapter 2: OS Overview 5

Keyboard Interrupts Keyboard Input Action Cntrl-X sig. Signal SIGINT to shell Clear input buffer

Keyboard Interrupts Keyboard Input Action Cntrl-X sig. Signal SIGINT to shell Clear input buffer sem. Signal in. Buffer. Ready Cntrl-R sig. Signal SIGCONT to all tasks Clear SIGSTOP from all tasks Clear SIGTSTP from all tasks sig. Signal SIGTSTP to all tasks Cntrl-W BYU CS 345 Chapter 2: OS Overview 6

Project 1 Signals Quiz 1. What is a signal? 2. Who can signal? 3.

Project 1 Signals Quiz 1. What is a signal? 2. Who can signal? 3. When is a signal acknowledged? 4. How are signals delivered to a process? 5. What operations are illegal within a signal handler? 6. How are parameters passed to a signal? 7. What signals might a process not handle? 8. How many signals might a system support? BYU CS 345 Chapter 2: OS Overview 7

$ kill –l 1) SIGHUP 5) SIGTRAP 9) SIGKILL 13) SIGPIPE 17) SIGCHLD 21)

$ kill –l 1) SIGHUP 5) SIGTRAP 9) SIGKILL 13) SIGPIPE 17) SIGCHLD 21) SIGTTIN 25) SIGXFSZ 29) SIGIO 35) SIGRTMIN+1 39) SIGRTMIN+5 43) SIGRTMIN+9 47) SIGRTMIN+13 51) SIGRTMAX-13 55) SIGRTMAX-9 59) SIGRTMAX-5 63) SIGRTMAX-1 BYU CS 345 2) SIGINT 6) SIGABRT 10) SIGUSR 1 14) SIGALRM 18) SIGCONT 22) SIGTTOU 26) SIGVTALRM 30) SIGPWR 36) SIGRTMIN+2 40) SIGRTMIN+6 44) SIGRTMIN+10 48) SIGRTMIN+14 52) SIGRTMAX-12 56) SIGRTMAX-8 60) SIGRTMAX-4 64) SIGRTMAX 3) SIGQUIT 7) SIGBUS 11) SIGSEGV 15) SIGTERM 19) SIGSTOP 23) SIGURG 27) SIGPROF 31) SIGSYS 37) SIGRTMIN+3 41) SIGRTMIN+7 45) SIGRTMIN+11 49) SIGRTMIN+15 53) SIGRTMAX-11 57) SIGRTMAX-7 61) SIGRTMAX-3 Chapter 2: OS Overview 4) SIGILL 8) SIGFPE 12) SIGUSR 2 16) SIGSTKFLT 20) SIGTSTP 24) SIGXCPU 28) SIGWINCH 34) SIGRTMIN 38) SIGRTMIN+4 42) SIGRTMIN+8 46) SIGRTMIN+12 50) SIGRTMAX-14 54) SIGRTMAX-10 58) SIGRTMAX-6 62) SIGRTMAX-2 8

CS 345 Stalling’s Chapter # Project 1: Computer System Overview 2: Operating System Overview

CS 345 Stalling’s Chapter # Project 1: Computer System Overview 2: Operating System Overview 4 P 1: Shell 3: Process Description and Control 4: Threads 4 P 2: Tasking 5: Concurrency: ME and Synchronization 6: Concurrency: Deadlock and Starvation 6 P 3: Jurassic Park 7: Memory Management 8: Virtual memory 6 P 4: Virtual Memory 9: Uniprocessor Scheduling 10: Multiprocessor and Real-Time Scheduling 6 P 5: Scheduling 11: I/O Management and Disk Scheduling 12: File Management 8 P 6: FAT Student Presentations 6 BYU CS 345 Chapter 2: OS Overview 9

CS 345 Computer System Overview Chapter 2

CS 345 Computer System Overview Chapter 2

Chapter 2 Learning Objectives n n n n n Summarize, at a top level,

Chapter 2 Learning Objectives n n n n n Summarize, at a top level, the key functions of an operating system. Discuss the evolution of operating systems from early simple batch systems to modern complex systems. Give a brief explanation of each of the major achievements in OS research. Discuss the key design areas that have been instrumental in the development of modern operating systems. Define and discuss virtual machines and virtualization. Understand the OS design issues raised by the introduction of multiprocessor and multicore organization. Understand the basic structure of Windows 7. Describe the essential elements of a traditional UNIX system. Explain the new features found in modern UNIX systems. Discuss Linux and its relationship to UNIX. BYU CS 345 Chapter 2: OS Overview 11

Evolution of Operating Systems n n n n n Early Systems (1950) Simple Batch

Evolution of Operating Systems n n n n n Early Systems (1950) Simple Batch Systems (1960) Multiprogrammed Batch Systems (1970) Time-Sharing and Real-Time Systems (1970) Personal/Desktop Computers (1980) Multiprocessor Systems (1980) Networked/Distributed Systems (1980) Web-based Systems (1990) Virtualization … https: //www. cs. rutgers. edu/~pxk/416/notes/01 -intro. html 1 st generation 1945 – 1955 - vacuum tubes, plug boards 2 nd generation 1955 – 1965 - transistors, batch systems 3 rd generation 1965 – 1980 - ICs and multiprogramming 4 th generation 1980 – - personal computers present 5 th generation - ? ? ? - ubiquitousness, mobile, BYU CS 345 Chapter 2: OS Overview 12

Chapter 2 Reading Quiz 1. What are the objectives of an OS? 2. What

Chapter 2 Reading Quiz 1. What are the objectives of an OS? 2. What services does an OS provide? 3. What computer resources need management? 4. What hardware advancements facilitated OS development? 5. What is JCL? 6. What does SPOOLing stand for? 7. What is a Virtual Machine? Why Virtualize? 8. What differentiates Windows 7, UNIX, and Linux? BYU CS 345 Chapter 2: OS Overview 13

Objectives 1. What are the Objectives of an OS? n Convenience n n Efficiency

Objectives 1. What are the Objectives of an OS? n Convenience n n Efficiency n n Make the computer more convenient to use Efficient use of computer system resources Accessibility Uniformity Ability to evolve n Permit effective development, testing, and introduction of new system functions without interfering with service BYU CS 345 Chapter 2: OS Overview 14

Services 2. What Services does an OS provide? n Program development n n Program

Services 2. What Services does an OS provide? n Program development n n Program execution n n Protection, authorization, resolve conflicts Error detection and response n n n Authorization, sharing, caching System access n n Uniform interface, hides details Operating systems are among the most complex pieces of software ever developed. . . Controlled access to files n n Initialization, scheduling Access to I/O devices n n Editors, debuggers, frameworks Hardware errors: memory error or device failure Software errors: arithmetic errors, access forbidden memory locations errors Accounting n Collect statistics (billing), monitor performance (future enhancements) BYU CS 345 Chapter 2: OS Overview 15

Resource Management 3. What Resources need management? n Memory n n n Peripherals Computer

Resource Management 3. What Resources need management? n Memory n n n Peripherals Computer programs n n Cache Virtual Secondary User programs Shared libraries Concurrency / Synchronization CPU cores BYU CS 345 Chapter 2: OS Overview 16

Hardware Advancements 4. What H/W Advancements? n Memory protection (1960’s) n n Privileged instructions

Hardware Advancements 4. What H/W Advancements? n Memory protection (1960’s) n n Privileged instructions n n n do not allow the memory area containing the monitor to be altered by a user program. can be executed only by the resident monitor. A trap occurs if a program tries these instructions. Interrupts (1956) n n provide flexibility for relinquishing control to and regaining control from user programs. Timer interrupts prevent a job from monopolizing the system. BYU CS 345 Chapter 2: OS Overview 17

Early Systems Characteristics of Early Systems Early software: Assemblers, Libraries of common subroutines (I/O,

Early Systems Characteristics of Early Systems Early software: Assemblers, Libraries of common subroutines (I/O, Floating-point), Device Drivers, Compilers, Linkers. n Need significant amount of setup time. n Extremely slow I/O devices. n Very low CPU utilization. n But computer was very secure. n BYU CS 345 Chapter 2: OS Overview 18

Early Systems n Structure n n Single user system. Programmer/User as operator (Open Shop).

Early Systems n Structure n n Single user system. Programmer/User as operator (Open Shop). Large machines run from console. Paper Tape or Punched cards. BYU CS 345 Chapter 2: OS Overview 19

Early Systems Early Computer System BYU CS 345 Chapter 2: OS Overview 20

Early Systems Early Computer System BYU CS 345 Chapter 2: OS Overview 20

Hardware Advancements Offline Operation n Problem: n n n Card Reader slow, Printer slow

Hardware Advancements Offline Operation n Problem: n n n Card Reader slow, Printer slow (compared to Tape). I/O and CPU could not overlap. Solution: Offline Operation (Satellite Computers) n Speed up computation by loading jobs into memory from tapes while card reading and line printing is done off-line using smaller machines. BYU CS 345 Chapter 2: OS Overview 21

Batch Systems Simple Batch Systems n n Use of high-level languages, magnetic tapes. Jobs

Batch Systems Simple Batch Systems n n Use of high-level languages, magnetic tapes. Jobs are batched together by type of languages. An operator was hired to perform the repetitive tasks of loading jobs, starting the computer, and collecting the output (Operator-driven Shop). It was not feasible for users to inspect memory or patch programs directly. BYU CS 345 Chapter 2: OS Overview 22

Batch Systems 5. What is JCL? n Job Control language is the language that

Batch Systems 5. What is JCL? n Job Control language is the language that provides instructions to the monitor: n n n what compiler to use what data to use Example of job format: ------->> n n n $FTN loads the compiler and transfers control to it. $LOAD loads the object code (in place of compiler). $RUN transfers control to user program. BYU CS 345 Chapter 2: OS Overview $JOB $FTN. . . FORTRAN program. . . $LOAD $RUN. . . Data. . . $END 23

Batch Systems Operator-driven Shop BYU CS 345 Chapter 2: OS Overview 24

Batch Systems Operator-driven Shop BYU CS 345 Chapter 2: OS Overview 24

Batch Systems Simple Batch Systems n n n The user submits a job (written

Batch Systems Simple Batch Systems n n n The user submits a job (written on cards or tape) to a computer operator. The computer operator place a batch of several jobs on an input device. A special program called the monitor, manages the execution of each program in the batch. n n n “Resident monitor” is always in main memory and available for execution. Monitor utilities are loaded when needed. Reduce setup time by batching similar jobs. Alternate execution between user program and the monitor program. Use Automatic Job Sequencing – automatically transfer control from one job when it finishes to another one. Rely on available hardware to effectively alternate execution from various parts of memory. BYU CS 345 Chapter 2: OS Overview 25

Batch Systems Control Cards • Special cards that tell the monitor which programs to

Batch Systems Control Cards • Special cards that tell the monitor which programs to run: $JOB $FTN $RUN $DATA $END • Special characters distinguish control cards from data or program cards: $ in column 1 // in column 1 and 2 709 in column 1 BYU CS 345 Chapter 2: OS Overview 26

Batch Systems Card Deck of a Job BYU CS 345 Chapter 2: OS Overview

Batch Systems Card Deck of a Job BYU CS 345 Chapter 2: OS Overview 27

Uniprogramming n n n I/O operations are exceedingly slow (compared to instruction execution). A

Uniprogramming n n n I/O operations are exceedingly slow (compared to instruction execution). A program containing even a very small number of I/O operations, will spend most of its time waiting for them. Hence: poor CPU usage when only one program is present in memory. BYU CS 345 Chapter 2: OS Overview 28

Multiprogramming Batch Multiprogramming Several jobs are kept in main memory at the same time,

Multiprogramming Batch Multiprogramming Several jobs are kept in main memory at the same time, and the CPU is multiplexed among them. BYU CS 345 Chapter 2: OS Overview 29

Multiprogramming Concurrent Multiprogramming Allows the processor to execute another program while one program must

Multiprogramming Concurrent Multiprogramming Allows the processor to execute another program while one program must wait for an I/O device. BYU CS 345 Chapter 2: OS Overview 30

Multiprogramming Why Multiprogramming? n n n Single user cannot keep CPU and I/O devices

Multiprogramming Why Multiprogramming? n n n Single user cannot keep CPU and I/O devices busy at all times. Multiprogramming organizes jobs (code and data) so CPU always has one to execute. A subset of total jobs in system is kept in memory. One job selected and run via job scheduling. When it has to wait, OS switches to another job. BYU CS 345 Chapter 2: OS Overview 31

Multiprogramming Requirements n Hardware support: n I/O interrupts and DMA controllers n n n

Multiprogramming Requirements n Hardware support: n I/O interrupts and DMA controllers n n n Timer interrupts for CPU to gain control. Memory management n n n in order to execute instructions while I/O device is busy. several ready-to-run jobs must be kept in memory. Memory protection (data and programs). Software support from the OS: n n For scheduling (which program is to be run next). To manage resource contention. BYU CS 345 Chapter 2: OS Overview 32

Multiprocessing Multi (processor/core) n Traditionally, the computer has been viewed as a sequential machine.

Multiprocessing Multi (processor/core) n Traditionally, the computer has been viewed as a sequential machine. n n n Multiple control signals Pipelining Parallelism n Symmetric Multiprocessors (SMP) n n Multicore Computers n n n 2 or more identical processors that share resources Integrated OS to control jobs, tasks, files, data elements… High degree of interaction/cooperation between processes Single piece of silicon (die) Independent processors + levels of cache Intel Core i 7 Prefetching Cluster computing n n BYU CS 345 Loosely coupled - network Client / server environment Middleware DME, RPC Chapter 2: OS Overview 33

Spooling 6. What does Spool stand for? n Problem: n n n Card reader,

Spooling 6. What does Spool stand for? n Problem: n n n Card reader, Line printer and Tape drives slow I/O and CPU could not overlap. Solution: Spooling n n Overlap I/O of one job with the computation of another job (using double buffering, DMA, etc). Technique is called SPOOLing: Simultaneous Peripheral Operation On Line. BYU CS 345 Chapter 2: OS Overview 34

Virtual Machine 7. What is a Virtual Machine? n n Virtualization technology enables a

Virtual Machine 7. What is a Virtual Machine? n n Virtualization technology enables a single PC or server to simultaneously run multiple operating systems on a single platform. The host OS can support many virtual machines, each with characteristics of a particular OS. BYU CS 345 Chapter 2: OS Overview 35

Windows 7 8. Windows 7, Unix, Linux? BYU CS 345 Chapter 2: OS Overview

Windows 7 8. Windows 7, Unix, Linux? BYU CS 345 Chapter 2: OS Overview 36

System Architecture Modern OS Architecture BYU CS 345 Chapter 2: OS Overview 37

System Architecture Modern OS Architecture BYU CS 345 Chapter 2: OS Overview 37

Desktop Market Share BYU CS 345 Chapter 2: OS Overview 38

Desktop Market Share BYU CS 345 Chapter 2: OS Overview 38

Desktop Market Share BYU CS 345 Chapter 2: OS Overview 39

Desktop Market Share BYU CS 345 Chapter 2: OS Overview 39

BYU CS 345 Chapter 2: OS Overview 40

BYU CS 345 Chapter 2: OS Overview 40