1 / 31

The OS Environment

The OS Environment. Fred Kuhns fredk@cse.wustl.edu Applied Research Laboratory, Department of Computer Science and Engineering, Washington University in St. Louis. Model and Core Abstractions. Basic model computer used to access, transform and store information.

kaden
Download Presentation

The OS Environment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The OS Environment Fred Kuhns fredk@cse.wustl.edu Applied Research Laboratory, Department of Computer Science and Engineering, Washington University in St. Louis

  2. Model and Core Abstractions • Basic model • computer used to access, transform and store information. • OS provides abstractions to facilitate the information processing task and its conceptualization. • Common abstractions in modern systems: • Process – basic unit of computation • File – basic unit of information storage • Less common abstractions (in an OS): Objects • Objects – basic unit of computation • performs computation on internal data in response to messages, may also send messages to other objects. • Using resources with the process model • a process must request resources from the OS • a process must suspend operation until resource is allocated CS422 – Operating Systems Concepts

  3. Process P0 Process P1 Process PN File F0 File F1 File FM other other other CPU NET DISKS DRAM Processes and Resources An application consists of one or more processes, a set of resources and state Resources Processes ... ... memory Ri ... CPU display Rj Operating System CS422 – Operating Systems Concepts

  4. Traditional UNIX Model execution environment application libraries user System call interface kernel File subsystem IPC Other Resources Process control subsystem scheduler memory hardware CS422 – Operating Systems Concepts

  5. Files • A container for data • typically persistent storage • also non-persistent such as memory based files • Sequential file: named linear stream of records • Typical operations: open, close, read, write, lseek, ioctl • UNIX and MS Windows attempt to use a common, file based interface. Process code: open(“myfile.txt”, ...) Process File Table Name: myfile.txt OS Descriptor: 2453, ... OS File Table OS Descriptor: 2453, ... Current byte offset CS422 – Operating Systems Concepts

  6. File Example #include <fcntl.h> #include <unistd.h> // you should: check for errors and read man pages for syntax and // requirements int main (int argc, char **argv) { int ifd, ofd, n; char buf[MAXFNAME] struct Env_t env; parseargs(&env, argc, argv); ifd = open(env.ifname, O_RDONLY); ofd = open(env.ofname, O_WRONLY); while ((n = read (ifd, (void *)buf, MAXFNAME)) > 0) { write(ofd, (void *)buf, n); } close (ifd); close (ofd); exit(0); } CS422 – Operating Systems Concepts

  7. Computations, Processes and Threads • Common model: A computation is the sequential execution of a set of instructions implementing some algorithm and applied to a specific data set. • A program results from the encoding of an algorithm using a programming language (like C or C++). • program source is compiled to produce instructions native to the target platform, i.e. the binary. • A programmer requests resources from the operating using the exported OS interface, aka system call interface. • Classical definition of a process is a program in execution and embodies all resources and state of a running program (CPU, memory, files,...) • Modern systems separate program execution context from other process resources. A process may have multiple execution contexts for a given process. Thread is an execution context. CS422 – Operating Systems Concepts

  8. Process Pk Resource R0 Code Data Resource R1 Context Resource RN Abstract Machine Environment (OS) Classic Process Model • Process consists of • object code (program) to be executed • data which the process works on • Required resources • Execution status, used by the OS to manage process CS422 – Operating Systems Concepts

  9. Process P3 Process P2 Process P1 Resource R0 Resource R0 Resource R0 Code Code Code Data Data Data Resource R1 Resource R1 Resource R1 Context Context Context Resource RN Resource RN Resource RN Abstract Machine Environment (OS) Abstract Machine Environment (OS) Abstract Machine Environment (OS) Classic Process Example traces for P1, P2 and P3 P1 P2 P3 Shared Code (Program) CS422 – Operating Systems Concepts

  10. Modern Process/Thread Model Process Pk • Process: encompasses • set of threads (computational entities) • collection of resources • Thread: Dynamic object representing an execution path and computational state. • threads have their own computational state: PC, stack, user registers and private data • Remaining resources are shared amongst threads in a process Resource R0 Code Data Resource R1 T1 context T1 context ... Resource RN Abstract Machine Environment (OS) CS422 – Operating Systems Concepts

  11. Resource 1 Data Text (code) Resource N Stack File 1 Status File 2 UNIX Process Model • Memory model: text, data and stack • Common file interface for many of the resources • kernel operates in trusted (i.e. system) mode • Process requests services from kernel using system calls • Each process has a unique ID (PID or process descriptor) UNIX Kernel (OS) CS422 – Operating Systems Concepts

  12. 0xffffffff Kernel stack Data 0x7fffffff Kernel Text stack Data Text (shared) 0x00000000 UNIX Memory Model Kernel address space Process address space CS422 – Operating Systems Concepts

  13. UNIX Process Operations • Well defined hierarchy: one parent and zero or more child processes. The init process is at the root of this tree • Create new process (i.e. child) using fork or vfork • create new address space • copies text, data and stack • child has access to all parent’s open files • Different programs may be run during the life of a process by calling exec • Processes terminate by calling exit • Parent may wait for child to terminate, and colledt exit status, by calling wait CS422 – Operating Systems Concepts

  14. Interacting with the “System”: Command Interpreters • User interaction is through a command interpreter –a system application • Fundamentally, it simply reads and executes commands • internal commands: pre-compiled into the program • external commands: stored in the filesystem as executable files • For external command, the shell will spawn a child process to perform the required function: • the child overwrites its address space with a new program, exec • the parent by default calls wait on the child process, then returns the exit status to the user. CS422 – Operating Systems Concepts

  15. Simple “Shell” while (TRUE) { /* repeat forever */ display_prompt( ); /* display prompt */ read_command (command, parameters) /* input from terminal */ if (fork() != 0) { /* fork child process */ /* Parent code goes there */ waitpid( -1, &status, 0); /* wait for child to exit */ } else { /* Child code goes here*/ execve (command, parameters, 0); /* execute command */ } } CS422 – Operating Systems Concepts

  16. Operating Systems: Approach and funtion • Common approach • Resource abstractions (data and “special” devices) • Resource virtualization to enable process abstraction (i.e. program instance executing within a virtual environment) • Resource management to ensure isolation and controlled sharing. • Common functions: • Device management • Process, thread and resource management • Memory management • File management CS422 – Operating Systems Concepts

  17. Lets Step Back and take another look at OSes • Issues in OS design • Performance – should be low overhead • Exclusive use of resources • protection and security – sharing, authorizing, authenticating • correctness – does what it is supposed to do • maintainability – universal goal • commercial – they are used by people and organizations • standards and open systems – conforming to standards • Common implementation mechanisms • Protection and processor modes • Trusted control program – kernel • Method for processes to request services of the OS – system calls CS422 – Operating Systems Concepts

  18. char block Device drivers Another Look at a typical UNIX System execution environment application trap libraries user System call interface kernel System Services File subsystem dispatcher IPC Process control subsystem Buffercache Scheduler Exceptions Interrupt Memory hardware CS422 – Operating Systems Concepts

  19. Policy and Mechanism • A recurring theme in OS design is ensuring exclusive use of system resources (real and abstract) • Administrators and developers define policies to define resource sharing and isolation • Mechanisms implement these policies • Common mechanisms: • hardware enforced processor modes to control execution of privileged instructions (such as for I/O or memory) • Core OS modules are trusted and have access to protected operations and all resources. This kernel of the OS is responsible for enforcing policies. • Well defined and protected mechanism for requesting services of the OS. There are two approaches: system calls or message passing. CS422 – Operating Systems Concepts

  20. UNIX: Basic Concepts and Mechanisms • Two privilege levels, or modes • user and system mode • kernel space protected: requires special instruction sequence to change from user to kernel mode • Process has "protected" address space - protection • All process share same kernel space - efficiency • Per process state (u_area) in kernel - efficiency • per process kernel stack, practical considerations • kernel is re-entrant • system versus processcontext – virtual property CS422 – Operating Systems Concepts

  21. Mode, Space and Context Privileged user kernel mode context process Application (user code) System calls Exceptions kernel X not allowed Interrupts, System tasks system space CS422 – Operating Systems Concepts

  22. The Kernel – UNIX or other general purpose OS • Trusted program that runs directly on the hardware • Loaded at boot time and initializes system, • creates some initial system processes. • remains in memory and manages the system • Resource manager/mediator - process is key abstraction. • Time share (time-slice) the CPU, • coordinate access to peripherals, • manage virtual memory. • Synchronization primitives. • Well defined entry points: • syscalls, exceptions or interrupts. • Performs privileged operations. CS422 – Operating Systems Concepts

  23. Entry into the Kernel • Synchronous - kernel performs work on behalf of the process: • System call interface (UNIX API): central component of the UNIX API • Hardware exceptions - unusual action of process • Asynchronous - kernel performs tasks that are possibly unrelated to current process. • Hardware interrupts - devices assert hardware interrupt mechanism to notify kernel of events which require attention (I/O completion, status change, real-time clock etc) • System processes - scheduled by OS • swapper and pagedaemon. CS422 – Operating Systems Concepts

  24. Trap or Interrupt Processing • Hardware switches to kernel mode, using the per/process kernel stack. • HW saves PC, Status word and possibly other state on kernel stack. • Assembly routine saves any other information necessary and dispatches event. • On completion a return from interrupt (RFI) instruction is performed. CS422 – Operating Systems Concepts

  25. Interrupt • Asynchronous event. • Name three? • Must be serviced in system context, • What does this mean? • Must not block, • Why? • What happens to the currently running process? • Multiple interrupt priority levels (ipl), traditionally 0-7. • User processes and kernel operate at the lowest ipl level. • Higher level Interrupts can preempt lower priority ones. • The current ipl level may be set while executing critical code. CS422 – Operating Systems Concepts

  26. Exception Handling • Exceptions: • Synchronous to the currently running process. What are some examples? • Must run in the current processes context. • An Interrupt can occur during the processing of an exception or trap. • Software Interrupts: • Interrupts typically have the highest priority in a system. • Software interrupts are assigned priorities above that of user processes but below that of interrupts. • Software interrupts are typically implemented in software. • Examples are callout queue processing and network packet processing. CS422 – Operating Systems Concepts

  27. System Calls • Interface between running program and the operating system • Generally written in assembly-language • Wrapper libraries provide high-level interface • Three general methods are used to pass parameters: • Pass parameters in registers. • Store the parameters in a table in memory. • Push (store) the parameters onto the stack by the program. • Trap into kernel dispatch routine which invokes a high-level system call. • User privileges are verified and any data is copied into kernel (copyin()). • On return, copy out any user data (copyout()), check for an Asynchronous System Trap (signal, preemption, etc). CS422 – Operating Systems Concepts

  28. Synchronization Approaches • Traditional • Kernel is re-entrant. • only one thread/processes active at any given time (others are blocked). • Nonpreemptive. • Blocking operations • Masking interrupts • Modern • threaded kernels • synchronization primitives used in kernel • locking granularity is issue CS422 – Operating Systems Concepts

  29. Blocking Operations • When resource is unavailable (possibly locked), process sets flag and calls sleep() • sleep places process on a blocked queue, sets state to asleep and calls swtch() • when resource released wakeup() is called • all sleeping processes are woken and state set to runnable (placed on the runnable queues). • When running, process must verify resource is available. Why? CS422 – Operating Systems Concepts

  30. Process Scheduling • Preemptive round-robin scheduling • fixed time quantum • priority is adjusted by nice value and usage factor. • Processes in the kernel are assigned a kernel priority (sleep priority) which is higher than user priorities. • Kernel 0-49, user 50-127. CS422 – Operating Systems Concepts

  31. Signals • Asynchronous events and exceptions • Signal generation using the kill() system call • Default operation or user specific handlers • sets a bit in the pending signals mask in the proc structure • All signals are handled before return to normal processing • System calls can be restarted CS422 – Operating Systems Concepts

More Related