MUTEX: Introduce simple mutex implementation
Subsystems (122)
Quoted 3 lines · Andrew Morton
Thus far I have this:
And this:
From: Andrew Morton <[email protected]>
Remove various things which were checking for gcc-1.x and gcc-2.x compilers.
---
arch/arm/kernel/asm-offsets.c | 7 +------ arch/arm26/kernel/asm-offsets.c | 7 ------- arch/ia64/kernel/head.S | 2 +- arch/ia64/kernel/ia64_ksyms.c | 2 +- arch/ia64/oprofile/backtrace.c | 2 +- drivers/md/raid0.c | 6 ------ fs/xfs/xfs_log.h | 8 +------- include/asm-um/rwsem.h | 4 ---- include/asm-v850/unistd.h | 18 ------------------ include/linux/seccomp.h | 6 +----- include/linux/spinlock_types_up.h | 14 -------------- 11 files changed, 6 insertions(+), 70 deletions(-)
drivers/md/raid0.c renamed from drivers/md/raid0.c~remove-gcc2-checks +0 -6
@@ -307,9 +307,6 @@ static int raid0_run (mddev_t *mddev)printk ("raid0 : conf->hash_spacing is %llu blocks.\n" , (unsigned long long )conf->hash_spacing); { -#if __GNUC__ <3 - volatile -#endif sector_t s = mddev->array_size;sector_t space = conf->hash_spacing;int round;
@@ -440,9 +437,6 @@ static int raid0_make_request (request_q { -#if __GNUC__ <3 - volatile -#endif sector_t x = block >> conf->preshift;sector_div (x, (u32 )conf->hash_spacing); zone = conf->hash_table[x];
fs/xfs/xfs_log.h renamed from fs/xfs/xfs_log.h~remove-gcc2-checks +1 -7
@@ -30,13 +30,7 @@* By comparing each compnent, we don't have to worry about extra * endian issues in treating two 32 bit numbers as one 64 bit number */ -static -#if defined(__GNUC__) && (__GNUC__ ==2 ) && ( (__GNUC_MINOR__ ==95 ) || (__GNUC_MINOR__ ==96 )) -__attribute__((unused))/* gcc 2.95, 2.96 miscompile this when inlined */ -#else -__inline__ -#endif -xfs_lsn_t _lsn_cmp (xfs_lsn_t lsn1,xfs_lsn_t lsn2) +static inline xfs_lsn_t _lsn_cmp (xfs_lsn_t lsn1,xfs_lsn_t lsn2) {if (CYCLE_LSN (lsn1) !=CYCLE_LSN (lsn2))return (CYCLE_LSN (lsn1)<CYCLE_LSN (lsn2))?-999 :999 ;
arch/arm/kernel/asm-offsets.c renamed from arch/arm/kernel/asm-offsets.c~remove-gcc2-checks +1 -6
@@ -23,18 +23,13 @@#error Sorry, your compiler targets APCS-26 but this kernel requires APCS-32#endif /* -* GCC 2.95.1, 2.95.2: ignores register clobber list in asm(). * GCC 3.0, 3.1: general bad code generation. * GCC 3.2.0: incorrect function argument offset calculation. * GCC 3.2.x: miscompiles NEW_AUX_ENT in fs/binfmt_elf.c * (http://gcc.gnu.org/PR8896) and incorrect structure * initialisation in fs/jffs2/erase.c */ -#if __GNUC__ <2 || \ - (__GNUC__ ==2 && __GNUC_MINOR__ <95 ) || \ - (__GNUC__ ==2 && __GNUC_MINOR__ ==95 && __GNUC_PATCHLEVEL__ !=0 && \ - __GNUC_PATCHLEVEL__ <3 ) || \ - (__GNUC__ ==3 && __GNUC_MINOR__ <3 ) +#if __GNUC__ <2 || (__GNUC__ ==3 && __GNUC_MINOR__ <3 )#error Your compiler is too buggy; it is known to miscompile kernels.#error Known good compilers: 2.95.3, 2.95.4, 2.96, 3.3#endif
arch/arm26/kernel/asm-offsets.c renamed from arch/arm26/kernel/asm-offsets.c~remove-gcc2-checks +0 -7
@@ -25,13 +25,6 @@#if defined(__APCS_32__) && defined(CONFIG_CPU_26 )#error Sorry, your compiler targets APCS-32 but this kernel requires APCS-26#endif -#if __GNUC__ <2 || (__GNUC__ ==2 && __GNUC_MINOR__ <95 ) -#error Sorry, your compiler is known to miscompile kernels. Only use gcc 2.95.3 and later. -#endif -#if __GNUC__ ==2 && __GNUC_MINOR__ ==95 -/* shame we can't detect the .1 or .2 releases */ -#warning GCC 2.95.2 and earlier miscompiles kernels. -#endif /* Use marker if you need to separate the values later */
arch/ia64/kernel/ia64_ksyms.c renamed from arch/ia64/kernel/ia64_ksyms.c~remove-gcc2-checks +1 -1
@@ -103,7 +103,7 @@ EXPORT_SYMBOL(unw_init_running);#ifdef ASM_SUPPORTED # ifdef CONFIG_SMP -# if __GNUC__ <3 || (__GNUC__ ==3 && __GNUC_MINOR__ <3 ) +# if (__GNUC__ ==3 && __GNUC_MINOR__ <3 )/* * This is not a normal routine and we don't want a function descriptor for it, so we use * a fake declaration here.
arch/ia64/kernel/head.S renamed from arch/ia64/kernel/head.S~remove-gcc2-checks +1 -1
@@ -1060,7 +1060,7 @@ SET_REG(b5); * the clobber lists for spin_lock() in include/asm-ia64/spinlock.h. */ -#if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 3) +#if (__GNUC__ == 3 && __GNUC_MINOR__ < 3) GLOBAL_ENTRY(ia64_spinlock_contention_pre3_4) .prologue
arch/ia64/oprofile/backtrace.c renamed from arch/ia64/oprofile/backtrace.c~remove-gcc2-checks +1 -1
@@ -32,7 +32,7 @@ typedef structu64 *prev_pfs_loc;/* state for WAR for old spinlock ool code */ } ia64_backtrace_t; -#if __GNUC__ <3 || (__GNUC__ ==3 && __GNUC_MINOR__ <3 ) +#if (__GNUC__ ==3 && __GNUC_MINOR__ <3 )/* * Returns non-zero if the PC is in the spinlock contention out-of-line code * with non-standard calling sequence (on older compilers).
include/linux/spinlock_types_up.h renamed from include/linux/spinlock_types_up.h~remove-gcc2-checks +0 -14
@@ -22,30 +22,16 @@ typedef struct {#else -/* -* All gcc 2.95 versions and early versions of 2.96 have a nasty bug -* with empty initializers. -*/ -#if (__GNUC__ >2 )typedef struct { }raw_spinlock_t ;#define __RAW_SPIN_LOCK_UNLOCKED { } -#else -typedef struct {int gcc_is_buggy; }raw_spinlock_t ; -#define __RAW_SPIN_LOCK_UNLOCKED (raw_spinlock_t) { 0 } -#endif #endif -#if (__GNUC__ >2 )typedef struct {/* no debug version on UP */ }raw_rwlock_t ;#define __RAW_RW_LOCK_UNLOCKED { } -#else -typedef struct {int gcc_is_buggy; }raw_rwlock_t ; -#define __RAW_RW_LOCK_UNLOCKED (raw_rwlock_t) { 0 } -#endif #endif /* __LINUX_SPINLOCK_TYPES_UP_H */
include/linux/seccomp.h renamed from include/linux/seccomp.h~remove-gcc2-checks +1 -5
@@ -26,11 +26,7 @@ static inline int has_secure_computing(s#else /* CONFIG_SECCOMP */ -#if (__GNUC__ >2 ) -typedef struct { }seccomp_t ; -#else -typedef struct {int gcc_is_buggy; }seccomp_t ; -#endif +typedef struct { }seccomp_t ;#define secure_computing (x) do { } while (0)/* static inline to preserve typechecking */
include/asm-um/rwsem.h renamed from include/asm-um/rwsem.h~remove-gcc2-checks +0 -4
@@ -1,10 +1,6 @@#ifndef __UM_RWSEM_H__#define __UM_RWSEM_H__ -#if __GNUC__ <2 || (__GNUC__ ==2 && __GNUC_MINOR__ <96 ) -#define __builtin_expect (exp,c) (exp) -#endif -#include "asm/arch/rwsem.h" #endif
include/asm-v850/unistd.h renamed from include/asm-v850/unistd.h~remove-gcc2-checks +0 -18
@@ -241,9 +241,6 @@/* User programs sometimes end up including this header file (indirectly, via uClibc header files), so I'm a bit nervous just including <linux/compiler.h>. */ -#if !defined(__builtin_expect) && __GNUC__ ==2 && __GNUC_MINOR__ <96 -#define __builtin_expect (x, expected_value) (x) -#endif #define __syscall_return (type, res) \ do { \
@@ -346,20 +343,6 @@ type name (atype a, btype b, ctype c, dt__syscall_return (type, __ret); \ } -#if __GNUC__ <3 -/* In older versions of gcc, `asm' statements with more than 10 -input/output arguments produce a fatal error. To work around this -problem, we use two versions, one for gcc-3.x and one for earlier -versions of gcc (the `earlier gcc' version doesn't work with gcc-3.x -because gcc-3.x doesn't allow clobbers to also be input arguments). */ -#define __SYSCALL6_TRAP (syscall, ret, a, b, c, d, e, f) \ - __asm__ __volatile__ ("trap " SYSCALL_LONG_TRAP \ - : "=r" (ret), "=r" (syscall) \ - : "1" (syscall), \ - "r" (a), "r" (b), "r" (c), "r" (d), \ - "r" (e), "r" (f) \ - : SYSCALL_CLOBBERS, SYSCALL_ARG4, SYSCALL_ARG5); -#else /* __GNUC__ >= 3 */ #define __SYSCALL6_TRAP (syscall, ret, a, b, c, d, e, f) \ __asm__ __volatile__ ("trap " SYSCALL_LONG_TRAP \ : "=r" (ret), "=r" (syscall), \
@@ -368,7 +351,6 @@ type name (atype a, btype b, ctype c, dt"r" (a),"r" (b),"r" (c),"r" (d), \"2" (e),"3" (f) \ : SYSCALL_CLOBBERS); -#endif #define _syscall6 (type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e, ftype, f) \ type name (atype a, btype b, ctype c, dtype d, etype e, ftype f) \
_
Quoted 24 lines · Andrew Morton
Quoted 3 lines · Andrew Morton
Thus far I have this:
And this:
From: Andrew Morton <[email protected]>
Remove various things which were checking for gcc-1.x and gcc-2.x compilers.
arch/arm/kernel/asm-offsets.c renamed from arch/arm/kernel/asm-offsets.c~remove-gcc2-checks +0
-1@@ -23,18 +23,13 @@#error Sorry, your compiler targets APCS-26 but this kernel requires APCS-32#endif /* -* GCC 2.95.1, 2.95.2: ignores register clobber list in asm(). * GCC 3.0, 3.1: general bad code generation. * GCC 3.2.0: incorrect function argument offset calculation. * GCC 3.2.x: miscompiles NEW_AUX_ENT in fs/binfmt_elf.c * (http://gcc.gnu.org/PR8896) and incorrect structure * initialisation in fs/jffs2/erase.c
arch/arm/kernel/asm-offsets.c line 35
Quoted 10 lines
arch/arm/kernel/asm-offsets.c renamed from arch/arm/kernel/asm-offsets.c~remove-gcc2-checks +1
-5*/ -#if __GNUC__ <2 || \ - (__GNUC__ ==2 && __GNUC_MINOR__ <95 ) || \ - (__GNUC__ ==2 && __GNUC_MINOR__ ==95 && __GNUC_PATCHLEVEL__ !=0 && \ - __GNUC_PATCHLEVEL__ <3 ) || \ - (__GNUC__ ==3 && __GNUC_MINOR__ <3 ) +#if __GNUC__ <2 || (__GNUC__ ==3 && __GNUC_MINOR__ <3 )#error Your compiler is too buggy; it is known to miscompile kernels.#error Known good compilers: 2.95.3, 2.95.4, 2.96, 3.3#endif
Guess
#if __GNUC__ == 3 && __GNUC_MINOR__ < 3
#error Your compiler is too buggy; it is known to miscompile kernels.
#error Known good compilers: 3.3, 3.4, 4.0
#endif
would be better. __GNUC__ < 2 will certainly be errored about in other places and it is bad to suggest compilers that are no longer supported as known good ones.
Jakub
Quoted 10 lines
Guess
#if
__GNUC__== 3 &&__GNUC_MINOR__< 3
#error Your compiler is too buggy; it is known to miscompile kernels.
#error Known good compilers: 3.3, 3.4, 4.0
#endifwould be better.
__GNUC__< 2 will certainly be errored about in other places and it is bad to suggest compilers that are no longer supported as known good ones.
Are there really any known serious miscompilation with 3.1/3.2? (I knew it used to miscompile some loops on x86-64, but I think I worked around all that)
Preventing SLES9 and RHEL3 users from easily compiling new kernels isn't good.
-Andi
Quoted 11 lines · Andi Kleen
Quoted 10 lines
Guess
#if
__GNUC__== 3 &&__GNUC_MINOR__< 3
#error Your compiler is too buggy; it is known to miscompile kernels.
#error Known good compilers: 3.3, 3.4, 4.0
#endifwould be better.
__GNUC__< 2 will certainly be errored about in other places and it is bad to suggest compilers that are no longer supported as known good ones.
Quoted 6 lines
Are there really any known serious miscompilation with 3.1/3.2? (I knew it used to miscompile some loops on x86-64, but I think I worked around all that)
Preventing SLES9 and RHEL3 users from easily compiling new kernels isn't good.
The above is ARM solely, the comment there mentions some ARM postreload bug that was only fixed in 3.3+.
I'd say 3.2 should be generally supported for the time being on arches where there weren't significant problems with it.
Jakub
Quoted 12 lines · Andi Kleen
Quoted 11 lines
Guess
#if
__GNUC__== 3 &&__GNUC_MINOR__< 3
#error Your compiler is too buggy; it is known to miscompile kernels.
#error Known good compilers: 3.3, 3.4, 4.0
#endifwould be better.
__GNUC__< 2 will certainly be errored about in other places and it is bad to suggest compilers that are no longer supported as known good ones.
Quoted 7 lines
Are there really any known serious miscompilation with 3.1/3.2? (I knew it used to miscompile some loops on x86-64, but I think I worked around all that)
Preventing SLES9 and RHEL3 users from easily compiling new kernels isn't good.
3.2.1 works OK on x86.
Quoted 10 lines · Andrew Morton
diff -puN
arch/arm/kernel/asm-offsets.c~remove-gcc2-checksarch/arm/kernel/asm-offsets.carch/arm/kernel/asm-offsets.c renamed from arch/arm/kernel/asm-offsets.c~remove-gcc2-checks +0
-1@@ -23,18 +23,13 @@#error Sorry, your compiler targets APCS-26 but this kernel requires APCS-32#endif /* -* GCC 2.95.1, 2.95.2: ignores register clobber list in asm(). * GCC 3.0, 3.1: general bad code generation. * GCC 3.2.0: incorrect function argument offset calculation.
arch/arm/kernel/asm-offsets.c line 32
Quoted 10 lines
arch/arm/kernel/asm-offsets.c renamed from arch/arm/kernel/asm-offsets.c~remove-gcc2-checks +1
-5* GCC 3.2.x: miscompiles NEW_AUX_ENT in fs/binfmt_elf.c * (http://gcc.gnu.org/PR8896) and incorrect structure * initialisation in fs/jffs2/erase.c */ -#if __GNUC__ <2 || \ - (__GNUC__ ==2 && __GNUC_MINOR__ <95 ) || \ - (__GNUC__ ==2 && __GNUC_MINOR__ ==95 && __GNUC_PATCHLEVEL__ !=0 && \ - __GNUC_PATCHLEVEL__ <3 ) || \ - (__GNUC__ ==3 && __GNUC_MINOR__ <3 ) +#if __GNUC__ <2 || (__GNUC__ ==3 && __GNUC_MINOR__ <3 )
Shouldn't this be:
+#if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 3)
?
arch/arm/kernel/asm-offsets.c line 34
Quoted 2 lines
arch/arm/kernel/asm-offsets.c renamed from arch/arm/kernel/asm-offsets.c~remove-gcc2-checks +0
-0#error Your compiler is too buggy; it is known to miscompile kernels.#error Known good compilers: 2.95.3, 2.95.4, 2.96, 3.3
And this should also have the 2.95 and 2.96 stuff edited out.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of: 2.6 Serial core
Quoted 9 lines · Andrew Morton
Quoted 4 lines · Andi Kleen
Can you please apply the following patch then?
Remove -Wdeclaration-after-statement
OK.
Thus far I have this:
Would it be possible to drop support for gcc 3.0 too?
AFAIK it has never been widely used. If we assume 3.1+ minimum it has the advantage that named assembly arguments work, which make
the inline assembly often a lot easier to read and maintain.
-Andi
Quoted 6 lines · Andi Kleen
Quoted 4 lines · Andrew Morton
Quoted 3 lines · Andi Kleen
Can you please apply the following patch then?
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Remove -Wdeclaration-after-statement
OK.
Thus far I have this:
Would it be possible to drop support for gcc 3.0 too?
Spose so - I don't know what people are using out there.
Quoted 3 lines
AFAIK it has never been widely used. If we assume 3.1+ minimum it has the advantage that named assembly arguments work, which make
the inline assembly often a lot easier to read and maintain.
There are a few places in the tree which refuse to compile with 3.1 and 3.2.
Quoted 1 line
Spose so - I don't know what people are using out there.
I don't think it was shipped in major distros at least (AFAIK) They all went from 2.95 to 3.1/3.2
Perhaps stick an error for 3.0 in and wait if people are complaining?
Quoted 6 lines
Quoted 4 lines
AFAIK it has never been widely used. If we assume 3.1+ minimum it has the advantage that named assembly arguments work, which make
the inline assembly often a lot easier to read and maintain.There are a few places in the tree which refuse to compile with 3.1 and 3.2.
Really? Which ones?
Haven't seen that and I still use 3.2 occasionally (it's the default compiler on SLES9 and I believe on RHEL3 too)
-Andi
Quoted 4 lines · Andi Kleen
Quoted 2 lines
There are a few places in the tree which refuse to compile with 3.1 and 3.2.
Really? Which ones?
grep for __GNUC_MINOR__
Quoted 7 lines · Andrew Morton
Quoted 4 lines · Andi Kleen
Quoted 2 lines
There are a few places in the tree which refuse to compile with 3.1 and 3.2.
Really? Which ones?
grep for
__GNUC_MINOR__
I reviewed them and I didn't find any that refused 3.2 or 3.3.
Some architectures have special code for old gccs, but nothing generic.
-Andi
Quoted 2 lines · Andi Kleen
Haven't seen that and I still use 3.2 occasionally (it's the default compiler on SLES9 and I believe on RHEL3 too)
SLES9 has 3.3-hammer.
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 6 lines · Andreas Schwab
Quoted 2 lines · Andi Kleen
Haven't seen that and I still use 3.2 occasionally (it's the default compiler on SLES9 and I believe on RHEL3 too)
SLES9 has 3.3-hammer.
You're right - i meant to write SLES8 where 3.2 was default.
-Andi
Quoted 4 lines · Andi Kleen
Quoted 1 line
Spose so - I don't know what people are using out there.
I don't think it was shipped in major distros at least (AFAIK) They all went from 2.95 to 3.1/3.2
Debian Woody (3.0) shipped a mess of compilers -- 2.95 for most, 2.96 for ia64 and 3.0 for parisc. That was released in July 2002. Sarge (3.1) shipped in June 2005 and uses GCC 3.3 on all architectures.
Quoted 7 lines · Andi Kleen
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Andi Kleen
Can you please apply the following patch then?
Remove -Wdeclaration-after-statement
Quoted 8 lines
Quoted 3 lines
OK.
Thus far I have this:
Would it be possible to drop support for gcc 3.0 too?
AFAIK it has never been widely used. If we assume 3.1+ minimum it has the advantage that named assembly arguments work, which make
the inline assembly often a lot easier to read and maintain.
3.2+ would be better than 3.1+
Remember that 3.2 would have been named 3.1.2 if there wasn't the C++ ABI change, and I don't remember any big Linux distribution actually using gcc 3.1 as default compiler.
And since gcc 3.2 was released one and a half years before kernel 2.6.0, I doubt there's any distribution both supporting kernel 2.6 and not shipping any gcc >= 3.2 .
Quoted 1 line
-Andi
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 5 lines
3.2+ would be better than 3.1+
Remember that 3.2 would have been named 3.1.2 if there wasn't the C++ ABI change, and I don't remember any big Linux distribution actually using gcc 3.1 as default compiler.
Yes, but the kernel doesn't use C++ and afaik other than that there were only a few minor bugfixes between 3.1 and 3.2. So it doesn't make any difference for this special case.
-Andi
Quoted 9 lines · Andi Kleen
Quoted 5 lines
3.2+ would be better than 3.1+
Remember that 3.2 would have been named 3.1.2 if there wasn't the C++ ABI change, and I don't remember any big Linux distribution actually using gcc 3.1 as default compiler.
Yes, but the kernel doesn't use C++ and afaik other than that there were only a few minor bugfixes between 3.1 and 3.2. So it doesn't make any difference for this special case.
gcc 3.2.3 is four bugfix releases and nine months later than 3.1.1, and there are virtually no gcc 3.1 users.
It's not a strong opinion, but if the question is whether to draw the line before or after gcc 3.1 I'd vote for dropping gcc 3.1 support.
Quoted 1 line
-Andi
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 4 lines · Andrew Morton
Quoted 3 lines · Andi Kleen
Can you please apply the following patch then?
Quoted 8 lines
Quoted 1 line
Remove -Wdeclaration-after-statement
OK.
Thus far I have this:
From: Andrew Morton <[email protected]>
hurray!!
Ingo
Quoted 5 lines
Remove -Wdeclaration-after-statement
Now that gcc 2.95 is not supported anymore it's ok to use C99 style mixed declarations everywhere.
Nack. This code style is pure obsfucation and we should disallow it forever.
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines
Remove -Wdeclaration-after-statement
Now that gcc 2.95 is not supported anymore it's ok to use C99 style mixed declarations everywhere.
Nack. This code style is pure obsfucation and we should disallow it forever.
agreed. I often get quilt mismerges uncovered by that warning. If someone wants to start a new section of code that is too large, it should go into a separate function.
Ingo
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines
Remove -Wdeclaration-after-statement
Now that gcc 2.95 is not supported anymore it's ok to use C99 style mixed declarations everywhere.
Nack. This code style is pure obsfucation and we should disallow it forever.
Why? It greatly increases readability when variable declarations can be moved close to their actual uses. glibc changed a lot of its codebase this way and from my experience it really helps.
Jakub
Quoted 4 lines · Jakub Jelinek
Quoted 3 lines · Christoph Hellwig
Quoted 3 lines
Remove -Wdeclaration-after-statement
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Now that gcc 2.95 is not supported anymore it's ok to use C99 style mixed declarations everywhere.
Nack. This code style is pure obsfucation and we should disallow it forever.
Why? It greatly increases readability when variable declarations can be moved close to their actual uses. glibc changed a lot of its codebase this way and from my experience it really helps.
mentioning glibc and readability in the same sentence disqualies your here, sorry ;-)
But serious, having to look all over the source instead of just a block beginning decreases code readability a lot. And if you have to scroll more than a page to the block beginning on a 80x24 terminal means the code needs a refactoring anyway.
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Jakub Jelinek
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines
Remove -Wdeclaration-after-statement
Now that gcc 2.95 is not supported anymore it's ok to use C99 style mixed declarations everywhere.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Nack. This code style is pure obsfucation and we should disallow it forever.
Why? It greatly increases readability when variable declarations can be moved close to their actual uses. glibc changed a lot of its codebase this way and from my experience it really helps.
mentioning glibc and readability in the same sentence disqualies your here, sorry ;-)
it's a different coding style, but otherwise i find glibc highly readable and well-maintained. It is also a more mature piece of code than say the kernel, e.g. API-wise, so we could indeed learn a few things. Just consider the fact that glibc has 10 times more APIs than the kernel, and still it is breaking apps less often than the kernel. But i digress :-)
Ingo
Quoted 2 lines · Christoph Hellwig
But serious, having to look all over the source instead of just a block beginning decreases code readability a lot.
My experience is quite the opposite.
Being forced to put declarations at the beginning of the block in practice means that people simply separate declarations from the first assignment. That uglifies and bloats the code, and seems to often cause bugs as well (because people seem to often not pay attention to what happens to a variable between the declaration and first assignment; having it simply _not exist_ before the first assignment helps quite a bit).
-Miles
Signature · 1 line
Run away! Run away!
Quoted 8 lines · Miles Bader
Quoted 2 lines · Christoph Hellwig
But serious, having to look all over the source instead of just a block beginning decreases code readability a lot.
My experience is quite the opposite.
Quoted 8 lines
Being forced to put declarations at the beginning of the block in practice means that people simply separate declarations from the first assignment. That uglifies and bloats the code, and seems to often cause bugs as well (because people seem to often not pay attention to what happens to a variable between the declaration and first assignment; having it simply
_notexist_before the first assignment helps quite a bit).
If your blocks are so big that you lose track of variables like this... then it is too big and/or complex.
And the argument about having it simply _not exist_ before the first assignment isn't convincing to me, because you cannot undeclare variables after you finish with them (do you also see code where people cause bugs by forgetting about the variable after its last use?).
IMO, the system of declaring all variables at the top of the block and they all disappear at the end is nice and symmetric... although I probably agree with Linus on the 'for (int i = 0;' feature.
Nick
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 4 lines · Andi Kleen
Quoted 2 lines
It's time to give up on it and just drink more coffee or play more tetris or something, I'm afraid.
Or start using icecream (http://wiki.kde.org/icecream)
distcc is pretty good too. I have a minimal kernel build done in 19 seconds, a fuller build (1.5MB bzImage that boots on all my testboxes) done in 45 seconds, using gcc 4.0.2.
with the default settings, distcc wasnt saturating my boxes, the key was to start distccd with a longer queue size (/etc/sysconfig/distccd):
OPTIONS="--nice 5 --jobs 128"
and to get the DISTCC_HOSTS tuning right:
export DISTCC_HOSTS='j/16 n/120 v/40 s/13 e2/7'
in fact my distcc builds are almost as fast as a fully cached ccache build coming straight out of RAM ...
Ingo
Quoted 5 lines
Quoted 1 line
Or start using icecream (http://wiki.kde.org/icecream)
distcc is pretty good too. I have a minimal kernel build done in 19 seconds, a fuller build (1.5MB bzImage that boots on all my testboxes) done in 45 seconds, using gcc 4.0.2.
icecream is better though - it reacts dynamically to your network and it handles different installed compiler versions and cross compilation nicely.
-Andi
Quoted 2 lines · Andi Kleen
Remove -Wdeclaration-after-statement
Please don't.
It's a coding style issue. We put our variable declarations where people can _find_ them, not in random places in the code.
Putting variables in the middle of code only improves readability when you have messy code.
Now, one feature that _may_ be worth it is the loop counter thing:
for (int i = 10; i; i--) ...
kind of syntax actually makes sense and is a real feature (it makes "i" local to the loop, and can actually help people avoid bugs - you can't use "i" by mistake after the loop).
But I think you need "--std=c99" for gcc to take that.
Linus
Using C99 in the kernel was Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
[dropping linux-arch because it seems to generate bounces]
Quoted 6 lines · Linus Torvalds
Quoted 2 lines · Andi Kleen
Remove -Wdeclaration-after-statement
Quoted 7 lines
Please don't.
It's a coding style issue. We put our variable declarations where people can _find_ them, not in random places in the code.
Putting variables in the middle of code only improves readability when you have messy code.
I like it when the scopes for variables are as small as possible because then I also find it good documentation when the first initialization of a variable also has the type.
While it's possible with nested {} blocks too that imho makes the code ugly because you either end up with non syntactic elements with wrong indentation (driving emacs/indent etc crazy) or with too much indentation.
I can see Ingo's argument about catching merging mistakes though - that is a good point against it that I didn't consider.
Quoted 11 lines
Now, one feature that _may_ be worth it is the loop counter thing:
for (int i = 10; i; i--) ...kind of syntax actually makes sense and is a real feature (it makes "i" local to the loop, and can actually help people avoid bugs - you can't use "i" by mistake after the loop).
But I think you need "--std=c99" for gcc to take that.
Ok. So should we enable that? Or rather --std=gnu99
But actually I tried it and it causes lots of
mm/page_alloc.c:49: error: initializer element is not constant
It looks like casts in constant initializers for global structures are not allowed anymore: struct foo x = (struct foo) { ... }; warns. That's not good because when the (struct foo){} is generated in a macro then it's the only easy way to allow initialization outside a declaration.
Common case is SPIN_LOCK_UNLOCKED() / DEFINE_SPINLOCK().
Richard, any comments on that?
P.S.: Linus, I wish you weren't so fond of using downcounting loops: I find them always slightly confusing (or rather they need more consideration than a standard upcounting loop to understand) and gcc is perfectly capable of reversing loops when suitable on its own.
-Andi
Re: Using C99 in the kernel was Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
Quoted 6 lines · Andi Kleen
It looks like casts in constant initializers for global structures are not allowed anymore: struct foo x = (struct foo) { ... }; warns. That's not good because when the (struct foo){} is generated in a macro then it's the only easy way to allow initialization outside a declaration.
Common case is
SPIN_LOCK_UNLOCKED()/DEFINE_SPINLOCK().
There are two similar things - struct initializers and compound literals. They are *not* the same, though; compound literal defines an unnamed object, so
{
struct foo x = (struct foo){...};is equivalent to
struct foo unnamed_variable = {....};
struct foo x = unnamed_variable;For auto variables it's fine; there initializer doesn't have to be constant. For globals it's _not_.
Note that it's really a definition of object - e.. you can say
f(&(struct foo){....});and have it work just fine.
IOW, DEFINE_SPINLOCK() should be spinlock_t x = __SPIN_LOCK_UNLOCKED() and SPIN_LOCK_UNLOCKED - (spinlock_t) __SPIN_LOCK_UNLOCKED. That's enough to make it valid C99...
Re: Using C99 in the kernel was Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
Quoted 1 line
There are two similar things - struct initializers and compound literals.
I know they are not the same, but it's still annoying that gcc arbitarily changes the definition of "GNU C" again. That is why I would consider it more a bug than a feature.
-Andi
Quoted 2 lines · Andrew Morton
scsi/sd.cis currently getting an ICE. None of the new SAS code compiles, due to extensive use of anonymous unions.
This is just the headers in the luben code which need redoing completely because they're doing other stupid things like using bitfields for on the wire structures.
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Andrew Morton
scsi/sd.cis currently getting an ICE. None of the new SAS code compiles, due to extensive use of anonymous unions.This is just the headers in the luben code which need redoing completely because they're doing other stupid things like using bitfields for on the wire structures.
Don't think so (you're referring to Jeff's git-sas-jg.patch?). It dies with current -linus tree.
drivers/scsi/sd.c: In function `sd_read_capacity':drivers/scsi/sd.c:1301: internal error--unrecognizable insn:
(insn 1274 1273 1797 (parallel[
(set (reg:SI 0 %eax)
(asm_operands ("") ("=a") 0[
(reg:DI 1 %edx)
]
[
(asm_input:DI ("A"))
] ("drivers/scsi/sd.c") 1282))
(set (reg:SI 1 %edx)
(asm_operands ("") ("=d") 1[
(reg:DI 1 %edx)
]
[
(asm_input:DI ("A"))
] ("drivers/scsi/sd.c") 1282))
] ) -1 (insn_list 1269 (nil))
(nil))It'll be workable aroundable of course, but it's a hassle.
Quoted 6 lines · Andrew Morton
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Andrew Morton
scsi/sd.cis currently getting an ICE. None of the new SAS code compiles, due to extensive use of anonymous unions.
Quoted 6 lines
Quoted 3 lines
This is just the headers in the luben code which need redoing completely because they're doing other stupid things like using bitfields for on the wire structures.
Don't think so (you're referring to Jeff's git-sas-jg.patch?). It dies with current -linus tree.
I didn't mean sd.c but the anonymous union usage. Everything that's stuffed into include/scsi/sas/ in -mm is far from mergeable. It's really badly done headers that need to be redone.
drivers/scsi/sd.c gcc-2.95.3
In reply to Andrew MortonQuoted 20 lines · Andrew Morton
drivers/scsi/sd.c: In function `sd_read_capacity':drivers/scsi/sd.c:1301: internal error--unrecognizable insn:
(insn 1274 1273 1797 (parallel[(set (reg:SI 0 %eax) (asm_operands ("") ("=a") 0[ (reg:DI 1 %edx) ] [ (asm_input:DI ("A")) ] ("drivers/scsi/sd.c") 1282)) (set (reg:SI 1 %edx) (asm_operands ("") ("=d") 1[ (reg:DI 1 %edx) ] [ (asm_input:DI ("A")) ] ("drivers/scsi/sd.c") 1282)) ] ) -1 (insn_list 1269 (nil)) (nil))
Quoted 1 line
It'll be workable aroundable of course, but it's a hassle.
FWIW,
drivers/scsi/sd.c +2 -2
@@ -1282,9 +1282,9 @@ got_data:sector_div (mb,1950 );printk (KERN_NOTICE "SCSI device %s: " -"%llu %d-byte hdwr sectors (%llu MB)\n" , +"%llu %d-byte hdwr sectors\n" , diskname, (unsigned long long )sdkp->capacity, - hard_sector, (unsigned long long )mb); + hard_sector); }/* Rescale capacity to 512-byte units */
Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Andrew Morton
I'd have thought that the way to do this is to simply reimplement
down(),up(),down_trylock(), etc using the new xchg-based code and to then hunt down those few parts of the kernel which actually use the old semaphore's counting feature and convert them to usedown_sem(),up_sem(), etc. And rename all the old semaphore code:
s/down/down_sem/etc.
Quoted 7 lines
even better than that, why not use the solution that we've implemented for the -rt patchset, more than a year ago?
the solution i took was this:
- i did not touch the 'struct semaphore' namespace, but introduced a 'struct
compat_semaphore'.
which I think is wrong. THis naming sucks. Sure doing a full sed on the tree is not pretty but it's also not THAT painful. And the pain of wrong names is something the kernel needs to carry around for years.
Quoted 6 lines
- i introduced a 'type-sensitive' macro wrapper that switches
down()(and the other APIs) to either to the assembly variant (if the variable's type is structcompat_semaphore), or switches it to the new generic mutex (if the type is struct semaphore), at build-time. There is no runtime overhead due to this build-time-switching.
while this is a smart trick, I rather prefer seperate functions, just so that people are "aware" which they use. Since 99% of the users is a mutex anyway, the new names are only used in a few special cases.
Quoted 11 lines · Arjan van de Ven
Quoted 7 lines
even better than that, why not use the solution that we've implemented for the -rt patchset, more than a year ago?
the solution i took was this:
- i did not touch the 'struct semaphore' namespace, but introduced a 'struct
compat_semaphore'.which I think is wrong. THis naming sucks. Sure doing a full sed on the tree is not pretty but it's also not THAT painful. And the pain of wrong names is something the kernel needs to carry around for years.
well, i'm all for renaming struct semaphore to struct mutex, but dont the same arguments apply as to 'struct timer_list'?
just to see the scope, i've attached semaphore-to-mutex.patch, which just dumbly converts all 'struct semaphore' occurances to 'struct mutex', against Linus-git-curr:
405 files changed, 568 insertions(+), 568 deletions(-)
it's not _that_ bad, if done overnight. It does not touch any of the down/up APIs. Touching those would create a monster patch and monster impact.
Ingo
Quoted 3 lines
it's not _that_ bad, if done overnight. It does not touch any of the down/up APIs. Touching those would create a monster patch and monster impact.
One argument for a full rename (and abandoning the old "struct semaphore" name completely) would be that it would offer a clean break for out tree code, no silent breakage.
-Andi
Quoted 7 lines · Andi Kleen
Quoted 3 lines
it's not _that_ bad, if done overnight. It does not touch any of the down/up APIs. Touching those would create a monster patch and monster impact.
One argument for a full rename (and abandoning the old "struct semaphore" name completely) would be that it would offer a clean break for out tree code, no silent breakage.
yeah. Another way to handle it would be to keep 'struct semaphore' for the traditional semaphore type (together with the APIs), and to mark them deprecated. I.e. we'd have 3 separate types and 3 separate sets of APIs:
'struct mutex' & APIs
'struct semaphore' & APIs
'struct compat_semaphore' & APIs
phase #1: we do an overnight rename to 'struct mutex' and to
'struct compat_semaphore', based on the info that has been mapped by the -rt tree. We mark 'struct semaphore' deprecated.
phase #2: we let out-of-tree code still work that uses struct
semaphore, but for new code applied, it must not be used.
phase #3: we remove 'struct semaphore' and APIs.
the problem with this approach is that it touches the semaphore APIs too, which increases the impact of the rename by a _factor of 10_. Right now we have ~600 places that use 'struct semaphore', but we have over 7000 places that use the APIs! I dont think it's realistic to do an overnight change of all the APIs, we'd break every out-of-kernel tree in a massive way. (the type change alone is much more manageable)
Ingo
Quoted 1 line
'struct
compat_semaphore'
I really think this data type needs a better name, one that reflects what it does.
Something like 'struct binary_semaphore' or something.
Cheers
Quoted 6 lines · Mark Lord
Quoted 1 line
'struct
compat_semaphore'I really think this data type needs a better name, one that reflects what it does.
Something like 'struct
binary_semaphore' or something.
see the thing is.. this is the counting one ;)
the -rt naming is just too confusing (but done to keep patch maintenance reasonable, which is fair enough for that purpose, but not good enough for kernel.org)
Quoted 7 lines · Andi Kleen
Quoted 3 lines
it's not _that_ bad, if done overnight. It does not touch any of the down/up APIs. Touching those would create a monster patch and monster impact.
One argument for a full rename (and abandoning the old "struct semaphore" name completely) would be that it would offer a clean break for out tree code, no silent breakage.
btw., in the -rt tree we rarely had 'silent breakage' - roughly 80% of the cases were caught build-time: we eliminated DECLARE_MUTEX_LOCKED, which is a clear sign for non-mutex semaphore usage. Another 19% was caught by runtime checks: 'does owner unlock the mutex'. The remaining 1% was breakage that was not found quickly.
Ingo
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · Arjan van de Ven
Quoted 7 lines
even better than that, why not use the solution that we've implemented for the -rt patchset, more than a year ago?
the solution i took was this:
- i did not touch the 'struct semaphore' namespace, but introduced a 'struct
compat_semaphore'.
Quoted 6 lines
Quoted 3 lines
which I think is wrong. THis naming sucks. Sure doing a full sed on the tree is not pretty but it's also not THAT painful. And the pain of wrong names is something the kernel needs to carry around for years.
well, i'm all for renaming struct semaphore to struct mutex, but dont the same arguments apply as to 'struct
timer_list'?
don't think so; this is not a "lets do them one by one over the year", this is a "do them all right now at once" move.
Quoted 2 lines · Ingo Molnar
- i did not touch the 'struct semaphore' namespace, but introduced a 'struct
compat_semaphore'.
Because it's totally brindead. Your compat_semaphore is a real semaphore and your semaphore is a mutex. So name them as such.
Quoted 5 lines
- i introduced a 'type-sensitive' macro wrapper that switches
down()(and the other APIs) to either to the assembly variant (if the variable's type is structcompat_semaphore), or switches it to the new generic mutex (if the type is struct semaphore), at build-time. There is no runtime overhead due to this build-time-switching.
And this one is probably is a great help to win the obsfucated C contests, but otherwise just harmfull.
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Ingo Molnar
- i did not touch the 'struct semaphore' namespace, but introduced a 'struct
compat_semaphore'.Because it's totally braindead. Your
compat_semaphoreis a real semaphore and your semaphore is a mutex. So name them as such.
well, i had the choice between a 30K patch, a 300K patch and a 3000K patch. I went for the 30K patch ;-)
Quoted 8 lines
Quoted 5 lines
- i introduced a 'type-sensitive' macro wrapper that switches
down()(and the other APIs) to either to the assembly variant (if the variable's type is structcompat_semaphore), or switches it to the new generic mutex (if the type is struct semaphore), at build-time. There is no runtime overhead due to this build-time-switching.And this one is probably is a great help to win the obsfucated C contests, but otherwise just harmfull.
i never found it to be harmful in any way, and we've now got a year of experience with them. Could you elaborate?
Ingo
Quoted 9 lines · Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 2 lines
- i did not touch the 'struct semaphore' namespace, but introduced a 'struct
compat_semaphore'.Because it's totally braindead. Your
compat_semaphoreis a real semaphore and your semaphore is a mutex. So name them as such.well, i had the choice between a 30K patch, a 300K patch and a 3000K patch. I went for the 30K patch ;-)
in that sense i'm all for going for the 300K patch, which is roughly the direction David is heading into: rename to 'struct mutex' but keep the down/up APIs, and introduce sem_down()/sem_up()/ for the cases that need full semaphores.
i dont think the 3000K patch (full API rename, introduction of mutex_down()/mutex_up()) is realistic.
Ingo
If we are doing global rename patches, could we make one of the deliverables a sed or perl script that exactly produces the patch, suitable for running one-time on out-of-kernel trees? Add the script in the kernel scripts directory.
It is usually too easy to produce a nearly correct script, and too difficult to produce an exactly right one, for all but serious sed or perl regex hackers.
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401Quoted 3 lines · Paul Jackson
It is usually too easy to produce a nearly correct script, and too difficult to produce an exactly right one, for all but serious sed or perl regex hackers.
I'd be especially impressed if you can get it to also analyse the context in which the semaphore is used and determine whether or not it should be a counting semaphore, a mutex or a completion. You can probably do this sort of thing with Perl regexes... they seem to be terrifically[*] powerful.
[*] and I mean that in the proper sense:-)
David
Quoted 3 lines
I'd be especially impressed if you can get it to also analyse the context in which the semaphore is used and determine whether or not it should be a counting semaphore, a mutex or a completion
That would impress me too, if I could do that.
I think that is well beyond my humble capabilities.
The sed/perl script to make the textual change should be practical. Indeed, I would claim that the initial big patch -should- be done that way. Keep refining a sed script until manual inspection and trial builds of all arch's, allconfig, show that it seems to be right. Each time you find an error doing this, don't manually edit the kernel source; rather refine the script and try applying it again.
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401Quoted 6 lines · Paul Jackson
The sed/perl script to make the textual change should be practical. Indeed, I would claim that the initial big patch -should- be done that way. Keep refining a sed script until manual inspection and trial builds of all arch's, allconfig, show that it seems to be right. Each time you find an error doing this, don't manually edit the kernel source; rather refine the script and try applying it again.
Actually, you may have a point.
If the order of patches is:
(1) Create new mutex as struct mutex/up_mutex/down_mutex, say.
(2) Make counting semaphore implementation struct semaphore/up_sem/down_sem.
(3) Convert uses of semaphores that should be completions into completions.
(4) Convert uses of semaphores that should be counting semaphores to use up_sem/down_sem.
(5) Mass convert by script all the remaining ups and downs into up_mutex and down_mutex.
(6) Make wrappers for up/down that map to counting semaphores with the deprecation attribute set.
That might work, and would be a lot easier; except for the humongous patch generated at step 5 - which could be regenerated by script. I think I can make a simple perl script to do that.
Note that I am assuming above that down == down/down_trylock/down_interruptible for clarity.
David
Quoted 3 lines · David Howells
(6) Make wrappers for up/down that map to counting semaphores with the deprecation attribute set.
(7) After a couple of months, remove up and down entirely.
David
Quoted 7 lines · David Howells
Quoted 3 lines · David Howells
(6) Make wrappers for up/down that map to counting semaphores with the deprecation attribute set.
(7) After a couple of months, remove up and down entirely.
Why bother. As has already been discussed up and down are the natural and normal names for counting semaphores. You don't need to obsolete the old API thats just silly, you need to add a new one and wait for people to use it.
The old API is still very useful for some applications that want counting semaphores.
Quoted 4 lines · Alan Cox
Why bother. As has already been discussed up and down are the natural and normal names for counting semaphores. You don't need to obsolete the old API thats just silly, you need to add a new one and wait for people to use it.
The vast majority of ups and downs are actually mutex related not semaphore related, so by majority share, up/down perhaps ought to be repurposed to
mutexes: they _are_ the preeminent uses.
From my modified tree, I see:
semaphore up down down_in down_try Counting 41 59 1 0 Mutex 4405 2824 362 107
Quoted 2 lines
The old API is still very useful for some applications that want counting semaphores.
Whilst that is true, they're in a small minority, and it'd be easier to change them.
David
Quoted 17 lines · David Howells
Quoted 4 lines · Alan Cox
Why bother. As has already been discussed up and down are the natural and normal names for counting semaphores. You don't need to obsolete the old API thats just silly, you need to add a new one and wait for people to use it.
The vast majority of ups and downs are actually mutex related not semaphore related, so by majority share, up/down perhaps ought to be repurposed to
mutexes: they _are_ the preeminent uses.From my modified tree, I see:
semaphore up down down_in down_try Counting 41 59 1 0 Mutex 4405 2824 362 107
Quoted 5 lines
Quoted 2 lines
The old API is still very useful for some applications that want counting semaphores.
Whilst that is true, they're in a small minority, and it'd be easier to change them.
You can do a full scripted rename of up/down to the mutex API and then fix up the 100 places used by semaphores manually.
tglx
Quoted 3 lines · Thomas Gleixner
You can do a full scripted rename of up/down to the mutex API and then fix up the 100 places used by semaphores manually.
Again, folks, this only works for current in-tree kernel code.
There are huge amounts of kernel code out-of-tree that still use up/down as (or potentially as) counting semaphores.
Yes, some of that code is closed-source, but most of it is open-source stuff in people's "queues", such as the network patch-o-matic queue and other stuff. Lots of open-source out-of-tree drivers, too.
Re-using the existing up()/down() names for a new purpose is a very very Bad Idea. Removing up()/down() entirely is not quite so bad, because at least then people will eventually notice the change.
Leaving up()/down() as-is is really the most sensible option.
Cheers
Quoted 10 lines · Mark Lord
Quoted 3 lines · Thomas Gleixner
You can do a full scripted rename of up/down to the mutex API and then fix up the 100 places used by semaphores manually.
Again, folks, this only works for current in-tree kernel code.
There are huge amounts of kernel code out-of-tree that still use up/down as (or potentially as) counting semaphores.
Quoted 6 lines
Yes, some of that code is closed-source, but most of it is open-source stuff in people's "queues", such as the network patch-o-matic queue and other stuff. Lots of open-source out-of-tree drivers, too.
Re-using the existing up()/down() names for a new purpose is a very very Bad Idea.
Ack.
Quoted 4 lines
Removing up()/down() entirely is not quite so bad,
because at least then people will eventually notice the change.Leaving up()/down() as-is is really the most sensible option.
Not at all.
Doing a s/down/lock_mutex/ s/up/unlock_mutex/ - or whatever naming convention we want to use - all over the place for mutexes while keeping the up/down for counting semaphores is an one time issue.
After the conversion every code breaks at compile time which tries to do up/down(mutex_type).
So the out of tree drivers have a clear indication what to fix. This is also a one time issue.
So where is the problem - except for fixing "huge" amounts of out of kernel code once ?
tglx
Quoted 1 line · Thomas Gleixner
On Wed, 2005-12-14 at 18:40 -0500, Mark Lord wrote:
...
Quoted 2 lines
Quoted 1 line
Leaving up()/down() as-is is really the most sensible option.
...
Quoted 4 lines
Doing a s/down/lock_mutex/ s/up/unlock_mutex/ - or whatever naming convention we want to use - all over the place for mutexes while keeping the up/down for counting semaphores is an one time issue.
Quoted 8 lines
After the conversion every code breaks at compile time which tries to do up/down(mutex_type).
So the out of tree drivers have a clear indication what to fix. This is also a one time issue.
So where is the problem - except for fixing "huge" amounts of out of kernel code once ?
Pointless API breakage. The same functions continue to exist, the old names CANNOT be reused for some (longish) time, so there's no point in renaming them. It just breaks an API for no good reason whatsoever.
Cheers
Quoted 13 lines · Mark Lord
Quoted 2 lines
Quoted 1 line
Leaving up()/down() as-is is really the most sensible option.
...
Quoted 10 lines
Doing a s/down/lock_mutex/ s/up/unlock_mutex/ - or whatever naming convention we want to use - all over the place for mutexes while keeping the up/down for counting semaphores is an one time issue.
After the conversion every code breaks at compile time which tries to do up/down(mutex_type).
So the out of tree drivers have a clear indication what to fix. This is also a one time issue.
Quoted 7 lines
Quoted 2 lines
So where is the problem - except for fixing "huge" amounts of out of kernel code once ?
Pointless API breakage. The same functions continue to exist, the old names CANNOT be reused for some (longish) time, so there's no point in renaming them. It just breaks an API for no good reason whatsoever.
Well, depends on the POV. A counting sempahore is a different beast than a mutex. At least as far as my limited knowledge of concurrency controls goes.
The API breakage was introduced by using up/down for mutexes and not by correcting this to a sane API.
tglx
Quoted 4 lines · Thomas Gleixner
Well, depends on the POV. A counting sempahore is a different beast than a mutex. At least as far as my limited knowledge of concurrency controls goes.
A real semaphore is counting.
Dammit, unless the pure mutex has a _huge_ performance advantage on major architectures, we're not changing it. There's absolutely zero point. A counting semaphore is a perfectly fine mutex - the fact that it can _also_ be used to allow more than 1 user into a critical region and generally do other things is totally immaterial.
It's _extra_ stupid to re-use the names "down()" and "up()" on a non-counting mutex, since then the names make zero sense at all. Use "lock_mutex()" and "unlock_mutex()" or something, and don't break existing code for no measurable gain.
Linus
Quoted 2 lines · Linus Torvalds
Dammit, unless the pure mutex has a _huge_ performance advantage on major architectures, we're not changing it.
Whilst it's true that the major archs are generally where the least advantage will be seen, consider the following points:
(1) The major archs are generally the ones where consuming a few extra bytes of kernel code so as to hold the slow paths for the mutexes would matter least.
(2) The minor archs are where the performance gain would be most noticable because many of them only have unconditional state substitution capabilities (XCHG/TAS/SWAP/BSET), and no matter how much you may not care for them, they do matter.
Having to use spinlocks and interrupt disablement in lieu of conditional state substitution (such as CMPXCHG) can cost quite a bit.
(3) Mutex performance should in no way be slower on any arch than counting semaphores being used to do the same job. Now, admittedly, my first attempt was suboptimal for archs that have better-than-XCHG capabilities, but I've amended that with Ingo's help, just not released it yet.
Quoted 2 lines
There's absolutely zero point. A counting semaphore is a perfectly fine mutex
But that isn't so in one particular case: debugging. A mutex would balk at a double-release, but a counting semaphore will just silently let things go wrong, because that's the nature of the beast.
Quoted 2 lines
- the fact that it can _also_ be used to allow more than 1 user into a critical region and generally do other things is totally immaterial.
There are about a dozen such uses of counting semaphores in the kernel, and they're mainly used as token/message counters.
Quoted 4 lines
It's _extra_ stupid to re-use the names "
down()" and "up()" on a non-counting mutex, since then the names make zero sense at all. Use "lock_mutex()" and "unlock_mutex()" or something, and don't break existing code for no measurable gain.
Okay. Repurposing up(), down(), DECLARE_MUTEX() and init_MUTEX() had the major benefit that the kernel required relatively few changes. The biggest problem with doing a whole new mutex type with a new and different API is that DECLARE_MUTEX and init_MUTEX are already taken... :-/
David
Quoted 3 lines · Mark Lord
Leaving up()/down() as-is is really the most sensible option.
Absolutely.
I must say that my interest in this stuff is down in needs-an-electron-microscope-to-locate territory. down() and up() work just fine and they're small, efficient, well-debugged and well-understood. We need a damn good reason for taking on tree-wide churn or incompatible renames or addition of risk. What's the damn good reason here?
Please. Go fix some bugs. We're not short of them.
Quoted 7 lines · Andrew Morton
Quoted 3 lines · Mark Lord
Leaving up()/down() as-is is really the most sensible option.
Absolutely.
Quoted 7 lines
I must say that my interest in this stuff is down in needs-an-electron-microscope-to-locate territory.
down()andup()work just fine and they're small, efficient, well-debugged and well-understood. We need a damn good reason for taking on tree-wide churn or incompatible renames or addition of risk. What's the damn good reason here?Please. Go fix some bugs. We're not short of them.
But this change is about fixing bugs: mutex assumes that
- only owner can unlock, and
- owner cannot lock (immediate self-deadlock).
This can be checked by the debugging code, and yes, these kinds of errors do happen.
Not to say that by looking at
struct foo_bar_baz {
struct mutex fbb_mutex;
...
};one can instantly infer that ->fbb_mutex is used to serialize something rather than serves as some fancy signaling mechanism.
Nikita.
Quoted 5 lines · Nikita Danilov
But this change is about fixing bugs: mutex assumes that
- only owner can unlock, and
- owner cannot lock (immediate self-deadlock).
So add mutex_up/mutex_down that use the same semaphores but do extra checks if lock debugging is enabled. All you need is an owner field for debugging.
Now generate a trace dump on up when up and to check for sleeping on a lock you already hold (for both sem and mutex).
Alan
Quoted 10 lines · Alan Cox
Quoted 5 lines · Nikita Danilov
But this change is about fixing bugs: mutex assumes that
- only owner can unlock, and
- owner cannot lock (immediate self-deadlock).
So add mutex_up/mutex_down that use the same semaphores but do extra checks if lock debugging is enabled. All you need is an owner field for debugging.
And to convert almost all calls to down/up to mutex_{down,up}. At which point, it no longer makes sense to share the same data-type for semaphore and mutex.
Also, (as was already mentioned several times) having separate data-type for mutex makes code easier to understand, as it specifies intended usage.
To avoid duplicating code, mutex can be implemented on top of semaphore, like
struct mutex {
struct semaphore sema;
#ifdef DEBUG_MUTEX
void *owner;#endif
};
or something similar.
Quoted 3 lines
Now generate a trace dump on up when up and to check for sleeping on a lock you already hold (for both sem and mutex).
Sleeping on a semaphore "held" by the current thread is perfectly reasonable usage of a generic counting semaphore, as it can be upped by another thread.
Quoted 2 lines
Alan
Nikita.
Quoted 3 lines · Nikita Danilov
And to convert almost all calls to down/up to mutex_{down,up}. At which point, it no longer makes sense to share the same data-type for semaphore and mutex.
But what to do about DECLARE_MUTEX? :-/
David
Quoted 9 lines · David Howells
Quoted 3 lines · Nikita Danilov
And to convert almost all calls to down/up to mutex_{down,up}. At which point, it no longer makes sense to share the same data-type for semaphore and mutex.
But what to do about
DECLARE_MUTEX? :-/David
Isn't "struct semaphore" already an opaque type. Nobody, except the optimizer wizards, should even care what's in them. They are already manipulated with init_MUTEX, up, down, etc. There shouldn't be any code changes if the actual internal workings are changed.
If some code is peeking into the internal workings, then it's broken. Don't break the whole kernel by a name-change. Sharing the same data-type, as long as there are no alignment problems, has no negative impact at all. If there is stuff inside those structures that is not used for a particular instance, who cares? Somebody doing debugging? If they are doing kernel debugging, they should know what they are doing, you don't dumb-down the kernel to the lowest common denominator because there may be different structure members used for different purposes!
Cheers,
Dick Johnson
Penguin : Linux version 2.6.13.4 on an i686 machine (5589.56 BogoMips). Warning : 98.36% of all statistics are fiction.
.
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
Quoted 2 lines · David Howells
But what to do about
DECLARE_MUTEX? :-/
It's correctly named right now (it _does_ declare a mutex, despite the insane noise from the sidelines).
I would suggest that if you create a new "mutex" type, you just keep the lower-case name. Don't re-use the DECLARE_MUTEX format, just do
struct mutex my_mutex = UNLOCKED_MUTEX;
for new code that uses the new stuff.
Think about it a bit. We don't have DECLARE_SPINLOCK either. Why?
Hint: we have DECLARE_MUTEX exactly because it's also DOCUMENTATION that we use a semaphore as a pure binary mutex. Not because we need it.
If you create a real "struct mutex", then something like the current DECLARE_MUTEX() is simply not relevant for the new type.
Linus
Quoted 1 line · Linus Torvalds
Think about it a bit. We don't have
DECLARE_SPINLOCKeither. Why?
I thought it was something to do with initialising struct list_heads, which spinlocks don't have.
David
Quoted 8 lines · Linus Torvalds
I would suggest that if you create a new "mutex" type, you just keep the lower-case name. Don't re-use the
DECLARE_MUTEXformat, just dostruct mutex my_mutex = UNLOCKED_MUTEX;for new code that uses the new stuff.
Think about it a bit. We don't have
DECLARE_SPINLOCKeither. Why?
Well, we have DEFINE_SPINLOCK() and we should have a matching one for mutexes DEFINE_MUTEX().
The reason is that you can implement complex initialization for debugging or extensions which can't be done by a var = INITIALZER, because you dont have a reference to var.
tglx
Quoted 2 lines · Linus
Hint: we have
DECLARE_MUTEXexactly because it's also DOCUMENTATION that we use a semaphore as a pure binary mutex. Not because we need it.
That's insane ...
This is stealth documentation at its finest. Who besides Linus even knew that's what this spelling of the DECLARE macro was telling us?
Paul "Hand me that chain saw, Billy Jo. This limb is coming -down-" Jackson
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401Quoted 4 lines · Paul Jackson
Quoted 2 lines
Hint: we have
DECLARE_MUTEXexactly because it's also DOCUMENTATION that we use a semaphore as a pure binary mutex. Not because we need it.That's insane ...
And abused/misused...
Quoted 4 lines
This is stealth documentation at its finest. Who besides Linus even knew that's what this spelling of the DECLARE macro was telling us?
Paul "Hand me that chain saw, Billy Jo. This limb is coming -down-" Jackson
I hope you're talking about trees...
David
Quoted 1 line
But what to do about
DECLARE_MUTEX? :-/
A phased change of just the renames:
DECLARE_MUTEX ==> DECLARE_SEM init_MUTEX ==> init_SEM DECLARE_MUTEX_LOCKED ==> DECLARE_SEM_LOCKED init_MUTEX_LOCKED ==> init_SEM_LOCKED
seems doable. A scripted replacement, so long as it specifies whole word replacement only, seems to be a very robust replacement for these four symbols, unlike "up"/"down", which are scary at best to consider wholesale replacement.
Add the new *_SEM in one release as aliases for the current *_MUTEX, do the wholesale replacement of the above names, leaving the old as aliases in a second release, remove the old *_MUTEX aliases in a third release, and them restore them as new 'real mutex' methods in a fourth release. Be sure that the new *_MUTEX versions will generate a compile error if handed the old counting semaphore type.
I'm a stickler for names ... at least until Linus/Andrew show me the foolishness of my ways, I could find such a change appealing.
Of course, they're the ones with all the sweat equity on the line, not me.
... I'd better duck and get back to bug fixing, before I get hit ...
Signature · 3 lines
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <[email protected]> 1.925.600.0401Quoted 6 lines · Paul Jackson
A phased change of just the renames:
DECLARE_MUTEX ==> DECLARE_SEM init_MUTEX ==> init_SEM DECLARE_MUTEX_LOCKED ==> DECLARE_SEM_LOCKED init_MUTEX_LOCKED ==> init_SEM_LOCKED
I'd prefer:
FROM TO ============================== ========================= DECLARE_MUTEX DECLARE_SEM_MUTEX DECLARE_MUTEX_LOCKED DECLARE_SEM_MUTEX_LOCKED Proper counting semaphore DECLARE_SEM
That way people can show their intent and can be seen more easily when violating it.
David
Quoted 6 lines · David Howells
FROM TO ============================== ========================= DECLARE_MUTEX DECLARE_SEM_MUTEX DECLARE_MUTEX_LOCKED DECLARE_SEM_MUTEX_LOCKED Proper counting semaphore DECLARE_SEM
That sounds fine. I wouldn't be adverse to doing that - but it would have to be independently of any other changes, and it would need to simmer for a while for out-of-tree drivers etc to notice (ie you should _not_ just introduce a new "DECLARE_MUTEX()" immediately to confuse things).
The patch could probably be fairly trivially generated with some trivial sed-script. Not that I'll take it at this point, but after the next release..
Linus
Quoted 10 lines · Linus Torvalds
Quoted 6 lines · David Howells
FROM TO ============================== ========================= DECLARE_MUTEX DECLARE_SEM_MUTEX DECLARE_MUTEX_LOCKED DECLARE_SEM_MUTEX_LOCKED Proper counting semaphore DECLARE_SEM
Quoted 4 lines
That sounds fine. I wouldn't be adverse to doing that - but it would have to be independently of any other changes, and it would need to simmer for a while for out-of-tree drivers etc to notice (ie you should _not_ just introduce a new "
DECLARE_MUTEX()" immediately to confuse things).
Going off at a tangent (or tangle, rather), why do we need DECLARE_FOO() macros at all? They
- do not look like C variable declarations, hide variable type, and hence are confusing,
- contrary to their naming actually _define_ rather than _declare_ an object.
In most cases
type var = INIT_FOO;
is much better (more readable and easier to understand) than
DECLARE_FOO(var); /* what is the type of var? */
In the cases where initializer needs an address of object being initialized
type var = INIT_FOO(var);
can be used.
Nikita.
Steven Rostedt
reviewerQuoted 15 lines · Nikita Danilov
Going off at a tangent (or tangle, rather), why do we need
DECLARE_FOO()macros at all? They- do not look like C variable declarations, hide variable type, and hence are confusing,
- contrary to their naming actually _define_ rather than _declare_ an object.
In most cases
type var = INIT_FOO;is much better (more readable and easier to understand) than
Quoted 8 lines
DECLARE_FOO(var); /* what is the type of var? */In the cases where initializer needs an address of object being initialized
type var = INIT_FOO(var);can be used.
That's just error prone. In the RT patch we had several bugs caused by cut and paste errors like:
type foo = INIT_TYPE(foo);
type bar = INIT_TYPE(foo);
These are not always easy to find.
-- Steve
Quoted 10 lines · Linus Torvalds
Quoted 6 lines · David Howells
FROM TO ============================== ========================= DECLARE_MUTEX DECLARE_SEM_MUTEX DECLARE_MUTEX_LOCKED DECLARE_SEM_MUTEX_LOCKED Proper counting semaphore DECLARE_SEMThat sounds fine.
They should be renamed to DEFINE_* while we're there. A "declaration" is "this thing is defined somewhere else". A "definition" is "this thing is defined here".
Quoted 1 line
I wouldn't be adverse to doing that
argh.
Quoted 4 lines · Andrew Morton
They should be renamed to DEFINE_* while we're there. A "declaration" is "this thing is defined somewhere else". A "definition" is "this thing is defined here".
Yeah, I confuse the two. Although by now I've gotten so used to DECLARE_ that at least me personally I like it.
Quoted 3 lines
Quoted 1 line
I wouldn't be adverse to doing that
argh.
Heh. At least there's only 310 DECLARE_MUTEX* references in the whole kernel. So we're not actually talking about a huge patch.
It's also fairly simple to work with in out-of-tree drivers, since it's always bound to be a #define, so you can do things like
#ifndef DECLARE_SEM_MUTEX #define DECLARE_SEM_MUTEX(x) DECLARE_MUTEX(x) #endif
or something.
Linus
Steven Rostedt
reviewerQuoted 10 lines · Andrew Morton
Quoted 9 lines · Linus Torvalds
Quoted 6 lines · David Howells
FROM TO ============================== ========================= DECLARE_MUTEX DECLARE_SEM_MUTEX DECLARE_MUTEX_LOCKED DECLARE_SEM_MUTEX_LOCKED Proper counting semaphore DECLARE_SEM
Quoted 5 lines
Quoted 1 line
That sounds fine.
They should be renamed to DEFINE_* while we're there. A "declaration" is "this thing is defined somewhere else". A "definition" is "this thing is defined here".
Why have the "MUTEX" part in there? Shouldn't that just be DECLARE_SEM (oops, I mean DEFINE_SEM). Especially that MUTEX_LOCKED! What is that? How does a MUTEX start off as locked. It can't, since a mutex must always have an owner (which, by the way, helped us in the -rt patch to find our "compat_semaphores"). So who's the owner of a DEFINE_SEM_MUTEX_LOCKED?
-- Steve
Quoted 17 lines · Steven Rostedt
Quoted 10 lines · Andrew Morton
Quoted 9 lines · Linus Torvalds
Quoted 6 lines · David Howells
FROM TO ============================== ========================= DECLARE_MUTEX DECLARE_SEM_MUTEX DECLARE_MUTEX_LOCKED DECLARE_SEM_MUTEX_LOCKED Proper counting semaphore DECLARE_SEMQuoted 5 lines
Quoted 1 line
That sounds fine.
They should be renamed to DEFINE_* while we're there. A "declaration" is "this thing is defined somewhere else". A "definition" is "this thing is defined here".
Quoted 6 lines
Why have the "MUTEX" part in there? Shouldn't that just be
DECLARE_SEM(oops, I meanDEFINE_SEM). Especially thatMUTEX_LOCKED! What is that? How does a MUTEX start off as locked. It can't, since a mutex must always have an owner (which, by the way, helped us in the -rt patch to find our "compat_semaphores"). So who's the owner of aDEFINE_SEM_MUTEX_LOCKED?
No one. It's not really a mutex, but a completion.
Gr{oetje,eeting}s,
Geert
P.S. Long live the common vocabulary ;-)
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 8 lines · Geert Uytterhoeven
Quoted 6 lines
Why have the "MUTEX" part in there? Shouldn't that just be
DECLARE_SEM(oops, I meanDEFINE_SEM). Especially thatMUTEX_LOCKED! What is that? How does a MUTEX start off as locked. It can't, since a mutex must always have an owner (which, by the way, helped us in the -rt patch to find our "compat_semaphores"). So who's the owner of aDEFINE_SEM_MUTEX_LOCKED?No one. It's not really a mutex, but a completion.
Well, then let us use a completion and not some semantically wrong workaround
tglx
Quoted 8 lines · Thomas Gleixner
Quoted 7 lines · Geert Uytterhoeven
Quoted 6 lines
Why have the "MUTEX" part in there? Shouldn't that just be
DECLARE_SEM(oops, I meanDEFINE_SEM). Especially thatMUTEX_LOCKED! What is that? How does a MUTEX start off as locked. It can't, since a mutex must always have an owner (which, by the way, helped us in the -rt patch to find our "compat_semaphores"). So who's the owner of aDEFINE_SEM_MUTEX_LOCKED?
Quoted 4 lines
Quoted 1 line
No one. It's not really a mutex, but a completion.
Well, then let us use a completion and not some semantically wrong workaround
It is _not_ wrong to have a semaphore start out in locked state.
For example, it makes perfect sense if the data structures that the semaphore needs need initialization. The way you _should_ handle that is to make the semaphore come up as locked, and the data structures in some "don't matter" state, and then the thing that initializes stuff can do so properly and then release the semaphore.
Yes, in some cases such a locked semaphore is only used once, and ends up being a "completion", but that doesn't invalidate the fact that this is a perfectly fine way to handle a real issue.
Linus
Quoted 14 lines · Linus Torvalds
Quoted 5 lines
Quoted 2 lines
No one. It's not really a mutex, but a completion.
Well, then let us use a completion and not some semantically wrong workaround
It is _not_ wrong to have a semaphore start out in locked state.
For example, it makes perfect sense if the data structures that the semaphore needs need initialization. The way you _should_ handle that is to make the semaphore come up as locked, and the data structures in some "don't matter" state, and then the thing that initializes stuff can do so properly and then release the semaphore.
Quoted 3 lines
Yes, in some cases such a locked semaphore is only used once, and ends up being a "completion", but that doesn't invalidate the fact that this is a perfectly fine way to handle a real issue.
Well, in case of a semaphore it is a semantically correct use case. In case of of a mutex it is not.
Gerd was talking about a mutex. The fact that a mutex is implemented on top (or on actually the same) mechanism as a semaphore - for what ever reason - does not change the semantical difference between semaphores and mutexes.
tglx
Quoted 3 lines · Thomas Gleixner
Well, in case of a semaphore it is a semantically correct use case. In case of of a mutex it is not.
I disagree.
Think of "initialization" as a user. The system starts out initializing stuff, and as such the mutex should start out being held. It's that simple. It _is_ mutual exclusion, with one user being the early bootup state.
Linus
Steven Rostedt
reviewerQuoted 6 lines · Linus Torvalds
Quoted 3 lines · Thomas Gleixner
Well, in case of a semaphore it is a semantically correct use case. In case of of a mutex it is not.
Quoted 6 lines
I disagree.
Think of "initialization" as a user. The system starts out initializing stuff, and as such the mutex should start out being held. It's that simple. It _is_ mutual exclusion, with one user being the early bootup state.
That's stretching it quite a bit. So you are saying that the owner is the first swapper task, from the booting CPU? Well, you better have that same process unlock that mutex, since a mutex has a owner and the owner _must_ be the one to unlock it. And in lots of these cases, it's some other thread that releases the lock.
With mutexs, the owner is not a state, but a task.
-- Steve
Quoted 6 lines · Linus Torvalds
Quoted 3 lines · Thomas Gleixner
Well, in case of a semaphore it is a semantically correct use case. In case of of a mutex it is not.
Quoted 6 lines
I disagree.
Think of "initialization" as a user. The system starts out initializing stuff, and as such the mutex should start out being held. It's that simple. It _is_ mutual exclusion, with one user being the early bootup state.
Mutual exclusion is available with various semantical characteristics. If you want to have a particular semantical functionality you have to chose a variant which fits that need. Arguing that the underlying mechanism (implemenation) can handle your request is broken by definition. It can, but it still is semantically wrong.
Mutexes have a well defined semantic of lock ownership, i.e. the thread which locked a mutex has to unlock it. Semaphores do not have this semantical requirement.
Therefor, if you want to handle that "init protection" scenario, do not use a mutex, because the owner can not be defined at compile - allocation time.
You can still implement (chose a mechanism) a mutex on top - or in case of lack of priority inheritance or debugging with exactly the same - mechanism as a semaphore, but this does not change the semantical difference at all.
tglx
Quoted 4 lines · Thomas Gleixner
Therefor, if you want to handle that "init protection" scenario, do not use a mutex, because the owner can not be defined at compile - allocation time.
Sure it could. We certainly have "init_task", for example. It may or may not be the right thing to use, of course. Depends on what the situation is.
Quoted 4 lines
You can still implement (chose a mechanism) a mutex on top - or in case of lack of priority inheritance or debugging with exactly the same - mechanism as a semaphore, but this does not change the semantical difference at all.
"Friends don't let friends use priority inheritance".
Just don't do it. If you really need it, your system is broken anyway.
Linus
Steven Rostedt
reviewerQuoted 4 lines · Linus Torvalds
"Friends don't let friends use priority inheritance".
Just don't do it. If you really need it, your system is broken anyway.
You've been hanging around Victor Yodaiken too much ;)
-- Steve
Quoted 8 lines · Linus Torvalds
Quoted 4 lines
You can still implement (chose a mechanism) a mutex on top - or in case of lack of priority inheritance or debugging with exactly the same - mechanism as a semaphore, but this does not change the semantical difference at all.
"Friends don't let friends use priority inheritance".
Just don't do it. If you really need it, your system is broken anyway.
We are not talking about priority inheritance and its usefulness at all.
Fact is that you can implement two semanticaly different concurrency controls with or on top of the same mechanism under given circumstances (no debugging, no ...). But the reverse attempt is wrong by defintion.
tglx
Quoted 3 lines · Linus Torvalds
"Friends don't let friends use priority inheritance".
Just don't do it. If you really need it, your system is broken anyway.
The Mars Pathfinder incident is sufficient proof that some solution to the priority inversion problem is required in real systems.
http://www.cs.cmu.edu/afs/cs/user/raj/www/mars.html
Regards,
Joe
--
"All the revision in the world will not save a bad first draft, for the architecture of the thing comes, or fails to come, in the first conception, and revision only affects the detail and ornament. -- T.E. Lawrence
Quoted 3 lines · Joe Korty
The Mars Pathfinder incident is sufficient proof that some solution to the priority inversion problem is required in real systems.
Ehh.
The Mars Pathfinder is just about the worst case "real system", and if I recall correctly, the reason it was able to continue was _not_ because it handled priority inversion, but because it reset itself every 24 hours or something like that, and had debugging facilities..
The _real_ lesson you should take away from it is not that priority inheritance is a good solution to priority inversion, but that having a failsafe switch when everthing goes wrong is critical. You don't know _what_ bug you'll encounter.
The bug itself could have been solved without priority inheritance, although I think in this case enabling that in VxWorks was the particular solution to the problem as being the least invasive.
Personally, I don't care what user space does. If some app wants to use priority inheritance to solve its bugs, that's fine. But it's like recursive locks: it's generally a _bandaid_ for bad locking. I definitely don't want the kernel depending on either.
So put a watchdog on your critical systems, and make sure you can debug them. Especially if they're on Mars.
Linus
Steven Rostedt
reviewerQuoted 18 lines · Linus Torvalds
Quoted 3 lines · Joe Korty
The Mars Pathfinder incident is sufficient proof that some solution to the priority inversion problem is required in real systems.
Ehh.
The Mars Pathfinder is just about the worst case "real system", and if I recall correctly, the reason it was able to continue was _not_ because it handled priority inversion, but because it reset itself every 24 hours or something like that, and had debugging facilities..
The _real_ lesson you should take away from it is not that priority inheritance is a good solution to priority inversion, but that having a failsafe switch when everthing goes wrong is critical. You don't know _what_ bug you'll encounter.
Quoted 8 lines
The bug itself could have been solved without priority inheritance, although I think in this case enabling that in VxWorks was the particular solution to the problem as being the least invasive.
Personally, I don't care what user space does. If some app wants to use priority inheritance to solve its bugs, that's fine. But it's like recursive locks: it's generally a _bandaid_ for bad locking. I definitely don't want the kernel depending on either.
So how does one handle real-time tasks that must contend with locks within the kernel that is shared with low priority tasks? Do you prefer the RTAI approach?
-- Steve
Quoted 4 lines · Steven Rostedt
So how does one handle real-time tasks that must contend with locks within the kernel that is shared with low priority tasks? Do you prefer the RTAI approach?
If you want hard real-time, either that, or just make sure you don't get locks that might be slow (for one reason or another). Finer granularities help there.
For example, to make things really concrete, please just name a semaphore that is relevant to a real-time task and that isn't fine enough grain that a careful and controlled environment can't avoid it being a bottle-neck for a real-time task.
The real problems often end up happening in things like memory management, and waiting for IO, where it's not about the locking at all, it's about event scheduling. And you just have to avoid those (through pre-allocation and buffering) in those kinds of real-time situations.
I really can't think of any blocking kernel lock where priority inheritance would make _any_ sense at all. Please give me an example.
Linus
Quoted 2 lines · Linus Torvalds
I really can't think of any blocking kernel lock where priority inheritance would make _any_ sense at all. Please give me an example.
I have a better example of something we currently get wrong that I haven't heard any RT person worry about yet. If two tasks are sleeping on the same semaphore, the one to be woken up will be the first one to wait for it, not the highest-priority task.
Obviously, this was introduced by the wake-one semantics. But how to fix it? Should we scan the entire queue looking for the best task to wake? Should we try to maintain the wait list in priority order? Or should we just not care? Should we document that we don't care? ;-)
Quoted 9 lines · Matthew Wilcox
Quoted 2 lines · Linus Torvalds
I really can't think of any blocking kernel lock where priority inheritance would make _any_ sense at all. Please give me an example.
I have a better example of something we currently get wrong that I haven't heard any RT person worry about yet. If two tasks are sleeping on the same semaphore, the one to be woken up will be the first one to wait for it, not the highest-priority task.
Quoted 4 lines
Obviously, this was introduced by the wake-one semantics. But how to fix it? Should we scan the entire queue looking for the best task to wake? Should we try to maintain the wait list in priority order? Or should we just not care? Should we document that we don't care? ;-)
It's well known that this is a problem:
http://developer.osdl.org/dev/robustmutexes/src/fusyn.hg/Documentation/fusyn/fusyn-why.txt
Lee
Quoted 6 lines · Lee Revell
Quoted 5 lines · Matthew Wilcox
I have a better example of something we currently get wrong that I haven't heard any RT person worry about yet. If two tasks are sleeping on the same semaphore, the one to be woken up will be the first one to wait for it, not the highest-priority task.
Quoted 8 lines
Quoted 4 lines
Obviously, this was introduced by the wake-one semantics. But how to fix it? Should we scan the entire queue looking for the best task to wake? Should we try to maintain the wait list in priority order? Or should we just not care? Should we document that we don't care? ;-)
It's well known that this is a problem:
http://developer.osdl.org/dev/robustmutexes/src/fusyn.hg/Documentation/fusyn/fusyn-why.txt
Erm. That paper is talking about user-space semaphores based on futexes. I'm talking about kernel semaphores. At a first glance, fixing futexes would be a very different job from fixing semaphores.
BTW, fuqueues? HAHAHAHA.
Quoted 14 lines · Matthew Wilcox
Quoted 13 lines · Lee Revell
Quoted 9 lines · Matthew Wilcox
I have a better example of something we currently get wrong that I haven't heard any RT person worry about yet. If two tasks are sleeping on the same semaphore, the one to be woken up will be the first one to wait for it, not the highest-priority task.
Obviously, this was introduced by the wake-one semantics. But how to fix it? Should we scan the entire queue looking for the best task to wake? Should we try to maintain the wait list in priority order? Or should we just not care? Should we document that we don't care? ;-)
It's well known that this is a problem:
Quoted 8 lines
Quoted 1 line
http://developer.osdl.org/dev/robustmutexes/src/fusyn.hg/Documentation/fusyn/fusyn-why.txt
Erm. That paper is talking about user-space semaphores based on futexes. I'm talking about kernel semaphores. At a first glance, fixing futexes would be a very different job from fixing semaphores.
BTW, fuqueues? HAHAHAHA.
Hmm, interesting, so in fact the scheduler does not always run the highest priority runnable process? Do you have a test case where userspace would experience priority inversion due to this?
Maybe it has not been a problem as all the PI cases would involve two RT processes that make system calls which end up blocking on a semaphore in the kernel, which is bad RT design anyway - normally you would separate the RT parts of the app which carefully avoid possibly blocking system calls from the non RT parts and communicate via lock free ringbuffers or a similar mechanism.
Lee
Quoted 9 lines · Matthew Wilcox
I have a better example of something we currently get wrong that I haven't heard any RT person worry about yet. If two tasks are sleeping on the same semaphore, the one to be woken up will be the first one to wait for it, not the highest-priority task.
Obviously, this was introduced by the wake-one semantics. But how to fix it? Should we scan the entire queue looking for the best task to wake? Should we try to maintain the wait list in priority order? Or should we just not care? Should we document that we don't care? ;-)
-rt deals with this using priority sorted wait queue and direct ownership hand off to the woken thread. It's working fine for now, but things like wake-all and company should probably be explored for various uses. A strict general purpose and RT usage of the Linux kernel have different performance characteristic and mutex selection at compile time should address things precisely.
bill
Quoted 2 lines · Linus Torvalds
I really can't think of any blocking kernel lock where priority inheritance would make _any_ sense at all. Please give me an example.
you are completely right, most of the blocking kernel locks we have in Linux are an extremely poor candidate for priority inheritance. Most of them are totally noncritical, or cover so long codepaths that 'latency guarantees' and 'priority inheritance' make little sense for them.
the reason why we still have transformed most of the stock semaphore users to generic mutexes in the -rt kernel is mostly because i wanted to have _one_ central lock implementation. Firstly, it makes alot of sense to consolidate code on embedded platforms anyway. Secondly, it was much easier to implement (and validate) one robust locking primitive, than to implement 5 separate primitives. The fact that this also made semaphores PI-able is just a side-effect, with little to no practical relevance.
maybe ->i_sem is one notable exception: it is often held in critical codepaths, and it's really hard for even the most-well-controlled RT app to achieve _total_ isolation from the 'unprivileged' filesystem space. So occasional 'resource sharing' in form of hitting an i_sem of another task may still occur, and PI can at least reduce the worst-case cost somehow. (even though i_sem codepaths are by no means deterministic!)
so in the -rt kernel, every semaphore, rw-semaphore, spinlock, rwlock and seqlock [and in the latest -rt patches, every futex too] is abstracted off a central generic mutex type, which mutex is blocking and supports priority queueing and priority inheritance. It also has an extensive debugging framework, which we didnt want to duplicate for every separate lock object.
we also have a facility in the -rt kernel that traces the worst-case latency path of critical applications (the 'latency tracer'), when mixed with non-critical workloads, so we have quite good experience about what kind of locks make a difference and what kind of locks make no difference.
we also definitely know that priority inheritance done over _all_ these lock objects makes a very real quality difference in practice, resulting in real-time apps experiencing much lower worst-case latencies than under the stock kernel. It is true that you could live without priority inheritance, in cases were the RT app can be rewritten to have totally separated resources, but in practice that is only possible for the simplest applications.
Ingo
Quoted 4 lines · Linus Torvalds
For example, to make things really concrete, please just name a semaphore that is relevant to a real-time task and that isn't fine enough grain that a careful and controlled environment can't avoid it being a bottle-neck for a real-time task.
Problem here is ownership tracking with a semaphore is an extremely difficult problem to solve without serializing the entire thing with a single spinlock. You lose parallelism here and possible create other problems since the contention window is larger surround critical sections using it.
Quoted 7 lines
The real problems often end up happening in things like memory management, and waiting for IO, where it's not about the locking at all, it's about event scheduling. And you just have to avoid those (through pre-allocation and buffering) in those kinds of real-time situations.
I really can't think of any blocking kernel lock where priority inheritance would make _any_ sense at all. Please give me an example.
The current kernel mostly using traditional spinlocks doesn't have locking complicated enough to warrant it. However, the -rt patch does create a circumstance where a fully preemptible may sleep task with mutexes held create and needs resolve priority inversions that results from it. That's of course assuming that priority is something that needs to be strictly obeyed in this variant of the kernel with consideration to priority inheritance.
bill
Quoted 4 lines · Bill Huey
The current kernel mostly using traditional spinlocks doesn't have locking complicated enough to warrant it. However, the -rt patch does create[s] a circumstance where a fully preemptible [kernel] may sleep task with mutexes held create[ing] [-and needs] [a need to] resolve priority inversions that results from it. That's of
With corrections...
Sorry, I meant a fully preemptive kernel has priority inversion as an inheritant property and needs to resolved using some kind of priority inheritance.
Quoted 3 lines
course assuming that priority is something that needs to be strictly obeyed in this variant of the kernel with consideration to priority inheritance.
bill
Quoted 7 lines · Linus Torvalds
The Mars Pathfinder is just about the worst case "real system", and if I recall correctly, the reason it was able to continue was _not_ because it handled priority inversion, but because it reset itself every 24 hours or something like that, and had debugging facilities..
...
So put a watchdog on your critical systems, and make sure you can debug them. Especially if they're on Mars.
Who are you and what have you done with the real[1]
Linus "I'm a sick and twisted person, and I trust people who write code without debuggers a lot more than I trust those who don't" Torvalds :-)
[1] http://www.ussg.iu.edu/hypermail/linux/kernel/9510/0103.html
Quoted 3 lines · Nikita Danilov
And to convert almost all calls to down/up to mutex_{down,up}. At which point, it no longer makes sense to share the same data-type for semaphore and mutex.
If we're going to call it a mutex, it would make sense to use familiar terminology and call it lock/unlock rather than down/up.
Chris
Steven Rostedt
reviewerQuoted 8 lines · Christopher Friesen
Quoted 3 lines · Nikita Danilov
And to convert almost all calls to down/up to mutex_{down,up}. At which point, it no longer makes sense to share the same data-type for semaphore and mutex.
If we're going to call it a mutex, it would make sense to use familiar terminology and call it lock/unlock rather than down/up.
ACK!
-- Steve
Steven Rostedt
reviewerQuoted 5 lines · Andrew Morton
Quoted 3 lines · Mark Lord
Leaving up()/down() as-is is really the most sensible option.
Quoted 8 lines
Absolutely.
I must say that my interest in this stuff is down in needs-an-electron-microscope-to-locate territory.
down()andup()work just fine and they're small, efficient, well-debugged and well-understood. We need a damn good reason for taking on tree-wide churn or incompatible renames or addition of risk. What's the damn good reason here?
****
Quoted 1 line
Please. Go fix some bugs. We're not short of them.
****
I'd give that the quote of the day!
-- Steve
Quoted 5 lines · Andrew Morton
I must say that my interest in this stuff is down in needs-an-electron-microscope-to-locate territory.
down()andup()work just fine and they're small, efficient, well-debugged and well-understood. We need a damn good reason for taking on tree-wide churn or incompatible renames or addition of risk. What's the damn good reason here?
Well...
(1) On some platforms counting semaphores _can't_ be implemented all that efficiently because the only atomic op you've got is something very simple that can only unconditionally exchange one state for another (XCHG/TAS/SWAP). In such cases counting semaphores have to be be implemented by disabling interrupts and taking spinlocks.
Okay, spinlocks are null ops when CONFIG_SMP and CONFIG_DEBUG_SPINLOCK are both disabled, but you still have to disable interrupts, and that slows things down, sometimes quite appreciably. It is, for example, something I really want to avoid doing on FRV as it takes a *lot* of cycles.
(2) I think Ingo has some RT requirements, but he's probably better to speak about them.
(3) As a slight aside, in a number of cases counting semaphores and their operators are being misused: there are, for example, places where completions should be used instead and places where *_MUTEX_LOCKED are used to initialise counting semaphores. There are also cases in there that seem unsure as to whether they're using counting semaphores or mutexes.
Whilst this is not an argument for a galaxy wide churn, in and of itself, it does show that a good review is needed and at the very least these cases need to be fixed.
(4) Various people want a mutex for which the semantics are tighter: in particular requiring that mutexes must be released in their owner's context. This makes debugging easier.
(5) Mutexes can catch a double-release, which counting semaphores by their very nature can't.
So... Would you then object to an implementation of a mutex appearing in the tree which semaphores that are being used as strict mutexes can be migrated over to as the opportunity arises?
David
Quoted 4 lines · David Howells
So... Would you then object to an implementation of a mutex appearing in the
tree which semaphores that are being used as strict mutexes can be migrated over to as the opportunity arises?
That would be sane. The semaphore->completion migration didn't hurt.
Quoted 9 lines · Andrew Morton
Quoted 4 lines · David Howells
So... Would you then object to an implementation of a mutex appearing in the
tree which semaphores that are being used as strict mutexes can be migrated over to as the opportunity arises?That would be sane.
But not very.
Look at it from the POV of major architectures: there's no way the new mutex code will be faster than down() and up(), so we're adding a bunch of new tricky locking code which bloats the kernel and has to be understood and debugged for no gain.
And I don't buy the debuggability argument really. It'd be pretty simple to add debug code to the existing semaphore code to trap non-mutex usages. Then go through the few valid non-mutex users and do:
#if debug sem->this_is_not_a_mutex = 1;
#endif
Steven Rostedt
reviewerQuoted 11 lines · Andrew Morton
Quoted 9 lines · Andrew Morton
Quoted 4 lines · David Howells
So... Would you then object to an implementation of a mutex appearing in the
tree which semaphores that are being used as strict mutexes can be migrated over to as the opportunity arises?That would be sane.
Quoted 6 lines
But not very.
Look at it from the POV of major architectures: there's no way the new mutex code will be faster than
down()andup(), so we're adding a bunch of new tricky locking code which bloats the kernel and has to be understood and debugged for no gain.
I see it as a stepping stone for RT ;)
Quoted 8 lines
And I don't buy the debuggability argument really. It'd be pretty simple to add debug code to the existing semaphore code to trap non-mutex usages. Then go through the few valid non-mutex users and do:
#if debug sem->this_is_not_a_mutex = 1;#endif
That just looks plain ugly. Still, if you want to keep the major archs unchanged (at least until RT is in!) then just add the following:
#define mutex_lock(x) down(x)
#define mutex_unlock(x) up(x)
#define mutex_trylock(x) (!down_trylock(x)) /* see previous email! */
Then you can add your ugly patch ;) where on debug we define those declared with DEFINE_SEM(x) add the this_is_not_a_mutex = 1
-- Steve
Quoted 5 lines
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 2 lines · Andrew Morton
Look at it from the POV of major architectures: there's no way the new mutex code will be faster than
down()andup()
I'm thinking of making the default implementation of mutexes a straight wrapper around down() and up(). That way it'll be exactly the same as counting semaphores, just with extra constraints when the debugging is enabled _and_ effectively extra inline documentation.
But! for archs where it does matter (and we have several - you might not care, but others do), it can be overridden with something faster.
David
Quoted 4 lines · Andrew Morton
Look at it from the POV of major architectures: there's no way the new mutex code will be faster than
down()andup(), so we're adding a bunch of new tricky locking code which bloats the kernel and has to be understood and debugged for no gain.
Look at it from the semantical POV first, which is the most important one.
semaphores are semantically different from mutexes, so they require different APIs.
When you have semantically different APIs, you can still implement them for whatever (e.g. peformance) reason on top of the same mechanism, but you can not make this work the other way round.
tglx
Quoted 2 lines · Ingo Molnar
all this simplified the 'compatibility conversion' to the patch below. No other non-generic changes are needed.
there were 3 more patches needed, which convert some semaphores to completions:
sx8-sem2completions.patch
cpu5wdt-sem2completions.patch
ide-gendev-sem-to-completion.patch
all attached.
Ingo
drivers/block/sx8.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
drivers/block/sx8.c +6 -5
@@ -27,6 +27,7 @@#include <linux/time.h> #include <linux/hdreg.h> #include <linux/dma-mapping.h> +#include <linux/completion.h> #include <asm/io.h> #include <asm/semaphore.h> #include <asm/uaccess.h>
@@ -303,7 +304,7 @@ struct carm_host {struct work_struct fsm_task; -struct semaphore probe_sem; +struct completion probe_comp; };struct carm_response {
@@ -1365,7 +1366,7 @@ static void carm_fsm_task (void *_data) }case HST_PROBE_FINISHED : -up (&host->probe_sem); +complete (&host->probe_comp);break ;case HST_ERROR :
@@ -1641,7 +1642,7 @@ static int carm_init_one (struct pci_dev host->flags = pci_dac ?FL_DAC :0 ;spin_lock_init (&host->lock);INIT_WORK (&host->fsm_task, carm_fsm_task, host); -init_MUTEX_LOCKED (&host->probe_sem); +init_completion (&host->probe_comp);for (i =0 ; i <ARRAY_SIZE (host->req); i++) host->req[i].tag = i;
@@ -1710,8 +1711,8 @@ static int carm_init_one (struct pci_devif (rc) goto err_out_free_irq; -DPRINTK ("waiting for probe_sem\n" ); -down (&host->probe_sem); +DPRINTK ("waiting for probe_comp\n" ); +wait_for_completion (&host->probe_comp); printk(KERN_INFO "%s: pci %s, ports %d, io %lx, irq %u, major %d\n", host->name, pci_name(pdev), (int) CARM_MAX_PORTS,
drivers/char/watchdog/cpu5wdt.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
drivers/char/watchdog/cpu5wdt.c +5 -4
@@ -28,6 +28,7 @@#include <linux/init.h> #include <linux/ioport.h> #include <linux/timer.h> +#include <linux/completion.h> #include <linux/jiffies.h> #include <asm/io.h> #include <asm/uaccess.h>
@@ -57,7 +58,7 @@ static int ticks = 10000;/* some device data */ static struct { - struct semaphore stop; + struct completion stop; volatile int running; struct timer_list timer; volatile int queue;
@@ -85,7 +86,7 @@ static void cpu5wdt_trigger(unsigned lon }else {/* ticks doesn't matter anyway */ -up (&cpu5wdt_device.stop); +complete (&cpu5wdt_device.stop); } }
@@ -239,7 +240,7 @@ static int __devinit cpu5wdt_init(void)if ( !val ) printk(KERN_INFO PFX "sorry, was my fault\n"); -init_MUTEX_LOCKED (&cpu5wdt_device.stop); +init_completion (&cpu5wdt_device.stop); cpu5wdt_device.queue =0 ;clear_bit (0 , &cpu5wdt_device.inuse);
@@ -269,7 +270,7 @@ static void __devexit cpu5wdt_exit(void) {if ( cpu5wdt_device.queue ) { cpu5wdt_device.queue =0 ; -down (&cpu5wdt_device.stop); +wait_for_completion (&cpu5wdt_device.stop); }misc_deregister (&cpu5wdt_misc);
The following patch is from Montavista. I modified it slightly. Semaphores are currently being used where it makes more sense for completions. This patch corrects that.
-- Steve
Source: MontaVista Software, Inc.
Description:
The patch changes semaphores that are initialized as locked to complete().
drivers/ide/ide-probe.c | 4 ++-- drivers/ide/ide.c | 8 ++++---- include/linux/ide.h | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-)
drivers/ide/ide-probe.c +2 -2
@@ -655,7 +655,7 @@ static void hwif_release_dev (struct dev {ide_hwif_t *hwif =container_of (dev, ide_hwif_t, gendev); -up (&hwif->gendev_rel_sem); +complete (&hwif->gendev_rel_comp); }static void hwif_register (ide_hwif_t *hwif)
@@ -1325,7 +1325,7 @@ static void drive_release_dev (struct de drive->queue =NULL ;spin_unlock_irq (&ide_lock); -up (&drive->gendev_rel_sem); +complete (&drive->gendev_rel_comp); }/*
drivers/ide/ide.c +4 -4
@@ -222,7 +222,7 @@ static void init_hwif_data(ide_hwif_t *h hwif->mwdma_mask =0x80 ;/* disable all mwdma */ hwif->swdma_mask =0x80 ;/* disable all swdma */ -sema_init (&hwif->gendev_rel_sem,0 ); +init_completion (&hwif->gendev_rel_comp);default_hwif_iops (hwif);default_hwif_transport (hwif);
@@ -245,7 +245,7 @@ static void init_hwif_data(ide_hwif_t *h drive->is_flash =0 ; drive->vdma =0 ;INIT_LIST_HEAD (&drive->list); -sema_init (&drive->gendev_rel_sem,0 ); +init_completion (&drive->gendev_rel_comp); } }
@@ -602,7 +602,7 @@ void ide_unregister(unsigned int index) }spin_unlock_irq (&ide_lock);device_unregister (&drive->gendev); -down (&drive->gendev_rel_sem); +wait_for_completion (&drive->gendev_rel_comp);spin_lock_irq (&ide_lock); } hwif->present =0 ;
@@ -662,7 +662,7 @@ void ide_unregister(unsigned int index)/* More messed up locking ... */ spin_unlock_irq (&ide_lock);device_unregister (&hwif->gendev); -down (&hwif->gendev_rel_sem); +wait_for_completion (&hwif->gendev_rel_comp);/* * Remove us from the kernel's knowledge
include/linux/ide.h +3 -2
@@ -18,6 +18,7 @@#include <linux/bio.h> #include <linux/device.h> #include <linux/pci.h> +#include <linux/completion.h> #include <asm/byteorder.h> #include <asm/system.h> #include <asm/io.h>
@@ -759,7 +760,7 @@ typedef struct ide_drive_s {int crc_count;/* crc counter to reduce drive speed */ struct list_head list;struct device gendev; -struct semaphore gendev_rel_sem;/* to deal with device release() */ +struct completion gendev_rel_comp;/* to deal with device release() */ } ide_drive_t;#define to_ide_device (dev)container_of(dev, ide_drive_t, gendev)
@@ -915,7 +916,7 @@ typedef struct hwif_s { unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */struct device gendev; -struct semaphore gendev_rel_sem;/* To deal with device release() */ +struct completion gendev_rel_comp;/* To deal with device release() */ void *hwif_data;/* extra hwif data */
Quoted 4 lines · Andrew Morton
Maybe I'm not understanding all this, but...
I'd have thought that the way to do this is to simply reimplement
down(),up(),down_trylock(), etc using the new xchg-based code
Which I did.
Quoted 3 lines
and to then hunt down those few parts of the kernel which actually use the old semaphore's counting feature and convert them to use
down_sem(),up_sem(), etc.
Done, I think. It's not always 100% obvious.
Quoted 1 line
And rename all the old semaphore code: s/down/down_sem/etc.
Done.
Quoted 1 line
So after such a transformation, this new "mutex" thingy would not exist.
Why not? I want to make them different types so that you can't use the wrong operators by accident or mix them.
Quoted 3 lines
Quoted 1 line
include/linux/mutex.h | 32 +++++++But it does.
Well, I could fold this into each asm/semaphore.h.
Quoted 3 lines
Quoted 1 line
+#define
mutex_grab(mutex)(xchg(&(mutex)->state, 1)== 0)
mutex_trylock(), please.
You're right.
Quoted 3 lines
Quoted 1 line
+#define
is_mutex_locked(mutex)((mutex)->state)Let's keep the namespace consistent.
mutex_is_locked().
But that's a poor name: it turns it from a question into a statement:-(
Quoted 5 lines
include/linux/mutex-simple.h line 127
Quoted 3 lines
include/linux/mutex-simple.h renamed from warthog/kernels/linux-2.6.15-rc5/include/linux/mutex-simple.h +3
-0+static inline void down (struct mutex *mutex) +{ +if (mutex_grab (mutex)) {
likely()
No... down_trylock().
Quoted 5 lines
include/linux/mutex-simple.h line 143
Quoted 3 lines
include/linux/mutex-simple.h renamed from warthog/kernels/linux-2.6.15-rc5/include/linux/mutex-simple.h +3
-0+static inline int down_interruptible (struct mutex *mutex) +{ +if (mutex_grab (mutex)) {
likely()
down_trylock() again.
Quoted 5 lines
include/linux/mutex-simple.h line 159
Quoted 3 lines
include/linux/mutex-simple.h renamed from warthog/kernels/linux-2.6.15-rc5/include/linux/mutex-simple.h +3
-0+static inline int down_trylock (struct mutex *mutex) +{ +if (mutex_grab (mutex)) {etc.
Yes.
Quoted 17 lines
You could just put
likely()intomutex_trylock(). err,mutex_grab().Quoted 15 lines
include/linux/mutex-simple.h renamed from warthog/kernels/linux-2.6.15-rc5/include/linux/mutex-simple.h +15
-0+/* +* release the mutex +*/ +static inline void up (struct mutex *mutex) +{ +unsigned long flags; + +#ifdef CONFIG_DEBUG_MUTEX_OWNER +if (mutex->__owner != current) +__up_bad (mutex); + mutex->__owner =NULL ; +#endif + +/* must prevent a race */ +spin_lock_irqsave (&mutex->wait_lock, flags);
Quoted 8 lines
include/linux/mutex-simple.h line 191
Quoted 6 lines
include/linux/mutex-simple.h renamed from warthog/kernels/linux-2.6.15-rc5/include/linux/mutex-simple.h +6
-0+if (!list_empty (&mutex->wait_list)) +__up (mutex); +else +mutex_release (mutex); +spin_unlock_irqrestore (&mutex->wait_lock, flags); +}This is too large to inline.
You're probably right.
Quoted 1 line
It's also significantly slower than the existing
up()?
Hmmm... If you've only got two states available to you and/or you can only exchange states, then there's a limit to what you can actually do. You can lose the spinlock in the up() fastpath if you're willing to forgo fairness or resort to waking up processes superfluously.
Ingo and Nick have a point about using CMPXCHG or equivalent if it's available. This lets you modify the state you have, rather than swapping it for a whole new state; in which case the state can be annotated to indicate that there is waking up to be done, thus permitting the fast path to be much faster. But this can only be done in the case where the state may be modified.
As I tried to make clear: this is the simplest I could come up with, but I have made provision for overriding it with something better if that's possible.
David
Quoted 5 lines · David Howells
Quoted 3 lines
Quoted 1 line
+#define
is_mutex_locked(mutex)((mutex)->state)Let's keep the namespace consistent.
mutex_is_locked().But that's a poor name: it turns it from a question into a statement:-(
Ah, but look at it in context of how it's used:
if (is_mutex_locked())
That's gramatically incorrect!
if (mutex_is_locked())
much better.
lib/mutex-simple.c line 33
Quoted 3 lines · David Howells
lib/mutex-simple.c renamed from warthog/kernels/linux-2.6.15-rc5/lib/mutex-simple.c +3
-0+/* set up my own style of waitqueue */ + waiter.task = tsk; +
Any reason why you're setting up your own style of waitqueue in mutex-simple.c instead of just using the kernel's style of waitqueue?
Quoted 14 lines
lib/mutex-simple.c renamed from warthog/kernels/linux-2.6.15-rc5/lib/mutex-simple.c +14
-0+ +/* +* release a single token back to a mutex +* - entered with lock held and interrupts disabled +* - the queue will not be empty +*/ +void __up (struct mutex *mutex) +{ +struct mutex_waiter *waiter; +struct task_struct *tsk; + +/* grant the token to the process at the front of the queue */ + waiter = list_entry(mutex->wait_list.next, struct mutex_waiter, list); +
lib/mutex-simple.c line 147
Quoted 10 lines
lib/mutex-simple.c renamed from warthog/kernels/linux-2.6.15-rc5/lib/mutex-simple.c +10
-0+/* we must be careful not to touch 'waiter' after we set ->task = NULL. +* - it is an allocated on the waiter's stack and may become invalid at +* any time after that point (due to a wakeup from another source). +*/ +list_del_init (&waiter->list); + tsk = waiter->task; +#ifdef CONFIG_DEBUG_MUTEX_OWNER + mutex->__owner = tsk; +#endif +mb ();
This should be smp_mb(), I think.
lib/mutex-simple.c line 151
Quoted 4 lines
lib/mutex-simple.c renamed from warthog/kernels/linux-2.6.15-rc5/lib/mutex-simple.c +4
-0+ waiter->task =NULL ; +wake_up_process (tsk); +put_task_struct (tsk); +}
Thanks,
Nick
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 2 lines · Nick Piggin
Any reason why you're setting up your own style of waitqueue in
mutex-simple.cinstead of just using the kernel's style of waitqueue?
Because I can steal the code from FRV's semaphores or rw-semaphores, and this way I can be sure of what I'm doing.
Note that the sleeping processes are generally dequeued and dispatched by the up() function, which means they don't have to take the spinlock themselves. This may be possible to do magically with the waitqueue stuff, but I'm not sure how to do it; it's horribly complicated to read through the sources and there isn't much documentation.
Quoted 3 lines
lib/mutex-simple.c line 147
Quoted 1 line
lib/mutex-simple.c renamed from warthog/kernels/linux-2.6.15-rc5/lib/mutex-simple.c +1
-0+mb ();This should be
smp_mb(), I think.
Yes.
David
Quoted 5 lines · David Howells
Quoted 2 lines
Any reason why you're setting up your own style of waitqueue in
mutex-simple.cinstead of just using the kernel's style of waitqueue?Because I can steal the code from FRV's semaphores or rw-semaphores, and this way I can be sure of what I'm doing.
And because:
struct mutex {
int state;
wait_queue_head_t wait_queue;
};Wastes 8 more bytes of memory than:
struct mutex {
int state;
spinlock_t wait_lock;
struct list_head wait_list;
};on a 64-bit machine if spinlock_t is 4 bytes. Both waste 4 bytes if spinlock_t is 8 bytes.
David
Arnd Bergmann
maintainerAm Dienstag 13 Dezember 2005 00:45 schrieb David Howells:
Quoted 2 lines
(7) Provides a debugging config option
CONFIG_DEBUG_MUTEX_OWNERby which the mutex owner can be tracked and by which over-upping can be detected.
I can't see how your code actually detects the over-upping, although it's fairly obvious how it would be done. Did you miss one patch for this?
Arnd <><
Quoted 2 lines · Arnd Bergmann
I can't see how your code actually detects the over-upping, although it's fairly obvious how it would be done. Did you miss one patch for this?
If owner is NULL, then you've probably upped twice.
David
Quoted 8 lines · David Howells
(1) Provides a simple
xchg()based semaphore as a default for all architectures that don't wish to override it and provide their own.Overriding is possible by setting
CONFIG_ARCH_IMPLEMENTS_MUTEXand supplyingasm/mutex.hPartial overriding is possible by #defining
mutex_grab(),mutex_release()andis_mutex_locked()to perform the appropriate optimised functions.
Your code is really similar to the RT mutex, which does everything that your mutex does at least ? Assuming you've reviewed the RT mutex, why would we want to use yours over it?
Daniel
Steven Rostedt
reviewerQuoted 8 lines · Daniel Walker
Quoted 6 lines · David Howells
(1) Provides a simple
xchg()based semaphore as a default for all architectures that don't wish to override it and provide their own.Overriding is possible by setting
CONFIG_ARCH_IMPLEMENTS_MUTEXand supplyingasm/mutex.h
Quoted 6 lines
Quoted 2 lines
Partial overriding is possible by #defining
mutex_grab(),mutex_release()andis_mutex_locked()to perform the appropriate optimised functions.Your code is really similar to the RT mutex, which does everything that your mutex does at least ? Assuming you've reviewed the RT mutex, why would we want to use yours over it?
Maybe this would be the better !PREEMPT_RT version. But the true mutex that Ingo is making would be used for the PREEMPT_RT side.
This code at least brings down the over head of semaphores where they are not really needed. Looking at the code slightly (I must admit, I spent maybe 30 seconds looking at it), it does seem a little similar to Ingo's. Could just be coincidence, since the methods are pretty much what multiple people would come up with. But you both work for RedHat, hmm.
-- Steve
Quoted 7 lines
(5) Redirects the following to apply to the new mutexes rather than the
traditional semaphores: down() down_trylock() down_interruptible() up()
This will BREAK a lot of out-of-tree stuff if merged.
So please figure out some way to hang a HUGE banner out there so that the external codebases know they need updating.
The simplest way would be to NOT re-use the up()/down() symbols, but rather to either keep them as-is (counting semaphores), or delete them entirely (so that external code *knows* of the change).
Cheers
Steven Rostedt
reviewerQuoted 8 lines · Mark Lord
Quoted 7 lines
(5) Redirects the following to apply to the new mutexes rather than the
traditional semaphores: down() down_trylock() down_interruptible() up()
Quoted 8 lines
This will BREAK a lot of out-of-tree stuff if merged.
So please figure out some way to hang a HUGE banner out there so that the external codebases know they need updating.
The simplest way would be to NOT re-use the up()/down() symbols, but rather to either keep them as-is (counting semaphores), or delete them entirely (so that external code *knows* of the change).
Actually, up and down don't imply mutex at all. So maybe it would be better to keep up and down as normal semaphores, rename what you want to mutex_lock / mutex_unlock which makes it obvious what it is, and then you can go through and find all the semaphores that are being used as mutexes (or is that mutices?) and make the change more incrementally.
-- Steve
Quoted 1 line · Mark Lord
This will BREAK a lot of out-of-tree stuff if merged.
Well, bad luck for them.
Quoted 3 lines
The simplest way would be to NOT re-use the up()/down() symbols, but rather to either keep them as-is (counting semaphores), or delete them entirely (so that external code *knows* of the change).
That I agree with actually. Keeping the semaphore interface as-is would simplify in-kernel transition a lot aswell and make it easier for people to get the API read. And the mutex symbols could get far more sensible names like mutex_lock, mutex_unlock and mutex_trylock..
Quoted 2 lines · David Howells
init_MUTEX_LOCKED()
DECLARE_MUTEX_LOCKED()
please kill these two in the simple mutex implementation - they are a sign of mutexes used as completions.
Quoted 2 lines
(7) Provides a debugging config option
CONFIG_DEBUG_MUTEX_OWNERby which the mutex owner can be tracked and by which over-upping can be detected.
another simplification: also enforce that only the owner can unlock the mutex. This is what we are doing in the -rt patch. (This rule also ensures that such mutexes can be used for priority inheritance.)
Ingo
Quoted 5 lines · Ingo Molnar
Quoted 2 lines
init_MUTEX_LOCKED()
DECLARE_MUTEX_LOCKED()please kill these two in the simple mutex implementation - they are a sign of mutexes used as completions.
That can be done later. It's not necessary to do it in this particular patch set.
David
Quoted 10 lines · David Howells
Quoted 5 lines · Ingo Molnar
Quoted 2 lines
init_MUTEX_LOCKED()
DECLARE_MUTEX_LOCKED()please kill these two in the simple mutex implementation - they are a sign of mutexes used as completions.
That can be done later. It's not necessary to do it in this particular patch set.
i disagree - it's necessary that we dont build complexities into the 'simple' mutex type, or the whole game starts again. I.e. the 'owner unlocks the mutex' rule must be enforced - which makes DECLARE_MUTEX_LOCKED() meaningless.
Ingo
Quoted 11 lines · David Howells
(5) Redirects the following to apply to the new mutexes rather than the
traditional semaphores: down() down_trylock() down_interruptible() up() init_MUTEX() init_MUTEX_LOCKED() DECLARE_MUTEX() DECLARE_MUTEX_LOCKED()
And you've audited every occurence ?
Quoted 3 lines
On the basis that most usages of semaphores are as mutexes, this makes sense for in most cases it's just then a matter of changing the type from struct semaphore to struct mutex.
You propose to rename the existing up and down, which are counting semaphores, documented and used that way everywhere with mutexes which are not. Worse still up/down are, second to P/V, the usual forms of referring to _counting_ semaphores.
It seems to me it would be far far saner to define something like
sleep_lock(&foo)
sleep_unlock(&foo)
sleep_trylock(&foo)
given the new mutex interface is actually a sleeping interface with the semantics of the spin_lock interface. Its then obvious what it does, you don't randomly break other drivers you've not reviewed and the interface is intuitive rather than obfuscated.
It won't take long for people to then change the name of the performance critical cases and the others will catch up in time.
It also saves breaking every piece of out of tree kernel code for now good reason.
Alan
Actually a PS to this while I think about it. spin_locks and mutex type locks could both do with a macro for
call_locked(&lock, foo(a,b,c,d))
to cut down on all the error path forgot to release a lock type errors.
Quoted 4 lines · Alan Cox
Actually a PS to this while I think about it.
spin_locksand mutex type locks could both do with a macro forcall_locked(&lock, foo(a,b,c,d))
reiser4 code was publicly humiliated for such macros, but indeed they are useful. The only problem is that one needs two macros: one for foo() returning void and one for all other cases.
Quoted 3 lines
to cut down on all the error path forgot to release a lock type errors.
Nikita.
Quoted 7 lines · Alan Cox
Quoted 4 lines
(5) Redirects the following to apply to the new mutexes rather than the
traditional semaphores: down()...
And you've audited every occurence ?
Outside of the arch directories, yes; but I don't know that I've made the correct decision in 100% of the cases.
I've changed some of the uses into completions, and found about a dozen or so uses of counting semaphores; but the vast majority of occurrences seem to be wanting mutex behaviour.
Quoted 5 lines
It seems to me it would be far far saner to define something like
sleep_lock(&foo)
sleep_unlock(&foo)
sleep_trylock(&foo)
Which would be a _lot_ more work. It would involve about ten times as many changes, I think, and thus be more prone to errors.
Quoted 2 lines
Its then obvious what it does, you don't randomly break other drivers you've not reviewed and the interface is intuitive rather than obfuscated.
I've attempted to review everything in 2.6.15-rc5 outside of most of the archs. I can't easily modify any driver not contained in that tarball, but at least the compiler will barf and force a review.
Quoted 2 lines
It won't take long for people to then change the name of the performance critical cases and the others will catch up in time.
It took about ten hours to go through the declarations of struct semaphore and review them; I hate to think how long it'd take to go through all the ups and downs too.
Quoted 2 lines
It also saves breaking every piece of out of tree kernel code for now good reason.
But my patch means the changes required are in the most cases minimal: just changing struct semaphore to struct mutex is sufficient for the vast majority of cases.
Your way requires a lot more work, both in the tree and out of it.
David
Quoted 6 lines · David Howells
Quoted 2 lines
Its then obvious what it does, you don't randomly break other drivers you've not reviewed and the interface is intuitive rather than obfuscated.
I've attempted to review everything in 2.6.15-rc5 outside of most of the archs. I can't easily modify any driver not contained in that tarball, but at least the compiler will barf and force a review.
Is there a reason you didnt answer the comment about down/up being the usual way computing refers to the operations on counting semaphores but just deleted it ?
Quoted 3 lines · Alan Cox
Is there a reason you didnt answer the comment about down/up being the usual way computing refers to the operations on counting semaphores but just deleted it ?
up/down is also used in conjunction with mutexes and R/W semaphores, so counting semaphores do not have exclusive rights to the terminology.
David
Quoted 6 lines · David Howells
Quoted 3 lines
Is there a reason you didnt answer the comment about down/up being the usual way computing refers to the operations on counting semaphores but just deleted it ?
up/down is also used in conjunction with mutexes and R/W semaphores, so counting semaphores do not have exclusive rights to the terminology.
I suspect that is only the case where the author of the mutex was accustomed to using semaphores as mutexes before-hand; "up/down" are rather poor names for mutex operations otherwise. lock/unlock are much better.
-Miles
Signature · 2 lines
Next to fried food, the South has suffered most from oratory. -- Walter Hines Page
Quoted 10 lines · David Howells
Quoted 5 lines · Alan Cox
It seems to me it would be far far saner to define something like
sleep_lock(&foo)
sleep_unlock(&foo)
sleep_trylock(&foo)Which would be a _lot_ more work. It would involve about ten times as many changes, I think, and thus be more prone to errors.
"lots of work" has never been a valid reason for not doing a kernel change...
In this case, introducing a new API means the changes can be made over time.
As time goes on you can convert more and more code to the mutex/sleep lock and any tricky code just stays with the older API until someone who understands it can vet it.
As Alan mentioned, the standard counting semaphore API is up/down. Making those refer to a sleeping mutex violates the principle of least surprise.
Chris
Quoted 9 lines · Christopher Friesen
Quoted 8 lines · David Howells
Quoted 5 lines · Alan Cox
It seems to me it would be far far saner to define something like
sleep_lock(&foo)
sleep_unlock(&foo)
sleep_trylock(&foo)
Quoted 7 lines
Quoted 2 lines
Which would be a _lot_ more work. It would involve about ten times as many changes, I think, and thus be more prone to errors.
"lots of work" has never been a valid reason for not doing a kernel change...
In this case, introducing a new API means the changes can be made over time.
in this case, doing this change gradual I think is a mistake. We should do all of the in-kernel code at least...
Quoted 7 lines · Arjan van de Ven
Quoted 1 line · Christopher Friesen
In this case, introducing a new API means the changes can be made over time.
in this case, doing this change gradual I think is a mistake. We should do all of the in-kernel code at least...
This means verifying all the users before patch submission, which may be problematic.
I guess the point I'm trying to make is that if you create a new API you have the option of converting the obvious cases first, which should cover the majority of users. Anywhere the behaviour is non-obvious can be left using the old API, and the out-of-tree users will continue to work correctly.
Chris
Quoted 4 lines · Christopher Friesen
Quoted 2 lines
Which would be a _lot_ more work. It would involve about ten times as many changes, I think, and thus be more prone to errors.
"lots of work" has never been a valid reason for not doing a kernel change...
There are a number of considerations:
(1) If _I_ am going to be doing the work, then I'm quite happy to reduce the load by 90%. And I think it'd be at least that, probably more. Finding struct semaphore with grep is much easier than finding up/down with grep because of:
(a) comments
(b) other instances of up/down names, including rw_semaphores
There are a lot fewer instances of struct semaphore than up and down.
(2) It makes it easier for other people. In most cases, all they need do is change "struct semaphore" to "struct mutex". If they've used DECLARE_MUTEX() then they need do nothing at all, and if they've used init_MUTEX(), then they don't need to convert sema_init() either.
(3) It forces people to reconsider how they want to use their semaphores.
I have no objection to making life easier for other people. I suspect most other people don't care that their semaphores are now mutexes, and think of them that way anyway.
I admit that there are downsides:
(1) up and down now do something effectively different (though in most cases it's also exactly the same).
(2) Users of counting semaphores have to change, but they're in the minority by quite a way.
(3) Some people want mutexes to be:
(a) only releasable in the same context as they were taken
(b) not accessible in interrupt context, or that (a) applies here also
(c) not initialisable to the locked state
But this means that the current usages all have to be carefully audited, and sometimes that unobvious.
David
Quoted 10 lines · David Howells
(3) Some people want mutexes to be:
(a) only releasable in the same context as they were taken
(b) not accessible in interrupt context, or that (a) applies here also
(c) not initialisable to the locked state
But this means that the current usages all have to be carefully audited, and sometimes that unobvious.
Only if you insist on replacing them immediately. If you submit a *small* patch which just adds the new mutexes then a series of small patches can gradually convert code where mutexes are better. People will naturally hit the hot and critical points first meaning that in a short time the users of semaphores will be those who need it, and those who are not critical to performance.
There is a problemn with init_MUTEX*/DECLARE_MUTEX naming being used for semaphore struct init and I don't see a nice way to fix that either. I'd rather see people just have to fix those as compiler errors (or a perl -e regexp run to make them all init_SEM/DECLARE_SEM before any other changes are made).
Quoted 7 lines · Alan Cox
Quoted 6 lines · David Howells
(3) Some people want mutexes to be:
(a) only releasable in the same context as they were taken
(b) not accessible in interrupt context, or that (a) applies here also
Quoted 8 lines
Quoted 4 lines
(c) not initialisable to the locked state
But this means that the current usages all have to be carefully audited, and sometimes that unobvious.
Only if you insist on replacing them immediately. If you submit a *small* patch which just adds the new mutexes then a series of small patches can gradually convert code where mutexes are better.
this unfortunately is not very realistic in practice...
Quoted 10 lines · Arjan van de Ven
Quoted 9 lines · Alan Cox
Quoted 8 lines · David Howells
(3) Some people want mutexes to be:
(a) only releasable in the same context as they were taken
(b) not accessible in interrupt context, or that (a) applies here also
(c) not initialisable to the locked state
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
But this means that the current usages all have to be carefully audited, and sometimes that unobvious.
Only if you insist on replacing them immediately. If you submit a *small* patch which just adds the new mutexes then a series of small patches can gradually convert code where mutexes are better.
this unfortunately is not very realistic in practice...
to expand on this; this kind of change no matter what needs a mass change inside the kernel, or the point of it all is sort of moot. The idea is to make the mutex type the most common one, since most users ARE mutexes. To make that happen a one time "rather big" change is needed and planned afaics.
What's remaining is
1) transition period for in kernel stuff
2) out of the kernel code compatibility
3) should a forgotten item be a compile time failure or be allowed to work still
1) is a matter of "do we do it all now" or in phases. I don't see a reason to not do it all now, otherwise a 2 year process will happen
2) that is a semi moot issue; sure a big bang change will break this compatibility, but so will a gradual switchover. A gradual switchover of converting core semaphores into mutexes will need changes in external modules regardless (think vfs but there's many more). The question is doing it once or doing it multiple times over a period of 2 years.
3) history has shown that non-compiletime items keep lingering on forever, since there is no incentive or even detection of "old" use. At minimum a compiler warning is needed. Just look at the sleep_on_*() api; more than half the users in 2.6 are *new code* in 2.6, even though it's a deprecated api for ... how long?
Quoted 8 lines · Arjan van de Ven
Quoted 6 lines
Quoted 2 lines
But this means that the current usages all have to be carefully audited, and sometimes that unobvious.
Only if you insist on replacing them immediately. If you submit a *small* patch which just adds the new mutexes then a series of small patches can gradually convert code where mutexes are better.
this unfortunately is not very realistic in practice...
Strange because it is how most such work has been done in the past, from the big kernel lock to the scsi core rewrite. You also forgot to attach a reason you think it isnt realistic ?
Alan
Quoted 4 lines · Alan Cox
Quoted 3 lines · Arjan van de Ven
Quoted 3 lines
Quoted 2 lines
But this means that the current usages all have to be carefully audited, and sometimes that unobvious.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Only if you insist on replacing them immediately. If you submit a *small* patch which just adds the new mutexes then a series of small patches can gradually convert code where mutexes are better.
this unfortunately is not very realistic in practice...
Strange because it is how most such work has been done in the past, from the big kernel lock to the scsi core rewrite.
1) the BKL change hasn't finished, and we're 5 years down the line. API changes done gradual tend to take forever in practice, esp if there's no "compile" incentive for people to fix things.
2) the scsi rewrite was a major functional change. that's different from a basically pure API change (split). Splitting functional changes to one part of the kernel up into a sequence is very good. THat's different
though: even in the scsi change, API changes that went outside the scsi core into the drivers were mostly done in one bang (not all of them, the ones that weren't ended up being rather painful)
Quoted 3 lines
You also forgot to attach
a reason you think it isnt realistic ?
that was in a follow up email
Quoted 3 lines · Arjan van de Ven
1) the BKL change hasn't finished, and we're 5 years down the line. API changes done gradual tend to take forever in practice, esp if there's no "compile" incentive for people to fix things.
This isn't a "fix" however, its merely a performance tweak. Drivers using the old API are not a problem because
a) The old API is needed long term for true counting sem users
b) Its a minor performance hit at most
Thats rather different to the BKL
Could someone please remind me why we're even discussing this, given that mutex_down() is slightly more costly than current down(), and mutex_up() is appreciably more costly than current up()?
Quoted 1 line · Andrew Morton
Could someone please remind me why we're even discussing this,
* cleaner API
* more declarative in terms of intent
which in turn allow
* higher performance
* enhanced options like the -rt patch is doing, such as boosting processes when a semaphore they're holding hits contention
* mutex use is a candidate for a "spinaphore" treatment (unlike counting semaphores)
Quoted 3 lines
given that
mutex_down()is slightly more costly than currentdown(), andmutex_up()is appreciably more costly than currentup()?
that's an implementation flaw in the current implementation that is not needed by any means and that Ingo has fixed in his version of this
Quoted 2 lines
* mutex use is a candidate for a "spinaphore" treatment (unlike counting semaphores)
I think that would be interesting experiment for page faults. But they actually use rwsems, not normal semaphores.
-Andi
Quoted 5 lines · Andi Kleen
Quoted 2 lines
* mutex use is a candidate for a "spinaphore" treatment (unlike counting semaphores)
I think that would be interesting experiment for page faults. But they actually use rwsems, not normal semaphores.
at least rwsems are only used as mutexes afaik... so those would just end up being mutexes.. .and could thus do this too...
(I don't think anyone ever thought of doing a counting rwsem... at least I sure hope so; the page fault one sure is a mutex)
Quoted 6 lines · Arjan van de Ven
Quoted 3 lines
given that
mutex_down()is slightly more costly than currentdown(), andmutex_up()is appreciably more costly than currentup()?that's an implementation flaw in the current implementation that is not needed by any means and that Ingo has fixed in his version of this
As do I. I wrote it yesterday with Ingo looking over my shoulder, as it were, but I haven't released it yet.
What I provided was a base implementation that anything can use provided it has an atomic op capable of exchanging between two states, and I suspect everything that can do multiprocessing has - if you can do spinlocks, then you can do this. I ALSO provided a mechanism by which it could be overridden if there's something better available on that arch.
As I see it there are four classes of arch:
(0) Those that have no atomic ops at all - in which case xchg is trivially implemented by disabling interrupts, and spinlocks must be null because they can't be implemented.
(1) Those that only have a limited exchange functionality. Several archs do
fall into this category: arm, frv, mn10300, 68000, i386.
(2) Those that have CMPXCHG or equivalent: 68020, i486+, x86_64, ia64, sparc.
(3) Those that have LL/SC or equivalent: mips (some), alpha, powerpc, arm6.
(This isn't an exhaustive list of archs)
Each higher class can emulate all the lower classes, but can probably do a better implementation than the lower class because they have more flexibility.
For instance class (1) mutexes can only practically support two states, but class (2) and (3) can support multiple states, and so can improve the up() fastpath as well as the down() fastpaths.
With some archs, such as FRV, it might be possible to emulate a higher class, but it's not necessarily practical in all circumstances.
David
Quoted 2 lines · David Howells
(1) Those that only have a limited exchange functionality. Several archs do
fall into this category: arm, frv, mn10300, 68000, i386.
sparc (32-bit CPUs) fall into this category too. V7 CPUs have just atomic load byte and store 0xff, later CPUs have swap insn, which is like ia32 xchg.
Quoted 1 line
(2) Those that have CMPXCHG or equivalent: 68020, i486+,
x86_64, ia64, sparc.
sparc64 here.
Quoted 1 line
(3) Those that have LL/SC or equivalent: mips (some), alpha, powerpc, arm6.
Jakub
Quoted 26 lines · David Howells
Quoted 6 lines · Arjan van de Ven
Quoted 3 lines
given that
mutex_down()is slightly more costly than currentdown(), andmutex_up()is appreciably more costly than currentup()?that's an implementation flaw in the current implementation that is not needed by any means and that Ingo has fixed in his version of this
As do I. I wrote it yesterday with Ingo looking over my shoulder, as it were, but I haven't released it yet.
What I provided was a base implementation that anything can use provided it has an atomic op capable of exchanging between two states, and I suspect everything that can do multiprocessing has - if you can do spinlocks, then you can do this. I ALSO provided a mechanism by which it could be overridden if there's something better available on that arch.
As I see it there are four classes of arch:
(0) Those that have no atomic ops at all - in which case xchg is trivially implemented by disabling interrupts, and spinlocks must be null because they can't be implemented.
Quoted 7 lines
(1) Those that only have a limited exchange functionality. Several archs do
fall into this category: arm, frv, mn10300, 68000, i386.(2) Those that have CMPXCHG or equivalent: 68020, i486+,
x86_64, ia64, sparc.(3) Those that have LL/SC or equivalent: mips (some), alpha, powerpc, arm6.
cmpxchg is basically exactly equivalent to a store-conditional, so 2 and 3 are the same level.
I don't know why you don't implement a "good" default implementation with atomic_cmpxchg.
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 7 lines · Nick Piggin
Quoted 4 lines
(2) Those that have CMPXCHG or equivalent: 68020, i486+,
x86_64, ia64,
sparc.
(3) Those that have LL/SC or equivalent: mips (some), alpha, powerpc, arm6.cmpxchg is basically exactly equivalent to a store-conditional, so 2 and 3 are the same level.
No, they're not. LL/SC is more flexible than CMPXCHG because under some circumstances, you can get away without doing the SC, and because sometimes you can do one LL/SC in lieu of two CMPXCHG's because LL/SC allows you to retrieve the value, consider it and then modify it if you want to. With CMPXCHG you have to anticipate, and so you're more likely to get it wrong.
Quoted 2 lines
I don't know why you don't implement a "good" default implementation with
atomic_cmpxchg.
Because it wouldn't be a good default. I'm thinking the best default is simply to wrap a counting semaphore. Where overriding this really matters is class 1 CPUs that don't have CMPXCHG, LL/SC, or in the x86 case, LOCK INC/DEC.
I've had a play with x86, and on there CMPXCHG, XCHG and XADD give worse performance than INC/DEC for some reason. I assume this is something to do with how the PPro CPU optimises itself. On PPro CPUs at least, counting semaphores really are the most efficient way. CMPXCHG, whilst it ought to be better, really isn't.
One thing I have noticed, though, is that the counting semaphore tends to be quite uneven in its distribution across threads in a situation where a lot of threads are all trying to thrash the semaphore at the same time:
insmod /tmp/synchro-test.ko v=1 do_sched=1 sm=20 ism=1
gives:
SEM: 2% 1% 2% 5% 4% 4% 3% 11% 2% 33% 1% 1% 5% 2% 2% 1% 2% 3% 3% 4%
on a dual 200MHz PPro.
Whereas my mutexes are much more even:
MTX: 5% 5% 4% 4% 4% 5% 5% 5% 5% 4% 4% 4% 4% 4% 6% 5% 4% 4% 4% 6%
(See attached module).
Now, I don't think that this situation is very likely to crop up in ordinary use, but it seems odd.
David
/* synchro-test.c: run some threads to test the synchronisation primitives
*
* Copyright (C) 2005 Red Hat, Inc. All Rights Reserved.
* Written by David Howells ([email protected])
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* run as something like:
*
* insmod synchro-test.ko rd=2 wr=2
* insmod synchro-test.ko mx=1
* insmod synchro-test.ko sm=2 ism=1
* insmod synchro-test.ko sm=2 ism=2
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/poll.h>
#include <linux/moduleparam.h>
#include <linux/stat.h>
#include <linux/init.h>
#include <asm/atomic.h>
#include <linux/personality.h>
#include <linux/smp_lock.h>
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/completion.h>
#include <linux/mutex.h>
#define VALIDATE_OPERATORS 0
static int nummx = 0;
static int numsm = 0, seminit = 4;
static int numrd = 0, numwr = 0, numdg = 0;
static int elapse = 5, load = 0, do_sched = 0;
static int verbose = 0;
MODULE_AUTHOR("David Howells"); MODULE_DESCRIPTION("Synchronisation primitive test demo"); MODULE_LICENSE("GPL");
module_param_named(v, verbose, int, 0);MODULE_PARM_DESC(verbose, "Verbosity");
module_param_named(mx, nummx, int, 0); MODULE_PARM_DESC(nummx, "Number of mutex threads");
module_param_named(sm, numsm, int, 0); MODULE_PARM_DESC(numsm, "Number of semaphore threads");
module_param_named(ism, seminit, int, 0); MODULE_PARM_DESC(seminit, "Initial semaphore value");
module_param_named(rd, numrd, int, 0); MODULE_PARM_DESC(numrd, "Number of reader threads");
module_param_named(wr, numwr, int, 0); MODULE_PARM_DESC(numwr, "Number of writer threads");
module_param_named(dg, numdg, int, 0); MODULE_PARM_DESC(numdg, "Number of downgrader threads");
module_param(elapse, int, 0); MODULE_PARM_DESC(elapse, "Number of seconds to run for");
module_param(load, int, 0);MODULE_PARM_DESC(load, "Length of load in uS");
module_param(do_sched, int, 0);MODULE_PARM_DESC(do_sched, "True if each thread should schedule regularly");
/* the semaphores under test */
static struct mutex ____cacheline_aligned mutex; static struct semaphore ____cacheline_aligned sem; static struct rw_semaphore ____cacheline_aligned rwsem;
static atomic_t ____cacheline_aligned do_stuff = ATOMIC_INIT(0);
#if VALIDATE_OPERATORS
static atomic_t ____cacheline_aligned mutexes = ATOMIC_INIT(0);
static atomic_t ____cacheline_aligned semaphores = ATOMIC_INIT(0);
static atomic_t ____cacheline_aligned readers = ATOMIC_INIT(0);
static atomic_t ____cacheline_aligned writers = ATOMIC_INIT(0);
#endif
static unsigned int ____cacheline_aligned mutexes_taken[20]; static unsigned int ____cacheline_aligned semaphores_taken[20]; static unsigned int ____cacheline_aligned reads_taken[20]; static unsigned int ____cacheline_aligned writes_taken[20]; static unsigned int ____cacheline_aligned downgrades_taken[20];
static struct completion ____cacheline_aligned mx_comp[20]; static struct completion ____cacheline_aligned sm_comp[20]; static struct completion ____cacheline_aligned rd_comp[20]; static struct completion ____cacheline_aligned wr_comp[20]; static struct completion ____cacheline_aligned dg_comp[20];
static struct timer_list ____cacheline_aligned timer;
#define ACCOUNT(var, N) var##_taken[N]++;
#if VALIDATE_OPERATORS
#define TRACK(var, dir) atomic_##dir(&(var))
#define CHECK(var, cond, val) \
do { \
int x = atomic_read(&(var)); \
if (unlikely(!(x cond (val)))) \
printk("check [%s %s %d, == %d] failed in %s\n", \
#var, #cond, (val), x, __func__); \
} while (0)#else
#define TRACK(var, dir) do {} while(0)
#define CHECK(var, cond, val) do {} while(0)
#endif
static inline void do_mutex_lock(unsigned int N)
{
mutex_lock(&mutex);
ACCOUNT(mutexes, N);
TRACK(mutexes, inc);
CHECK(mutexes, ==, 1);
}static inline void do_mutex_unlock(unsigned int N)
{
CHECK(mutexes, ==, 1);
TRACK(mutexes, dec);
mutex_unlock(&mutex);
}static inline void do_down(unsigned int N)
{
CHECK(mutexes, <, seminit);
down(&sem);
ACCOUNT(semaphores, N);
TRACK(semaphores, inc);
}static inline void do_up(unsigned int N)
{
CHECK(semaphores, >, 0);
TRACK(semaphores, dec);
up(&sem);
}static inline void do_down_read(unsigned int N)
{
down_read(&rwsem);
ACCOUNT(reads, N);
TRACK(readers, inc);
CHECK(readers, >, 0);
CHECK(writers, ==, 0);
}static inline void do_up_read(unsigned int N)
{
CHECK(readers, >, 0);
CHECK(writers, ==, 0);
TRACK(readers, dec);
up_read(&rwsem);
}static inline void do_down_write(unsigned int N)
{
down_write(&rwsem);
ACCOUNT(writes, N);
TRACK(writers, inc);
CHECK(writers, ==, 1);
CHECK(readers, ==, 0);
}static inline void do_up_write(unsigned int N)
{
CHECK(writers, ==, 1);
CHECK(readers, ==, 0);
TRACK(writers, dec);
up_write(&rwsem);
}static inline void do_downgrade_write(unsigned int N)
{
CHECK(writers, ==, 1);
CHECK(readers, ==, 0);
TRACK(writers, dec);
TRACK(readers, inc);
downgrade_write(&rwsem);
ACCOUNT(downgrades, N);
}static inline void sched(void)
{
if (do_sched)
schedule();
}int mutexer(void *arg)
{
unsigned int N = (unsigned long) arg;
daemonize("Mutex%u", N);
while (atomic_read(&do_stuff)) {
do_mutex_lock(N);
if (load)
udelay(load);
do_mutex_unlock(N);
sched();
}
if (verbose >= 2)
printk("%s: done\n", current->comm);
complete_and_exit(&mx_comp[N], 0);
}int semaphorer(void *arg)
{
unsigned int N = (unsigned long) arg;
daemonize("Sem%u", N);
while (atomic_read(&do_stuff)) {
do_down(N);
if (load)
udelay(load);
do_up(N);
sched();
}
if (verbose >= 2)
printk("%s: done\n", current->comm);
complete_and_exit(&sm_comp[N], 0);
}int reader(void *arg)
{
unsigned int N = (unsigned long) arg;
daemonize("Read%u", N);
while (atomic_read(&do_stuff)) {
do_down_read(N);
#ifdef LOAD_TEST
if (load)
udelay(load);
#endif
do_up_read(N);
sched();
}
if (verbose >= 2)
printk("%s: done\n", current->comm);
complete_and_exit(&rd_comp[N], 0);
}int writer(void *arg)
{
unsigned int N = (unsigned long) arg;
daemonize("Write%u", N);
while (atomic_read(&do_stuff)) {
do_down_write(N);
#ifdef LOAD_TEST
if (load)
udelay(load);
#endif
do_up_write(N);
sched();
}
if (verbose >= 2)
printk("%s: done\n", current->comm);
complete_and_exit(&wr_comp[N], 0);
}int downgrader(void *arg)
{
unsigned int N = (unsigned long) arg;
daemonize("Down%u", N);
while (atomic_read(&do_stuff)) {
do_down_write(N);
#ifdef LOAD_TEST
if (load)
udelay(load);
#endif
do_downgrade_write(N);
#ifdef LOAD_TEST
if (load)
udelay(load);
#endif
do_up_read(N);
sched();
}
if (verbose >= 2)
printk("%s: done\n", current->comm);
complete_and_exit(&dg_comp[N], 0);
}static void stop_test(unsigned long dummy)
{
atomic_set(&do_stuff, 0);
}static unsigned int total(const char *what, unsigned int counts[], int num)
{
unsigned int tot = 0, max = 0, min = UINT_MAX, zeros = 0, cnt;
int loop;
for (loop = 0; loop < num; loop++) {
cnt = counts[loop];
if (cnt == 0) {
zeros++;
min = 0;
continue;
}
tot += cnt;
if (tot > max)
max = tot;
if (tot < min)
min = tot;
}
if (verbose && tot > 0) {
printk("%s:", what);
for (loop = 0; loop < num; loop++) {
cnt = counts[loop];
if (cnt == 0)
printk(" zzz");
else
printk(" %d%%", cnt * 100 / tot);
}
printk("\n");
}
return tot;
}/*****************************************************************************/ /*
*
*/
static int __init do_tests(void)
{
unsigned long loop;
unsigned int mutex_total, sem_total, rd_total, wr_total, dg_total;
if (nummx < 0 || nummx > 20 ||
numsm < 0 || numsm > 20 ||
numrd < 0 || numrd > 20 ||
numwr < 0 || numwr > 20 ||
numdg < 0 || numdg > 20 ||
seminit < 1 ||
elapse < 1
) {
printk("Parameter out of range\n");
return -ERANGE;
}
if ((nummx | numsm | numrd | numwr | numdg) == 0) {
printk("Nothing to do\n");
return -EINVAL;
}
if (verbose)
printk("\nStarting synchronisation primitive tests...\n");
mutex_init(&mutex);
sema_init(&sem, seminit);
init_rwsem(&rwsem);
atomic_set(&do_stuff, 1);
/* kick off all the children */
for (loop = 0; loop < 20; loop++) {
if (loop < nummx) {
init_completion(&mx_comp[loop]);
kernel_thread(mutexer, (void *) loop, 0);
}
if (loop < numsm) {
init_completion(&sm_comp[loop]);
kernel_thread(semaphorer, (void *) loop, 0);
}
if (loop < numrd) {
init_completion(&rd_comp[loop]);
kernel_thread(reader, (void *) loop, 0);
}
if (loop < numwr) {
init_completion(&wr_comp[loop]);
kernel_thread(writer, (void *) loop, 0);
}
if (loop < numdg) {
init_completion(&dg_comp[loop]);
kernel_thread(downgrader, (void *) loop, 0);
}
}
/* set a stop timer */
init_timer(&timer);
timer.function = stop_test;
timer.expires = jiffies + elapse * HZ;
add_timer(&timer);
/* now wait until it's all done */
for (loop = 0; loop < nummx; loop++)
wait_for_completion(&mx_comp[loop]);
for (loop = 0; loop < numsm; loop++)
wait_for_completion(&sm_comp[loop]);
for (loop = 0; loop < numrd; loop++)
wait_for_completion(&rd_comp[loop]);
for (loop = 0; loop < numwr; loop++)
wait_for_completion(&wr_comp[loop]);
for (loop = 0; loop < numdg; loop++)
wait_for_completion(&dg_comp[loop]);
atomic_set(&do_stuff, 0);
del_timer(&timer);
if (mutex_is_locked(&mutex))
printk(KERN_ERR "Mutex is still locked!\n");
/* count up */
mutex_total = total("MTX", mutexes_taken, nummx);
sem_total = total("SEM", semaphores_taken, numsm);
rd_total = total("RD ", reads_taken, numrd);
wr_total = total("WR ", writes_taken, numwr);
dg_total = total("DG ", downgrades_taken, numdg);
/* print the results */
if (verbose) {
printk("mutexes taken: %u\n", mutex_total);
printk("semaphores taken: %u\n", sem_total);
printk("reads taken: %u\n", rd_total);
printk("writes taken: %u\n", wr_total);
printk("downgrades taken: %u\n", dg_total);
}
else {
printk("%3d %3d %3d %3d %3d %c %3d %9u %9u %9u %9u %9u\n",
nummx, numsm, numrd, numwr, numdg,
do_sched ? 's' : '-',
load,
mutex_total,
sem_total,
rd_total,
wr_total,
dg_total);
}
/* tell insmod to discard the module */
if (verbose)
printk("Tests complete\n");
return -ENOANO;} /* end do_tests() */
module_init(do_tests);
Quoted 2 lines · David Howells
No, they're not. LL/SC is more flexible than CMPXCHG because under some circumstances, you can get away without doing the SC,
Of course, CMPXCHG doesn't have to store either, though it still performs a locked-write-cycle on x86 if I remember correctly.
David
Quoted 3 lines · David Howells
Of course, CMPXCHG doesn't have to store either, though it still performs a locked-write-cycle on x86 if I remember correctly.
It does so on any sane architecture (side note: you don't do locked memory cycles on the bus these days. You do cache coherency protocols).
From a bus standpoint you _have_ to do the initial read with intent to write, nothing else makes any sense. You'll just waste bus cycles otherwise. Sure, the write may never come, but it just isn't sensible to optimize for the case where the compare will fail. If that's the common case, then software is doing something wrong (it should do just a much cheaper "load + compare" first if it knows it's probably going to fail).
Linus
David S. Miller
maintainerFrom: Linus Torvalds <[email protected]>
Date: Fri, 16 Dec 2005 08:33:10 -0800 (PST)
Quoted 6 lines
From a bus standpoint you _have_ to do the initial read with intent to write, nothing else makes any sense. You'll just waste bus cycles otherwise. Sure, the write may never come, but it just isn't sensible to optimize for the case where the compare will fail. If that's the common case, then software is doing something wrong (it should do just a much cheaper "load + compare" first if it knows it's probably going to fail).
Actually, this points out a problem with "compare and swap". The typical loop is of the form:
LOAD [MEM], REG1
OP REG1, X, REG2
CAS [MEM], REG1, REG2
That first LOAD instruction, if it misses in the L2, causes the cache line to be requested for sharing. Then the CAS instruction will need to issue another cache coherency transaction to get the cache line into owned state.
Basically, this guarentees that you'll have 2 cache coherency transactions, a huge waste, every time an atomic update sequence executes for a data item not in cache already.
(Are there any CPUs that peek forward and look for the CAS
instruction to decide to issue the more appropriate request for the cache line in Owned state? That would be cool...)
At least with "load locked / store conditional" the cpu is being told that we intend to write to that cache line, so it can request sole ownership on the bus when the load misses.
The only workaround I can come up with is the do a prefetch for write right before the LOAD. I've been tempted to add this on sparc64 for a long time.
Quoted 4 lines · David S. Miller
Actually, this points out a problem with "compare and swap". The typical loop is of the form:
Quoted 8 lines
LOAD [MEM], REG1
OP REG1, X, REG2
CAS [MEM], REG1, REG2That first LOAD instruction, if it misses in the L2, causes the cache line to be requested for sharing. Then the CAS instruction will need to issue another cache coherency transaction to get the cache line into owned state.
A number of architectures have a "prefetch for write ownership" instruction that you can use for this. Exactly because "ld+cas" should not get a shared line initially.
I though sparc had an ASI to do the same? No?
Quoted 3 lines
(Are there any CPUs that peek forward and look for the CAS
instruction to decide to issue the more appropriate request for the cache line in Owned state? That would be cool...)
I don't think anybody does, although it wouldn't be impossible. Any OoO processor would _tend_ to have enough visibility that they could see any stores that are "close" (not just a cas) and might be clever enough to modify a memory read to be a read-with-intent-to-write op.
Of course, if it was in memory (as opposed to somebody elses caches), I think most cache protocols will start it up in exclusive state anyway. Same may or may not happen when you have a dirty hit on another CPU that requires a write-back (ie the other CPU would always invalidate on writeback).
It would seem to be the obvious thing to do for better lock performance, and I'd assume that locks are some of the most common cases of real cache interactions, so maybe the shared case only effectively happens if two CPU's are reading at the same time.
Somebody who looks at cache protocol diagrams could check. I'm too lazy.
Linus
David S. Miller
maintainerFrom: Linus Torvalds <[email protected]>
Date: Fri, 16 Dec 2005 14:38:47 -0800 (PST)
Quoted 5 lines
A number of architectures have a "prefetch for write ownership" instruction that you can use for this. Exactly because "ld+cas" should not get a shared line initially.
I though sparc had an ASI to do the same? No?
No, no special ASI exists to do that, although it would be nice. :-) I'd have to use a prefetch for write.
BTW, it is interesting that you can use CAS to get a cache line into the local processor in Owned state with %100 certainty (unlike prefetch for write which might get cancelled) by doing something like:
CAS [MEM], ZERO, ZERO
and you can do this to any valid memory address without changing the contents. This is useful for doing things like resetting parity bits while doing memory error recorvery.
Quoted 6 lines
It would seem to be the obvious thing to do for better lock performance, and I'd assume that locks are some of the most common cases of real cache interactions, so maybe the shared case only effectively happens if two CPU's are reading at the same time.
Somebody who looks at cache protocol diagrams could check. I'm too lazy.
For both MOESI and MOSI cache coherency protocols, misses on loads result in a Shared state cache line when another processor has the data in it's cache too, regardless of whether that line in the other cpu is dirty or not.
When the write comes along, the next transaction occurs to kick it out the other cpu(s) caches and then the local line is placed into Owned state.
I'll have to add "put write prefetch in CAS sequences" onto my sparc64 TODO list :-)
Quoted 6 lines · David S. Miller
When the write comes along, the next transaction occurs to kick it out the other cpu(s) caches and then the local line is placed into Owned state.
I'll have to add "put write prefetch in CAS sequences" onto my sparc64 TODO list :-)
Note that under contention prefetching with a write bias can cause a lot more cache line bouncing than a regular load into shared state (assuming you do a load and test before you try the CAS). We actually saw this on large Altix machines,
http://lia64.bkbits.net:8080/to-linus-2.5/cset%403f2082b3xCvMG9OSeNu3aWhoe6jnOg?nav=index.html|
src/.|src/include|src/include/asm-ia64| related/include/asm-ia64/spinlock.h fixed things up for us.
Jesse
David S. Miller
maintainerFrom: Jesse Barnes <[email protected]>
Date: Fri, 16 Dec 2005 16:41:49 -0800
Quoted 3 lines
Note that under contention prefetching with a write bias can cause a lot more cache line bouncing than a regular load into shared state (assuming you do a load and test before you try the CAS).
If there is some test guarding the CAS, yes.
But if there isn't, for things like atomic increment and decrement, where the CAS is unconditional, you'll always eat the two bus transactions without the prefetch for write.
Quoted 6 lines · David S. Miller
If there is some test guarding the CAS, yes.
But if there isn't, for things like atomic increment and decrement, where the CAS is unconditional, you'll always eat the two bus transactions without the prefetch for write.
Side note: there may be hardware cache protocol _scheduling_ reasons why some particular hw platform might prefer to go through the "Shared" state in their cache protocol.
For example, you might have hardware that otherwise ends up being very unfair, where the two-stage lock aquire might actually allow another node to come in at all. Fairness and balance often comes at a cost, both in hw and in sw.
Arguably such hardware sounds pretty broken, but the point is that these things can certainly depend on the platform around the CPU as well as on what the CPU itself does.
I'm not saying that that is necessarily what Jesse was arguing about, but lock contention behaviour can be "interesting".
Linus
Quoted 9 lines · Linus Torvalds
Side note: there may be hardware cache protocol _scheduling_ reasons why some particular hw platform might prefer to go through the "Shared" state in their cache protocol.
For example, you might have hardware that otherwise ends up being very unfair, where the two-stage lock aquire might actually allow another node to come in at all. Fairness and balance often comes at a cost, both in hw and in sw.
Quoted 6 lines
Arguably such hardware sounds pretty broken, but the point is that these things can certainly depend on the platform around the CPU as well as on what the CPU itself does.
I'm not saying that that is necessarily what Jesse was arguing about, but lock contention behaviour can be "interesting".
Yeah, that's a good point. Getting lock behavior 'just right' can get pretty platform specific. For instance, on a CMP type machine, bouncing a lock between CPUs can be nearly free, whereas on a large directory based machine like the Altix, pretty much any cache line write (or fake write like ia64's ld.bias) is an expensive operation since it involves lots of relatively slow network activity.
Jesse
Quoted 8 lines · David S. Miller
From: Jesse Barnes <[email protected]>
Date: Fri, 16 Dec 2005 16:41:49 -0800Quoted 3 lines
Note that under contention prefetching with a write bias can cause a lot more cache line bouncing than a regular load into shared state (assuming you do a load and test before you try the CAS).
If there is some test guarding the CAS, yes.
Yeah, I was only referring to that particular case (the ia64 code does test then CAS, so removing the write bias on the load avoided a lot of thrashing for locks under contention).
Quoted 3 lines
But if there isn't, for things like atomic increment and decrement, where the CAS is unconditional, you'll always eat the two bus transactions without the prefetch for write.
Right, in that case, biasing for read might make sense, as long as some other CPU doesn't cause the line to go back to shared before you actually get to the CAS.
Jesse
Quoted 2 lines · David S. Miller
I'll have to add "put write prefetch in CAS sequences" onto my sparc64 TODO list :-)
You might consider just beginning your loops like
mov zero, old
cas [mem], zero, old
to do the initial read, since old will now contain the contents of the memory, and we havn't changed the memory.
r~
David S. Miller
maintainerFrom: Richard Henderson <[email protected]>
Date: Sat, 17 Dec 2005 14:38:24 -0800
Quoted 7 lines
You might consider just beginning your loops like
mov zero, old
cas [mem], zero, oldto do the initial read, since old will now contain the contents of the memory, and we havn't changed the memory.
CAS is 32 cycles minimum on sparc64 even on a cache hit, so I think the prefetch+load will be faster :-) But it deserves checking out, that's for sure.
Either way, that is a clever use of CAS :)
Quoted 12 lines · David Howells
Quoted 7 lines · Nick Piggin
Quoted 4 lines
(2) Those that have CMPXCHG or equivalent: 68020, i486+,
x86_64, ia64, sparc.
(3) Those that have LL/SC or equivalent: mips (some), alpha, powerpc, arm6.cmpxchg is basically exactly equivalent to a store-conditional, so 2 and 3 are the same level.
Quoted 6 lines
No, they're not. LL/SC is more flexible than CMPXCHG because under some circumstances, you can get away without doing the SC, and because sometimes you can do one LL/SC in lieu of two CMPXCHG's because LL/SC allows you to retrieve the value, consider it and then modify it if you want to. With CMPXCHG you have to anticipate, and so you're more likely to get it wrong.
I don't think that is more flexible, just different. For example with cmpxchg you may not have to do the explicit load if you anticipate an unlocked mutex as the fastpath.
My point is that they are of semantically equal strength.
Quoted 6 lines
Quoted 3 lines
I don't know why you don't implement a "good" default implementation with
atomic_cmpxchg.Because it wouldn't be a good default.
You were proposing a worse default, which is the reason I suggested it.
Quoted 2 lines
I'm thinking the best default is simply
to wrap a counting semaphore.
Probably.
Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 1 line · Nick Piggin
You were proposing a worse default, which is the reason I suggested it.
I'd like to qualify that. "for architectures with native cmpxchg".
For general consumption (not specifically related to mutex stuff)...
For architectures with llsc, sequences stuch as:
load
modify
cmpxchg
are inefficient because they have to be implemented as:
load
modify
load
compare
store conditional
Now, if we consider using llsc as the basis of atomic operations:
load
modify
store conditional
and for cmpxchg-based architectures:
load
modify
cmpxchg
Notice that the cmpxchg-based case does _not_ get any worse - in fact it's exactly identical. Note, however, that the llsc case becomes more efficient.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of: 2.6 Serial core
Quoted 31 lines · Russell King
Quoted 1 line · Nick Piggin
You were proposing a worse default, which is the reason I suggested it.
I'd like to qualify that. "for architectures with native cmpxchg".
For general consumption (not specifically related to mutex stuff)...
For architectures with llsc, sequences stuch as:
load
modify
cmpxchgare inefficient because they have to be implemented as:
load
modify
load
compare
store conditionalNow, if we consider using llsc as the basis of atomic operations:
load
modify
store conditionaland for cmpxchg-based architectures:
Quoted 8 lines
load
modify
cmpxchgNotice that the cmpxchg-based case does _not_ get any worse - in fact it's exactly identical. Note, however, that the llsc case becomes more efficient.
True in many cases. However in a lock fastpath one could do the atomic_cmpxchg without an initial load, assuming the lock is unlocked.
atomic_cmpxchg(&lock, UNLOCKED, LOCKED)
which should basically wind up to the most optimal code on both the cmpxchg and ll/sc platforms (aside from other quirks David pointed out like cmpxchg being worse than lock inc on x86).
Ah - I see you pointed out "for general consumption", I missed that. Indeed for general consumption one should still be careful using atomic_cmpxchg.
Nick
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 14 lines · Russell King
Quoted 2 lines · Nick Piggin
You were proposing a worse default, which is the reason I suggested it.
I'd like to qualify that. "for architectures with native cmpxchg".
For general consumption (not specifically related to mutex stuff)...
For architectures with llsc, sequences stuch as:
load
modify
cmpxchg
Quoted 8 lines
are inefficient because they have to be implemented as:
load
modify
load
compare
store conditional
I dont know what arch u have in mind but for ppc it is:
load-reserve
modify
store-conditional
and NOT the sequence you show.
Signature · 1 line
Linh Dang
Quoted 26 lines · Linh Dang
Quoted 14 lines · Russell King
Quoted 2 lines · Nick Piggin
You were proposing a worse default, which is the reason I suggested it.
I'd like to qualify that. "for architectures with native cmpxchg".
For general consumption (not specifically related to mutex stuff)...
For architectures with llsc, sequences stuch as:
load
modify
cmpxchgQuoted 8 lines
are inefficient because they have to be implemented as:
load
modify
load
compare
store conditional
Quoted 7 lines
I dont know what arch u have in mind but for ppc it is:
load-reserve
modify
store-conditionaland NOT the sequence you show.
Wrong - because you haven't understood what I'm getting at. If you're using "cmpxchg" as the low level generic atomic operation (as in the atomic_cmpxchg() function) then atomic_cmpxchg _has_ to be implemented on llsc as:
load (reserve if you need this detail)
compare
store conditional
So, let's illustrate this. Let's say you want to atomically multiply a value by N.
do {
old = atomic_read(&foo);
new = old * N;
} while(atomic_cmpxchg(&foo, old, new) != old);For an architecture supporting cmpxchg, this becomes:
loop: load foo => old
new = old * N
cmpxchg ret, old, new, foo
compare ret & old
if not equal goto loop
And for architectures with llsc, this becomes:
loop: load foo => old
new = old * N
loop2: load locked foo => ret
compare ret & old
if equal store conditional new in foo
if store failed because we lost the lock, goto loop2
compare ret & old
if not equal goto loop
Do you now see what I mean? (yup, ARM is a llsc architecture.)
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of: 2.6 Serial core
Quoted 73 lines · Russell King
Quoted 28 lines · Linh Dang
Quoted 16 lines · Russell King
Quoted 2 lines · Nick Piggin
You were proposing a worse default, which is the reason I suggested it.
I'd like to qualify that. "for architectures with native cmpxchg".
For general consumption (not specifically related to mutex stuff)...
For architectures with llsc, sequences stuch as:
load
modify
cmpxchgQuoted 8 lines
are inefficient because they have to be implemented as:
load
modify
load
compare
store conditionalQuoted 7 lines
I dont know what arch u have in mind but for ppc it is:
load-reserve
modify
store-conditionaland NOT the sequence you show.
Wrong - because you haven't understood what I'm getting at. If you're using "cmpxchg" as the low level generic atomic operation (as in the
atomic_cmpxchg()function) thenatomic_cmpxchg_has_ to be implemented on llsc as:load (reserve if you need this detail)
compare
store conditionalSo, let's illustrate this. Let's say you want to atomically multiply a value by N.
do { old = atomic_read(&foo); new = old * N; } while(atomic_cmpxchg(&foo, old, new) != old);For an architecture supporting cmpxchg, this becomes:
loop: load foo => old
new = old * N
cmpxchg ret, old, new, foo
compare ret & old
if not equal goto loopAnd for architectures with llsc, this becomes:
loop: load foo => old
new = old * N
loop2: load locked foo => ret
compare ret & old
if equal store conditional new in foo
if store failed because we lost the lock, goto loop2
compare ret & old
if not equal goto loop
Quoted 1 line
Do you now see what I mean? (yup, ARM is a llsc architecture.)
Well, it may be true for ARM but for ppc (i dunno what exactly llsc means but someone in the thread put ppc in llsc group) it's:
loop:
load-reserve foo => old
new = old * N
store-conditional new => foo
if failed goto loop
Quoted 6 lines · Linh Dang
Quoted 1 line
Do you now see what I mean? (yup, ARM is a llsc architecture.)
Well, it may be true for ARM but for ppc (i dunno what exactly llsc means but someone in the thread put ppc in llsc group) it's:
load locked or load with lock, IIRC.
Quoted 6 lines
loop:
load-reserve foo => old
new = old * N
store-conditional new => foo
if failed goto loop
The point is that the typical use case for a cmpxchg is less optimal if cmpxchg is simulated with llsc than if the same functionality were directly implemented with llsc instructions.
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 7 lines · Linh Dang
Well, it may be true for ARM but for ppc (i dunno what exactly llsc means but someone in the thread put ppc in llsc group) it's:
loop:
load-reserve foo => old
new = old * N
store-conditional new => foo
if failed goto loop
LLSC == Load-Locked/Store-Conditional. It's a slightly different name for your Load-Reserve/Store-Conditional
You still miss his point. That is _GOOD_ code. Russell's point is that if somebody does this in generic code:
do {
old = atomic_read(&foo);
new = old * 2;
} while (atomic_cmpxchg(&foo, old, new) != old);On PPC or ARM or another LLSC architecture it does not end up looking like the good code, it looks like this (which is clearly inefficient):
Quoted 10 lines
Quoted 10 lines
And for architectures with llsc, this becomes:
loop: load foo => old
new = old * N
loop2: load locked foo => ret
compare ret & old
if equal store conditional new in foo
if store failed because we lost the lock, goto loop2
compare ret & old
if not equal goto loop
Cheers,
Kyle Moffett
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCM/CS/IT/E/U d- s++: a18 C++++>$ ULBX*++++(+++)>$ P++++(+++)>$ L++++(+++)>$ !E- W+++(++) N+++(++) o? K? w--- O? M++ V? PS+() PE+(-) Y+ PGP+ t+(+++) 5 X R? !tv-(--) b++++(++) DI+(++) D+++ G e>++++$ h*(+)>++$ r%(--) !y?-(--) ------END GEEK CODE BLOCK------
Quoted 1 line · Russell King
Do you now see what I mean? (yup, ARM is a llsc architecture.)
Out of interest, at what point did ARM become so? ARM6?
David
Quoted 5 lines · David Howells
Quoted 1 line · Russell King
Do you now see what I mean? (yup, ARM is a llsc architecture.)
Out of interest, at what point did ARM become so? ARM6?
Yes, ARM architecture version 6.
See the ldrex (load exclusive) / strex (store exclusive) instructions.
Signature · 3 lines
Russell King Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/ maintainer of: 2.6 Serial core
Quoted 1 line · Russell King
Do you now see what I mean? (yup, ARM is a llsc architecture.)
Oh, I do see your point now! sorry for all the newbie noise!
Signature · 1 line
Linh Dang
Quoted 20 lines · Nick Piggin
Quoted 12 lines · David Howells
Quoted 7 lines · Nick Piggin
Quoted 4 lines
(2) Those that have CMPXCHG or equivalent: 68020, i486+,
x86_64, ia64, sparc.
(3) Those that have LL/SC or equivalent: mips (some), alpha, powerpc, arm6.cmpxchg is basically exactly equivalent to a store-conditional, so 2 and 3 are the same level.
Quoted 6 lines
No, they're not. LL/SC is more flexible than CMPXCHG because under some circumstances, you can get away without doing the SC, and because sometimes you can do one LL/SC in lieu of two CMPXCHG's because LL/SC allows you to retrieve the value, consider it and then modify it if you want to. With CMPXCHG you have to anticipate, and so you're more likely to get it wrong.
Quoted 5 lines
I don't think that is more flexible, just different. For example with cmpxchg you may not have to do the explicit load if you anticipate an unlocked mutex as the fastpath.
My point is that they are of semantically equal strength.
In the context of implementing mutex they most likely are. But not
generally: LL/SC fails when _any_ write was made into monitored location, whereas CAS fails only when value stored in that location changes. As a result, CAS has to deal with "ABA problem" when value (e.g., first element in a queue) is changed from A to B (head of the queue is removed) and then back to A (old head is inserted back).
Nikita.
Quoted 6 lines · David Howells
No, they're not. LL/SC is more flexible than CMPXCHG because under some circumstances, you can get away without doing the SC, and because sometimes you can do one LL/SC in lieu of two CMPXCHG's because LL/SC allows you to retrieve the value, consider it and then modify it if you want to. With CMPXCHG you have to anticipate, and so you're more likely to get it wrong.
You can think of LL/SC as directly translating into LD/CMPXCHG, so in that sense CMPXCHG is no less flexible. LL/SC still has other advantages, though. See later.
Quoted 5 lines
I've had a play with x86, and on there CMPXCHG, XCHG and XADD give worse performance than INC/DEC for some reason. I assume this is something to do with how the PPro CPU optimises itself. On PPro CPUs at least, counting semaphores really are the most efficient way. CMPXCHG, whilst it ought to be better, really isn't.
The notion that CMPXCHG "ought to be better" is a load of bull.
There are two advantages of "lock inc/dec" over "ld/cmpxchg": one is the obvious one that the CPU core just has a much easier time with the unconditional one, and never has to worry about things like conditional branches or waste cycles on multiple instructions. Just compare the sequences:
lock inc mem
vs
back:
load mem,reg1 reg2 = reg1+1 cmpxchg mem,reg1,reg2 jne forward # get branch prediction right return
forward:
jmp back
guess which one is faster?
The other one depends on cache coherency: the "lock inc" can just get the cacheline for exclusive use immediately ("read with intent to write"). In contrast, the ld/cmpxchg first gets the cacheline for reading, and then has to turn it into an exclusive one. IOW, there may literally be lots of extra bus traffic from doing a load first.
In other words, there are several advantages to just using the simple instructions.
(Of course, some CPU's have "get cacheline for write" instructions, so you can then make the second sequence even longer by using that).
Using "xadd" should be fine, although for all I know, even then microarchitectural issues may make it cheaper to use the simpler "lock add" whenever possible.
In LL/SC, I _think_ LL generally does its read with intent to write.
Linus
Quoted 4 lines · Andrew Morton
Could someone please remind me why we're even discussing this, given that
mutex_down()is slightly more costly than currentdown(), andmutex_up()is appreciably more costly than currentup()?
That's a good question. The new mutex implementation here is big regression to what we have right now. What I had in mind when brainstorming something like this would be to have a slow-path pure C semaphore implementation that is cross-platform, and keep the current semaphore code as mutex. Once that is done the mutex code could be optimized further because it doesn't need to deal with the broader uses of the semaphore, and we could add lots of useful debugging.
The current patchkit is far from that.
What might be more useful as a start is to implement a mutex type ontop of the current semaphore that has lots of additional checks for the DEBUG build so we have nice diagnostics. Once we have all users of mutex semantics using that API we can change the underlying implementation to whatever we want.
Quoted 6 lines · Alan Cox
Quoted 3 lines · Arjan van de Ven
1) the BKL change hasn't finished, and we're 5 years down the line. API changes done gradual tend to take forever in practice, esp if there's no "compile" incentive for people to fix things.
This isn't a "fix" however, its merely a performance tweak.
it's a conceptual API split that, if nothing else, declares intent and usage pattern more specifically. Performance is just one of the angles. Other angles are that it's possible to treat mutex users different (like Ingo is doing in -rt, where you can temporary boost a mutex owner if the mutex gets contended, other uses are better hold time metrics etc etc)
Quoted 4 lines
Drivers
using the old API are not a problem becausea) The old API is needed long term for true counting sem users
this is skipping one bridge ;)
A counting semaphore is needed long term. API is up for debate in the sense that it's not clear that a non-compile-time thing is the right solution.
Quoted 1 line
Thats rather different to the BKL
BKL is different in that it's more work to do a conversion (eg the BKL semantics are rather complex compared to normal spinlock / semaphore / mutex semantics). So yes BKL is harder, and not really possible to do in one go. Unlike these...
For BKL there was no choice. Here there is.
Quoted 10 lines · David Howells
(3) Some people want mutexes to be:
(a) only releasable in the same context as they were taken
(b) not accessible in interrupt context, or that (a) applies here also
(c) not initialisable to the locked state
But this means that the current usages all have to be carefully audited, and sometimes that unobvious.
(a) and (c) is not a big problem, are they are essentially the constraints of -rt mutexes. As long as there's good debugging code, it's very much doable. We dont want to change semantics _yet again_, later down the line.
Ingo
Steven Rostedt
reviewerQuoted 5 lines · David Howells
Quoted 3 lines · Alan Cox
Quoted 3 lines
(5) Redirects the following to apply to the new mutexes rather than the traditional semaphores:
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
down()...
And you've audited every occurence ?
Outside of the arch directories, yes; but I don't know that I've made the correct decision in 100% of the cases.
I'm in the crowd that thinks that the mutex downs and ups should be converted to mutex_lock/mutex_unlock. Simply because that is basically what a mutex is doing. I rather not have another "historical" API in the kernel.
Quoted 4 lines
I've changed some of the uses into completions, and found about a dozen or so uses of counting semaphores; but the vast majority of occurrences seem to be wanting mutex behaviour.
And we can take our time in looking at this in a case by case basis.
Quoted 9 lines
Quoted 6 lines
It seems to me it would be far far saner to define something like
sleep_lock(&foo)
sleep_unlock(&foo)
sleep_trylock(&foo)Which would be a _lot_ more work. It would involve about ten times as many changes, I think, and thus be more prone to errors.
I don't think this should be a one shot patch. Your patch (and what you would be responsible for) would just introduce the use of the mutex. Let others go around and find the places where a semaphore is used where a mutex should be. Yes there is a lot more mutexes than true semaphores, and that is why we really should look at this in a case by case basis. One big global change will probably more likely miss a case that should be a semaphore.
Quoted 8 lines
Quoted 3 lines
Its then obvious what it does, you don't randomly break other drivers you've not reviewed and the interface is intuitive rather than obfuscated.
I've attempted to review everything in 2.6.15-rc5 outside of most of the archs. I can't easily modify any driver not contained in that tarball, but at least the compiler will barf and force a review.
Quoted 6 lines
Quoted 2 lines
It won't take long for people to then change the name of the performance critical cases and the others will catch up in time.
It took about ten hours to go through the declarations of struct semaphore and review them; I hate to think how long it'd take to go through all the ups and downs too.
That's why this should be a step by step integration.
Quoted 7 lines
Quoted 3 lines
It also saves breaking every piece of out of tree kernel code for now good reason.
But my patch means the changes required are in the most cases minimal: just changing struct semaphore to struct mutex is sufficient for the vast majority of cases.
But not every case.
Quoted 2 lines
Your way requires a lot more work, both in the tree and out of it.
Not really. Over time this would be all cleaned up, but introducing a new API should be the first step, then we can go to each and every spot to find where a semaphore should be a mutex. You'll get a lot more people helping you in that method then you globally changing it, and people only help when it breaks.
I'm sure I'm not the only one that would be happy to send patches in to convert semaphores to mutexes where I find them. But I'd be more confused if something suddenly breaks that use to work, and then have to see that "Oh this was a semaphore that mistakenly became a mutex!".
-- Steve