Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1helKd-0002E6-QD for pgsql-bugs@arkaria.postgresql.org; Sat, 22 Jun 2019 19:05:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1helKb-00037a-0O for pgsql-bugs@arkaria.postgresql.org; Sat, 22 Jun 2019 19:05:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1helKa-00037T-LZ for pgsql-bugs@lists.postgresql.org; Sat, 22 Jun 2019 19:05:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1helKW-0006LB-Ir for pgsql-bugs@lists.postgresql.org; Sat, 22 Jun 2019 19:05:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x5MJ5Woa019683; Sat, 22 Jun 2019 15:05:32 -0400 From: Tom Lane To: YunQiang Su cc: Andres Freund , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15844: MIPS: remove .set mips2 in s_lock.h to fix r6 build In-reply-to: References: <15844-8f62fe7e163939b3@postgresql.org> <15052.1560455595@sss.pgh.pa.us> <23287.1560655935@sss.pgh.pa.us> <25321.1560659282@sss.pgh.pa.us> <22615.1560701813@sss.pgh.pa.us> <20190617163207.kgi5m4v2g2m252t5@alap3.anarazel.de> <8749.1560790222@sss.pgh.pa.us> Comments: In-reply-to YunQiang Su message dated "Sat, 22 Jun 2019 12:21:09 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19681.1561230332.1@sss.pgh.pa.us> Date: Sat, 22 Jun 2019 15:05:32 -0400 Message-ID: <19682.1561230332@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk YunQiang Su writes: > Since NetBSD set the default ISA as MIPS I, and then we use ".set mips2", > in fact a bug. > I think that we should use some non-asm code for MIPS I ( our own > spinlock implementations?) You probably won't be surprised to hear that we keep having this discussion ;-). Sure, we could essentially throw away all of s_lock.h in favor of relying on __sync_lock_test_and_set() and __sync_lock_release(). But doing that would essentially abdicate having control over, or even having much knowledge about, infrastructure that's absolutely critical to the correctness and performance of Postgres. And we've seen a bunch of cases where the compiler builtins are just not very well implemented for non-mainstream architectures. I got debian-mips-under-qemu working thanks to the files you sent a link to, and I was curious to see what that gcc version would generate for __sync_lock_test_and_set() and __sync_lock_release(), if I asked for MIPS-I code. That's not the default of course, but "gcc -march=mips1 -mabi=32" seems to work. And what I get is .set push .set mips2 1: ll $2,0($3) li $1,1 sc $1,0($3) beq $1,$0,1b nop sync .set pop and .set push .set mips2 sync .set pop sw $0,0($3) So the gcc guys aren't any more wedded than we are to the rule that one must not generate LL/SC on MIPS-I. They're probably assuming the same thing we are, which is that if you're actually doing this on MIPS-I then you'll get an instruction trap and the kernel will emulate it for you. Any other choice would be completely disastrous for performance on anything newer than MIPS-I ... and really, if you are doing something that requires userland synchronization primitives, you'd better not be using MIPS-I. It hasn't got them. In short, moving to __sync_lock_test_and_set() would change basically nothing on MIPS, but we'd no longer have any visibility into or control over what it was doing. It would open us to other problems too -- for example, if you try to apply __sync_lock_test_and_set() to a char rather than an int, the code you get for that on MIPS is a whole lot worse, but we'd have no visibility of that. > Do you have any NetBSD image that I can have a test of new patch? I've not been able to get NetBSD/MIPS to work under qemu. It does mostly work under gxemul, but that has so many bugs as to be nigh useless --- the float arithmetic emulation is what usually gets me when I try to do anything with Postgres. regards, tom lane