🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3486

Re: SysV shared memory coherency issues

#3486
From: "Nils O. Selåsdal"
Date: Tue, 14 Feb 2006 07:42
64 lines
4868 bytes
Ryan Underwood wrote:
> [This is crossposted to comp.lang.asm.x86 due to the instruction level issue
> below]
> 
> Hi,
> I'm getting really puzzled here.  The basic story is that we have a 4 way Xeon
> machine with hyperthreading enabled (8 logical processors).  The application is
> a fairly straightforward SysV (not POSIX) shared memory application.  The
> shared memory region is declared as a volatile double *.  We are using GCC
> 4.0.2 with -O0 and a 2.6.6 Linux kernel with RTLinux extensions.
> 
> One of the processes sets up essentially a RPC call by placing several double
> arguments in the shared memory region along with a function ID, and then
> setting a flag to notify the other process that a call is waiting.  The other
> process is doing soft-realtime computational work as fast as it can with no
> system calls, and occasionally checks the flag mailbox to see if a RPC is
> waiting.  If it is, then it reads the function ID and arguments and goes to
> work on that task.
> 
> This seemed to work fine in my test cases, but eventually broke down for a
> different user.  The shared memory is written to and verified by the writer
> process, but the computation process _never_ "sees" the flag even if allowed to
> run forever.  I can get the computation process to "see" the flag in several
> ways:
> 
> 1) Insert a sleep of between 1 and 10ms before the flag is polled (less than
> 1ms is not sufficient)
> 
> 2) Print the contents of the mailbox on the computation process side before
> polling the flag
> 
> Running under gdb or valgrind does not affect the bug.
> 
> Based on the above, my hypothesis is that in the cases where the condition
> improves, it is because a system call has been taken, and thus the registers
> clobbered.  In the case where the sleep is insufficient, I think it is because
> short sleep durations are executed as busy waits instead of forfeiting the
> processor.
> 
> However, as a matter of experimentation, I changed the memory access in the
> computation process from:
> 
> 	if (m_Mailbox[STALE_MBOX] != 1)
> 		{ /* these actions are never taken */ }
> 
> which generated the following assembly:
> 
> 	movl    8(%ebp), %eax   # this, this
> 	movl    32(%eax), %eax  # <variable>.m_Mail
> 	addl    $288, %eax      #, D.40882
> 	fldl    (%eax)  #* D.40882
> 	fld1
> 
> to: [with knowledge that sizeof(double)==2*sizeof(uint32_t)]
> 
> 	if (((uint32_t*)m_Mailbox)[STALE_MBOX*2] != 1)
> 		{ /* these actions are taken when mbox value is set to 0 */ }

Why all this casting ?

It'd be interresting to see what differences there were if you made
the flag a simple int, with the volatile keyword too.

(But really - you should be protecting this using semaphores)
Technical Details
Message-ID: <43f189d7$1@news.broadpark.no>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fdn.fr!freenix!sn-xt-sjc-04!sn-xt-sjc-06!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mail
References: <-Z-dneLPKKkNlWzeRVn-oQ@fidnet.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: fc89c,83404d35faeda18b
X-Google-Thread: f5392,83404d35faeda18b
X-Google-Thread: 11318c,83404d35faeda18b
X-Google-Thread: 114917,83404d35faeda18b
X-Google-Attributes: gidfc89c,gidf5392,gid11318c,gid114917,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fdn.fr!freenix!sn-xt-sjc-04!sn-xt-sjc-06!sn-post-01!supernews.com!corp.supernews.com!news.crayne.org!clax86!robomod!not-for-mail
From: "Nils O. Selåsdal"  <spamtrap@crayne.org>
Newsgroups: comp.unix.programmer,comp.os.linux.development.system,gnu.gcc.help,comp.lang.asm.x86
Subject: Re: SysV shared memory coherency issues
Approved: CLAX86 Moderators <ccrayne@crayne.org>
Date: Tue, 14 Feb 2006 08:42:14 +0100
Organization: Crayne Consulting
Message-ID: <43f189d7$1@news.broadpark.no>
Sender: clax86@wotan.crayne.org
References: <-Z-dneLPKKkNlWzeRVn-oQ@fidnet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-CLAX86-Policy: http://www.pacificsites.com/~ccrayne/clax86.html
X-CLAX86-Faq: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.asm.x86.html
X-CLAX86-Info-1: Send submissions to comp-lang-asm-x86@moderators.isc.org
X-CLAX86-Info-2: Send technical complaints to clax86-admin@crayne.org
X-CLAX86-Info-3: Send complaints about policy to clax86-admin@crayne.org
X-Comment: moderators do not necessarily agree or disagree with this article.
User-Agent: Thunderbird 1.5 (Windows/20051201)
X-Original-NNTP-Posting-Host: 2.80-203-154.nextgentel.com
X-OriginalArrivalTime: 14 Feb 2006 08:04:37.0656 (UTC) FILETIME=[4CB87180:01C6313D]
X-PacificInternet-MailScanner-Information: Please contact the ISP for more information
X-PacificInternet-MailScanner: Found to be clean
X-PacificInternet-MailScanner-SpamCheck: not spam (whitelisted),
 SpamAssassin (score=0, required 5.5, autolearn=disabled)
X-PacificInternet-MailScanner-From: nos@utel.no
X-Spam-Status: No
X-UIDL: $8#"!#p&#!$YT!!k_8!!
X-Complaints-To: abuse@supernews.com
Lines: 65