9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: presotto@plan9.bell-labs.com presotto@plan9.bell-labs.com
Subject: porting linux programs and drivers to plan9
Date: Sun, 20 Apr 1997 23:36:37 -0400	[thread overview]
Message-ID: <19970421033637.fb9882Ri5y2asR-v6dd10U1PYhjEh1I9gjzPMn6I5lU@z> (raw)

Jmk's on vacation so I'm answering for him.  The Pentium
Pro does speculative reads.  The result of these reads is
a relaxed coherence described below.  The thing most
affected was our sleep wakeup.  To paraphrase sleep and wakeup:

A sleeper does:

	p = u->p;
	lock(&p->rlock);
	r->p = u->p;		/* put myself in the rendezvous structure */
A:	if(wakeup_condition){
		r->p = 0;		/* no need to sleep */
		unlock(&p->rlock);
		return;
	} else {
		/* go to sleep */
		p->state = Wakeme;
		p->r = r;
		unlock(&p->rlock);
		sched();
	}

A waker does:

	wakeup_condition = 1;

	p = r->p;
	if(p == 0)
		return;
	lock(&p->rlock);
B:	if(r->p == p && p->r == r){
		r->p = 0;
		p->r = 0;
		ready(p);
	}
	unlock(&p->rlock);

The assumed invariant was that given any interleaving of these
two sequences, we would always have either

	wakeup_condition == 1  at point A:
or
	p == 1 at point B:

that is, either the process wouldn't sleep or the wakeup would
get it going again.

Unfortunately, on the Pro we found that, for example, the
following execution ordering on different processors could result
in both being 0 at those points:

	wakeup_condition = 1;

			p = u->p;
			lock(&p->rlock);
			r->p = p;		/* put myself in the rendezvous structure */
		A:	if(wakeup_condition){
				r->p = 0;		/* no need to sleep */
				unlock(&p->rlock);
				return;
			} else {

	p = r->p;
	if(p == 0)
		return;
	lock(&p->rlock);
B:	if(r->p == p && p->r == r){
		r->p = 0;
		p->r = 0;
		ready(p);
	}
	unlock(r);

				/* go to sleep */
				p->state = Wakeme;
				p->r = r;
				unlock(&p->rlock);
				sched();
			}

Ordering of remote writes and local reads to the same
location can no longer be trusted since the speculative
read may have happened before the write was performed.
The caches are still 'coherent' but since the value has
already been read out of the cache and is lurking in the
cpu, it doesn't necessarily match reality.  This is a case
where the caches are coherent but the processors aren't. 
An interlock instruction will force coherence at the processor
level.  That means that we had to make sure some sort of interlocked instruction
occurs after any setting of state that another cooperating process
must see.  The lock(r) following the 'wakeup_condition = 1'
was sufficient for the wakeup() side.  However, the 'r->p = u->p'
had no interlock following it, hence the screw up.

We've fixed it by putting an interlock after 'r->p = u->p'.
However, this has made us very scared.  We don't know of
other places in the kernel where this applies but that
doesn't mean there aren't any.  Ken is instrumenting the
compiler to help us check.

cheers.

------ forwarded message follows ------

>From cse.psu.edu!owner-9fans Sun Apr 20 12:39:20 EDT 1997
Received: from cse.psu.edu by plan9; Sun Apr 20 12:39:20 EDT 1997
Received: from localhost (majordom@localhost) by cse.psu.edu (8.8.5/8.7.3) with SMTP id MAA11975; Sun, 20 Apr 1997 12:17:36 -0400 (EDT)
Received: by claven.cse.psu.edu (bulk_mailer v1.5); Sun, 20 Apr 1997 12:17:07 -0400
Received: (from majordom@localhost) by cse.psu.edu (8.8.5/8.7.3) id MAA11933 for 9fans-outgoing; Sun, 20 Apr 1997 12:17:01 -0400 (EDT)
X-Authentication-Warning: claven.cse.psu.edu: majordom set sender to owner-9fans using -f
Received: from hamnavoe.demon.co.uk (hamnavoe.demon.co.uk [158.152.225.204]) by cse.psu.edu (8.8.5/8.7.3) with SMTP id MAA11929 for <9fans@cse.psu.edu>; Sun, 20 Apr 1997 12:16:54 -0400 (EDT)
From: hamnavoe.demon.co.uk!miller
Message-Id: <199704201616.MAA11929@cse.psu.edu>
To: cse.psu.edu!9fans
Date: Sun, 20 Apr 1997 17:12:45 BST
Subject: Re: porting linux programs and drivers to plan9
Sender: cse.psu.edu!owner-9fans
Reply-To: cse.psu.edu!9fans
Precedence: bulk

plan9.bell-labs.com!jmk wrote:

> ... we've found one problem caused by the weak memory ordering of the Pentium
> Pro

Can you be more explicit, please?

-- Richard Miller




             reply	other threads:[~1997-04-21  3:36 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-21  3:36 presotto [this message]
  -- strict thread matches above, loose matches on Subject: below --
1997-04-21 20:59 miller
1997-04-21 16:27 Eric
1997-04-21 14:53 Milon
1997-04-21 12:50 miller
1997-04-21 11:29 Nigel
1997-04-21  8:05 Boyd
1997-04-21  7:16 chad
1997-04-21  1:03 David
1997-04-20 16:12 miller
1997-04-19 16:49 Magnus
1997-04-19 10:22 Digby
1997-04-19  4:59 chad
1997-04-19  4:09 ozan
1997-04-19  3:52 Berry
1997-04-19  1:51 David
1997-04-19  0:56 Rich
1997-04-19  0:41 Rich
1997-04-18 21:19 Paul
1997-04-18 21:01 Digby
1997-04-18 20:47 Digby
1997-04-18 16:39 presotto
1997-04-18 16:10 Eric
1997-04-18 16:07 Eric
1997-04-18 15:57 Eric
1997-04-18 15:51 Eric
1997-04-18 15:37 Dean
1997-04-18 15:14 forsyth
1997-04-18 13:54 Brandon
1997-04-18  9:50 Andrew
1997-04-18  8:10 Digby
1997-04-18  8:04 Digby
1997-04-18  7:58 Steve_Kilbane
1997-04-18  7:52 Steve_Kilbane
1997-04-18  7:15 Nigel
1997-04-18  5:57 Nickolay
1997-04-18  5:49 Brandon
1997-04-18  4:59 jmk
1997-04-18  3:15 Steve
1997-04-18  0:33 Pete
1997-04-17 23:43 Eric
1997-04-17 23:19 Eric
1997-04-17 21:55 Eric
1997-04-17 21:46 Rich
1997-04-17 21:45 Rich
1997-04-17 18:43 Eric
1997-04-17 18:17 forsyth
1997-04-17 18:13 forsyth
1997-04-17 17:59 Bodet
1997-04-17 17:07 Pete
1997-04-17 16:33 Rich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19970421033637.fb9882Ri5y2asR-v6dd10U1PYhjEh1I9gjzPMn6I5lU@z \
    --to=presotto@plan9.bell-labs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).