Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZRk0-0008RB-Lj for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Feb 2017 00:28:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cZRk0-0006H7-76 for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Feb 2017 00:28:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cZRib-0004iV-8O for pgsql-hackers@postgresql.org; Fri, 03 Feb 2017 00:27:13 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cZRiY-0006yJ-0V for pgsql-hackers@postgresql.org; Fri, 03 Feb 2017 00:27:11 +0000 Received: by mail-pg0-x243.google.com with SMTP id v184so360891pgv.1 for ; Thu, 02 Feb 2017 16:27:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ysO6sdMaEs5AMp3WutPRkkpPxcXzN99zXmAWZdxDoOc=; b=fDAYgcyxG1FWAUJWfIh9/+OYMMZKjz4PrLA2NoayHmVxRjlcspX/nkOD5Po9LbMIpK LiCsCyD+qyu1MwxmW6BYiPbjbDKP6m9rhyH32G5IWCjgY+dJZPOirPME6MJxRB9vybEo y7yN+VuDNvb+JQoHTqxKnpHW7ds1xJmYURC/U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ysO6sdMaEs5AMp3WutPRkkpPxcXzN99zXmAWZdxDoOc=; b=AR0C0EX47x7r8sm7+VmxagICzAj8AOTs/EVIoT2TloOePDAGXXsh9ois1K6yyHcQrr XGiRO48srwYR4iPHwmgOvZ9auO51XBr2Cda0DxlhwlvRI07mz9q0j2RyRdMhQq9BpH0B 1Jq0VA3UwNOwyU1HyE2dDDAqKvkU75zYtrodvXY57SipXFFpt4SzG70ZqPP2QwMXBNSB HicDLY2l3mScUHYn+grENraDFT2BLy1Vfu73NCOmkUXHi7tVLid7VYbRQuwHcsuJ08rl imN2CbvmaCqo6pcPg+qoXzPpNEYvo65T4LoKYNM8yxVSue38kaXSLi+p6/VU2+KFgnLt jyyw== X-Gm-Message-State: AIkVDXJq34HvnsXqSp75BAcR7wNxl+USw6RCQD+ZCjgQ63R+JOYAysCT7fBP2W9OTuLh6Q== X-Received: by 10.98.21.131 with SMTP id 125mr14267701pfv.110.1486081628261; Thu, 02 Feb 2017 16:27:08 -0800 (PST) Received: from tornado.leadboat.com (c-98-248-47-228.hsd1.ca.comcast.net. [98.248.47.228]) by smtp.gmail.com with ESMTPSA id o1sm48920853pgf.25.2017.02.02.16.27.05 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 02 Feb 2017 16:27:06 -0800 (PST) Date: Fri, 3 Feb 2017 00:26:50 +0000 From: Noah Misch To: Heikki Linnakangas Cc: Konstantin Knizhnik , PostgreSQL Hackers , Bernd Helmle Subject: Re: Deadlock in XLogInsert at AIX Message-ID: <20170203002650.GA775605@tornado.leadboat.com> References: <0184657d-cf64-10f6-9706-7329f23f5f89@iki.fi> <85a1966c-aeee-fb38-77bd-6cad9a90b35f@postgrespro.ru> <2c4037f1-b35d-4d71-0d32-40a97523b31c@postgrespro.ru> <5de6b64a-f842-9166-e41a-ed7b87a2729b@iki.fi> <7609057e-b021-56d8-afb6-27acc1dfdeea@postgrespro.ru> <15802dd8-4601-d9d2-3388-35dcb326b4a2@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <15802dd8-4601-d9d2-3388-35dcb326b4a2@iki.fi> User-Agent: Mutt/1.5.24 (2015-08-30) X-Pg-Spam-Score: -2.0 (--) 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 Wed, Feb 01, 2017 at 02:39:25PM +0200, Heikki Linnakangas wrote: > On 02/01/2017 01:07 PM, Konstantin Knizhnik wrote: > >Attached please find my patch for XLC/AIX. > >The most critical fix is adding __sync to pg_atomic_fetch_add_u32_impl. > >The comment in this file says that: > > > > * __fetch_and_add() emits a leading "sync" and trailing "isync", > >thereby > > * providing sequential consistency. This is undocumented. > > > >But it is not true any more (I checked generated assembler code in > >debugger). > >This is why I have added __sync() to this function. Now pgbench working > >normally. Konstantin, does "make -C src/bin/pg_bench check" fail >10% of the time in the bad build? > Seems like it was not so much undocumented, but an implementation detail > that was not guaranteed after all.. Seems so. > There was a long thread on these things the last time this was changed: https://www.postgresql.org/message-id/20160425185204.jrvlghn3jxulsb7i%40alap3.anarazel.de. > I couldn't find an explanation there of why we thought that fetch_and_add > implicitly performs sync and isync. It was in the generated code, for AIX xlc 12.1.0.0. > >Also there is mysterious disappearance of assembler section function > >with sync instruction from pg_atomic_compare_exchange_u32_impl. > >I have fixed it by using __sync() built-in function instead. > > __sync() seems more appropriate there, anyway. We're using intrinsics for > all the other things in generic-xlc.h. But it sure is scary that the "asm" > sections just disappeared. That is a problem, but it's a stretch to conclude that asm sections are generally prone to removal, while intrinsics are generally durable. > @@ -73,11 +73,19 @@ pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, > static inline uint32 > pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_) > { > + uint32 ret; > + > /* > - * __fetch_and_add() emits a leading "sync" and trailing "isync", thereby > - * providing sequential consistency. This is undocumented. > + * Use __sync() before and __isync() after, like in compare-exchange > + * above. > */ > - return __fetch_and_add((volatile int *)&ptr->value, add_); > + __sync(); > + > + ret = __fetch_and_add((volatile int *)&ptr->value, add_); > + > + __isync(); > + > + return ret; > } Since this emits double syncs with older xlc, I recommend instead replacing the whole thing with inline asm. As I opined in the last message of the thread you linked above, the intrinsics provide little value as abstractions if one checks the generated code to deduce how to use them. Now that the generated code is xlc-version-dependent, the port is better off with compiler-independent asm like we have for ppc in s_lock.h. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers