linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: shared memory problem on ARM v5TE using threads
Date: Tue, 15 Dec 2009 17:14:40 +0000	[thread overview]
Message-ID: <20091215171440.GA15855@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <cabda6420912150301n2c1a54d6ta7407d89f4d0f9cf@mail.gmail.com>

On Tue, Dec 15, 2009 at 12:01:56PM +0100, christian pellegrin wrote:
> Thanks for your answers, unfortunately it turned out to be quite easy
> to write a program [0] that shows exactly what Russell described. :-(

Try this:

- create a 4K file
- create three programs:
  1. repeatedly uses read() and write() to increment the first word of
     this file
  2. uses one shared mmap of this file to increment the 256th word (offset
     1024)
  3. uses two shared mmaps of this file, reading the 128th word from one
     shared mmap, reads the 128th word from the other, increments the
     first value and writes it to the 128th word in the second map,
     printing the two values read.  It also reads the first and 256th
     word and prints the result

This should be an adequate test of most of the important scenarios: the
third program should show an increasing number for both locations.

If it doesn't, then the value is being cached somewhere.  I suspect
what you'll find is that on Feroceon, the only values you will see
increment is the 128th value.  The remainder will be static.

That means multiple shared mmaps on Feroceon are incoherent with:
1. file updates via read/write.
2. other shared mappings in other processes.

And because of (1) I expect that a read() followed by another read() of
the same file offset as being updated by (3) will not show updates - so
it should be both lost write()s and stale data on read()s (which will
mean PIO write-outs - eg swap out, file update - will be affected.)

> int main(int argc, char *argv[])
> {
>   int fd, fd1;
>   char *s1, *s2, *p;
>   volatile char x;

As a note, you want s1, s2 and p to be volatile, otherwise the compiler
can cache the result.

>   fd = open("prova", O_RDWR);
>   assert(fd);
> 
>   fd1 = open("prova", O_RDWR);
>   assert(fd1);
> 
>   p = mmap(NULL, 1024, PROT_WRITE|PROT_READ, MAP_PRIVATE,
> 	   fd1, 0);
>   assert((long) p != -1);
> 
>   x = *p;
> 
>   s1 = mmap(NULL, 1024, PROT_WRITE|PROT_READ, MAP_SHARED,
> 	     fd, 0);
>   assert((long) s1 != -1);
>   s2 = mmap(NULL, 1024, PROT_WRITE|PROT_READ, MAP_SHARED,
> 	     fd, 0);
>   assert((long) s2 != -1);
> 
>   fprintf(stderr,"s1 %p s2 %p p %p\n", s1, s2, p);
>   fprintf(stderr, "1: s1 %d s2 %d p %d\n", s1[0], s2[0], p[0]);
> 
>   s1[0] = 'a';
>   s2[0] = 'b';
> 
>   msync(s1, 1024, MS_SYNC);
>   msync(s2, 1024, MS_SYNC);

These msyncs should not be required for data via one shared mmap to be
visible via another mmap.

>   assert(lseek(fd1, SEEK_SET, 0) == 0);
>   assert(read(fd1, &x, 1) == 1);
>   fprintf(stderr, "2: s1 %d s2 %d p %d x %d\n", s1[0], s2[0], p[0], x);
> 
>   return 0;
> }

  parent reply	other threads:[~2009-12-15 17:14 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-04 11:23 shared memory problem on ARM v5TE using threads Heiko Schocher
2009-12-04 12:26 ` Joerg Wagner
2009-12-04 13:13 ` Russell King - ARM Linux
2009-12-04 13:42   ` Heiko Schocher
2009-12-04 15:42     ` Russell King - ARM Linux
2009-12-04 15:58       ` Heiko Schocher
2009-12-04 16:38         ` Russell King - ARM Linux
2009-12-04 16:59           ` Russell King - ARM Linux
2009-12-04 17:53           ` Heiko Schocher
2009-12-04 19:13             ` Russell King - ARM Linux
2009-12-04 19:35               ` Heiko Schocher
2009-12-06 13:53                 ` Ronen Shitrit
2009-12-06 14:16                   ` Russell King - ARM Linux
2009-12-07  7:54                     ` Ronen Shitrit
2009-12-07  8:33                     ` Heiko Schocher
2009-12-07 11:31                     ` saeed bishara
2009-12-07 11:42                       ` Russell King - ARM Linux
2009-12-07 12:16                         ` Ronen Shitrit
2009-12-07 12:27                           ` Heiko Schocher
2009-12-07 12:42                             ` Ronen Shitrit
2009-12-07 15:24                               ` Nicolas Pitre
2009-12-07 12:24                         ` Heiko Schocher
2009-12-07 12:55                           ` Ronen Shitrit
2009-12-07 14:52                             ` Russell King - ARM Linux
2009-12-07 15:37                               ` Nicolas Pitre
2009-12-07 17:05                                 ` Russell King - ARM Linux
2009-12-07 17:33                                   ` Nicolas Pitre
2009-12-07 17:56                                     ` Russell King - ARM Linux
2009-12-13 11:48                                       ` Ronen Shitrit
2009-12-13 12:00                                         ` Russell King - ARM Linux
2009-12-13 12:06                                           ` Russell King - ARM Linux
2009-12-13 15:42                                             ` Ronen Shitrit
2009-12-14 13:13                                             ` christian pellegrin
2009-12-14 14:46                                               ` Ronen Shitrit
2009-12-14 17:48                                                 ` christian pellegrin
2009-12-14 20:14                                                   ` Nicolas Pitre
2009-12-15  7:50                                                     ` saeed bishara
2009-12-15 11:01                                                       ` christian pellegrin
2009-12-15 15:31                                                         ` christian pellegrin
2009-12-15 17:18                                                           ` Russell King - ARM Linux
2009-12-16 14:08                                                             ` Ronen Shitrit
2009-12-15 17:14                                                         ` Russell King - ARM Linux [this message]
2009-12-16 16:35                                                           ` christian pellegrin
2009-12-16 17:38                                                             ` christian pellegrin
2009-12-17  7:35                                                               ` Ronen Shitrit
2009-12-18 20:22                                                               ` Nicolas Pitre
2009-12-18 20:44                                                                 ` Russell King - ARM Linux
2009-12-18 21:23                                                                   ` Nicolas Pitre
2009-12-18 21:57                                                                     ` Russell King - ARM Linux
2009-12-19 11:24                                                                       ` christian pellegrin
2009-12-19 11:27                                                                         ` [PATCH] Fix coherency problems on ARM v5 with L2 PIPT cache Christian Pellegrin
2009-12-14 19:59                                               ` shared memory problem on ARM v5TE using threads Nicolas Pitre
2009-12-15 10:33                                                 ` christian pellegrin
2009-12-18 18:45                                           ` Pavel Machek
2009-12-18 19:00                                             ` Nicolas Pitre
2009-12-20 19:51                                               ` Pavel Machek
2009-12-20 22:32                                                 ` Nicolas Pitre
2009-12-21  7:40                                                   ` Pavel Machek
2009-12-18 19:16                                             ` Russell King - ARM Linux
2009-12-20 19:56                                               ` Pavel Machek
2009-12-17 11:31                                         ` Heiko Schocher
2009-12-18  8:08                                           ` christian pellegrin
2009-12-07 15:40                               ` Russell King - ARM Linux
2009-12-07 15:57                                 ` Nicolas Pitre
2009-12-07 16:06                                   ` Ronen Shitrit
2009-12-07 17:17                                   ` Russell King - ARM Linux
2009-12-04 17:25 ` Nicolas Pitre
2009-12-04 17:31   ` Russell King - ARM Linux
2009-12-04 17:47   ` Heiko Schocher
2009-12-04 17:56     ` Nicolas Pitre
2009-12-04 19:33       ` Heiko Schocher

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=20091215171440.GA15855@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).