pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
To: Bruce Momjian <bruce@momjian.us>
To: Sergey E. Koposov <math@sai.msu.ru>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Noah Misch <noah@leadboat.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Re: [PATCH] Use CC atomic builtins if available [was: Re: TAS patch for building on armel/armhf thumb]
Date: Mon, 06 Feb 2012 12:24:32 +0100
Message-ID: <4F2FB870.3060104@enterprisedb.com> (raw)
In-Reply-To: <20120203014821.GA11939@momjian.us>
References: <4EEB1C77.1000309@enterprisedb.com>
	<20111218224203.GA2950@piware.de>
	<CA+TgmoZzgNrWT3af50YL3_zfSN8AtNXK9sOeACti=5ukwiR0vg@mail.gmail.com>
	<4EEF5397.8090200@enterprisedb.com>
	<20111219200341.GB9495@tornado.leadboat.com>
	<14852.1324325578@sss.pgh.pa.us>
	<4EEFABB2.5050100@enterprisedb.com>
	<20120203014821.GA11939@momjian.us>

On 03.02.2012 02:48, Bruce Momjian wrote:
> Sorry for the late reply, but Heikki, can you get this Itanium
> information into s_lock.h as a comment, particularly the information
> about the +Ovolatile=__unordered flag?

Good idea. I came up with the attached, hope that explains it.

Looking back at the discussions, we concluded that the current code is 
safe on gcc, because it implicitly adds the .rel/.acq opcodes to 
volatile accesses, and HP's compiler does the same as long as you don't 
explicitly disable it with +Ovolatile=__unordered. But what about 
Intel's icc compiler? Presumably it's also safe, but looking at Intel's 
manuals that I found, I'm not completely sure about it. There's an 
option, -m[no-]serialize-volatile, that controls it, but I couldn't 
figure out which is the default. Looking at the docs on that from Intel 
that I found [1], it seems to me that on Linux, the default is *not* 
safe, but on Windows it is.

Sergey, you have dugong in the buildfarm that uses Intel's compiler on 
Itanium. Could you verify whether the -mno-serialize-volatile is the 
default? If you could for example extract the assembler code generated 
by icc for xlog.c, and send it over. Whether it's generating the 
.rel/.acq opcodes should be easy to see in the generated code of the 
XLogGetLastRemoved() function, for example, which doesn't do much else 
than grab a spinlock. On gcc, the -s flag generates the assembly files, 
I presume it's the same on icc.

Perhaps we should set those compiler flags explicitly in configure, 
regardless of the defaults.

[1] 
http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/cpp/lin/compiler_c/copt...

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

Attachments:

document-itanium-volatile-behavior-1.patch (text/x-diff, 1.9K) download diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h index 074838e..d55b662 100644 --- a/src/include/storage/s_lock.h +++ b/src/include/storage/s_lock.h @@ -234,7 +234,22 @@ spin_delay(void) #endif /* __x86_64__ */ -#if defined(__ia64__) || defined(__ia64) /* Intel Itanium */ +#if defined(__ia64__) || defined(__ia64) +/* + * Intel Itanium, gcc or Intel's compiler. + * + * Itanium has weak memory ordering, but we rely on the compiler to enforce + * strict ordering of accesses to volatile data. In particular, while the + * xchg instruction implicitly acts as a memory barrier with 'acquire' + * semantics, we do not have an explicit memory fence instruction in the + * S_UNLOCK macro. We use a regular assignment to clear the spinlock, and + * trust that the compiler marks the generated store instruction with the + * ".rel" opcode. + * + * Testing shows that assumption holds on gcc, although I could not find any + * official statement on that in the gcc manual. In Intel's compiler, the + * -m[no-]serialize-volatile option controls that. Keep it enabled! + */ #define HAS_TEST_AND_SET typedef unsigned int slock_t; @@ -785,7 +800,19 @@ tas(volatile slock_t *lock) #if defined(__hpux) && defined(__ia64) && !defined(__GNUC__) - +/* + * HP-UX on Itanium, non-gcc compiler + * + * We assume that the compiler enforces strict ordering of loads/stores on + * volatile data (see comments on the gcc-version earlier in this file). + * Note that this assumption does *not* hold if you use the + * +Ovolatile=__unordered option on the HP-UX compiler, so don't do that. + * + * See also Implementing Spinlocks on the Intel Itanium Architecture and + * PA-RISC, by Tor Ekqvist and David Graves, for more information. As of + * this writing, version 1.0 of the manual is available at: + * http://h21007.www2.hp.com/portal/download/files/unprot/itanium/spinlocks.pdf + */ #define HAS_TEST_AND_SET typedef unsigned int slock_t;

view thread (17+ messages)  latest in thread

Message-ID: <4F2FB870.3060104@enterprisedb.com>
Permalink:  ../4F2FB870.3060104@enterprisedb.com/
Also on:    postgresql.org/message-id/4F2FB870.3060104@enterprisedb.com

 ·  · 

reply

Reply instructions:

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

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: heikki.linnakangas@enterprisedb.com, bruce@momjian.us, math@sai.msu.ru, tgl@sss.pgh.pa.us, noah@leadboat.com, robertmhaas@gmail.com
  Subject: Re: [PATCH] Use CC atomic builtins if available [was: Re: TAS patch for building on armel/armhf thumb]
  In-Reply-To: <4F2FB870.3060104@enterprisedb.com>
  References: <4EEB1C77.1000309@enterprisedb.com> <20111218224203.GA2950@piware.de> <CA+TgmoZzgNrWT3af50YL3_zfSN8AtNXK9sOeACti=5ukwiR0vg@mail.gmail.com> <4EEF5397.8090200@enterprisedb.com> <20111219200341.GB9495@tornado.leadboat.com> <14852.1324325578@sss.pgh.pa.us> <4EEFABB2.5050100@enterprisedb.com> <20120203014821.GA11939@momjian.us> <4F2FB870.3060104@enterprisedb.com>

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

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox