diff options
author | des <des@FreeBSD.org> | 2002-07-03 01:50:27 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2002-07-03 01:50:27 +0000 |
commit | 9f5a919b22e40d0f0ee15fe90cf7a432bdf24448 (patch) | |
tree | 659160e6411c4d07c804f57f0e8d6b93a0b9839a | |
parent | b11caeadba9fff4b4ccff860d028b0c59abd6657 (diff) | |
download | FreeBSD-src-9f5a919b22e40d0f0ee15fe90cf7a432bdf24448.zip FreeBSD-src-9f5a919b22e40d0f0ee15fe90cf7a432bdf24448.tar.gz |
Add mtx_ prefixes to the fields used for mutex profiling, and fix a bug
where the profiling code would report the release point instead of the
acquisition point.
Requested by: bde
-rw-r--r-- | sys/kern/kern_mutex.c | 23 | ||||
-rw-r--r-- | sys/kern/subr_turnstile.c | 23 | ||||
-rw-r--r-- | sys/sys/_mutex.h | 6 |
3 files changed, 27 insertions, 25 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index c2e79d0..bc78e7f 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -322,10 +322,10 @@ _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line) WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line); #ifdef MUTEX_PROFILING /* don't reset the timer when/if recursing */ - if (m->acqtime == 0) { - m->file = file; - m->line = line; - m->acqtime = mutex_prof_enable ? nanoseconds() : 0; + if (m->mtx_acqtime == 0) { + m->mtx_filename = file; + m->mtx_lineno = line; + m->mtx_acqtime = mutex_prof_enable ? nanoseconds() : 0; ++mutex_prof_acquisitions; } #endif @@ -338,7 +338,7 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) MPASS(curthread != NULL); mtx_assert(m, MA_OWNED); #ifdef MUTEX_PROFILING - if (m->acqtime != 0) { + if (m->mtx_acqtime != 0) { static const char *unknown = "(unknown)"; struct mutex_prof *mpp; u_int64_t acqtime, now; @@ -346,19 +346,20 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) volatile u_int hash; now = nanoseconds(); - acqtime = m->acqtime; - m->acqtime = 0; + acqtime = m->mtx_acqtime; + m->mtx_acqtime = 0; if (now <= acqtime) goto out; - for (p = file; strncmp(p, "../", 3) == 0; p += 3) + for (p = m->mtx_filename; strncmp(p, "../", 3) == 0; p += 3) /* nothing */ ; if (p == NULL || *p == '\0') p = unknown; - for (hash = line, q = p; *q != '\0'; ++q) + for (hash = m->mtx_lineno, q = p; *q != '\0'; ++q) hash = (hash * 2 + *q) % MPROF_HASH_SIZE; mtx_lock_spin(&mprof_mtx); for (mpp = mprof_hash[hash]; mpp != NULL; mpp = mpp->next) - if (mpp->line == line && strcmp(mpp->file, p) == 0) + if (mpp->line == m->mtx_lineno && + strcmp(mpp->file, p) == 0) break; if (mpp == NULL) { /* Just exit if we cannot get a trace buffer */ @@ -369,7 +370,7 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) mpp = &mprof_buf[first_free_mprof_buf++]; mpp->name = mtx_name(m); mpp->file = p; - mpp->line = line; + mpp->line = m->mtx_lineno; mpp->next = mprof_hash[hash]; if (mprof_hash[hash] != NULL) ++mutex_prof_collisions; diff --git a/sys/kern/subr_turnstile.c b/sys/kern/subr_turnstile.c index c2e79d0..bc78e7f 100644 --- a/sys/kern/subr_turnstile.c +++ b/sys/kern/subr_turnstile.c @@ -322,10 +322,10 @@ _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line) WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line); #ifdef MUTEX_PROFILING /* don't reset the timer when/if recursing */ - if (m->acqtime == 0) { - m->file = file; - m->line = line; - m->acqtime = mutex_prof_enable ? nanoseconds() : 0; + if (m->mtx_acqtime == 0) { + m->mtx_filename = file; + m->mtx_lineno = line; + m->mtx_acqtime = mutex_prof_enable ? nanoseconds() : 0; ++mutex_prof_acquisitions; } #endif @@ -338,7 +338,7 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) MPASS(curthread != NULL); mtx_assert(m, MA_OWNED); #ifdef MUTEX_PROFILING - if (m->acqtime != 0) { + if (m->mtx_acqtime != 0) { static const char *unknown = "(unknown)"; struct mutex_prof *mpp; u_int64_t acqtime, now; @@ -346,19 +346,20 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) volatile u_int hash; now = nanoseconds(); - acqtime = m->acqtime; - m->acqtime = 0; + acqtime = m->mtx_acqtime; + m->mtx_acqtime = 0; if (now <= acqtime) goto out; - for (p = file; strncmp(p, "../", 3) == 0; p += 3) + for (p = m->mtx_filename; strncmp(p, "../", 3) == 0; p += 3) /* nothing */ ; if (p == NULL || *p == '\0') p = unknown; - for (hash = line, q = p; *q != '\0'; ++q) + for (hash = m->mtx_lineno, q = p; *q != '\0'; ++q) hash = (hash * 2 + *q) % MPROF_HASH_SIZE; mtx_lock_spin(&mprof_mtx); for (mpp = mprof_hash[hash]; mpp != NULL; mpp = mpp->next) - if (mpp->line == line && strcmp(mpp->file, p) == 0) + if (mpp->line == m->mtx_lineno && + strcmp(mpp->file, p) == 0) break; if (mpp == NULL) { /* Just exit if we cannot get a trace buffer */ @@ -369,7 +370,7 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) mpp = &mprof_buf[first_free_mprof_buf++]; mpp->name = mtx_name(m); mpp->file = p; - mpp->line = line; + mpp->line = m->mtx_lineno; mpp->next = mprof_hash[hash]; if (mprof_hash[hash] != NULL) ++mutex_prof_collisions; diff --git a/sys/sys/_mutex.h b/sys/sys/_mutex.h index 39b8b39..cccaa13 100644 --- a/sys/sys/_mutex.h +++ b/sys/sys/_mutex.h @@ -42,9 +42,9 @@ struct mtx { LIST_ENTRY(mtx) mtx_contested; /* Next contested mtx. */ /* Fields used only if MUTEX_PROFILING is configured: */ - u_int64_t acqtime; - const char *file; - int line; + u_int64_t mtx_acqtime; + const char *mtx_filename; + int mtx_lineno; }; #endif /* !_SYS__MUTEX_H_ */ |