From owner-svn-src-head@freebsd.org Tue Jul 21 14:39:21 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 155AD35E6FA; Tue, 21 Jul 2020 14:39:21 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BB1Sm6qtLz3TkN; Tue, 21 Jul 2020 14:39:20 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CDA681FD81; Tue, 21 Jul 2020 14:39:20 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06LEdK5R018836; Tue, 21 Jul 2020 14:39:20 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06LEdK3f018834; Tue, 21 Jul 2020 14:39:20 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202007211439.06LEdK3f018834@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Tue, 21 Jul 2020 14:39:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363392 - in head/sys: kern sys X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: kern sys X-SVN-Commit-Revision: 363392 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jul 2020 14:39:21 -0000 Author: mjg Date: Tue Jul 21 14:39:20 2020 New Revision: 363392 URL: https://svnweb.freebsd.org/changeset/base/363392 Log: lockmgr: add a helper for reading the lock value Modified: head/sys/kern/kern_lock.c head/sys/sys/lockmgr.h Modified: head/sys/kern/kern_lock.c ============================================================================== --- head/sys/kern/kern_lock.c Tue Jul 21 14:35:50 2020 (r363391) +++ head/sys/kern/kern_lock.c Tue Jul 21 14:39:20 2020 (r363392) @@ -140,7 +140,7 @@ LK_CAN_SHARE(uintptr_t x, int flags, bool fp) #define lockmgr_xlocked_v(v) \ (((v) & ~(LK_FLAGMASK & ~LK_SHARE)) == (uintptr_t)curthread) -#define lockmgr_xlocked(lk) lockmgr_xlocked_v((lk)->lk_lock) +#define lockmgr_xlocked(lk) lockmgr_xlocked_v(lockmgr_read_value(lk)) static void assert_lockmgr(const struct lock_object *lock, int how); #ifdef DDB @@ -233,7 +233,7 @@ static void lockmgr_note_exclusive_release(struct lock *lk, const char *file, int line) { - if (LK_HOLDER(lk->lk_lock) != LK_KERNPROC) { + if (LK_HOLDER(lockmgr_read_value(lk)) != LK_KERNPROC) { WITNESS_UNLOCK(&lk->lock_object, LOP_EXCLUSIVE, file, line); TD_LOCKS_DEC(curthread); } @@ -246,7 +246,7 @@ lockmgr_xholder(const struct lock *lk) { uintptr_t x; - x = lk->lk_lock; + x = lockmgr_read_value(lk); return ((x & LK_SHARE) ? NULL : (struct thread *)LK_HOLDER(x)); } @@ -309,7 +309,7 @@ wakeupshlk(struct lock *lk, const char *file, int line wakeup_swapper = 0; for (;;) { - x = lk->lk_lock; + x = lockmgr_read_value(lk); if (lockmgr_sunlock_try(lk, &x)) break; @@ -318,7 +318,7 @@ wakeupshlk(struct lock *lk, const char *file, int line * path in order to handle wakeups correctly. */ sleepq_lock(&lk->lock_object); - orig_x = lk->lk_lock; + orig_x = lockmgr_read_value(lk); retry_sleepq: x = orig_x & (LK_ALL_WAITERS | LK_EXCLUSIVE_SPINNERS); v = LK_UNLOCKED; @@ -515,7 +515,7 @@ lockmgr_slock_try(struct lock *lk, uintptr_t *xp, int * waiters, if we fail to acquire the shared lock * loop back and retry. */ - *xp = lk->lk_lock; + *xp = lockmgr_read_value(lk); while (LK_CAN_SHARE(*xp, flags, fp)) { if (atomic_fcmpset_acq_ptr(&lk->lk_lock, xp, *xp + LK_ONE_SHARER)) { @@ -603,7 +603,7 @@ lockmgr_slock_hard(struct lock *lk, u_int flags, struc * probabilly will need to manipulate waiters flags. */ sleepq_lock(&lk->lock_object); - x = lk->lk_lock; + x = lockmgr_read_value(lk); retry_sleepq: /* @@ -772,7 +772,7 @@ lockmgr_xlock_hard(struct lock *lk, u_int flags, struc * probabilly will need to manipulate waiters flags. */ sleepq_lock(&lk->lock_object); - x = lk->lk_lock; + x = lockmgr_read_value(lk); retry_sleepq: /* @@ -889,7 +889,7 @@ lockmgr_upgrade(struct lock *lk, u_int flags, struct l tid = (uintptr_t)curthread; _lockmgr_assert(lk, KA_SLOCKED, file, line); - v = lk->lk_lock; + v = lockmgr_read_value(lk); x = v & LK_ALL_WAITERS; v &= LK_EXCLUSIVE_SPINNERS; @@ -970,7 +970,7 @@ lockmgr_lock_flags(struct lock *lk, u_int flags, struc LOP_EXCLUSIVE, file, line, flags & LK_INTERLOCK ? ilk : NULL); tid = (uintptr_t)curthread; - if (lk->lk_lock == LK_UNLOCKED && + if (lockmgr_read_value(lk) == LK_UNLOCKED && atomic_cmpset_acq_ptr(&lk->lk_lock, LK_UNLOCKED, tid)) { lockmgr_note_exclusive_acquire(lk, 0, 0, file, line, flags); @@ -1054,7 +1054,7 @@ lockmgr_xunlock_hard(struct lock *lk, uintptr_t x, u_i goto out; sleepq_lock(&lk->lock_object); - x = lk->lk_lock; + x = lockmgr_read_value(lk); v = LK_UNLOCKED; /* @@ -1178,7 +1178,7 @@ lockmgr_unlock(struct lock *lk) line = __LINE__; _lockmgr_assert(lk, KA_LOCKED, file, line); - x = lk->lk_lock; + x = lockmgr_read_value(lk); if (__predict_true(x & LK_SHARE) != 0) { lockmgr_note_shared_release(lk, file, line); if (lockmgr_sunlock_try(lk, &x)) { @@ -1292,7 +1292,7 @@ __lockmgr_args(struct lock *lk, u_int flags, struct lo * In order to preserve waiters flags, just spin. */ for (;;) { - x = lk->lk_lock; + x = lockmgr_read_value(lk); MPASS((x & LK_EXCLUSIVE_SPINNERS) == 0); x &= LK_ALL_WAITERS; if (atomic_cmpset_rel_ptr(&lk->lk_lock, tid | x, @@ -1305,7 +1305,7 @@ __lockmgr_args(struct lock *lk, u_int flags, struct lo break; case LK_RELEASE: _lockmgr_assert(lk, KA_LOCKED, file, line); - x = lk->lk_lock; + x = lockmgr_read_value(lk); if (__predict_true(x & LK_SHARE) != 0) { lockmgr_note_shared_release(lk, file, line); @@ -1359,7 +1359,7 @@ __lockmgr_args(struct lock *lk, u_int flags, struct lo * probabilly will need to manipulate waiters flags. */ sleepq_lock(&lk->lock_object); - x = lk->lk_lock; + x = lockmgr_read_value(lk); /* * if the lock has been released while we spun on @@ -1545,7 +1545,7 @@ _lockmgr_disown(struct lock *lk, const char *file, int * In order to preserve waiters flags, just spin. */ for (;;) { - x = lk->lk_lock; + x = lockmgr_read_value(lk); MPASS((x & LK_EXCLUSIVE_SPINNERS) == 0); x &= LK_ALL_WAITERS; if (atomic_cmpset_rel_ptr(&lk->lk_lock, tid | x, @@ -1597,7 +1597,7 @@ lockstatus(const struct lock *lk) int ret; ret = LK_SHARED; - x = lk->lk_lock; + x = lockmgr_read_value(lk); v = LK_HOLDER(x); if ((x & LK_SHARE) == 0) { Modified: head/sys/sys/lockmgr.h ============================================================================== --- head/sys/sys/lockmgr.h Tue Jul 21 14:35:50 2020 (r363391) +++ head/sys/sys/lockmgr.h Tue Jul 21 14:39:20 2020 (r363392) @@ -119,6 +119,7 @@ _lockmgr_args_rw(struct lock *lk, u_int flags, struct /* * Define aliases in order to complete lockmgr KPI. */ +#define lockmgr_read_value(lk) ((lk)->lk_lock) #define lockmgr(lk, flags, ilk) \ _lockmgr_args((lk), (flags), (ilk), LK_WMESG_DEFAULT, \ LK_PRIO_DEFAULT, LK_TIMO_DEFAULT, LOCK_FILE, LOCK_LINE)