From owner-svn-src-head@freebsd.org Thu May 16 13:17:58 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 254D6159668C; Thu, 16 May 2019 13:17:58 +0000 (UTC) (envelope-from kib@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) server-signature RSA-PSS (4096 bits) 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 BF85A75EB0; Thu, 16 May 2019 13:17:57 +0000 (UTC) (envelope-from kib@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 97C7B2151F; Thu, 16 May 2019 13:17:57 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4GDHvIw066396; Thu, 16 May 2019 13:17:57 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4GDHvMr066395; Thu, 16 May 2019 13:17:57 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201905161317.x4GDHvMr066395@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Thu, 16 May 2019 13:17:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r347694 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 347694 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: BF85A75EB0 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.97)[-0.972,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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: Thu, 16 May 2019 13:17:58 -0000 Author: kib Date: Thu May 16 13:17:57 2019 New Revision: 347694 URL: https://svnweb.freebsd.org/changeset/base/347694 Log: subr_turnstile: Extract some common code to a helper. Code walks the list of contested turnstiles to calculate the priority to unlend. Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/sys/kern/subr_turnstile.c Modified: head/sys/kern/subr_turnstile.c ============================================================================== --- head/sys/kern/subr_turnstile.c Thu May 16 13:13:33 2019 (r347693) +++ head/sys/kern/subr_turnstile.c Thu May 16 13:17:57 2019 (r347694) @@ -897,6 +897,24 @@ turnstile_broadcast(struct turnstile *ts, int queue) } } +static u_char +turnstile_calc_unlend_prio_locked(struct thread *td) +{ + struct turnstile *nts; + u_char cp, pri; + + THREAD_LOCK_ASSERT(td, MA_OWNED); + mtx_assert(&td_contested_lock, MA_OWNED); + + pri = PRI_MAX; + LIST_FOREACH(nts, &td->td_contested, ts_link) { + cp = turnstile_first_waiter(nts)->td_priority; + if (cp < pri) + pri = cp; + } + return (pri); +} + /* * Wakeup all threads on the pending list and adjust the priority of the * current thread appropriately. This must be called with the turnstile @@ -906,9 +924,8 @@ void turnstile_unpend(struct turnstile *ts) { TAILQ_HEAD( ,thread) pending_threads; - struct turnstile *nts; struct thread *td; - u_char cp, pri; + u_char pri; MPASS(ts != NULL); mtx_assert(&ts->ts_lock, MA_OWNED); @@ -932,7 +949,6 @@ turnstile_unpend(struct turnstile *ts) * priority however. */ td = curthread; - pri = PRI_MAX; thread_lock(td); mtx_lock_spin(&td_contested_lock); /* @@ -946,11 +962,7 @@ turnstile_unpend(struct turnstile *ts) ts->ts_owner = NULL; LIST_REMOVE(ts, ts_link); } - LIST_FOREACH(nts, &td->td_contested, ts_link) { - cp = turnstile_first_waiter(nts)->td_priority; - if (cp < pri) - pri = cp; - } + pri = turnstile_calc_unlend_prio_locked(td); mtx_unlock_spin(&td_contested_lock); sched_unlend_prio(td, pri); thread_unlock(td); @@ -991,7 +1003,7 @@ void turnstile_disown(struct turnstile *ts) { struct thread *td; - u_char cp, pri; + u_char pri; MPASS(ts != NULL); mtx_assert(&ts->ts_lock, MA_OWNED); @@ -1017,15 +1029,10 @@ turnstile_disown(struct turnstile *ts) * priority however. */ td = curthread; - pri = PRI_MAX; thread_lock(td); mtx_unlock_spin(&ts->ts_lock); mtx_lock_spin(&td_contested_lock); - LIST_FOREACH(ts, &td->td_contested, ts_link) { - cp = turnstile_first_waiter(ts)->td_priority; - if (cp < pri) - pri = cp; - } + pri = turnstile_calc_unlend_prio_locked(td); mtx_unlock_spin(&td_contested_lock); sched_unlend_prio(td, pri); thread_unlock(td);