From owner-freebsd-mips@FreeBSD.ORG Tue Jan 26 09:47:50 2010 Return-Path: Delivered-To: freebsd-mips@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AF42D106566B for ; Tue, 26 Jan 2010 09:47:50 +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 733378FC14 for ; Tue, 26 Jan 2010 09:47:50 +0000 (UTC) Received: by iwn42 with SMTP id 42so1420956iwn.9 for ; Tue, 26 Jan 2010 01:47:49 -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=XawEb1lPkuOw+kgzjSVM7zldKuga380tfVhPLDFzRHQ=; b=L1HBKaJaY7/heADy6KQqXNOEjroTPQj7u9+7Z0WMBE4xNlqx2MemFE/0B1YGA34Mgl f6pF4BLaGQw6/HPVSd+jgC4PvXuahcoX0vRLNjjDcqmn8N9f6w+KvRpOa1paDXJMGmn7 5eX+lnPTp1teMrLLHyGgE6WDAQJRCRzmbAgX0= 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=RR+giH64hn2yRRXpdO8EmCaG1q8Yxiovkck1wxGJY7JLkMiO5JUXfBeyfMxgMu8a8k nSH4a8wFV7WJn13FBYL21C+a7qqepnF3xHkAQ5iOcWVd72QuqymRFDvbcMEnd++sOouk 9+ktcCE43hC3BbLAj/2an3qCn1l8f1lwBGdEo= MIME-Version: 1.0 Sender: asmrookie@gmail.com Received: by 10.231.155.18 with SMTP id q18mr1805586ibw.80.1264497934939; Tue, 26 Jan 2010 01:25:34 -0800 (PST) In-Reply-To: <3bbf2fe11001260124h423bd73ev38ba939d34155c54@mail.gmail.com> References: <5D3E417C-FE51-49A7-B8CC-564932BF0D3E@lakerest.net> <489828.45501.qm@web34403.mail.mud.yahoo.com> <3bbf2fe11001260124h423bd73ev38ba939d34155c54@mail.gmail.com> Date: Tue, 26 Jan 2010 10:25:34 +0100 X-Google-Sender-Auth: 90cfe5433151ea5d Message-ID: <3bbf2fe11001260125t43b833feha759555f3e4d0fe8@mail.gmail.com> From: Attilio Rao To: Neelkanth Natu Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-mips@freebsd.org Subject: Re: AR71XX RTC X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jan 2010 09:47:50 -0000 2010/1/26 Attilio Rao : > 2010/1/25 Neelkanth Natu : >> Hi Randall, >> >> --- On Mon, 1/25/10, Randall Stewart wrote: >> >>> From: Randall Stewart >>> Subject: Re: AR71XX RTC >>> To: "Neelkanth Natu" >>> Cc: "M. Warner Losh" , freebsd-mips@freebsd.org >>> Date: Monday, January 25, 2010, 12:51 PM >>> Neil: >>> >>> Thanks for the patch.. it does look good since the old >>> code was tromping part of the old threads PCB which is >>> definitely not right ;-0 .. I do have a question for you.. >>> forgive my ignorance.. >>> >>> What exactly are we trying to switch here. It seems >>> that cpu_switch(...) is now being called with >>> oldtd, newtd and mtx... >>> >>> I see that the thread structure has a struct mutex *td_lock >>> as >>> its first member. But what is this supposed to be pointing >>> to? >>> And when we switch are we trying to take the >>> >>> oldtd->td_lock and place it into the newtd->td_lock >>> >>> Or? >>> >>> What... I guess I just don't have any context for whats >>> going on.. >>> >> >> I am not very sure about this myself so take this with a grain of salt: >> >> When a thread is being switched out because it is on a sleep queue the >> intent is that some other thread running on a different cpu should not b= e >> allowed to muck with this thread's state. To make this happen the 'td_lo= ck' >> of 'oldtd' is switched from what it was originally (viz. the sleep queue >> chain lock) to 'blocked_lock'. The 'blocked_lock' is special because >> it is always locked. This all happens in sched_switch(). >> >> cpu_switch() is passed the original value of 'oldtd->td_lock' >> as the third argument. When the context is switched to 'newtd' we will >> switch back the 'oldtd->td_lock' from 'blocked_lock' to its original >> value. And this way we don't lose any wakeups that may happen while we >> are in sched_switch(). >> >> At least that is my very naive understanding of it. CCing Attilio to >> shed more light on this. > > Hope this little explanation may give more guidance: > http://lists.freebsd.org/pipermail/svn-src-head/2010-January/014038.html > > anyways, the interesting bits in, eg. i386 are: > > #if defined(SMP) && defined(SCHED_ULE) > #define SETOP =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 xchgl > #define BLOCK_SPIN(reg) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0movl =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0$blocked_lock,%eax ; =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0\ > =C2=A0 =C2=A0 =C2=A0 =C2=A0100: ; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0\ > =C2=A0 =C2=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=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0\ > =C2=A0 =C2=A0 =C2=A0 =C2=A0101: > #else > #define SETOP =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 movl > #define BLOCK_SPIN(reg) > #endif > > The difference with SETOP is just for providing a rel memory barriers > vs. not providing a rel memory barrier (thus be careful, if you want > to support ULE, to follow the same logic), while BLOCK_SPIN() does: > > while (oldtd->td_lock =3D=3D &blocked_lock) cpu_spinwait(); s/oldtd/newtd. Attilio --=20 Peace can only be achieved by understanding - A. Einstein