scheduling with spinlocks held ?
Hi,
Is it safe to assume that the kernel will not preempt a process when its holding a spinlock ? I know most parts of the code make sure they dont yield the cpu when they are holding spinlocks, but I was just curious if there is any place that does that.
Basically, the context is, I need to change the scheduler a bit to implement "perfect nice -19" semantics, i.e. give cpu to nice 19 process only if no other normal process is ready to run. I am wondering if there is a possibility of priority inversion if the nice-d process happens to yield the cpu and then never get scheduled because a normal process is spinning on the lock.
thanks for any input,
Muthian.
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
Quoted 5 lines · Muthian Sivathanu
Is it safe to assume that the kernel will not preempt a process when its holding a spinlock ? I know most parts of the code make sure they dont yield the cpu when they are holding spinlocks, but I was just curious if there is any place that does that.
Correct.
Quoted 8 lines
Basically, the context is, I need to change the scheduler a bit to implement "perfect nice -19" semantics, i.e. give cpu to nice 19 process only if no other normal process is ready to run. I am wondering if there is a possibility of priority inversion if the nice-d process happens to yield the cpu and then never get scheduled because a normal process is spinning on the lock.
You will hit priority inversion... not with spinlocks but with semaphores (and possibly more subtle issues).
The only safe way to do this safely is to boost the task's priority out of the "idle" class when the task is inside the kernel.
It is nontrivial to juggle user vs. kernel returns such as that. Google for Ingo Molnar's SCHED_BATCH addition to the O(1) scheduler.
Robert Love
thanks for the pointers !
in general, would it make sense to explicitly distinguish between mutex semaphores and others (maybe for producer consumer queues), i.e. have a separate structure mutex_semaphore with its own up() and down()
-- this will probably facilitate more fine grained
handling of such priority inversion problems since one can accurately track the number of mutexes, if any, that a process is holding at any given point ?
Muthian.
Quoted 37 lines · --- Robert Love
Quoted 1 line · Muthian Sivathanu
Is it safe to assume that the kernel will not
preempt
Quoted 1 line
a process when its holding a spinlock ? I know
most
Quoted 1 line
parts of the code make sure they dont yield the
cpu
Quoted 2 lines
when they are holding spinlocks, but I was just curious if there is any place that does that.
Correct.
Quoted 3 lines
Basically, the context is, I need to change the scheduler a bit to implement "perfect nice -19" semantics, i.e. give cpu to nice 19 process only
if no
Quoted 1 line
other normal process is ready to run. I am
wondering
Quoted 1 line
if there is a possibility of priority inversion if
the
Quoted 1 line
nice-d process happens to yield the cpu and then
never
Quoted 1 line
get scheduled because a normal process is spinning
on
Quoted 1 line
the lock.
You will hit priority inversion... not with
spinlocks but with
semaphores (and possibly more subtle issues).The only safe way to do this safely is to boost the task's priority out
of the "idle" class when the task is inside the kernel.
Quoted 8 lines
It is nontrivial to juggle user vs. kernel returns such as that. Google
for Ingo Molnar'sSCHED_BATCHaddition to the O(1) scheduler.Robert Love
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
Hi,
Is there a version of Ingo Molnar's patch for the 2.4 line kernels ?
thanks,
Muthian.
Quoted 37 lines · --- Robert Love
Quoted 1 line · Muthian Sivathanu
Is it safe to assume that the kernel will not
preempt
Quoted 1 line
a process when its holding a spinlock ? I know
most
Quoted 1 line
parts of the code make sure they dont yield the
cpu
Quoted 2 lines
when they are holding spinlocks, but I was just curious if there is any place that does that.
Correct.
Quoted 3 lines
Basically, the context is, I need to change the scheduler a bit to implement "perfect nice -19" semantics, i.e. give cpu to nice 19 process only
if no
Quoted 1 line
other normal process is ready to run. I am
wondering
Quoted 1 line
if there is a possibility of priority inversion if
the
Quoted 1 line
nice-d process happens to yield the cpu and then
never
Quoted 1 line
get scheduled because a normal process is spinning
on
Quoted 1 line
the lock.
You will hit priority inversion... not with
spinlocks but with
semaphores (and possibly more subtle issues).The only safe way to do this safely is to boost the task's priority out
of the "idle" class when the task is inside the kernel.
Quoted 8 lines
It is nontrivial to juggle user vs. kernel returns such as that. Google
for Ingo Molnar'sSCHED_BATCHaddition to the O(1) scheduler.Robert Love
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
Quoted 2 lines · Muthian Sivathanu
Is there a version of Ingo Molnar's patch for the 2.4 line kernels ?
No idea.
I do not have a repository of Ingo's patches, I just remember him posting the SCHED_BATCH stuff a couple times. Like I said, google.
Robert Love