summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2004-08-04 20:18:45 +0000
committerjhb <jhb@FreeBSD.org>2004-08-04 20:18:45 +0000
commitc75eeac1dfdfc56d2aadab24b5ff9a35f2c42d46 (patch)
tree6b816a946ea3b88a6556df9bc12b49efeb2f2c7d /sys
parent1f29360fadc7c072b586a85e336874c798f0b701 (diff)
downloadFreeBSD-src-c75eeac1dfdfc56d2aadab24b5ff9a35f2c42d46.zip
FreeBSD-src-c75eeac1dfdfc56d2aadab24b5ff9a35f2c42d46.tar.gz
Cache the value of curthread in the _get_sleep_lock() and _get_spin_lock()
macros and pass the value to the associated _mtx_*() functions to avoid more curthread dereferences in the function implementations. This provided a very modest perf improvement in some benchmarks. Suggested by: rwatson Tested by: scottl
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_mutex.c9
-rw-r--r--sys/sys/mutex.h24
2 files changed, 20 insertions, 13 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index 7b66186..884eeda 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -417,10 +417,10 @@ _mtx_trylock(struct mtx *m, int opts, const char *file, int line)
* sleep waiting for it), or if we need to recurse on it.
*/
void
-_mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line)
+_mtx_lock_sleep(struct mtx *m, struct thread *td, int opts, const char *file,
+ int line)
{
struct turnstile *ts;
- struct thread *td = curthread;
#if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES)
struct thread *owner;
#endif
@@ -562,7 +562,8 @@ _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line)
* is handled inline.
*/
void
-_mtx_lock_spin(struct mtx *m, int opts, const char *file, int line)
+_mtx_lock_spin(struct mtx *m, struct thread *td, int opts, const char *file,
+ int line)
{
int i = 0;
@@ -570,7 +571,7 @@ _mtx_lock_spin(struct mtx *m, int opts, const char *file, int line)
CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m);
for (;;) {
- if (_obtain_lock(m, curthread))
+ if (_obtain_lock(m, td))
break;
/* Give interrupts a chance while we spin. */
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
index be78144..2275685 100644
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -100,17 +100,19 @@ void mtx_init(struct mtx *m, const char *name, const char *type, int opts);
void mtx_destroy(struct mtx *m);
void mtx_sysinit(void *arg);
void mutex_init(void);
-void _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line);
+void _mtx_lock_sleep(struct mtx *m, struct thread *td, int opts,
+ const char *file, int line);
void _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line);
-void _mtx_lock_spin(struct mtx *m, int opts, const char *file, int line);
+void _mtx_lock_spin(struct mtx *m, struct thread *td, int opts,
+ const char *file, int line);
void _mtx_unlock_spin(struct mtx *m, int opts, const char *file, int line);
int _mtx_trylock(struct mtx *m, int opts, const char *file, int line);
void _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line);
void _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line);
void _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file,
- int line);
+ int line);
void _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file,
- int line);
+ int line);
#ifdef INVARIANT_SUPPORT
void _mtx_assert(struct mtx *m, int what, const char *file, int line);
#endif
@@ -144,8 +146,10 @@ void _mtx_assert(struct mtx *m, int what, const char *file, int line);
*/
#ifndef _get_sleep_lock
#define _get_sleep_lock(mp, tid, opts, file, line) do { \
- if (!_obtain_lock((mp), (tid))) \
- _mtx_lock_sleep((mp), (opts), (file), (line)); \
+ struct thread *_tid = (tid); \
+ \
+ if (!_obtain_lock((mp), _tid)) \
+ _mtx_lock_sleep((mp), _tid, (opts), (file), (line)); \
} while (0)
#endif
@@ -158,12 +162,14 @@ void _mtx_assert(struct mtx *m, int what, const char *file, int line);
*/
#ifndef _get_spin_lock
#define _get_spin_lock(mp, tid, opts, file, line) do { \
+ struct thread *_tid = (tid); \
+ \
critical_enter(); \
- if (!_obtain_lock((mp), (tid))) { \
- if ((mp)->mtx_lock == (uintptr_t)(tid)) \
+ if (!_obtain_lock((mp), _tid)) { \
+ if ((mp)->mtx_lock == (uintptr_t)_tid) \
(mp)->mtx_recurse++; \
else \
- _mtx_lock_spin((mp), (opts), (file), (line)); \
+ _mtx_lock_spin((mp), _tid, (opts), (file), (line)); \
} \
} while (0)
#endif
OpenPOWER on IntegriCloud