<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/kernel/spinlock.c, branch v2.6.12.2</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v2.6.12.2</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v2.6.12.2'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2005-05-21T17:46:48Z</updated>
<entry>
<title>[PATCH] spin_unlock_bh() and preempt_check_resched()</title>
<updated>2005-05-21T17:46:48Z</updated>
<author>
<name>Samuel Thibault</name>
<email>samuel.thibault@labri.fr</email>
</author>
<published>2005-05-21T15:50:15Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=10f02d1c59e55f529140dda3a92f0099d748451c'/>
<id>urn:sha1:10f02d1c59e55f529140dda3a92f0099d748451c</id>
<content type='text'>
In _spin_unlock_bh(lock):
	do { \
		_raw_spin_unlock(lock); \
		preempt_enable(); \
		local_bh_enable(); \
		__release(lock); \
	} while (0)

there is no reason for using preempt_enable() instead of a simple
preempt_enable_no_resched()

Since we know bottom halves are disabled, preempt_schedule() will always
return at once (preempt_count!=0), and hence preempt_check_resched() is
useless here...

This fixes it by using "preempt_enable_no_resched()" instead of the
"preempt_enable()", and thus avoids the useless preempt_check_resched()
just before re-enabling bottom halves.

Signed-off-by: Samuel Thibault &lt;samuel.thibault@ens-lyon.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] break_lock fix</title>
<updated>2005-03-28T11:51:53Z</updated>
<author>
<name>Ingo Molnar</name>
<email>mingo@elte.hu</email>
</author>
<published>2005-03-28T11:51:53Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=7f03bb0f68caef3a6b4f79e22c80c89b8fff6c41'/>
<id>urn:sha1:7f03bb0f68caef3a6b4f79e22c80c89b8fff6c41</id>
<content type='text'>
lock-&gt;break_lock is set when a lock is contended, but cleared only in
cond_resched_lock.  Users of need_lockbreak (journal_commit_transaction,
copy_pte_range, unmap_vmas) don't necessarily use cond_resched_lock on it.

So, if the lock has been contended at some time in the past, break_lock
remains set thereafter, and the fastpath keeps dropping lock unnecessarily.
 Hanging the system if you make a change like I did, forever restarting a
loop before making any progress.  And even users of cond_resched_lock may
well suffer an initial unnecessary lockbreak.

There seems to be no point at which break_lock can be cleared when
unlocking, any point being either too early or too late; but that's okay,
it's only of interest while the lock is held.  So clear it whenever the
lock is acquired - and any waiting contenders will quickly set it again.
Additional locking overhead?  well, this is only when CONFIG_PREEMPT is on.

Since cond_resched_lock's spin_lock clears break_lock, no need to clear it
itself; and use need_lockbreak there too, preferring optimizer to #ifdefs.

Signed-off-by: Hugh Dickins &lt;hugh@veritas.com&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] nonintrusive spin-polling loop in kernel/spinlock.c</title>
<updated>2005-01-20T07:28:52Z</updated>
<author>
<name>Ingo Molnar</name>
<email>mingo@elte.hu</email>
</author>
<published>2005-01-20T07:28:52Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8522703fd856bebf42b41df1430632ffcdb8a705'/>
<id>urn:sha1:8522703fd856bebf42b41df1430632ffcdb8a705</id>
<content type='text'>
This re-implements the nonintrusive spin-polling loop for the
SMP+PREEMPT spinlock/rwlock variants, using the new *_can_lock()
primitives.  (The patch also adds *_can_lock() to the UP branch of
spinlock.h, for completeness.)

build- and boot-tested on x86 SMP+PREEMPT and SMP+!PREEMPT.

Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>Revert "Don't busy-lock-loop in preemptable spinlocks" patch</title>
<updated>2005-01-19T23:59:25Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@ppc970.osdl.org</email>
</author>
<published>2005-01-19T23:59:25Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8a4f2189be5c5c1fe13bc68810da0163f1c8ff88'/>
<id>urn:sha1:8a4f2189be5c5c1fe13bc68810da0163f1c8ff88</id>
<content type='text'>
The locking tests were wrong, and the fixes are up in the air. In the
meantime, the get-it-working patch is to just not do this.

Cset exclude: mingo@elte.hu[torvalds]|ChangeSet|20050115174045|30241
</content>
</entry>
<entry>
<title>[PATCH] Don't busy-lock-loop in preemptable spinlocks</title>
<updated>2005-01-15T01:40:45Z</updated>
<author>
<name>Ingo Molnar</name>
<email>mingo@elte.hu</email>
</author>
<published>2005-01-15T01:40:45Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8b0a7bd8add3c87583556ce8770bd4bc8f83cf41'/>
<id>urn:sha1:8b0a7bd8add3c87583556ce8770bd4bc8f83cf41</id>
<content type='text'>
Paul Mackerras points out that doing the _raw_spin_trylock each time
through the loop will generate tons of unnecessary bus traffic.
Instead, after we fail to get the lock we should poll it with simple
loads until we see that it is clear and then retry the atomic op. 
Assuming a reasonable cache design, the loads won't generate any bus
traffic until another cpu writes to the cacheline containing the lock.

Agreed.

Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] improve preemption on SMP</title>
<updated>2005-01-08T05:49:02Z</updated>
<author>
<name>Ingo Molnar</name>
<email>mingo@elte.hu</email>
</author>
<published>2005-01-08T05:49:02Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=38e387ee01e5a57cd3ed84062930997b87fa3896'/>
<id>urn:sha1:38e387ee01e5a57cd3ed84062930997b87fa3896</id>
<content type='text'>
SMP locking latencies are one of the last architectural problems that cause
millisec-category scheduling delays.  CONFIG_PREEMPT tries to solve some of
the SMP issues but there are still lots of problems remaining: spinlocks
nested at multiple levels, spinning with irqs turned off, and non-nested
spinning with preemption turned off permanently.

The nesting problem goes like this: if a piece of kernel code (e.g.  the MM
or ext3's journalling code) does the following:

	spin_lock(&amp;spinlock_1);
	...
	spin_lock(&amp;spinlock_2);
	...

then even with CONFIG_PREEMPT enabled, current kernels may spin on
spinlock_2 indefinitely.  A number of critical sections break their long
paths by using cond_resched_lock(), but this does not break the path on
SMP, because need_resched() *of the other CPU* is not set so
cond_resched_lock() doesnt notice that a reschedule is due.

to solve this problem i've introduced a new spinlock field,
lock-&gt;break_lock, which signals towards the holding CPU that a
spinlock-break is requested by another CPU.  This field is only set if a
CPU is spinning in a spinlock function [at any locking depth], so the
default overhead is zero.  I've extended cond_resched_lock() to check for
this flag - in this case we can also save a reschedule.  I've added the
lock_need_resched(lock) and need_lockbreak(lock) methods to check for the
need to break out of a critical section.

Another latency problem was that the stock kernel, even with CONFIG_PREEMPT
enabled, didnt have any spin-nicely preemption logic for the following,
commonly used SMP locking primitives: read_lock(), spin_lock_irqsave(),
spin_lock_irq(), spin_lock_bh(), read_lock_irqsave(), read_lock_irq(),
read_lock_bh(), write_lock_irqsave(), write_lock_irq(), write_lock_bh().
Only spin_lock() and write_lock() [the two simplest cases] where covered.

In addition to the preemption latency problems, the _irq() variants in the
above list didnt do any IRQ-enabling while spinning - possibly resulting in
excessive irqs-off sections of code!

preempt-smp.patch fixes all these latency problems by spinning irq-nicely
(if possible) and by requesting lock-breaks if needed.  Two
architecture-level changes were necessary for this: the addition of the
break_lock field to spinlock_t and rwlock_t, and the addition of the
_raw_read_trylock() function.

Testing done by Mark H Johnson and myself indicate SMP latencies comparable
to the UP kernel - while they were basically indefinitely high without this
patch.

i successfully test-compiled and test-booted this patch ontop of BK-curr
using the following .config combinations: SMP &amp;&amp; PREEMPT, !SMP &amp;&amp; PREEMPT,
SMP &amp;&amp; !PREEMPT and !SMP &amp;&amp; !PREEMPT on x86, !SMP &amp;&amp; !PREEMPT and SMP &amp;&amp;
PREEMPT on x64.  I also test-booted x86 with the generic_read_trylock
function to check that it works fine.  Essentially the same patch has been
in testing as part of the voluntary-preempt patches for some time already.

NOTE to architecture maintainers: generic_raw_read_trylock() is a crude
version that should be replaced with the proper arch-optimized version
ASAP.

From: Hugh Dickins &lt;hugh@veritas.com&gt;

The i386 and x86_64 _raw_read_trylocks in preempt-smp.patch are too
successful: atomic_read() returns a signed integer.

Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Hugh Dickins &lt;hugh@veritas.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] Move __preempt_*lock into kernel_spinlock, clean up.</title>
<updated>2004-09-10T00:13:40Z</updated>
<author>
<name>Anton Blanchard</name>
<email>anton@samba.org</email>
</author>
<published>2004-09-10T00:13:40Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=f7e26c10ea8511941a0d764698a9568e74ef76e3'/>
<id>urn:sha1:f7e26c10ea8511941a0d764698a9568e74ef76e3</id>
<content type='text'>
 - create in_lock_functions() to match in_sched_functions(). Export it
   for use in oprofile.
 - use char __lock_text_start[] instead of long __lock_text_start when
   declaring linker symbols. Rusty fixed a number of these a while ago
   based on advice from rth.
 - Move __preempt_*_lock into kernel/spinlock.c and make it inline. This
   means locks are only one deep.
 - Make in_sched_functions() check in_lock_functions()

Signed-off-by: Anton Blanchard &lt;anton@samba.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] out-of-line locks / generic</title>
<updated>2004-09-04T09:18:26Z</updated>
<author>
<name>Zwane Mwaikambo</name>
<email>zwane@linuxpower.ca</email>
</author>
<published>2004-09-04T09:18:26Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=50658d3358fa5127fa50c4301dbbb688b9b5e21a'/>
<id>urn:sha1:50658d3358fa5127fa50c4301dbbb688b9b5e21a</id>
<content type='text'>
This patch achieves out of line spinlocks by creating kernel/spinlock.c
and using the _raw_* inline locking functions.

Now, as much as this is supposed to be arch agnostic, there was still a
fair amount of rummaging about in archs, mostly for the cases where the
arch already has out of line locks and i wanted to avoid the extra call,
saving that extra call also makes lock profiling easier.  PPC32/64 was
an example of such an arch and i have added the necessary profile_pc()
function as an example. 

Size differences are with CONFIG_PREEMPT enabled since we wanted to
determine how much could be saved by moving that lot out of line too.

ppc64 = 259897 bytes:
   text    data     bss     dec     hex filename
5489808 1962724  709064 8161596  7c893c vmlinux-after
5749577 1962852  709064 8421493  808075 vmlinux-before

sparc64 = 193368 bytes:
  text    data     bss     dec     hex filename
3472037  633712  308920 4414669  435ccd vmlinux-after
3665285  633832  308920 4608037  465025 vmlinux-before

i386 = 416075 bytes
   text    data     bss     dec     hex filename
5808371  867442  326864 7002677  6ada35 vmlinux-after
6221254  870634  326864 7418752  713380 vmlinux-before

x86-64 = 282446 bytes
   text    data     bss     dec     hex filename
4598025 1450644  523632 6572301  64490d vmlinux-after
4881679 1449436  523632 6854747  68985b vmlinux-before

It has been compile tested (UP, SMP, PREEMPT) on i386, x86-64, sparc,
sparc64, ppc64, ppc32 and runtime tested on i386, x86-64 and sparc64.

Signed-off-by: Zwane Mwaikambo &lt;zwane@fsmlabs.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
</feed>
