From: Andrea Arcangeli <andrea@suse.de>
To: Manfred Spraul <manfred@colorfullife.com>
Cc: Stephen Hemminger <shemminger@osdl.org>,
Richard Henderson <rth@twiddle.net>,
linux-kernel@vger.kernel.org
Subject: Re: frlock and barrier discussion
Date: Thu, 30 Jan 2003 19:26:22 +0100 [thread overview]
Message-ID: <20030130182622.GR18538@dualathlon.random> (raw)
In-Reply-To: <3E396CF1.5000300@colorfullife.com>
On Thu, Jan 30, 2003 at 07:20:33PM +0100, Manfred Spraul wrote:
> Stephen wrote:
>
> [snip - memory barrier for fr_write_begin]
>
> >Using mb() is more paranoid than necessary.
>
>
> What about the memory barrier in fr_read_begin?
> If I understand the Intel documentation correctly, then i386 doesn't need
> them:
> "Writes by a single processor are observed in the same order by all
> processors"
>
> I think "smp_read_barrier_depends()" (i.e. a nop for i386) is sufficient.
I don't see what you mean, there is no dependency we can rely on between
the read of the sequence number and the critical section reads, the
critical section reads has nothing to do with the sequence number reads
and the frlock itself.
> Attached is a test app - could someone try it? I don't have access to a SMP
> system right now.
>
>
> What about permitting arch overrides for the memory barriers? E.g. ia64 has
> acquire and release memory barriers - it doesn't map to the Linux
> wmb()/rmb() scheme.
>
> --
> Manfred
>
>
>
>
>
>
>
>
>
>
>
>
> /*
> * frlock: test for Intel memory ordering.
> * Copyright (C) 1999,2003 by Manfred Spraul.
> *
> * Redistribution of this file is permitted under the terms of the GNU
> * Public License (GPL)
> * $Header: /pub/home/manfred/cvs-tree/movopt/frlock.cpp,v 1.2 2003/01/26 10:41:39 manfred Exp $
> */
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
> #include <pthread.h>
> #include <assert.h>
>
> static volatile int g_val1;
> static volatile int g_val2;
> static volatile int g_seq1;
> static volatile int g_seq2;
>
> static volatile int start;
> #define MB() __asm__ __volatile__ ("lock;addl $0,(%%esp)\n\t" \
> :/* no output*/ \
> :/* no input*/:"cc","memory")
>
> #define DELAY() do { int i; for(i=0;i<1000;i++); } while(0)
>
> void* threadfnc(void* param)
> {
> while(!start);
> if(1 == (int)param)
> goto cpu1;
> if(2 == (int)param)
> goto cpu2;
> assert(0);
> cpu1:
> { // reader:
> for(;;) {
> int x1,x2,val1,val2;
>
> x1 = g_seq1;
> val1 = g_val1;
> val2 = g_val2;
> x2 = g_seq2;
> if (x1 == x2) {
> if (val1 != val2) {
> printf("Bad! memory ordering violation with %d/%d: %d/%d.\n", x1, x2, val1, val2);
> }
> }
> }
> }
> cpu2:
> { // writer:
> int target = 0;
> for (;;) {
>
> // write 1:
> target++;
> g_seq1 = target;
> g_val1 = target;
> g_val2 = target;
> g_seq2 = target;
> DELAY();
>
> // write 2:
> target++;
> g_seq1 = target;
> g_val1 = target;
> MB();
> g_val2 = target;
> g_seq2 = target;
> DELAY();
>
> // write 3:
> target++;
> g_seq1 = target;
> g_val2 = target;
> g_val1 = target;
> g_seq2 = target;
> DELAY();
>
> // write 4:
> target++;
> g_seq1 = target;
> g_val2 = target;
> MB();
> g_val1 = target;
> g_seq2 = target;
> DELAY();
>
>
>
> // write 5:
> target++;
> g_seq1 = target;
> g_val1 = target;
> MB(); MB();
> g_val2 = target;
> g_seq2 = target;
> DELAY();
>
> // write 6:
> target++;
> g_seq1 = target;
> g_val1 = target;
> MB(); DELAY();
> g_val2 = target;
> g_seq2 = target;
> DELAY();
>
> // write 7:
> target++;
> g_seq1 = target;
> g_val2 = target;
> MB(); MB();
> g_val1 = target;
> g_seq2 = target;
> DELAY();
>
> // write 8:
> target++;
> g_seq1 = target;
> g_val2 = target;
> MB(); DELAY();
> g_val1 = target;
> g_seq2 = target;
> DELAY();
> }
> }
> }
>
> void start_thread(int id)
> {
> pthread_t thread;
> int res;
>
> res = pthread_create(&thread,NULL,threadfnc,(void*)id);
> if(res != 0)
> assert(false);
> }
>
>
>
> int main()
> {
> printf("movopt:\n");
> start_thread(1);
> start_thread(2);
> printf(" starting, please wait.\n");
> fflush(stdout);
> start = 1;
> for(;;) sleep(1000);
> }
Andrea
next prev parent reply other threads:[~2003-01-30 18:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-30 18:20 frlock and barrier discussion Manfred Spraul
2003-01-30 18:26 ` Andrea Arcangeli [this message]
2003-01-30 19:05 ` Manfred Spraul
2003-01-30 19:54 ` Davide Libenzi
2003-01-30 22:32 ` Alan Cox
-- strict thread matches above, loose matches on Subject: below --
2003-01-28 23:42 [PATCH] (1/4) 2.5.59 fast reader/writer lock for gettimeofday Stephen Hemminger
2003-01-29 7:06 ` Richard Henderson
2003-01-30 1:15 ` frlock and barrier discussion Stephen Hemminger
2003-01-30 1:29 ` Andrea Arcangeli
2003-01-30 1:41 ` Richard Henderson
2003-01-30 1:52 ` Andrea Arcangeli
2003-01-31 0:41 ` Richard Henderson
2003-01-31 0:57 ` Andrea Arcangeli
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=20030130182622.GR18538@dualathlon.random \
--to=andrea@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=rth@twiddle.net \
--cc=shemminger@osdl.org \
/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