Questions tagged [context-switch]

A context switch is the process of storing and restoring the state (context) of a process.

In computing, a context switch is the process of storing and restoring the state (context) of a process so that execution can be resumed from the same point at a later time. This enables multiple processes to share a single CPU and is an essential feature of a multitasking operating system. What constitutes the context is determined by the processor and the operating system.

313 questions
155
votes
9 answers

Thread context switch Vs. process context switch

Could any one tell me what is exactly done in both situations? What is the main cost each of them?
Leon
  • 8,151
  • 11
  • 45
  • 51
83
votes
3 answers

Context switch internals

I want to learn and fill gaps in my knowledge with the help of this question. So, a user is running a thread (kernel-level) and it now calls yield (a system call I presume). The scheduler must now save the context of the current thread in the TCB…
Bruce
  • 33,927
  • 76
  • 174
  • 262
76
votes
4 answers

simplest tool to measure C program cache hit/miss and cpu time in linux?

I'm writing a small program in C, and I want to measure it's performance. I want to see how much time do it run in the processor and how many cache hit+misses has it made. Information about context switches and memory usage would be nice to have…
jperelli
  • 6,988
  • 5
  • 50
  • 85
57
votes
2 answers

System call and context switch

I am sorry to ask this question when it has already been asked but I couldn't get a clarity from them. So I am asking the following related questions to get the difference between system call (mode-switch) and context switch Why is it said that…
vjain27
  • 3,514
  • 9
  • 41
  • 60
56
votes
4 answers

Steps in Context Switching

I am asked to describe the steps involved in a context switch (1) between two different processes and (2) between two different threads in the same process. During a context switch, the kernel will save the context of the old process in its PCB and…
raphnguyen
  • 3,565
  • 18
  • 56
  • 74
36
votes
4 answers

What is the overhead of a context-switch?

Originally I believed the overhead to a context-switch was the TLB being flushed. However I just saw on wikipedia: http://en.wikipedia.org/wiki/Translation_lookaside_buffer In 2008, both Intel (Nehalem)[18] and AMD (SVM)[19] have introduced tags…
user997112
  • 29,025
  • 43
  • 182
  • 361
31
votes
1 answer

How does schedule()+switch_to() functions from linux kernel actually work?

I'm trying to understand how the schedule process in linux kernel actually works. My question is not about the scheduling algorithm. Its about how the functions schedule() and switch_to() work. I'll try to explain. I saw that: When a process runs…
derf
  • 391
  • 1
  • 5
  • 8
27
votes
6 answers

Write a C program to measure time spent in context switch in Linux OS

Can we write a c program to find out time spent in context switch in Linux? Could you please share code if you have one? Thanks
Gautham
  • 3,418
  • 3
  • 30
  • 41
18
votes
1 answer

Cost of context switch between threads of same process, on Linux

Is there any good empirical data on the cost of context switching between threads of the same process on Linux (x86 and x86_64, mainly, are of interest)? I'm talking about the number of cycles or nanoseconds between the last instruction one thread…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
17
votes
3 answers

System calls overhead

I just started studying about system calls. I would like to know what causes overhead when a system call is made. For example, if we consider getpid(), when a system call is made to getpid() my guess is that if the control is…
16
votes
1 answer

MultiCore CPUs, Multithreading and context switching?

Let's say we have a CPU with 20 cores and a process with 20 CPU-intensive independent of each other threads: One thread per CPU core. I'm trying to figure out whether context switching happens in this case. I believe it happens because there are…
Ivan Voroshilin
  • 5,233
  • 3
  • 32
  • 61
15
votes
4 answers

What is saved in a context switch?

What is exactly saved and restored in a context switch between two threads in the same process between two processes
Nizar Grira
  • 743
  • 2
  • 7
  • 21
13
votes
1 answer

(Writing kernel) How do I modify the interrupt descriptor table?

I am writing a small kernel just to poke around the low level stuff a bit. Right now, it boots in Virtual Box and I can display text to the screen, allocate some memory, and other really basic things. It's written in C++ and a little asm. One of…
rovaughn
  • 1,213
  • 15
  • 24
12
votes
2 answers

What is a kernel stack used for?

The following is a description I read of a context switch between process A and process B. I don't understand what a kernel stack is used for. There is suppose to be a per process kernel stack. And the description I am reading speaks of saving…
user782220
  • 10,677
  • 21
  • 72
  • 135
12
votes
6 answers

Cause of involuntary context switches

I'm trying to profile a multithreaded program I've written on a somewhat large machine (32-cores, 256GB RAM). I've noticed that between runs, the performance of the program can vary drastically (70-80%). I can't seem to find the cause of this…
nomad
  • 1,809
  • 2
  • 18
  • 33
1
2 3
20 21