Vous êtes sur la page 1sur 6

A Survey Paper on Context Switching

Muhammad Q Shahzad
CIS-657 Term Paper
Syracuse University
mqshahza@syr.edu

1.Abstract
This paper will highlight the issues pertaining to context switching and some of the ways that
we can minimize the impact and create an optimized process execution while doing a context
switch that will increase the efficiency based on the previous research. In Hope of doing some
of the previous research and conclusions are quoted and don’t give a bright picture in this
regard.

2.Introduction:
The context switching plays an important part in the process lifecycle and where the processes
need to be run and complete quickly and efficiently. Real time environment processes are more
time constraint. Real-time systems require the deadline to be achieved for the processes. If the
overhead cost is decreased the process will have high performance. Systems failing to meet the
constraint can become fatal failure. The context switch is a switch that is required for the queue
to keep moving and without this functionality defined, the system could be lost, hence context
switch plays an important role in process execution.

3. Context Switch:
Switching the processor from the Kernel to the process A and vice versa from process A to the
kernel is context switching [1]. In the Operating system it is the switching of the CPU from a
process to another process. In embedded systems it is the process of storing the state of the
process that can be restored or executed from the same point later, this will allow the
processes to share a single CPU.

1
It Saves the registers of the old process in the process table entry for it. Registers R1-R5, the
stack pointer, the program counter, and the process status are all saved.. In Xinu Operating
system it is identified as ctxsw.
ctxsw (oldRegArea, newRegArea),

Process resumption and suspension are implemented by the procedures resume and suspend.
it saves the return address of ctxsw. Thus, when the old process is resumed, it starts executing
after the statement in Resched that calls ctxsw. The stack pointer must be adjusted to make it
look as if a return from ctxsw occurred.
The diagram below illustrates the process of context switching.

Figure 1: Example of a context switch

2
3. Context Switch Process improvement
analysis:
There are multiple analysis that have been done to show the possibility of the improvement in
performance in context switching and the ways it affects the process and the processor, the time
it will take , the clock cycle , input and output from the user, all of these will be taken into effect.
The processes that are less CPU intensive and are also called lightweight processes will share the
address space with the high CPU intensive processes . The context switch between two
lightweight processes will reduce in this environment will reduce the amount of state necessary
to save and restore [2] but it will still cost to save and restore.
According to another research done by Agarwal[3] large caches suffered considerable
performance loss when forced to purge their contents after each context switch, whereas small
caches did not suffer as much. As in the research above with the lightweight and the heavy
weight processes, it correlates this research.

There is another possibility that a data flow analysis that will could be done to identify the dead
registers that are not in use will introduce a concept of Fast context switching that will in turn
provide more efficiency with register remapping that is used by a live range optimization
allocated to a scratch register.
The register transfer represents a change in the machine's state, and instructions which cause
more than one state change are represented by lists of register transfers. [4]
In this research [6],direct time cost per context switch where processes make no data access was
measured and the the total time cost per context switch that includes the direct cost of restoring
cache state. The overall data size has a substantial impact on the cost of the context if it is larger
then the cache size [5], based on this study , the environment where this research was done
played a significant role as well.As illustrated in the final execution graph below that identifies
the performance of the context switch when the Array size is in between 0 -2048 with cache size
of 512 KB and the context switch time ranges from 0 - 1500

3
The effect of access stride on the cost of context switch

To increase the efficiency for the [7]context switching selective context switching is utilized as it
makes decision at the point between a request for handling I/O requests in the process context
and the activation of the device in the kernel context. An illustration of this concept can be seen
below:

Figure 3 : Selective Context Switching

ARM Cortex-M3 processor achieves a shorter context switch time [8]. In this research The figure
below illustrates the improvement in time by using this processor and also g Task Yielding in a
Priority-based Scheduler.This processor uses a hardware based trap for the context switching , the
software traps have their own overheads. But using the task yielding algorithm with the hardware trap
the performance was increased.

4
Figure 4: Experimental result of context switching

This task yielding algorithm that was utilized in the study is as follow:

Figure 5: Task yielding algorithm

Conclusion:

Based on the papers surveyed above and the research the context switching is expensive and
the cost is really difficult to reduce, the CPU overhead cannot be reduced but using multiple
threads can decrease only the saving and restoring the register states but will still impact the
overall performance. In the selective context switching scheme that increase the performance ,
but flash memory was utilized. Also when the hardware based trap for context based switching is
utilized the performance is greatly increased. If the performance of the context switching can be

5
increased based on the Operating systems , it will result in the system performance that we have never
imagined

Reference:
[1] An Operating Systems Vade Mecum Raphael A. Finkel University of Wisconsin at Madison

[2] Shem-Tov Levi and Ashok K. Agrawala, Real-Time Systems Design, McGraw{Hill, 1990.

[3] Gary J. Nutt, Centralized and Distributed Operating Systems, Prentice{Hall, Inc., 1992.

[4] Anant Agarwal, John Hennessy, and Mark Horowitz, \Cache Performance of Operating System and
Multiprogramming Workloads", ACM Transactions on Computer Systems, November 1988, 6(4):393{431.

[5] Jack W. Davidson and David B. Whalley, \A Design Environment for Addressing Architecture and
Compiler Interactions", Microprocessors and Microsystems, November 1991, 15(9):459{472.

[6] Chuanpeng Li,Chen Ding,Kai Shen \ Quantifying The Cost of Context Switch ,” D.4.8 [Operating
Systems]: Performance—Measurements; C.4 [Computer Systems Organization]: Performance of
Systems—Measurement techniques”

[7] Sehwan Lee, Seunghwan Hyun, \ Selective Context Switching Scheme on Flash Memory , “2009
International Conference on Computational Science and Its Applications”

[8] Evaluations of Hardware and Software-Based Context Switching Methods in Cortex-M3 for Embedded
Applications \ Hayeon Choi and Sangsoo Park , ” International Journal of Smart Home Vol. 9, No. 2 (2015),
pp. 111-122 “

Vous aimerez peut-être aussi