HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Do system calls always means a context switch?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
callssystemalwaysmeanscontextswitch

Problem

When a system call takes place some kernel code must be executed. If some kernel code is being executed it means it can alter register values. So before this code gets executed the old process state must be saved. This is called context switch.
Now Wikipedia says that not all system calls need context switch. How is this possible?

Solution

A system call does not necessarily require a context switch in general, but rather a privilege switch. This is because the kernel memory is mapped in each process memory. The user process cannot access the kernel's memory because the memory mapping indicates which part are for the user and which parts are for the system. Thus a system call is really just a change of privilege, not of process. On some systems, like micro-kernels, a system call may involve a context switch because drivers are in a different process. But on monolithic systems like Linux this is not necessary. Linux also supports what is called the vDSO to implement some system calls entirely in userspace.

EDIT: attached a picture

Context

StackExchange Computer Science Q#83246, answer score: 17

Revisions (0)

No revisions yet.