Questions tagged [preemption]
131 questions
5
votes
3 answers
Why is Go considered partially preemptive?
I am trying to get a better understanding of the definition preemptive and cooperative in the context of Go. Wiki states for preemptive multitasking
In computing, preemption is the act of temporarily interrupting an executing task, with the…

HelloWorld
- 2,392
- 3
- 31
- 68
5
votes
2 answers
What is the difference between nonpreemptive and preemptive kernels, when switching to user mode?
I'm reading "Understanding the Linux Kernel, 3rd Edition", and in Chapter 5, Section "Kernel Preemption", it says:
All process switches are performed by the switch_to macro. In both preemptive
and nonpreemptive kernels, a process switch occurs…

Mano Mini
- 607
- 4
- 15
5
votes
0 answers
Count number of preemption for a running process in Linux
Is there any way to count preemption for specific PID from user space ? I am interested to measure how many times a process is preempted.

ARH
- 1,355
- 3
- 18
- 32
5
votes
1 answer
Linux HZ and fair schedule timeslice
In sched_fair.c it has:
unsigned int sysctl_sched_latency = 5000000ULL //5m
unsigned int sysctl_sched_min_granularity = 1000000ULL //1ms
I understand that Linux fair timeslice varies depending on the nr_running and the relative weight of this…

HelloYou
- 51
- 4
5
votes
2 answers
SCHED_FIFO thread is preempted by SCHED_OTHER thread in Linux
I have written a test program to test out SCHED_FIFO. I have learnt that SCHED_FIFO cannot be preempted by SCHED_OTHER threads. But I couldn't explain the results obtained when same program is run multiple times.
/* Includes */
#include …

GoT
- 530
- 1
- 13
- 35
5
votes
2 answers
How can I avoid preemption of my thread in user mode
I have a simple chunk of deterministic work that only takes thirteen machine instructions to complete. Because the first instruction takes a homemade semaphore (spinlock) and the last instruction releases it, I am safe from all of the other threads…

wapadomo
- 57
- 1
- 5
4
votes
1 answer
Is it safe to use rcu_dereference() inside local_bh_disable()/local_bh_enable()?
The local_bh_disable-function changes per-cpu (in case of x86 and recent kernels) __preempt_count or current_thread_info()->preempt_count otherwise.
Anyway that gives us a grace period, so we can assume that it will be redundant to do…

red0ct
- 4,840
- 3
- 17
- 44
4
votes
1 answer
When does preempt_count() & PREEMPT_ACTIVE == 0?
I am looking at scheduler code in Linux:
if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
if (unlikely(signal_pending_state(prev->state, prev))) {
prev->state = TASK_RUNNING;
} else {
deactivate_task(rq, prev,…

Saksham Jain
- 537
- 3
- 14
4
votes
2 answers
How RCU reader section is protected from preemption?
(From an article on LWN)
1 rcu_read_lock();
2 list_for_each_entry_rcu(p, head, list) {
3 do_something_with(p->a, p->b, p->c);
4 }
5 rcu_read_unlock();
The RCU update operation will do synchronize_rcu() in order to assert each CPU switched…

4pie0
- 29,204
- 9
- 82
- 118
4
votes
1 answer
Why in linux kernel radix_tree_preload returns with preemption disabled
I was going through an article on linux kernel radix tree implementation, link of article is mentioned below:
http://lwn.net/Articles/175432/
In this article it mentions that radix_tree_preload allocates sufficient memory so that the subsequent…

pastum
- 609
- 1
- 5
- 4
4
votes
3 answers
Sleeping in the kernel using set_current_state
I've been reading http://www.linuxjournal.com/article/8144 and thinking about the following situation:
4253 /* Wait for kthread_stop */
4254 set_current_state(TASK_INTERRUPTIBLE);
4255 while (!kthread_should_stop()) {
4256 …

rmn
- 2,386
- 1
- 14
- 21
3
votes
1 answer
Why do kprobes disable preemption and when is it safe to reenable it?
According to the docs, kprobes disable preemption:
Probe handlers are run with preemption disabled. Depending on the
architecture and optimization state, handlers may also run with
interrupts disabled (e.g., kretprobe handlers and optimized…

Georg Schölly
- 124,188
- 49
- 220
- 267
3
votes
2 answers
C - select() seems to block for longer than timeout
I am writing a data acquisitioning program that needs to
wait for serial with select()
read serial data (RS232 at 115200 baud),
timestamp it (clock_gettime()),
read an ADC on SPI,
interpret it,
send new data over another tty device
loop and…

Stefan Hartman
- 41
- 1
- 4
3
votes
2 answers
Why a "barrier()" is enough for disabling or enabling the preemption?
From Linux kernel code,I can see the preempt_enable() and preempt_disable() are nothing except just barrier():
#define preempt_disable() barrier()
#define preempt_enable() barrier()
I can't understand it. Why just a barrier() is…

Nan Xiao
- 16,671
- 18
- 103
- 164
3
votes
1 answer
Measure time a task spends between 2 points in linux (task profiling)
I'll soon start banging my head on the wall:
It's very simple really, I want to measure the time a task spends between 2 points (in Linux - 1 core - 1 CPU).
During this time the task must have total control over the CPU and NOT get interrupted by…

fakr00n
- 103
- 6