31
Operating System Concepts What is an operating system, what does it do, and how do you talk to it? Paul Krzyzanowski January 26, 2012 [original version: September 13, 2010] What’s an operating system? A number of definitions of operating system abound. A basic definition could be that it’s a program that lets you run other programs. If it didn’t do at least that then we would never have programs running on our computers except for the operating system itself. We need to differentiate this from a command interpreter or a windowing system, however, either of which could be just another program that requests the operating system to run other programs based on user requests. Another definition that we can use is that an operating system is a program that provides controlled access to a computer’s resources. These resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse (device drivers), persistent storage (file systems), and the network. At the most basic level, the operating system provides a level of abstraction (a set of APIs) so that user programs don’t have to deal with the details of accessing the hardware. This is essentially what early operating systems in the 1950s gave us as well as what we got from early personal computer operating systems, such as MS-DOS. On a more sophisticated level, the operating system is also responsible for enforcing proper protections and some concept of “fairness”. You don’t want a process to use an unfair share of the memory or CPU. You also don’t want one process to be able to overwrite the memory of another or to access files on the disk that another user wants restricted.

Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

Operating System Concepts What is an operating system, what does it do, and how do you talk to it?

Paul Krzyzanowski

January 26, 2012 [original version: September 13, 2010]

What’s an operating system?A number of definitions of operating system abound. A basic definition could be that it’s a program that lets you run other programs. If it didn’t do at least that then we would never have programs running on our computers except for the operating system itself. We need to differentiate this from a command interpreter or a windowing system, however, either of which could be just another program that requests the operating system to run other programs based on user requests. Another definition that we can use is that an operating system is a program that provides controlled access to a computer’s resources. These resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse (device drivers), persistent storage (file systems), and the network.

At the most basic level, the operating system provides a level of abstraction (a set of APIs) so that user programs don’t have to deal with the details of accessing the hardware. This is essentially what early operating systems in the 1950s gave us as well as what we got from early personal computer operating systems, such as MS-DOS. On a more sophisticated level, the operating system is also responsible for enforcing proper protections and some concept of “fairness”. You don’t want a process to use an unfair share of the memory or CPU. You also don’t want one process to be able to overwrite the memory of another or to access files on the disk that another user wants restricted.

Building an operating system: monolithic, layered, modular?

Older operating systems were largely monolithic. Every system-related function was performed by one block of code that was part of the operating system.

As the functionality of the system grew, the operating system software became increasingly more difficult to maintain and understand, so operating system software started to get modular. A modular design allows certain pieces of the operating system to be replaced or installed as needed. For example, components such as the process scheduler can be replaced with alternate versions. Specific device drivers, such as iSCSI or USB can be created as a separate modules and “plugged in” to the kernel (linked into the kernel after the base part has loaded). The modules of Linux are an example of this structure.

The later trend in operating system design was to keep the core of the operating system small and move as much as possible into separate programs that have the proper security privileges to do

Page 2: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

what just they need. The kernel will invoke separate processes to deal with things such as parsing a file system, interfacing with the network, or even making a process scheduling decision. This approach is called a microkernel.

What’s a kernel?

When people refer to an operating system, they often talk not just about the program that controls access to resources, but also the command interpreter, utilities, and other programs and drivers that make up one’s perception of an operating system — the entire operating environment. The kernel is the core component of the operating system; the central program that manages resource access and process scheduling.

An example of some of the things a typical operating system kernel does is:

controls execution of processes: allowing their creation, termination, and inter-process communication

schedules processes fairly for execution on the processor or processors allocates memory for an executing process. If the system runs low on free memory, it frees

memory by writing regions of memory to secondary memory. If it writes the entire process, then the system is a swapping system. If it writes pages of memory, it is called a paging system.

allocates secondary memory for storing and retrieving data (file systems) and enforcing proper access permissions and mutual exclusion

allows processes controlled access to peripheral devices: displays, keyboard, mouse, disk drives, networks — also enforcing proper access permissions and mutual exclusion

Am I in user mode?A processor contains certain instructions that are only available to “privileged programs”, such as the operating system. These instructions include those to manipulate memory mappings, set timers, define interrupt vectors, access restricted memory, or halt the processor. Clearly, it is not a good idea for regular programs to be allowed to mess with these instructions since they could wreak havoc on the system. They will also be able to circumvent any protection mechanisms that have been put in place since a process will now be able to interact with any device and any memory as it sees fit.

Most processors have a flag in a status register that tells them whether they’re running in user mode or kernel mode. Kernel mode is also known as privileged, system, or supervisor mode. If a process is running in kernel mode, it has full powers to access all of these restricted operations. If a process is running in user mode, it does not.

The processor starts up in kernel mode and the boot loader runs in kernel mode. The operating system is loaded and, it too, runs in kernel mode. The processes that it launches run in user mode.

Note: When we cover machine virtualization, we will see that there’s a third mode for running a hypervisor (a virtual machine manager). Don’t worry about this for now. Also, most Intel

Page 3: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

processors start up in what’s known as real mode, which is a 16-bit 8086-compatible mode with 20-bit addressing. From this mode, the processor can switch to 32-bit or 64-bit mode. Intel processors actually have additional modes but we won’t concern ourselves with them here.

Switching between user and kernel modes

If a processor is running in kernel mode, it can switch itself to user mode by setting the status register that defines its operating mode. Once it is running in user mode, however, it cannot simply set itself to run in kernel mode since that would be a privilege violation.

Traps, also known as software interrupts, let us do the user mode to kernel mode transition. A trap is an instruction that forces the program to jump to a well-known address based on the number of the trap. The trap (or a hardware interrupt, for that matter) acts as a spontaneous subroutine call. The current program counter is pushed on the stack and the program jumps to a well-known address. That address usually contains a jump instruction (vector) to the code that will handle that trap. The action of taking a trap causes the processor to switch from user mode to kernel mode.

The entire set of trap vectors (all the addresses that various parameters to a trap instruction jump to) is set up by the boot loader and can later be modified by the operating system when it starts up. When a user program executes a trap (e.g., INT instruction on older Intel processors; other processors and all current Intel/AMD processors have some form of a syscall instruction), control is transferred to the appropriate trap vector and the processor now runs in kernel mode. Operating system code is run and, when the operating system is ready to transfer control back to the user, it executes a return from exception instruction (IRET on Intel processors). That switches the processor back to user mode operation and transfers control to the address on the top of the stack.

Violations

What happens if a user program tries to execute an instruction that is available only in kernel mode? … Or tries to access a memory location that is not available to it? What generally happens in this case is that a trap takes place. Depending on what happened it would be one of several traps, such as a memory access violation, an illegal instruction violation, or a register access violation. The trap switches the processor’s execution to kernel mode and switches control to the operating system, which then decides on a course of action. The address is defined by the trap vector, which is set up when the operating system starts up.

The attempted operation may have been a valid one, such as accessing a perfectly valid memory location that the operating system just did not load into memory yet. In this case, the operating system would load the needed chunk of memory and restart the instruction (return from exception). If the action was not a valid one, such as attempting to access an invalid memory location, the operating system may send a specific signal to the process. If the process does not have a signal handler for it, it will just be killed. When we look at machine virtualization, we will see that there’s a case where the operating system may need to simulate the action of the privileged instruction and then return control back to the next instruction in the user’s process.

Page 4: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

To summarize, there are several ways where the flow of control switches to the kernel:

1. Via a software trap (interrupt). For example, via an INT instruction or a system call instruction, such as the sysenter on Intel processors, syscall on AMD processors, or swi on ARM processors.

2. Because of an access violation (invalid memory, invalid instruction, etc.).3. Via a hardware interrupt, such as a timer or a network device that is tied to the processor’s

interrupt controller.

Another note: Intel processors before the Core 2 Duo did not generate a trap when a user program tried to execute a privileged instruction; they just ignored it. As we’ll see when we look at virtualization, this made creating a virtual machine a big headache.

The system callA program often needs to read a file, write to some device, or maybe even run another program. All these are require operating system intervention. The interface between the operating system and user programs is the set of system calls (open, close, read, fork, execve, etc). Making a system call uses the trap mechanism to switch to a well-defined point in the kernel, running in kernel mode.

To execute a system call usually involves storing the parameters on a specially created stack, storing the number of the system call (each function has a corresponding number), and then issue a trap to switch control to the operating system operating in kernel mode.

For example, a call to the getpid system call (get process ID) on Intel/Linux systems puts the number 20 into register eax (20 happens to be the number corresponding to the getpid system call) and then executes INT 0x80, which generates a trap.

The kernel will have to be careful to save all user registers and restore everything before it returns.

All this ugliness is hidden from the programmer with a set of library routines that correspond to each of the system calls. The library routines save the parameters, issue the trap, and copy the results back onto the user’s stack so the system call looks exactly like a regular function call.

PreemptionHow do we ensure that the operating system always gets a chance to regain control over the computing environment? For example, we don’t want to have one process spinning in a loop that is keeping the operating system or any other process from getting anything done.

To give the operating system a chance to to run periodically, we program a timer interrupt. On Linux/Intel systems, we set the 8254 (or 8253) Programmable Interval Timer to generate an interrupt (IRQ 0) approximately every 10 milliseconds, although this interval can be modified

Page 5: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

based on the environment. This means that, no matter what is going on with a process, the operating system will receive a periodic interrupt from the timer and get to run. It may do a number of things when it runs: increment a time of day counter; see whether any input is waiting on input devices; see whether any outstanding transmits have completed; and see whether it is time to let another process run. This last decision is called process scheduling and is handled by the scheduler component of the operating system. If several processes are loaded in memory, the operating system can resume any one of them by loading the appropriate process’ saved state into the processor’s registers and executing a return from exception.

An interrupt or trap results in a mode switch. This simply means that the processor is switched from running in user mode to running in kernel mode.

This mode switch is often accompanied by a context switch. A context switch means that the processor’s context (its registers, flags, program counter, stack pointer, memory mapping, etc.) is saved in the kernel’s memory. When the kernel is ready to switch control back to a user process, the scheduler component decides which process gets to have the processor next. It then restores the saved state of the process and returns from the trap. A mode switch does not save and restore the program’s context. A context switch does.

DevicesPeripheral devices are most any hardware that connects to your processor. They could be components built onto the main board or external plug-in devices. Peripherals include input/output devices that interact with the user, such as mice, keyboards, hardware audio codecs, video displays, and printers. They also include mass storage devices such as disk drives, Blu-ray players, and flash memory cards. Other devices include network controllers which allow computers to communicate with other computers over a communications network.

Some devices, such as disks, are addressable. For instance, you may be able to read block 2107 on a disk and later on read that same block again and get the same data. These are called block devices. Block devices lend themselves to caching — storing frequently used blocks in memory to avoid having to fetch them from the actual device, which would take much more time. This operating system cache of frequently used data blocks is called a buffer cache.

Devices such as keyboards, printers, and mice have non-addressable data. They either produce or consume an ever-changing stream of data. Such devices are called character devices. They send and/or receive byte streams and are not suitable for long term caching.

Finally, network devices are similar to character devices (and often lumped in the same category) in that they operate on ever-changing streams of data instead of addressable blocks. They are often put into a separate category because networks are packet-based and send and receive messages instead of arbitrary byte streams. Depending on the type of network and communications employed, some data might be considered special and be sent as expedited packets. Packet schedulers can also affect how packet streams are interleaved on the network link.

Page 6: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

The code for managing a specific device is called a device driver.

Accessing devices

Devices, such as network or USB controllers, come with their own control logic that is usually governed by a microcontroller or some other processor that resides on the device. The control logic supports some form of programming interface to allow the host system to send requests to transmit data, receive data, see if data is ready, write data, read data, seek to a location, or get the status of a device. The actual functions, of course, depend on the device.

An clean way of interacting with peripheral devices is to map the device’s command registers onto the system memory bus. This way, accessing certain memory locations will not reference system memory but instead read and write data to the device registers. The beauty of this scheme is that the programmer can use standard memory load and store instructions. Moreover, the memory protection mechanisms provided by the processor and set up by the operating system now cover device access too. This technique of mapping device input/output to memory is called memory-mapped I/O.

Device registers also tell you when data is ready (e.g., a packet has been received) or if the device is ready for more data (e.g., a packet has been transmitted). We could have our operating system sit in a busy loop and check these registers. Unfortunately, we will chew up tons of processor cycles just waiting for the device and not be able to use the time to do anything else. Instead, whenever we get a periodic clock interrupt (e.g., every 10 milliseconds), we can have the operating system go and check those device registers. That avoids the busy loop.

An alternative, and more popular, approach to this is to have the peripheral device trigger an interrupt whenever the device has data or when the device informs the system that it has finished transmitting and can accept more data. The benefit of an interrupt is that the processor does not have to do any checking until the device pokes it. The downside is that the interrupt will force a mode switch and that may be time consuming. On some systems, it may also invoke a context switch, which is even more costly. On startup, a device driver registers an interrupt handler. Whenever the interrupt takes place, the interrupt handler is invoked and is responsible for handling that interrupt. Since interrupts are precious resources (a processor may have only 16 or so of them), a device driver may sometimes have to share an interrupt line with other device drivers. In this case, the kernel will call each driver that registered that interrupt in sequence.

Moving data between the device and the kernel can also be accomplished by reading and writing the device registers (i.e., reading and writing specific memory locations to which those registers have been mapped). This is called programmed I/O since software is responsible for moving the bytes between main memory and the device via the device’s registers. Some devices support DMA (direct memory access). This is a technique where the device is allowed direct access to system memory and can, on its own, read data from a region of memory or write data to it. The most common use of DMA is for disk access, where the disk controller will read a requested block of data from the disk, transfer it to a specific region of the system’s memory, and then indicate (e.g., via an interrupt) that the operation is complete and the data is ready.

Page 7: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

Files and file systemsIn operating systems, a file is traditionally a collection of data with a name associated with it along with other information (length, create time, access time, owner, users who can modify the file, etc.). In many systems, a file may also refer to a device or even a process. Files are often organized in a hierarchical structure into sets of directories (sometimes referred to as folders, mostly by users of windowing interfaces that adopt a desktop metaphor) and files. A directory is a name of an entity that contains zero or more files or directories. A file system is generally a collection of directories and their files and subdirectories that occupies an entire disk or a defined section of a disk. It is a region of storage upon which the logical structure of file attributes and contents is laid.

The file system is a logical construct – a bunch of data structures – stored on the physical disk. The device driver for the disk sees it simply as a collection of fixed-size blocks that it can read and write. The operating system provides a buffer cache for storing frequently-accessed blocks in memory. The file system is responsible for managing the file system that is implemented on those blocks. Most operating systems support a variety of file systems. For instance, an Apple Mac’s native file system is HFS+ while an SHXC card that’s plugged in from a digital camera is formatted with a Microsoft exFAT file system and a Blu-ray disk will have a UDF (Universal Disk Format, also known as ISO/IEC 13346) file system on it.

When I log in, don’t I type commands to the operating system?Yes, with some systems, mostly older and more primitive ones. With CP/M and early versions of MS-DOS, the console command processor was part of the operating system. Usually, the user’s interface to the system is a command interpreter, also known as a shell or a window manager. On UNIX systems, the name of the shell program is specified for each user in the password file. The shell is run when the user logs in. The windowing system may be spawned from a startup script for that user. The UNIX shell is a little language that supports redirecting input and output from and to other programs and/or files and allows conditional tests, looping constructs, and variable assignments. Together with the standard UNIX system utilities, one can use the shell as a basis for significant programming projects.

What’s a process?A process is ultimately the reason why we have an operating system and the computer and is thus one of the most important concepts in operating systems. A process is essentially a program in execution (one program may correspond to no processes if it’s not running or to several processes if it’s run multiple times). On a multitasking (or multiprogramming) system, several processes appear to run at once. In reality (unless there are multiple processors, in which case it’s also a multiprocessing system) that is not the case. The processor is continually stopping one

Page 8: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

process and starting another, context switching among them. Multitasking works as well as it does because most programs (especially interactive or data intensive ones) spend most of their time sleeping and waiting on input or output. Operating systems that work like this are called time-sharing systems.

Processes may start other processes. A new process becomes a child of the parent process. Processes can be able to send signals to each other, send messages and share data.

Structure of a typical operating system

OS Structure

Using system calls under UNIX systemsAll system calls under the various versions of UNIX (and indeed on just about every other operating system) are enveloped in library functions. To the user they appear no different from any other system library functions. On most UNIX systems (various flavors of Linux, OS X, FreeBSD, OpenBSD, NetBSD), the functions that invoke the system calls are in the library called libc, which also includes non-system call functions (such as printf and strtok). System calls are documented in section 2 of the programming manual and can be found on-line with the man command. For information on using the man command, run man man, which will show the manual page for the man command.

Most system calls return a positive result upon successful completion (check the man page for the particular call you’re using) and a –1 for an error. In the case of an error, a global variable,

Page 9: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

errno, is set to a particular error code. An exhaustive list of error codes is described in the introduction to section 2 of the manual (man 2 intro) and is listed in the include file errno.h (/usr/include/sys/errno.h). The library function (not system call) perror consults a table to print the error as descriptive text. This is often useful for debugging (for info, run man perror). For example, the stat system call gives us information about a file. Running man 2 stat tells us what it does and how to invoke the function (it also refers us to the man page for mknod to find out how to check for the mode of a file). We can write a little program that will loop over each argument and print the file size (in bytes) for that file:

#include <stdio.h> /* for printf */ #include <sys/stat.h> /* stat wants this */ main(int argc, char **argv) { struct stat buf; while (*++argv) /* for each argument… */ if (stat(*argv, &buf) != -1) { if (buf.st_mode & S_IFREG) /* check the mode fo the file */ printf("%s: %lu bytes\n", *argv, (unsigned long)buf.st_size); else printf("%s: not a regular file\n", *argv); } else /* system call failed */ perror(*argv); }

Download this file

Save this file by control-clicking or right clicking the download link and then saving it as stat.c. Compile this program via:

gcc -o stat stat.c

If you don’t have gcc, You may need to substitute the gcc command with cc or another name of your compiler. Run the program:

./stat *

to see info about the files in your current directory. Run the program with an argument that does not correspond to a valid file name to see perror in action.

References Linux Multitasking , Chapter 6, KernelAnalysis-HOWTO, Linux Documentation Project Kernel command using Linux system calls - Explore the SCI and add your own calls, M.

Tim Jones, Consultant Engineer, Emulex IBM developerWorks Technical Library The Implementation of a Linux System Call , Phil Kearns, Fall 2008 Linux Device Drivers , Chapter 9, by Alessandro Rubini & Jonathan Corbet 2nd Edition

June 2001, ISBN 0–59600–008–1

Context switch From Wikipedia, the free encyclopedia

Jump to: navigation, search

Page 10: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

For other uses, see Switch (disambiguation).

This article includes a list of references, but its sources remain unclear because it has insufficient inline citations. Please help to improve this article by introducing more precise citations. (November 2009)

A context switch is the computing process of storing and restoring the state (context) of a CPU so that execution can be resumed from the same point at a later time. This enables multiple processes to share a single CPU. The context switch is an essential feature of a multitasking operating system. Context switches are usually computationally intensive and much of the design of operating systems is to optimize the use of context switches. A context switch can mean a register context switch, a task context switch, a thread context switch, or a process context switch. What constitutes the context is determined by the processor and the operating system. Switching from one process to another requires a certain amount of time for doing the administration - saving and loading registers and memory maps, updating various tables and list etc.

Contents [hide]

1 When to switch? o 1.1 Multitasking o 1.2 Interrupt handling o 1.3 User and kernel mode switching

2 Context switch: steps 3 Software vs hardware context switching 4 References 5 External links

[edit] When to switch?

There are three situations where a context switch needs to occur. They are:

[edit] Multitasking

Most commonly, within some scheduling scheme, one process needs to be switched out of the CPU so another process can run. This context switch can be triggered by the process making itself unrunnable, such as by waiting for an I/O or synchronization operation to complete. On a pre-emptive multitasking system, the scheduler may also switch out processes which are still runnable. To prevent other processes from being starved of CPU time, preemptive schedulers often configure a timer interrupt to fire when a process exceeds its time slice. This interrupt ensures that the scheduler will gain control to perform a context switch.

Page 11: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

[edit] Interrupt handling

Modern architectures are interrupt driven. This means that if the CPU requests data from a disk, for example, it does not need to busy-wait until the read is over; it can issue the request and continue with some other execution. When the read is over, the CPU can be interrupted and presented with the read. For interrupts, a program called an interrupt handler is installed, and it is the interrupt handler that handles the interrupt from the disk.

When an interrupt occurs, the hardware automatically switches a part of the context (at least enough to allow the handler to return to the interrupted code). The handler may save additional context, depending on details of the particular hardware and software designs. Often only a minimal part of the context is changed in order to minimize the amount of time spent handling the interrupt. The kernel does not spawn or schedule a special process to handle interrupts, but instead the handler executes in the (often partial) context established at the beginning of interrupt handling. Once interrupt servicing is complete, the context in effect before the interrupt occurred is restored so that the interrupted process can resume execution in its proper state.

[edit] User and kernel mode switching

When a transition between user mode and kernel mode is required in an operating system, a context switch is not necessary; a mode transition is not by itself a context switch. However, depending on the operating system, a context switch may also take place at this time.

[edit] Context switch: steps

In a switch, the state of the first process must be saved somehow, so that, when the scheduler gets back to the execution of the first process, it can restore this state and continue.

The state of the process includes all the registers that the process may be using, especially the program counter, plus any other operating system specific data that may be necessary. This data is usually stored in a data structure called a process control block (PCB), or switchframe.

In order to switch processes, the PCB for the first process must be created and saved. The PCBs are sometimes stored upon a per-process stack in kernel memory (as opposed to the user-mode call stack), or there may be some specific operating system defined data structure for this information.

Since the operating system has effectively suspended the execution of the first process, it can now load the PCB and context of the second process. In doing so, the program counter from the PCB is loaded, and thus execution can continue in the new process. New processes are chosen from a queue or queues. Process and thread priority can influence which process continues execution, with processes of the highest priority checked first for ready threads to execute.

Page 12: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

[edit] Software vs hardware context switching

Context switching can be performed primarily by software or hardware. Some processors, like the Intel 80386 and its successors,[1] have hardware support for context switches, by making use of a special data segment designated the Task State Segment or TSS. A task switch can be explicitly triggered with a CALL or JMP instruction targeted at a TSS descriptor in the global descriptor table. It can occur implicitly when an interrupt or exception is triggered if there's a task gate in the interrupt descriptor table. When a task switch occurs the CPU can automatically load the new state from the TSS. As with other tasks performed in hardware, one would expect this to be rather fast; however, mainstream operating systems, including Windows and Linux,[2] do not use this feature.

This is due mainly to two reasons:1. hardware context switching does not save all the registers (only general purpose registers, not floating point registers — although the TS bit is automatically turned on in the CR0 control register, resulting in a fault when executing floating point instructions and giving the OS the opportunity to save and restore the floating point state as needed).2. associated performance issues, e.g., software context switching can be selective and store only those registers that need storing, whereas hardware context switching stores nearly all registers whether they're required or not.

[edit] References

1. ̂ http://www.linfo.org/context_switch.html2. ̂ Bovet, Daniel Pierre; Cesatí, Marco (2006). Understa

2. Context Switch Definition3.

A context switch (also sometimes referred to as a process switch or a task switch) is the switching of the CPU (central processing unit) from one process or thread to another.

A process (also sometimes referred to as a task) is an executing (i.e., running) instance of a program. In Linux, threads are lightweight processes that can run in parallel and share an address space (i.e., a range of memory locations) and other resources with their parent processes (i.e., the processes that created them).

A context is the contents of a CPU's registers and program counter at any point in time. A register is a small amount of very fast memory inside of a CPU (as opposed to the slower RAM main memory outside of the CPU) that is used to speed the execution of computer programs by providing quick access to commonly used values, generally those in the midst of a calculation. A program counter is a specialized register that indicates the position of the CPU in its instruction sequence and which holds either the address of the instruction being executed or the address of the next

Page 13: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

instruction to be executed, depending on the specific system.

Context switching can be described in slightly more detail as the kernel (i.e., the core of the operating system) performing the following activities with regard to processes (including threads) on the CPU: (1) suspending the progression of one process and storing the CPU's state (i.e., the context) for that process somewhere in memory, (2) retrieving the context of the next process from memory and restoring it in the CPU's registers and (3) returning to the location indicated by the program counter (i.e., returning to the line of code at which the process was interrupted) in order to resume the process.

A context switch is sometimes described as the kernel suspending execution of one process on the CPU and resuming execution of some other process that had previously been suspended. Although this wording can help clarify the concept, it can be confusing in itself because a process is, by definition, an executing instance of a program. Thus the wording suspending progression of a process might be preferable.

Context Switches and Mode Switches

Context switches can occur only in kernel mode. Kernel mode is a privileged mode of the CPU in which only the kernel runs and which provides access to all memory locations and all other system resources. Other programs, including applications, initially operate in user mode, but they can run portions of the kernel code via system calls. A system call is a request in a Unix-like operating system by an active process (i.e., a process currently progressing in the CPU) for a service performed by the kernel, such as input/output (I/O) or process creation (i.e., creation of a new process). I/O can be defined as any movement of information to or from the combination of the CPU and main memory (i.e. RAM), that is, communication between this combination and the computer's users (e.g., via the keyboard or mouse), its storage devices (e.g., disk or tape drives), or other computers.

The existence of these two modes in Unix-like operating systems means that a similar, but simpler, operation is necessary when a system call causes the CPU to shift to kernel mode. This is referred to as a mode switch rather than a context switch, because it does not change the current process.

Context switching is an essential feature of multitasking operating systems. A multitasking operating system is one in which multiple processes execute on a single CPU seemingly simultaneously and without interfering with each other. This illusion of concurrency is achieved by means of context switches that are occurring in rapid succession (tens or hundreds of times per second). These context switches occur as a result of processes voluntarily relinquishing their time in the CPU or as a result of the scheduler making the switch when a process has used up its CPU time slice.

A context switch can also occur as a result of a hardware interrupt, which is a signal

Page 14: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

from a hardware device (such as a keyboard, mouse, modem or system clock) to the kernel that an event (e.g., a key press, mouse movement or arrival of data from a network connection) has occurred.

Intel 80386 and higher CPUs contain hardware support for context switches. However, most modern operating systems perform software context switching, which can be used on any CPU, rather than hardware context switching in an attempt to obtain improved performance. Software context switching was first implemented in Linux for Intel-compatible processors with the 2.4 kernel.

One major advantage claimed for software context switching is that, whereas the hardware mechanism saves almost all of the CPU state, software can be more selective and save only that portion that actually needs to be saved and reloaded. However, there is some question as to how important this really is in increasing the efficiency of context switching. Its advocates also claim that software context switching allows for the possibility of improving the switching code, thereby further enhancing efficiency, and that it permits better control over the validity of the data that is being loaded.

The Cost of Context Switching

Context switching is generally computationally intensive. That is, it requires considerable processor time, which can be on the order of nanoseconds for each of the tens or hundreds of switches per second. Thus, context switching represents a substantial cost to the system in terms of CPU time and can, in fact, be the most costly operation on an operating system.

Consequently, a major focus in the design of operating systems has been to avoid unnecessary context switching to the extent possible. However, this has not been easy to accomplish in practice. In fact, although the cost of context switching has been declining when measured in terms of the absolute amount of CPU time consumed, this appears to be due mainly to increases in CPU clock speeds rather than to improvements in the efficiency of context switching itself.

One of the many advantages claimed for Linux as compared with other operating systems, including some other Unix-like systems, is its extremely low cost of context switching and mode switching.

Question : Difference between RISC and CISC

Page 15: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

CategoryHardware and Software Design Interview Questions

Rating (0.4) By 593 users

Added on10/13/2005

Views3626

Rate it!

Answers:

RISC-Means Reduced Instruction Set Computer.a Riscsystem has reduced number of instructions and moreimportantly it is load store architecture werepipelining can be implemented easily.Eg.ATMEL AVR

CISC-Means Complex instruction set architecure.A CISCsystem has complex instructions such as directaddition between data in two memory locations.Eg.8085

Submitted by H.Ranga samy ([email protected])

Features of RISC: Uniform instruction format, using a single word with the opcode in the same bit positions in every instruction, demanding less decoding; Identical general purpose registers, allowing any register to be used in any context, simplifying compiler design (although normally there are separate floating point registers); Simple addressing modes. Complex addressing performed via sequences of arithmetic and/or load-store operations; Few data types in hardware, some CISCs have byte string instructions, or support complex numbers; this is so far unlikely to be found on a RISC.

Features of CISC:* complex instruction.* more addressing mode.* Highly pipelined.vice-versa of RISC.

4322

* * * * * Rate

Page 16: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

Posted by: sandeep    

Contact sandeep

RISC CISCUsed by Apple Used by Intel and AMD processorsRequires less registers therefore it is easier to design Slower than RISC chips when performing instructionsFaster that CISC More expensive to make compared to RISCReduced Instruction Set Computer Complex Instruction Set ArchitecturePipelining can be implemented easily Pipelining implementation is not easyDirect addition is not possible Direct addition between data in two memory locations. Ex.8085Fewer, simpler and faster instructions Large amount of different and complex instructionsRISC architecture is not widely used Atleast 75% of the processor use CISC architectureRISC chips require fewer transistors and cheaper to produce. Finally, it's easier to write powerful optimized compilers. In common CISC chips are relatively slow (compared to RISC chips) per instruction, but use little (less than RISC) instructions.RISC puts a greater burden on the software. Software developers need to write more lines for the same tasks. In CISC, software developers no need to write more lines for the same tasksMainly used for real time applications Mainly used in normal PC?s, Workstations and serversLarge number of registers, most of which can be used as general purpose registers CISC processors cannot have a large number of registers.RISC processor has a number of hardwired instructions. CISC processor executes microcode instructions.

Posted by: Gopi Krishnan. D    

Contact Gopi Krishnan. D

RISC-Means Reduced Instruction Set Computer.a Riscsystem has reduced number of instructions and moreimportantly it is load store architecture werepipelining can be implemented easily.Eg.ATMEL AVR

CISC-Means Complex instruction set architecure.A CISCsystem has complex instructions such as direct

Page 17: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

addition between data in two memory locations.Eg.8085

Posted by: NAV    

Contact NAV

risc-risc is reduced instruction set computer .risc is cheaper than cisc because cisc consist of complex instructions,cisc stands for complex instruction set computer.risc reduces the instructions in the computer so coputer takes the speed as fast than cisc,cisc consist instruction more than risc.risc is efficient than cisc.risc& cisk are applicable for all microprocessors

Posted by: nana banagar    

Contact nana banagar

in risc limietd instuction in it. and in cisc many instruction perform by one.

Posted by: sandeep18391    

Contact sandeep18391

CISCRISC

1.Emphasis on hardware.Emphasis on Software.2.Includes multi-clock.Single clock.3.Complex instructions.Reduced instructions only.4.Memory to memory load & store.Register to register load & store.5.Incorporated in instructions.Are independent instructions.

Page 18: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

6.Small Code Sizes.Large Code Sizes.7.High Cycles per second.Low cycles per second.8.Transistors used for storing complex instructions.Spends more transistors on memory registers.

Posted by: Cheenu Gawri    

Contact Cheenu Gawri

RISC: REDUCED INSTRUCTION SET COMPUTERThe concept of RISC architecture involves an attempt to reduce execution time bye simplifying the instruction set of the computer . the major characteristics of a RISC processor are:1 relatively few instructions2 relatively few addressing modes 3 memory access limited to load and store instructions4 all operations done within the registers of the CPU5 fixed length, easily decoded instruction format6 single-cycle instruction execution.7 hardwired rather than microprogrammed control

CISC :COMPLEX INSTRUCTION SET COMPUTERA computer with a large number of instruction is classified as a complex instruction set computer,abbreviated CISC.Before the RISC philosophy became prominent, many computer architects tried to bridge the so called semantic gap, i.e. to design instruction sets that directly supported high-level programming constructs such as procedure calls, loop control, and complex addressing modes, allowing data structure and array accesses to be combined into single instructions. Instructions are also typically highly encoded in order to further enhance the code density

Posted by: dev malhotra    

Contact dev malhotra

risc means reduced instruction set of

Page 19: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

computer where as in cisc are complexinstruction set of computer where asthe risc is cheeper than cisc

Posted by: Raza Muhammad khan pathan    

Contact Raza Muhammad khan pathan

If you have the better answer, then send it to us. We will display your answer after the approval. Rules to Post Answers in CoolInterview.com:-

There should not be any Spelling Mistakes. There should not be any Gramatical Errors. Answers must not contain any bad words.

Answers should not be the repeat of same answer, already approved. Answer should be complete in itself.

Name :*

Sample Functional Description: Register FunctionsCraig Borysowich | Jan 7, 2009 | Comments (0)

in Share

0

x.x.x.x Calculate Amount Due

This function provides both the clerk and the customer with the total amount payable for the sale. The primary output is a display of the total on the operator and customer displays. This function can be invoked by either the TOTAL or SUBTOTAL key. The difference in the system's response is as follows:

SUBTOTAL - the amount owing is displayed,

- system continues where it left off.

TOTAL - the amount owing is displayed,

- total lines are printed,

- tender may be entered or the clerk may continue entering more items.

4322

Page 20: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

In addition, this function is automatically invoked any time payment fails to cover the amount owing (i.e., multiple tenders).

If the operator encounters an error while processing this function, the clear/validate key can be used to return to the previous operator prompt.

Triggers: Request to calculate amount due,

Insufficient payment entered.

Dataflows: Input - TOTAL REQUEST

Output - TOTAL DISPLAY

AMOUNT DUE LINES

AMOUNT DUE DETAILS

Datastores: Input - NONE

Output - RECEIPT/TRANSACTION JOURNAL

TRANSACTION LOG

Security: Calculate amount due is a clerk function and is restricted to those with the security of clerk and above, excluding the auditor.

Online Processing:

# Processing Operator Display Customer Display1. Once the clerk has finished entering the item being

sold, he/she presses the TOTAL key (or SUBTOTAL if more items need to be entered). The 9999 is the employee number of the clerk signed on.

DESCRIPTION

99 9999.99

9999.99

2. The system prints a total line with an amount equal to the sale price of all items, less any discounts or allowances entered.

   

3. The system displays the amount due for the sale.    

4. The clerk may continue with another transaction or may tender the sale.

   

Offline Processing:

When the store controller is offline, there will be no deviations from the normal online processing.

Technorati Profile Blog Weblog Directory     

Page 21: Operating System Concepts - gcdeeplove.files.wordpress.com  · Web viewThese resources include the CPU (process scheduling), memory (memory management), display, keyboard, mouse

Comment on this article

Popular White Paper On This Topic  2011 Trends Report: Customer Relationship Management

Related White Papers  Oracle Solaris and Sun SPARC Systems - Integrated and ...  Oracle Solaris Optimized for Sun x86 Systems in the ...  2010 Essential Features of Manufacturing ERP Software

More   White   Papers

Leave a Comment

 Connect to this blog to be notified of new entries.

 

You are not logged in.

 Sign In to post unmoderated comments.

 Join the community to create your free profile today.

Want to read more from Craig Borysowich? Check out the blog archive.

Archive Category: Business Analysis

Keyword Tags:  Sample   Functional   Description   Register   Functions

Disclaimer: Blog contents express the viewpoints of their independent authors and are not reviewed for correctness or accuracy by Toolbox for IT. Any opinions, comments, solutions or other commentary expressed by blog authors are not endorsed or recommended by Toolbox for IT or any vendor. If you feel a blog entry is inappropriate, click here to notify Toolbox for IT.

Browse   all   IT   Blogs

Ads by Google

what's this?

Convert XLS to TXT FilesYou specify column widths in textfile. 20 times faster than Excel.Softinterface.com/Convert-XLS-2-TXT

Top 20 ERP SoftwareGet Free ERP evaluation reportsfor software selections, comparisonERP.TechnologyEvaluation.com

TI Bare Die DistributionYour Value Added Supplier of TIBare Die, Wafer and Much More.www.micross.com

IT Architecture PodcastCritical Enterprise ArchitectureJust listen in, it's freeCea.podbean.com

IT services

Name Your email address

Submit

PREVIEW