Re: Let's make PostgreSQL multi-threaded

From: Andres Freund <andres(at)anarazel(dot)de>
To: Konstantin Knizhnik <knizhnik(at)garret(dot)ru>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Let's make PostgreSQL multi-threaded
Date: 2023-06-08 16:59:58
Message-ID: 20230608165958.dbmoiwqupqrmqeng@awork3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2023-06-08 16:47:48 +0300, Konstantin Knizhnik wrote:
> Actually TLS not not more expensive then accessing struct fields (at least
> at x86 platform), consider the following program:

It really depends on the OS and the architecture, not just the
architecture. And even on x86-64 Linux, the fact that you're using the segment
offset in the address calculation means you can't use the more complicated
addressing modes for other reasons. And plenty instructions, e.g. most (?) SSE
instructions, won't be able to use that kind of addressing directly.

Even just compiling your, example you can see that with gcc -O2 you get
considerably faster code with the non-TLS version.

As a fairly extreme example, here's the mingw -O3 compiled code:

use_struct:
movq xmm1, QWORD PTR .LC0[rip]
movq xmm0, QWORD PTR [rcx]
add DWORD PTR 8[rcx], 1
paddd xmm0, xmm1
movq QWORD PTR [rcx], xmm0
ret
use_tls:
sub rsp, 40
lea rcx, __emutls_v.a[rip]
call __emutls_get_address
lea rcx, __emutls_v.b[rip]
add DWORD PTR [rax], 1
call __emutls_get_address
lea rcx, __emutls_v.c[rip]
add DWORD PTR [rax], 1
call __emutls_get_address
add DWORD PTR [rax], 1
add rsp, 40
ret

Greetings,

Andres Freund

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ilya Anfimov 2023-06-08 17:02:46 Re: Let's make PostgreSQL multi-threaded
Previous Message Tom Lane 2023-06-08 16:58:08 Re: Making Vars outer-join aware