From owner-svn-src-all@FreeBSD.ORG Tue Jan 26 21:20:47 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7F270106566C; Tue, 26 Jan 2010 21:20:47 +0000 (UTC) (envelope-from asmrookie@gmail.com) Received: from mail-iw0-f204.google.com (mail-iw0-f204.google.com [209.85.223.204]) by mx1.freebsd.org (Postfix) with ESMTP id 0B8218FC0A; Tue, 26 Jan 2010 21:20:46 +0000 (UTC) Received: by iwn42 with SMTP id 42so2026783iwn.9 for ; Tue, 26 Jan 2010 13:20:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=C5O2vyS1YLaY8YIyw3NzuEQrmnx55B6aobrr3qLzTuE=; b=Ex/hQcjFaaCeLAwcStuDNrvQ++yBi82NTzxmJialO9Eb94SboylNZQERveqHCmaiUG P4HJH/ZW/yLqShZP5XJdTE/0I9F3hmWr71BQQZz1X/88ZW9eGdTgYcQEs3Lr9IJhoShc Vqb4xrf8dHU2vbDbOopTjOuUsV/5W2DFH7vA4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=KalpC1qFNvMwBBcVgagl3OSIlw7jTPzpQSN09p6asWJMsZPjv1hXNGxUsgMah2QXlt 2VukLgj7bFaPieOy++JOe1nowrUpErxi/hRlaCDS43fIXHNfMK3jzLaSIxXwhW3IRclk yGyYLIVyCjDLEUVjLZ4JisB0kXLoqbr2hraW8= MIME-Version: 1.0 Sender: asmrookie@gmail.com Received: by 10.231.154.197 with SMTP id p5mr5085220ibw.28.1264540846133; Tue, 26 Jan 2010 13:20:46 -0800 (PST) In-Reply-To: <201001261551.52206.jhb@freebsd.org> References: <3bbf2fe11001260058i65604619l664bd0e49c1dbbd@mail.gmail.com> <20100126.130932.722022410132669562.imp@bsdimp.com> <201001261551.52206.jhb@freebsd.org> Date: Tue, 26 Jan 2010 22:20:46 +0100 X-Google-Sender-Auth: da681ea0f94b12bc Message-ID: <3bbf2fe11001261320k654b2b8ck3d03c4d94ae8d9c1@mail.gmail.com> From: Attilio Rao To: John Baldwin Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jan 2010 21:20:47 -0000 2010/1/26 John Baldwin : > On Tuesday 26 January 2010 3:09:32 pm M. Warner Losh wrote: >> In message: >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 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) >> { >> =C2=A0 =C2=A0 =C2=A0 /* Save the registers to the pcb */ >> =C2=A0 =C2=A0 =C2=A0 old->td_lock =3D mtx; >> #if defined(SMP) && defined(SCHED_ULE) >> =C2=A0 =C2=A0 =C2=A0 /* s/long/int/ if sizeof(long) !=3D sizeof(void *) = */ >> =C2=A0 =C2=A0 =C2=A0 /* as we have no 'void *' version of the atomics */ >> =C2=A0 =C2=A0 =C2=A0 while (atomic_load_acq_long(&new->td_lock) =3D=3D (= long)&blocked_lock) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue; >> #endif >> =C2=A0 =C2=A0 =C2=A0 /* Switch to new context */ >> } > > FYI, that is what the '_ptr' variants of atomic ops are for. =C2=A0I do t= hink 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 instea= d: - old->td_lock =3D mtx; + atomic_store_rel_ptr(&old->td_lock, mtx); Thanks, Attilio --=20 Peace can only be achieved by understanding - A. Einstein