From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <9ab217670704151334k121fbbffp426cd8c379848bad@mail.gmail.com> Date: Sun, 15 Apr 2007 16:34:05 -0400 From: "Devon H. O'Dell" To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu> Subject: Re: [9fans] Re: [sources] 20070413: /rc/bin/cpurc.local In-Reply-To: <20070415175854.B53311E8C26@holo.morphisms.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <9ab217670704151043j1da7acc2j61869c6d54f736f7@mail.gmail.com> <20070415175854.B53311E8C26@holo.morphisms.net> Topicbox-Message-UUID: 49307bd0-ead2-11e9-9d60-3106f5b1d025 2007/4/15, Russ Cox : > /* cooperative scheduling until the clock ticks */ > if((p=m->readied) && p->mach==0 && p->state==Ready > && runq[Nrq-1].head == nil && runq[Nrq-2].head == nil){ > > The tests are: > > p=m->readied > some process p was last readied on this cpu (Mach) > > p->mach == 0 > p is not running on any cpu right now Not to be overly annoying, but _is_ it possible that between the assignment and that test, p->mach is set, indicating another CPU took over? It just doesn't seem like m->readied is locked, at all; it seems like another CPU could pick it up in the middle. > p->state == Ready > p is still Ready (waiting to run) > > runq[Nrq-1].head == nil && runq[Nrq-2].head == nil > there are no real-time processes waiting to run > > If all those succeed, then the code tries to choose > p to run next. But it might not -- the next thing that > happens is > > p = dequeueproc(rq, p); > > which can return nil if p has already been grabbed > or even if there is contention for the runq lock. > All the accesses in the if condition are just fine -- > they happen without a lock but dequeueproc double-checks > that p is okay to schedule. > > If dequeueproc returns nil, then runproc won't pick > the readied p after all -- it will fall into the regular > scheduling loop to find a process. > > Russ Thanks for the low-level explanation. It does really help my understanding. --dho