From owner-freebsd-current@FreeBSD.ORG Tue May 17 17:01:21 2011 Return-Path: <owner-freebsd-current@FreeBSD.ORG> Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0AB521065672; Tue, 17 May 2011 17:01:21 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id D48FD8FC0C; Tue, 17 May 2011 17:01:20 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 89C7246B06; Tue, 17 May 2011 13:01:20 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 0C7B98A052; Tue, 17 May 2011 13:01:20 -0400 (EDT) From: John Baldwin <jhb@freebsd.org> To: Max Laier <max@love2party.net> Date: Tue, 17 May 2011 12:56:40 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110325; KDE/4.5.5; amd64; ; ) References: <4DCD357D.6000109@FreeBSD.org> <4DD26720.3000001@FreeBSD.org> <4DD2A058.6050400@love2party.net> In-Reply-To: <4DD2A058.6050400@love2party.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201105171256.41091.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Tue, 17 May 2011 13:01:20 -0400 (EDT) Cc: neel@freebsd.org, Andriy Gapon <avg@freebsd.org>, Attilio Rao <attilio@freebsd.org>, FreeBSD current <freebsd-current@freebsd.org>, Stephan Uphoff <ups@freebsd.org>, Peter Grehan <grehan@freebsd.org> Subject: Re: proposed smp_rendezvous change X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current <freebsd-current.freebsd.org> List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-current>, <mailto:freebsd-current-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/freebsd-current> List-Post: <mailto:freebsd-current@freebsd.org> List-Help: <mailto:freebsd-current-request@freebsd.org?subject=help> List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-current>, <mailto:freebsd-current-request@freebsd.org?subject=subscribe> X-List-Received-Date: Tue, 17 May 2011 17:01:21 -0000 On Tuesday, May 17, 2011 12:20:40 pm Max Laier wrote: > On 05/17/2011 05:16 AM, John Baldwin wrote: > ... > > Index: kern/kern_switch.c > > =================================================================== > > --- kern/kern_switch.c (revision 221536) > > +++ kern/kern_switch.c (working copy) > > @@ -192,15 +192,22 @@ > > critical_exit(void) > > { > > struct thread *td; > > - int flags; > > + int flags, owepreempt; > > > > td = curthread; > > KASSERT(td->td_critnest != 0, > > ("critical_exit: td_critnest == 0")); > > > > if (td->td_critnest == 1) { > > + owepreempt = td->td_owepreempt; > > + td->td_owepreempt = 0; > > + /* > > + * XXX: Should move compiler_memory_barrier() from > > + * rmlock to a header. > > + */ > > XXX: If we get an interrupt at this point and td_owepreempt was zero, > the new interrupt will re-set it, because td_critnest is still non-zero. > > So we still end up with a thread that is leaking an owepreempt *and* > lose a preemption. I don't see how this can still leak owepreempt. The nested interrupt should do nothing (except for possibly set owepreempt) until td_critnest is 0. However, we can certainly lose preemptions. I wonder if we can abuse the high bit of td_critnest for the owepreempt flag so it is all stored in one cookie. We only set owepreempt while holding thread_lock() (so interrupts are disabled), so I think we would be ok and not need atomic ops. Hmm, actually, the top-half code would have to use atomic ops. Nuts. Let me think some more. -- John Baldwin