03 say Basics: CPU context switches often said what that means (a)

1, multi-task CPU competition, CPU transformed task context switching when a CPU (context switch). CPU tasks There are four ways: processes, threads, or cause interruption of the hardware signal by triggering calls.
2, when the task switching, record the current status of the task requires access to information and the task and the address of the next (pointer), which is the content of the context. Thus, context refers to the contents of the CPU registers at a time point (Register CPU) and a program counter (PC), and further comprising broadly virtual address mapping information in the memory processes.
3, during a context switch:
(1) Record the current task context (i.e., registers and all state calculator);
(2) to find and load the new task context;
(3) switches to a new task program counter position, to restore its tasks.
4. The form of execution of tasks, the above respective switches with process context switching, thread context switching, and three interrupt context switch.
5, the difference between processes and threads:
the process is the basic unit of resource allocation and execution; thread is the basic unit of task scheduling and running. Thread does not have resources to provide pointers to process virtual memory, stack, variables and other shared resources, and threads can share resources processes.
6, a process context switch: switching means from one process to another.
(1) processes running state and the state is running a kernel process runnable. Kernel space mode resource comprises a kernel stack, registers and the like; user space - resource comprises a virtual memory, stacks, variables, text, data, etc.
(2) system call (software interrupt) in kernel mode is completed, the need for secondary CPU context switching (user space -> kernel space -> user space), the user does not involve state resources, nor does switching process.
(3) the process is scheduled and managed by the kernel, the process switching can occur only in the kernel mode. Therefore, the context of the process includes not only the resource user space, including kernel space resources.
Context (4) the process of handover process:
(a) receiving a switching signal to suspend the process, the recording current process virtual memory, and other resources stored in the stack;
(B) the state of the process in the CPU context stored in it;
(C) and then retrieves the next in memory context of the process;
(D) and loaded into a register of the CPU recovery;
(3) virtual memory and also to refresh the user process stack;
(F) jumps to the last location pointed to by the program counter (i.e., jump to lines of code when the process is interrupted) to restore the process.
(5), the following process will trigger a context switch scenarios:
(A), according to a scheduling policy, the dicing is CPU time slice corresponding to a time when the time slice is exhausted, the current process must be suspended.
(b), lack of resources, before obtaining sufficient resources to process hangs.
(c), the process hangs sleep process.
(D), high-priority process causes the current progress of the suspended
(E), a hardware interrupt, causes the current process to hang
7, thread context switching:
(1), the barrier between the thread context switching processes, which processes and process context switch roughly the same.
(2), into the threads within a process context switch. User resource without switching process, only need to switch thread private data and registers. This process will be less than the process context switching consumes resources, so compared to the advantages of multi-threaded multi-process.
8, the interrupt context switch
incident rapid response to hardware interrupts normal scheduling and execution process will interrupt the process. The same CPU, hardware interrupt higher priority than process. Switching process is similar to the system calls when the user runs do not involve state resources. But a lot of the same interrupt context switching can cause performance problems.

Guess you like

Origin www.cnblogs.com/xiaobao2/p/11592315.html