summaryrefslogtreecommitdiffstats
path: root/sys/sys
diff options
context:
space:
mode:
authorkmacy <kmacy@FreeBSD.org>2006-12-16 02:37:58 +0000
committerkmacy <kmacy@FreeBSD.org>2006-12-16 02:37:58 +0000
commitad3abace0cb8e4401b0dd5b68b63f1c8405baeef (patch)
treef0bcef7d4d608e41f61c1ec11703db59af89df11 /sys/sys
parent1d3d170d84fa1e6127bdf989319a5d7a91f81745 (diff)
downloadFreeBSD-src-ad3abace0cb8e4401b0dd5b68b63f1c8405baeef.zip
FreeBSD-src-ad3abace0cb8e4401b0dd5b68b63f1c8405baeef.tar.gz
- Fix some gcc warnings in lock_profile.h
- add cnt_hold cnt_lock support for spin mutexes - make sure contested is initialized to zero to only bump contested when appropriate - move initialization function to kern_mutex.c to avoid cyclic dependency between mutex.h and lock_profile.h
Diffstat (limited to 'sys/sys')
-rw-r--r--sys/sys/lock_profile.h34
-rw-r--r--sys/sys/mutex.h4
2 files changed, 20 insertions, 18 deletions
diff --git a/sys/sys/lock_profile.h b/sys/sys/lock_profile.h
index 1b11187..fb4eb1d 100644
--- a/sys/sys/lock_profile.h
+++ b/sys/sys/lock_profile.h
@@ -35,6 +35,7 @@
#include <sys/stdint.h>
#include <sys/ktr.h>
#include <sys/mutex.h>
+#include <machine/atomic.h>
#include <machine/cpufunc.h>
#ifndef LPROF_HASH_SIZE
@@ -61,7 +62,6 @@ struct lock_prof {
};
extern struct lock_prof lprof_buf[LPROF_HASH_SIZE];
-extern int allocated_lprof_buf;
#define LPROF_SBUF_SIZE 256 * 400
/* We keep a smaller pool of spin mutexes for protecting the lprof hash entries */
@@ -74,24 +74,11 @@ extern int allocated_lprof_buf;
extern struct mtx lprof_locks[LPROF_LOCK_SIZE];
extern int lock_prof_enable;
-extern int lock_prof_records;
-extern int lock_prof_rejected;
-extern int lock_prof_collisions;
void _lock_profile_obtain_lock_success(struct lock_object *lo, uint64_t waittime, const char *file, int line);
void _lock_profile_update_wait(struct lock_object *lo, uint64_t waitstart);
void _lock_profile_release_lock(struct lock_object *lo);
-static inline void lock_profile_init(void)
-{
- int i;
- /* Initialize the mutex profiling locks */
- for (i = 0; i < LPROF_LOCK_SIZE; i++) {
- mtx_init(&lprof_locks[i], "mprof lock",
- NULL, MTX_SPIN|MTX_QUIET|MTX_NOPROFILE);
- }
-}
-
static inline void lock_profile_object_init(struct lock_object *lo, struct lock_class *class, const char *name) {
const char *p;
u_int hash = 0;
@@ -138,8 +125,11 @@ static inline void lock_profile_obtain_lock_failed(struct lock_object *lo, int *
{
struct lock_profile_object *l = &lo->lo_profile_obj;
if (lock_prof_enable) {
- *contested = 1;
- atomic_add_int(&l->lpo_contest_holding, 1);
+ if (*contested == 0) {
+ atomic_add_int(&l->lpo_contest_holding, 1);
+ *contested = 1;
+
+ }
}
}
@@ -155,6 +145,15 @@ static inline void lock_profile_update_wait(struct lock_object *lo, uint64_t wai
_lock_profile_update_wait(lo, waitstart);
}
+static inline void lock_profile_update_contest_locking(struct lock_object *lo, int contested)
+{
+ if (lock_prof_enable) {
+ lo->lo_profile_obj.lpo_contest_holding = 0;
+ if (contested)
+ lo->lo_profile_obj.lpo_contest_locking++;
+ }
+}
+
static inline void lock_profile_release_lock(struct lock_object *lo)
{
struct lock_profile_object *l = &lo->lo_profile_obj;
@@ -163,9 +162,8 @@ static inline void lock_profile_release_lock(struct lock_object *lo)
}
#else /* !LOCK_PROFILING */
-
-static inline void lock_profile_init(void) {;}
static inline void lock_profile_update_wait(struct lock_object *lo, uint64_t waitstart) {;}
+static inline void lock_profile_update_contest_locking(struct lock_object *lo, int contested) {;}
static inline void lock_profile_waitstart(uint64_t *waittime) {;}
static inline void lock_profile_release_lock(struct lock_object *lo) {;}
static inline void lock_profile_obtain_lock_failed(struct lock_object *lo, int *contested) {;}
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
index c5acf6c..90be6cc 100644
--- a/sys/sys/mutex.h
+++ b/sys/sys/mutex.h
@@ -39,6 +39,7 @@
#ifdef _KERNEL
#include <sys/pcpu.h>
+#include <sys/lock_profile.h>
#include <machine/atomic.h>
#include <machine/cpufunc.h>
#endif /* _KERNEL_ */
@@ -172,14 +173,17 @@ void _mtx_assert(struct mtx *m, int what, const char *file, int line);
#ifdef SMP
#define _get_spin_lock(mp, tid, opts, file, line) do { \
uintptr_t _tid = (uintptr_t)(tid); \
+ int contested = 0; \
\
spinlock_enter(); \
if (!_obtain_lock((mp), _tid)) { \
+ lock_profile_obtain_lock_failed(&mp->mtx_object, &contested);\
if ((mp)->mtx_lock == _tid) \
(mp)->mtx_recurse++; \
else \
_mtx_lock_spin((mp), _tid, (opts), (file), (line)); \
} \
+ lock_profile_update_contest_locking(&mp->mtx_object, contested);\
} while (0)
#else /* SMP */
#define _get_spin_lock(mp, tid, opts, file, line) do { \
OpenPOWER on IntegriCloud