FACTOID # 6: Michigan is ranked 22nd in land area, but since 41.27% of the state is composed of water, it jumps to 11th place in total area.
 
 Home   Encyclopedia   Statistics   States A-Z   Flags   Maps   FAQ   About 
   
 
WHAT'S NEW
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Context switch

A context switch is the computing process of storing and restoring the state (context) of a CPU such that multiple processes can share a single CPU resource. 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. RAM (Random Access Memory) Look up computing in Wiktionary, the free dictionary. ... In information processing, a state is the complete set of properties (for example, its energy level, etc. ... There are very few or no other articles that link to this one. ... “CPU” redirects here. ... In computing, a process is an instance of a computer program that is being executed. ... In computing, multitasking is a method by which multiple tasks, also known as processes, share common processing resources such as a CPU. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning that the CPU is... An operating system (OS) is the software that manages the sharing of the resources of a computer and provides programmers with an interface used to access those resources. ... An operating system (OS) is the software that manages the sharing of the resources of a computer and provides programmers with an interface used to access those resources. ... For the form of code consisting entirely of subroutine calls, see Threaded code. ...

Contents

When to switch?

There are three scenarios where a context switch needs to occur.


Multitasking

Most commonly, within some scheduling scheme, one process needs to be switched out of the CPU so another process can run. Within a preemptive multitasking operating system, the scheduler allows every task to run for some certain amount of time, called its time slice. Scheduling is a key concept in computer multitasking and multiprocessing operating system design, and in real-time operating system design. ... Pre-emptive multitasking is a form of multitasking in which processes are not allowed to take an indefinitely long time to complete execution in the CPU. Each process, in turn, is granted a portion of CPU time (usually called a time slice, on the order of milliseconds). ... Pre-emption as used with respect to operating systems means the ability of the operating system to preempt or stop a currently scheduled task in favour of a higher priority task. ...


If a process does not voluntarily yield the CPU (for example, by performing an I/O operation), a timer interrupt fires, and the operating system schedules another process for execution instead. This ensures that the CPU cannot be monopolized by any one processor-intensive application. Energy Input: The energy placed into a reaction. ...


Interrupt handling

Some architectures (like the Intel x86 architecture) 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. Intel Corporation (NASDAQ: INTC, SEHK: 4335), founded in 1968 as Integrated Electronics Corporation, is an American multinational corporation that is best known for designing and manufacturing microprocessors and specialized integrated circuits. ... x86 or 80x86 is the generic name of a microprocessor architecture first developed and manufactured by Intel. ... In computing, an interrupt is an asynchronous signal from hardware or software indicating the need for attention. ... To wait for an event by iterating through a tight loop or time-delayed loop that polls for the occurrence of the event on each pass rather than calling an interrupt and continuing execution on another part of the process. ... An interrupt handler, also known as an interrupt service routine, is a subroutine in an operating system or device driver whose execution is triggered by the reception of an interrupt. ...


Clearly, there is a necessity to switch contexts when issuing interrupts - the state of the currently running process must be suspended so that the interrupt handler can be executed.


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. User mode refers to two similar concepts in computer architecture. ... In processors with memory protection, kernel mode (as opposed to user mode) is the mode in which the operating system kernel runs. ...


Context switch: steps

In a context 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 normally.


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. Often, all the data that is necessary for state is stored in one data structure, called a switchframe or a process control block. The program counter (also called the instruction pointer in some computers) is a register in a computer processor which indicates where the computer is in its instruction sequence. ... A Process Control Block (PCB, also called Task Control Block or Task Struct) is a data structure in the operating system kernel containing the information needed to manage a particular process. ...


Now, in order to switch processes, the switchframe for the first process must be created and saved. The switchframes are sometimes stored upon a per-process stack in kernel memory (as opposed to the user-mode stack), or there may be some specific operating system defined data structure for this information. Look up stack in Wiktionary, the free dictionary. ...


Since the operating system has effectively suspended the execution of the first process, it can now load the switchframe and context of the second process. In doing so, the program counter from the switchframe is loaded, and thus execution can continue in the new process.


Software vs hardware context switching

Context switching can be performed primarily by software or hardware. Some processors, like the Intel 80286 and higher CPUs, have hardware support for context switches, by making use of a special data segment designated the Task State Segment or TSS. When a task switch occurs (implicitly due to a CALL instruction, referring to a task gate, or explicitly due to an interrupt or exception) the CPU can automatically load the new state from the TSS. With other tasks performed in hardware, one would expect this to be rather fast; however, mainstream operating systems, including Windows, do not use this feature. This is due mainly to two reasons: that 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, which gives the OS the opportunity to do saving and restoring of the floating point state), and associated performance issues. AMD 80286 at 12 MHz. ... The Task State Segment is a special x86 structure which holds information about a task. ... “CPU” redirects here. ... “Windows” redirects here. ... A floating-point number is a digital representation for a number in a certain subset of the rational numbers, and is often used to approximate an arbitrary real number on a computer. ... A control register is a processor register which changes or controls the behavior of a CPU or other digital device. ...


Some architectures contain logic to allow several hardware contexts to exist simultaneously, eliminating the need to store and restore the CPU context to memory on context switch. The extreme case is the barrel processor architecture, which switches between threads of execution on every cycle. A barrel processor is a CPU that switches between threads of execution on every cycle. ...


External Links

  • Context Switch Definition - by The Linux Information Project (LINFO)

  Results from FactBites:
 
Context Switch definition (928 words)
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 context switch can also occur as a result of a hardware interrupt, which is a signal 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.
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.
Context switch - definition of Context switch in Encyclopedia (697 words)
A context switch is the computing process of storing and restoring the state of a CPU (the context) such that multiple processes can share a single CPU resource.
Context switches are usually computationally intensive and much of the design of operating systems is to optimize the use of context switches.
In a context switch, the state of the first process must be saved somehow, so when the scheduler gets back to the execution of the first process, it can restore this state and continue normally.
  More results at FactBites »

 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m