Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X1vUv-0000ed-W0 for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Jul 2014 10:41:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X1vUu-0006Q4-LZ for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Jul 2014 10:41:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X1vUt-0006Pt-GQ for pgsql-hackers@postgresql.org; Tue, 01 Jul 2014 10:41:11 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X1vUl-0000PV-O3 for pgsql-hackers@postgresql.org; Tue, 01 Jul 2014 10:41:10 +0000 Received: by mail.anarazel.de (Postfix, from userid 108) id 33D4C500001; Tue, 1 Jul 2014 12:41:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail X-Spam-Level: X-Spam-Status: No, score=-5.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from anarazel.de (p54AF441C.dip0.t-ipconnect.de [84.175.68.28]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id B90924F0001; Tue, 1 Jul 2014 12:40:58 +0200 (CEST) Received: by anarazel.de (Postfix, from userid 1000) id 413B9100054; Tue, 1 Jul 2014 12:40:58 +0200 (CEST) Date: Tue, 1 Jul 2014 12:40:58 +0200 From: Andres Freund To: Amit Kapila Cc: Robert Haas , Tom Lane , Peter Geoghegan , Pg Hackers , Ants Aasma Subject: Re: better atomics - v0.5 Message-ID: <20140701104058.GZ26930@awork2.anarazel.de> References: <20140625171434.GG24114@awork2.anarazel.de> <20140628081818.GA6450@awork2.anarazel.de> <20140629092421.GH6450@awork2.anarazel.de> <20140630092401.GJ21422@awork2.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2014-07-01 10:44:19 +0530, Amit Kapila wrote: > I think for such usage, we need to rely on barriers wherever there is a > need for synchronisation, recent example I have noticed is in your patch > where we have to use pg_write_barrier() during wakeup. However if we > go by atomic ops definition, then no such dependency is required, like > if somewhere we need to use pg_atomic_compare_exchange_u32(), > after that we don't need to ensure about barriers, because this atomic > API adheres to Full barrier semantics. > I think defining barrier support for some atomic ops and not for others > will lead to inconsistency with specs and we need to additionally > define rules for such atomic ops usage. Meh. It's quite common that read/load do not have barrier semantics. The majority of read/write users won't need barriers and it'll be expensive to provide them with them. > > > > > > b) It's only supported from vista onwards. Afaik we still support > XP. > > > > Well, with barrier.h as it stands they'd get a compiler error if it > > indeed is unsupported? But I think there's something else going on - > > msft might just be removing XP from it's documentation. > > Okay, but why would they remove for MemoryBarrier() and not > for InterlockedCompareExchange(). I think it is bit difficult to predict > the reason and if we want to use anything which is not as msft docs, > we shall do that carefully and have some way to ensure that it will > work fine. Well, we have quite good evidence for it working by knowing that postgres has in the past worked on xp? If you have a better idea, send in a patch for today's barrier.h and I'll adopt that. > > > In this case, I have a question for you. > > > > > > Un-patched usage in barrier.h is as follows: > > > .. > > > > > > If I understand correctly the current define mechanism in barrier.h, > > > it will have different definition for Itanium processors even for windows. > > > > Either noone has ever tested postgres on itanium windows (quite > > possible), because afaik _Asm_sched_fence() doesn't work on > > windows/msvc, or windows doesn't define __ia64__/__ia64. Those macros > > arefor HP's acc on HPUX. > > Hmm.. Do you think in such a case, it would have gone in below > define: > #elif defined(__INTEL_COMPILER) > /* > * icc defines __GNUC__, but doesn't support gcc's inline asm syntax > */ > #if defined(__ia64__) || defined(__ia64) > #define pg_memory_barrier() __mf() > #elif defined(__i386__) || defined(__x86_64__) > #define pg_memory_barrier() _mm_mfence() > #endif Hm? Since _Asm_sched_fence isn't for the intel compiler but for HP's acc, I don't see why? But they should go into atomics-generic-acc.h. > -#define pg_compiler_barrier() __memory_barrier() > > Currently this will be considered as compiler barrier for > __INTEL_COMPILER, but after patch, I don't see this define. I think > after patch, it will be compiler_impl specific, but why such a change? #if defined(__INTEL_COMPILER) #define pg_compiler_barrier_impl() __memory_barrier() #else #define pg_compiler_barrier_impl() __asm__ __volatile__("" ::: "memory") #endif There earlier was a typo defining pg_compiler_barrier instead of pg_compiler_barrier_impl for intel, maybe that's what you were referring to? Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers