Date: Sun, 25 Jun 2006 05:02:19 GMT From: Kip Macy <kmacy@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 99967 for review Message-ID: <200606250502.k5P52J0Z071951@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=99967 Change 99967 by kmacy@kmacy_storage:sun4v_work_sleepq on 2006/06/25 05:01:48 fix wait tracking to handle nested locking in sleep mutexes Affected files ... .. //depot/projects/kmacy_sun4v/src/sys/kern/kern_mutex.c#17 edit .. //depot/projects/kmacy_sun4v/src/sys/kern/kern_sx.c#4 edit .. //depot/projects/kmacy_sun4v/src/sys/sys/lock_profile.h#6 edit .. //depot/projects/kmacy_sun4v/src/sys/sys/proc.h#10 edit Differences ... ==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_mutex.c#17 (text+ko) ==== @@ -273,18 +273,21 @@ void _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line) { - + + uint64_t waittime; MPASS(curthread != NULL); KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep, ("mtx_lock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name, file, line)); WITNESS_CHECKORDER(&m->mtx_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line); + + lock_profile_waitstart(&waittime); _get_sleep_lock(m, curthread, opts, file, line); LOCK_LOG_LOCK("LOCK", &m->mtx_object, opts, m->mtx_recurse, file, line); WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line); - lock_profile_obtain_lock_success(&m->mtx_object, file, line); + lock_profile_obtain_lock_success(&m->mtx_object, waittime, file, line); } void @@ -307,18 +310,19 @@ void _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file, int line) { - + uint64_t waittime; MPASS(curthread != NULL); KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_spin, ("mtx_lock_spin() of sleep mutex %s @ %s:%d", m->mtx_object.lo_name, file, line)); WITNESS_CHECKORDER(&m->mtx_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line); + lock_profile_waitstart(&waittime); _get_spin_lock(m, curthread, opts, file, line); LOCK_LOG_LOCK("LOCK", &m->mtx_object, opts, m->mtx_recurse, file, line); WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line); - lock_profile_obtain_lock_success(&m->mtx_object, file, line); + lock_profile_obtain_lock_success(&m->mtx_object, waittime, file, line); } void @@ -345,8 +349,9 @@ int _mtx_trylock(struct mtx *m, int opts, const char *file, int line) { + uint64_t waittime = 0; int rval; - + MPASS(curthread != NULL); KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep, ("mtx_trylock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name, @@ -363,7 +368,7 @@ if (rval) { WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE | LOP_TRYLOCK, file, line); - lock_profile_obtain_lock_success(&m->mtx_object, file, line); + lock_profile_obtain_lock_success(&m->mtx_object, waittime, file, line); } return (rval); } @@ -382,13 +387,8 @@ volatile struct thread *owner; #endif uintptr_t v; -#ifdef KTR -#if 0 - int cont_logged = 0; -#endif -#endif int contested; - + if (mtx_owned(m)) { KASSERT((m->mtx_object.lo_flags & LO_RECURSABLE) != 0, ("_mtx_lock_sleep: recursed on non-recursive mutex %s @ %s:%d\n", ==== //depot/projects/kmacy_sun4v/src/sys/kern/kern_sx.c#4 (text+ko) ==== @@ -113,6 +113,7 @@ { int contested; + uint64_t waittime = 0; mtx_lock(sx->sx_lock); KASSERT(sx->sx_xholder != curthread, @@ -123,6 +124,8 @@ /* * Loop in case we lose the race for lock acquisition. */ + if (sx->sx_cnt < 0) + lock_profile_waitstart(&waittime); while (sx->sx_cnt < 0) { sx->sx_shrd_wcnt++; lock_profile_obtain_lock_failed(&sx->sx_object, &contested); @@ -135,7 +138,7 @@ sx->sx_cnt++; if (sx->sx_cnt == 1) - lock_profile_obtain_lock_success(&sx->sx_object, file, line); + lock_profile_obtain_lock_success(&sx->sx_object, waittime, file, line); LOCK_LOG_LOCK("SLOCK", &sx->sx_object, 0, 0, file, line); WITNESS_LOCK(&sx->sx_object, 0, file, line); @@ -166,7 +169,8 @@ { int contested; - + uint64_t waittime = 0; + mtx_lock(sx->sx_lock); /* @@ -183,6 +187,8 @@ line); /* Loop in case we lose the race for lock acquisition. */ + if (sx->sx_cnt) + lock_profile_waitstart(&waittime); while (sx->sx_cnt != 0) { sx->sx_excl_wcnt++; lock_profile_obtain_lock_failed(&sx->sx_object, &contested); @@ -196,7 +202,7 @@ sx->sx_cnt--; sx->sx_xholder = curthread; - lock_profile_obtain_lock_success(&sx->sx_object, file, line); + lock_profile_obtain_lock_success(&sx->sx_object, waittime, file, line); LOCK_LOG_LOCK("XLOCK", &sx->sx_object, 0, 0, file, line); WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line); ==== //depot/projects/kmacy_sun4v/src/sys/sys/lock_profile.h#6 (text+ko) ==== @@ -84,34 +84,34 @@ } } +static inline void lock_profile_waitstart(uint64_t *waittime) +{ + *waittime = rd(tick); +} + static inline void lock_profile_obtain_lock_failed(struct lock_object *lo, int *contested) { struct lock_profile_object *l = &lo->lo_profile_obj; if (mutex_prof_enable) { *contested = 1; atomic_add_int(&l->lpo_contest_holding, 1); - if (curthread->td_waittime == 0) - curthread->td_waittime = rd(tick); } } -static inline void lock_profile_obtain_lock_success(struct lock_object *lo, const char *file, int line) +static inline void lock_profile_obtain_lock_success(struct lock_object *lo, uint64_t waittime, const char *file, int line) { struct lock_profile_object *l = &lo->lo_profile_obj; - + /* don't reset the timer when/if recursing */ if (mutex_prof_enable && l->lpo_acqtime == 0) { l->lpo_filename = file; l->lpo_lineno = line; l->lpo_acqtime = rd(tick); /* substitute for more general TSC read */ - if (curthread->td_waittime) { - struct thread *td = curthread; - if (l->lpo_acqtime > td->td_waittime) - l->lpo_waittime = l->lpo_acqtime - td->td_waittime; - td->td_waittime = 0; + if (waittime) { + if (l->lpo_acqtime > waittime) + l->lpo_waittime = l->lpo_acqtime - waittime; } - } else - curthread->td_waittime = 0; + } } static inline void lock_profile_release_lock(struct lock_object *lo) ==== //depot/projects/kmacy_sun4v/src/sys/sys/proc.h#10 (text+ko) ==== @@ -259,9 +259,6 @@ struct mdthread td_md; /* (k) Any machine-dependent fields. */ struct td_sched *td_sched; /* (*) Scheduler-specific data. */ struct kaudit_record *td_ar; /* (k) Active audit record, if any. */ -#ifdef MUTEX_PROFILING - uint64_t td_waittime; /* time in ns that thread started waiting for lock */ -#endif }; /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606250502.k5P52J0Z071951>