RE: [PATCH 0/5] sched: Lazy preemption muck
From: David Laight
Date: Thu Oct 10 2024 - 06:25:04 EST
...
> And once all the problems with LAZY are sorted then this cond_resched()
> line just goes away and the loop looks like this:
>
> while ($cond) {
> spin_lock(L);
> do_stuff();
> spin_unlock(L);
> }
The problem with that pattern is the cost of the atomics.
Thay can easily be significant especially if there are
a lot of iterations and do_stuff() is cheap;
If $cond needs the lock, the code is really:
spin_lock(L);
while ($cond) {
do_stuff();
spin_unlock(L);
spin_lock(L);
}
spin_unlock(L);
which make it even more obvious that you need a cheap
test to optimise away the unlock/lock pair.
Perhaps it could be wrapped inside a spin_relax(L)?
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)