diff options
author | Brian Behlendorf <[email protected]> | 2009-09-25 14:14:35 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2009-09-25 14:14:35 -0700 |
commit | d28db80fd0fd4fd63aec09037c44408e51a222d6 (patch) | |
tree | 5a0d35c042fe4ae8146b59715dcbb73dbd27a37b /module/spl | |
parent | e811949a57044d60d12953c5c3b808a79a7d36ef (diff) |
Update rwlocks to track owner to ensure correct semantics
The behavior of RW_*_HELD was updated because it was not quite right.
It is not sufficient to return non-zero when the lock is help, we must
only do this when the current task in the holder.
This means we need to track the lock owner which is not something
tracked in a Linux semaphore. After some experimentation the
solution I settled on was to embed the Linux semaphore at the start
of a larger krwlock_t structure which includes the owner field.
This maintains good performance and allows us to cleanly intergrate
with the kernel lock analysis tools. My reasons:
1) By placing the Linux semaphore at the start of krwlock_t we can
then simply cast krwlock_t to a rw_semaphore and pass that on to
the linux kernel. This allows us to use '#defines so the preprocessor
can do direct replacement of the Solaris primative with the linux
equivilant. This is important because it then maintains the location
information for each rw_* call point.
2) Additionally, by adding the owner to krwlock_t we can keep this
needed extra information adjacent to the lock itself. This removes
the need for a fancy lookup to get the owner which is optimal for
performance. We can also leverage the existing spin lock in the
semaphore to ensure owner is updated correctly.
3) All helper functions which do not need to strictly be implemented
as a define to preserve location information can be done as a static
inline function.
4) Adding the owner to krwlock_t allows us to remove all memory
allocations done during lock initialization. This is good for all
the obvious reasons, we do give up the ability to specific the lock
name. The Linux profiling tools will stringify the lock name used
in the code via the preprocessor and use that.
Update rwlocks validated on:
- SLES10 (ppc64)
- SLES11 (x86_64)
- CHAOS4.2 (x86_64)
- RHEL5.3 (x86_64)
- RHEL6 (x86_64)
- FC11 (x86_64)
Diffstat (limited to 'module/spl')
-rw-r--r-- | module/spl/spl-generic.c | 35 | ||||
-rw-r--r-- | module/spl/spl-rwlock.c | 3 |
2 files changed, 24 insertions, 14 deletions
diff --git a/module/spl/spl-generic.c b/module/spl/spl-generic.c index 8e0ef9263..8bf97e0cf 100644 --- a/module/spl/spl-generic.c +++ b/module/spl/spl-generic.c @@ -30,6 +30,7 @@ #include <sys/vnode.h> #include <sys/kmem.h> #include <sys/mutex.h> +#include <sys/rwlock.h> #include <sys/taskq.h> #include <sys/debug.h> #include <sys/proc.h> @@ -365,49 +366,54 @@ static int __init spl_init(void) return rc; if ((rc = spl_kmem_init())) - GOTO(out , rc); + GOTO(out1, rc); if ((rc = spl_mutex_init())) - GOTO(out2 , rc); + GOTO(out2, rc); - if ((rc = spl_taskq_init())) + if ((rc = spl_rw_init())) GOTO(out3, rc); - if ((rc = vn_init())) + if ((rc = spl_taskq_init())) GOTO(out4, rc); - if ((rc = proc_init())) + if ((rc = vn_init())) GOTO(out5, rc); - if ((rc = kstat_init())) + if ((rc = proc_init())) GOTO(out6, rc); + if ((rc = kstat_init())) + GOTO(out7, rc); + if ((rc = set_hostid())) - GOTO(out7, rc = -EADDRNOTAVAIL); + GOTO(out8, rc = -EADDRNOTAVAIL); #ifndef HAVE_KALLSYMS_LOOKUP_NAME if ((rc = set_kallsyms_lookup_name())) - GOTO(out7, rc = -EADDRNOTAVAIL); + GOTO(out8, rc = -EADDRNOTAVAIL); #endif /* HAVE_KALLSYMS_LOOKUP_NAME */ if ((rc = spl_kmem_init_kallsyms_lookup())) - GOTO(out7, rc); + GOTO(out8, rc); printk("SPL: Loaded Solaris Porting Layer v%s\n", SPL_META_VERSION); RETURN(rc); -out7: +out8: kstat_fini(); -out6: +out7: proc_fini(); -out5: +out6: vn_fini(); -out4: +out5: spl_taskq_fini(); +out4: + spl_rw_fini(); out3: spl_mutex_fini(); out2: spl_kmem_fini(); -out: +out1: debug_fini(); printk("SPL: Failed to Load Solaris Porting Layer v%s, " @@ -424,6 +430,7 @@ static void spl_fini(void) proc_fini(); vn_fini(); spl_taskq_fini(); + spl_rw_fini(); spl_mutex_fini(); spl_kmem_fini(); debug_fini(); diff --git a/module/spl/spl-rwlock.c b/module/spl/spl-rwlock.c index 8ff66bf9f..5120b2c81 100644 --- a/module/spl/spl-rwlock.c +++ b/module/spl/spl-rwlock.c @@ -91,3 +91,6 @@ __down_write_trylock_locked(struct rw_semaphore *sem) EXPORT_SYMBOL(__down_write_trylock_locked); #endif + +int spl_rw_init(void) { return 0; } +void spl_rw_fini(void) { } |