From owner-svn-src-head@freebsd.org Tue May 22 19:24:58 2018 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 7865BEACFDE; Tue, 22 May 2018 19:24:58 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1C96985E44; Tue, 22 May 2018 19:24:58 +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 D3589184AC; Tue, 22 May 2018 19:24:57 +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 w4MJOvYT091582; Tue, 22 May 2018 19:24:57 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4MJOvEH091581; Tue, 22 May 2018 19:24:57 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201805221924.w4MJOvEH091581@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Tue, 22 May 2018 19:24:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334062 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 334062 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.26 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, 22 May 2018 19:24:58 -0000 Author: mjg Date: Tue May 22 19:24:57 2018 New Revision: 334062 URL: https://svnweb.freebsd.org/changeset/base/334062 Log: Move preemption handling out of critical_exit. In preperataion for making the enter/exit pair inline. Reviewed by: kib Modified: head/sys/kern/kern_switch.c Modified: head/sys/kern/kern_switch.c ============================================================================== --- head/sys/kern/kern_switch.c Tue May 22 19:11:06 2018 (r334061) +++ head/sys/kern/kern_switch.c Tue May 22 19:24:57 2018 (r334062) @@ -209,48 +209,49 @@ critical_enter(void) (long)td->td_proc->p_pid, td->td_name, td->td_critnest); } -void -critical_exit(void) +static void __noinline +critical_exit_preempt(void) { struct thread *td; int flags; td = curthread; - KASSERT(td->td_critnest != 0, - ("critical_exit: td_critnest == 0")); + KASSERT(td->td_owepreempt != 0, + ("critical_exit: td_owepreempt == 0")); + if (td->td_critnest != 0) + return; + if (kdb_active) + return; - if (td->td_critnest == 1) { - td->td_critnest = 0; + /* + * Microoptimization: we committed to switch, + * disable preemption in interrupt handlers + * while spinning for the thread lock. + */ + td->td_critnest = 1; + thread_lock(td); + td->td_critnest--; + flags = SW_INVOL | SW_PREEMPT; + if (TD_IS_IDLETHREAD(td)) + flags |= SWT_IDLE; + else + flags |= SWT_OWEPREEMPT; + mi_switch(flags, NULL); + thread_unlock(td); +} - /* - * Interrupt handlers execute critical_exit() on - * leave, and td_owepreempt may be left set by an - * interrupt handler only when td_critnest > 0. If we - * are decrementing td_critnest from 1 to 0, read - * td_owepreempt after decrementing, to not miss the - * preempt. Disallow compiler to reorder operations. - */ - __compiler_membar(); - if (td->td_owepreempt && !kdb_active) { - /* - * Microoptimization: we committed to switch, - * disable preemption in interrupt handlers - * while spinning for the thread lock. - */ - td->td_critnest = 1; - thread_lock(td); - td->td_critnest--; - flags = SW_INVOL | SW_PREEMPT; - if (TD_IS_IDLETHREAD(td)) - flags |= SWT_IDLE; - else - flags |= SWT_OWEPREEMPT; - mi_switch(flags, NULL); - thread_unlock(td); - } - } else - td->td_critnest--; +void +critical_exit(void) +{ + struct thread *td; + td = curthread; + KASSERT(td->td_critnest != 0, + ("critical_exit: td_critnest == 0")); + td->td_critnest--; + __compiler_membar(); + if (__predict_false(td->td_owepreempt)) + critical_exit_preempt(); CTR4(KTR_CRITICAL, "critical_exit by thread %p (%ld, %s) to %d", td, (long)td->td_proc->p_pid, td->td_name, td->td_critnest); }