From owner-svn-src-head@FreeBSD.ORG Tue Jan 26 22:17:17 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 65CFE1065670; Tue, 26 Jan 2010 22:17:17 +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 F16508FC15; Tue, 26 Jan 2010 22:17:16 +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 7ED8F46B66; Tue, 26 Jan 2010 17:17:16 -0500 (EST) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPA id B6C338A01F; Tue, 26 Jan 2010 17:17:15 -0500 (EST) From: John Baldwin To: Attilio Rao Date: Tue, 26 Jan 2010 17:17:00 -0500 User-Agent: KMail/1.12.1 (FreeBSD/7.2-CBSD-20100120; KDE/4.3.1; amd64; ; ) References: <3bbf2fe11001260058i65604619l664bd0e49c1dbbd@mail.gmail.com> <201001261551.52206.jhb@freebsd.org> <3bbf2fe11001261320k654b2b8ck3d03c4d94ae8d9c1@mail.gmail.com> In-Reply-To: <3bbf2fe11001261320k654b2b8ck3d03c4d94ae8d9c1@mail.gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201001261717.00070.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Tue, 26 Jan 2010 17:17:15 -0500 (EST) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, xcllnt@mac.com, marcel@freebsd.org, svn-src-head@freebsd.org, "M. Warner Losh" Subject: Re: svn commit: r202889 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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, 26 Jan 2010 22:17:17 -0000 On Tuesday 26 January 2010 4:20:46 pm Attilio Rao wrote: > 2010/1/26 John Baldwin : > > On Tuesday 26 January 2010 3:09:32 pm M. Warner Losh wrote: > >> In message: > >> Marcel Moolenaar writes: > >> : Maybe what is in order right now is a description (using pseudo > >> : code if you like) of what exactly needs to happen with the 3rd > >> : argument, when and how (i.e. what must be atomic and what does > >> : not have to be atomic). > >> > >> I believe the proper pseudo code should be: > >> > >> cpu_switch(struct thread *old, struct thread *new, struct mutext *mtx) > >> { > >> /* Save the registers to the pcb */ > >> old->td_lock = mtx; > >> #if defined(SMP) && defined(SCHED_ULE) > >> /* s/long/int/ if sizeof(long) != sizeof(void *) */ > >> /* as we have no 'void *' version of the atomics */ > >> while (atomic_load_acq_long(&new->td_lock) == (long)&blocked_lock) > >> continue; > >> #endif > >> /* Switch to new context */ > >> } > > > > FYI, that is what the '_ptr' variants of atomic ops are for. I do think that > > the 'acq' membar on the load is needed to ensure the CPU doesn't try to > > speculatively read any of the 'new' thread's PCB until it sees the update to > > td_lock. > > I think it is more important to store the old lock via a rel barrier instead: > > - old->td_lock = mtx; > + atomic_store_rel_ptr(&old->td_lock, mtx); Both are required to ensure the new CPU does not load stale values from the pcb. -- John Baldwin