1

When a user process performs a system call, a kernel process gets invoked. Now how does this NOT result in a context switch ? Since the kernel process is different from a user process . Or Am I wrong in saying that a kernel routine (invoked by system call) and user processes belong to the same process ?

artless noise
  • 21,212
  • 6
  • 68
  • 105
Sharat Chandra
  • 4,434
  • 7
  • 49
  • 66

1 Answers1

2

'When a user process performs a system call, a kernel process gets invoked' - not really, kernel code gets invoked. Any system call will inevitably result in a protection context change - a ring-cycle. How deep this gets depends on the call. If the call reaches ring 0, the kernel code there has access to all user and kernel threads, so the kernel code there cannot, in general, be described as a 'process' - something that has a memory-management/security context to provide protection. Typically, a ring-cycle to/from ring 0 takes 2000+ cpu-cycles, (except in German operas, where it takes three days). This overhead is absolutely required whether or not the system-call results in a thread context switch and/or process-context switch.

In those cases where the system call results in changing the set of running threads, there will be the extra overhead of a thread-context switch, especially if the change requires preemption of a thread that is running on another processor.

If any newly-running thread belongs to a different process than the preempted thread, there is the yet heavier overhead of a process-context switch.

Martin James
  • 24,453
  • 3
  • 36
  • 60
  • So is the kernel code part of the binary/executable image of the user process ? Does the kernel code become part of the user process binary file during linking ? – Sharat Chandra Feb 02 '12 at 01:58
  • 1
    The details of OS linking are OS-dependent. Typically, a build-time library is linked in that provides the OS access at runtime, eg. by dynamic linking with a DLL. So, the code to access the kernel becomes part of the binary executable file and the actual kernel code is shared by all processes. – Martin James Feb 02 '12 at 10:37