Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Clothes make the man. Naked people have little or no influence on society. -- Mark Twain


devel / comp.lang.c++ / alignas c++20...

SubjectAuthor
* alignas c++20...Chris M. Thomasson
+- Re: alignas c++20...Chris M. Thomasson
+- Re: alignas c++20...Chris M. Thomasson
`* Re: alignas c++20...Pavel
 `* Re: alignas c++20...Chris M. Thomasson
  `* Re: alignas c++20...Pavel
   `* Re: alignas c++20...Chris M. Thomasson
    `* Re: alignas c++20...Pavel
     `- Re: alignas c++20...Chris M. Thomasson

1
alignas c++20...

<u391ei$3gmnh$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=36&group=comp.lang.c%2B%2B#36

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: alignas c++20...
Date: Sun, 7 May 2023 13:24:49 -0700
Organization: A noiseless patient Spider
Lines: 143
Message-ID: <u391ei$3gmnh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 7 May 2023 20:24:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="541ef8fd2f6ba13a9c694402e0002b42";
logging-data="3693297"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cpiQjQQERY4brVNelJHQbkh5h0OAePKQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.10.1
Cancel-Lock: sha1:qzIMaQFLc2ouTtLaMqi9l4W83AY=
Content-Language: en-US
 by: Chris M. Thomasson - Sun, 7 May 2023 20:24 UTC

I can get this working with C++20, can anybody else? Over allocating and
aligning on a page size:
_________________________
#include <iostream>
#include <atomic>
#include <cstdint>
#include <cstdlib>

static constexpr std::size_t ct_page_size = 8192;
static constexpr std::size_t ct_l2_cacheline_size = 64;

struct alignas(ct_l2_cacheline_size) ct_cacheline
{ std::atomic<std::uint64_t> m_state;
};

struct alignas(ct_page_size) ct_page
{ ct_cacheline m_line_0;
ct_cacheline m_line_1;
};

int main()
{ if (sizeof(ct_cacheline) != ct_l2_cacheline_size)
{
std::cout << "Crap! ct_cacheline is not padded!\n";
}

if (sizeof(ct_page) != ct_page_size)
{
std::cout << "Crap! ct_page is not padded!\n";
}

ct_page* page = new ct_page;

std::cout << "page = " << page << "\n";

if ((std::uintptr_t)(page) % ct_page_size)
{
std::cout << "Crap! page is not aligned!\n";
}

if ((std::uintptr_t)(&page->m_line_1) % ct_l2_cacheline_size)
{
std::cout << "Crap! page->m_line_1 is not aligned!\n";
}

delete page;

return 0;
} _________________________

I get:

page = 0000017135410000

as an output. I get no crap output, so to speak... ;^)

Also, this is working fine in C++20 on msvc.
_________________________
#include <iostream>
#include <atomic>
#include <cstdint>
#include <cstdlib>
#include <vector>

static constexpr std::size_t ct_pages_n = 3;
static constexpr std::size_t ct_page_size = 8192;
static constexpr std::size_t ct_l2_cacheline_size = 64;

template<typename T>
static inline bool
ct_assert_align(T const* ptr, std::size_t alignment)
{ return !((std::uintptr_t)(ptr) % alignment);
}

struct alignas(ct_l2_cacheline_size) ct_cacheline
{ std::atomic<std::uint64_t> m_state;
};

struct alignas(ct_page_size) ct_page
{ ct_cacheline m_line_0;
ct_cacheline m_line_1;
ct_cacheline m_line_2;
ct_cacheline m_line_3;
};

static_assert(sizeof(ct_page) == ct_page_size);
static_assert(sizeof(ct_cacheline) == ct_l2_cacheline_size);

static void
ct_page_iter(
std::vector<ct_page> const& pages,
std::size_t n
) {
for (std::size_t i = 0; i < n; ++i)
{
ct_page const& page = pages[i];

if (!ct_assert_align(&page.m_line_2, ct_l2_cacheline_size))
{
std::cout << "Crap!\n";
}
}
}

int main()
{ std::vector<ct_page> page(ct_pages_n);

// validate first element wrt page alignment
if (! ct_assert_align(&page[0], ct_page_size))
{
std::cout << "Big Time Crap!\n";
}

// validate cache lines
ct_page_iter(page, page.size());

return 0;
} _________________________

Get any crap? It works for me. Over allocating and aligning is very
useful... It seems as if C++20 is working fine on MSVC.

Re: alignas c++20...

<u39f9o$3jfqg$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=37&group=comp.lang.c%2B%2B#37

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: alignas c++20...
Date: Sun, 7 May 2023 17:21:11 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <u39f9o$3jfqg$1@dont-email.me>
References: <u391ei$3gmnh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 8 May 2023 00:21:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d2c7a55820c79dd175750f71e6ffdaa7";
logging-data="3784528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+96jhv58U5EXU1Ws/IfMMjWPOLW2IiuxE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.10.1
Cancel-Lock: sha1:HbY3scrr0X4Coek22vAkjAYj/XA=
Content-Language: en-US
In-Reply-To: <u391ei$3gmnh$1@dont-email.me>
 by: Chris M. Thomasson - Mon, 8 May 2023 00:21 UTC

On 5/7/2023 1:24 PM, Chris M. Thomasson wrote:
> I can get this working with C++20, can anybody else? Over allocating and
> aligning on a page size:
[...
>
> Get any crap? It works for me. Over allocating and aligning is very
> useful... It seems as if C++20 is working fine on MSVC.

MSVC c++20 works and aligns on page boundary and cache line boundaries:

https://i.ibb.co/93XFNh0/image.png

No crap output... ;^)

Re: alignas c++20...

<u39fhd$3jfqg$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=38&group=comp.lang.c%2B%2B#38

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: alignas c++20...
Date: Sun, 7 May 2023 17:25:16 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <u39fhd$3jfqg$2@dont-email.me>
References: <u391ei$3gmnh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 8 May 2023 00:25:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d2c7a55820c79dd175750f71e6ffdaa7";
logging-data="3784528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bAJeaZLRkcPtgw2dfCdP/tA34nnpheUA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.10.1
Cancel-Lock: sha1:nSl+ELvbVW9vtMB+fMRcDBsIuu8=
In-Reply-To: <u391ei$3gmnh$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 8 May 2023 00:25 UTC

On 5/7/2023 1:24 PM, Chris M. Thomasson wrote:
> I can get this working with C++20, can anybody else? Over allocating and
> aligning on a page size:
> _________________________
[...]
> Get any crap? It works for me. Over allocating and aligning is very
> useful... It seems as if C++20 is working fine on MSVC.

It's working with MSVC fine, however I don't think GCC is going to like
it very much. The alignments might be off...

I can do all of this manually, but I thought alignas would work fine
with new and std::vectors.

Re: alignas c++20...

<ZGd8M.590313$Lfzc.111793@fx36.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=130&group=comp.lang.c%2B%2B#130

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx36.iad.POSTED!not-for-mail
Subject: Re: alignas c++20...
Newsgroups: comp.lang.c++
References: <u391ei$3gmnh$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.15
MIME-Version: 1.0
In-Reply-To: <u391ei$3gmnh$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 28
Message-ID: <ZGd8M.590313$Lfzc.111793@fx36.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sun, 14 May 2023 22:56:57 UTC
Date: Sun, 14 May 2023 18:56:48 -0400
X-Received-Bytes: 1242
 by: Pavel - Sun, 14 May 2023 22:56 UTC

Chris M. Thomasson wrote:
> I can get this working with C++20, can anybody else? Over allocating and
> aligning on a page size:
> _________________________
[snipped]
> _________________________
>
> I get:
>
> page = 0000017135410000
>
> as an output. I get no crap output, so to speak... ;^)
>
[snipped]
Seems to work for me as well

g++ (GCC) 13.1.1 20230429

$ ./a.out
page = 0x55f3f83da000
$

g++ (GCC) 13.1.1 20230429 on x86_64 GNU/Linux

-Pavel

Re: alignas c++20...

<u3u9iu$35r66$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=133&group=comp.lang.c%2B%2B#133

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: alignas c++20...
Date: Mon, 15 May 2023 14:52:31 -0700
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <u3u9iu$35r66$1@dont-email.me>
References: <u391ei$3gmnh$1@dont-email.me> <ZGd8M.590313$Lfzc.111793@fx36.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 15 May 2023 21:52:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="50aa990ff73dd94820d5cadef6ff223d";
logging-data="3337414"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Oi9oua0MBgUl4MRNYQTdZsBE67s6L7Og="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:CpTlXnGmlF4fkYGfK4m9TN2tisc=
In-Reply-To: <ZGd8M.590313$Lfzc.111793@fx36.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 15 May 2023 21:52 UTC

On 5/14/2023 3:56 PM, Pavel wrote:
> Chris M. Thomasson wrote:
>> I can get this working with C++20, can anybody else? Over allocating
>> and aligning on a page size:
>> _________________________
> [snipped]
>> _________________________
>>
>> I get:
>>
>> page = 0000017135410000
>>
>> as an output. I get no crap output, so to speak... ;^)
>>
> [snipped]
> Seems to work for me as well
>
> g++ (GCC) 13.1.1 20230429
>
> $ ./a.out
> page = 0x55f3f83da000
> $
>
> g++ (GCC) 13.1.1 20230429 on x86_64 GNU/Linux

Nice! I do not have that version installed. How does it respond to the
program that uses a std::vector? MSVC likes it and everything is padded
and aligned. Iirc, std::vector should honor alignas, right?

Re: alignas c++20...

<lmC8M.2869946$iU59.885057@fx14.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=134&group=comp.lang.c%2B%2B#134

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
Subject: Re: alignas c++20...
Newsgroups: comp.lang.c++
References: <u391ei$3gmnh$1@dont-email.me> <ZGd8M.590313$Lfzc.111793@fx36.iad>
<u3u9iu$35r66$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.15
MIME-Version: 1.0
In-Reply-To: <u3u9iu$35r66$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 46
Message-ID: <lmC8M.2869946$iU59.885057@fx14.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Tue, 16 May 2023 03:01:37 UTC
Date: Mon, 15 May 2023 23:01:19 -0400
X-Received-Bytes: 2166
 by: Pavel - Tue, 16 May 2023 03:01 UTC

Chris M. Thomasson wrote:
> On 5/14/2023 3:56 PM, Pavel wrote:
>> Chris M. Thomasson wrote:
>>> I can get this working with C++20, can anybody else? Over allocating
>>> and aligning on a page size:
>>> _________________________
>> [snipped]
>>> _________________________
>>>
>>> I get:
>>>
>>> page = 0000017135410000
>>>
>>> as an output. I get no crap output, so to speak... ;^)
>>>
>> [snipped]
>> Seems to work for me as well
>>
>> g++ (GCC) 13.1.1 20230429
>>
>> $ ./a.out
>> page = 0x55f3f83da000
>> $
>>
>> g++ (GCC) 13.1.1 20230429 on x86_64 GNU/Linux
>
> Nice! I do not have that version installed. How does it respond to the
> program that uses a std::vector?
The vector prog's output is empty, so everything is good.

> MSVC likes it and everything is padded
> and aligned. Iirc, std::vector should honor alignas, right?
>
I don's think it is the vector specifically that honors alignas; I
rather think the data structure of type ct_page, whether allocated by
vector or in any other legal way, can get aligned accordingly to its
alignment specifier (on my system, it's implementation specific as
alignof(std::max_align_t) is 16 so the alignments of 64 are "extended"
-- but happen to be supported.

On a side note, see if your code benefits from using
std::hardware_constructive_interference_size instead of hardcoded 64 for
the cacheline_size.

HTH
-Pavel

Re: alignas c++20...

<u4113s$3jv7m$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=140&group=comp.lang.c%2B%2B#140

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: alignas c++20...
Date: Tue, 16 May 2023 15:46:21 -0700
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <u4113s$3jv7m$2@dont-email.me>
References: <u391ei$3gmnh$1@dont-email.me> <ZGd8M.590313$Lfzc.111793@fx36.iad>
<u3u9iu$35r66$1@dont-email.me> <lmC8M.2869946$iU59.885057@fx14.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 16 May 2023 22:46:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="61fa68a2837ac948d6a11e1f97d70f68";
logging-data="3800310"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+h93XTziXhYlfmPBB3FI/HDUx4ndUKWrM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:FKvbhN1Su15wMJFX/4xfhrCQbMI=
Content-Language: en-US
In-Reply-To: <lmC8M.2869946$iU59.885057@fx14.iad>
 by: Chris M. Thomasson - Tue, 16 May 2023 22:46 UTC

On 5/15/2023 8:01 PM, Pavel wrote:
> Chris M. Thomasson wrote:
>> On 5/14/2023 3:56 PM, Pavel wrote:
>>> Chris M. Thomasson wrote:
>>>> I can get this working with C++20, can anybody else? Over allocating
>>>> and aligning on a page size:
>>>> _________________________
>>> [snipped]
>>>> _________________________
>>>>
>>>> I get:
>>>>
>>>> page = 0000017135410000
>>>>
>>>> as an output. I get no crap output, so to speak... ;^)
>>>>
>>> [snipped]
>>> Seems to work for me as well
>>>
>>> g++ (GCC) 13.1.1 20230429
>>>
>>> $ ./a.out
>>> page = 0x55f3f83da000
>>> $
>>>
>>> g++ (GCC) 13.1.1 20230429 on x86_64 GNU/Linux
>>
>> Nice! I do not have that version installed. How does it respond to the
>> program that uses a std::vector?
> The vector prog's output is empty, so everything is good.

Excellent. Thanks for taking the time to give it a go, Pavel. I really
need to install a recent GCC. Stuck on MSVC right now for a project.

>> MSVC likes it and everything is padded and aligned. Iirc, std::vector
>> should honor alignas, right?
>>
> I don's think it is the vector specifically that honors alignas; I
> rather think the data structure of type ct_page, whether allocated by
> vector or in any other legal way, can get aligned accordingly to its
> alignment specifier (on my system, it's implementation specific as
> alignof(std::max_align_t) is 16 so the alignments of 64 are "extended"
> -- but happen to be supported.

Remember those early hyperthreaded Pentium's? There was something called
the aliasing problem that would make two hyperthreaded threads falsely
share cache lines and would destroy performance? Iirc, the l2 cache
lines were 128 bytes split into two 64 byte regions. The workaround was
to offset the stacks of each thread using alloca.

> On a side note, see if your code benefits from using
> std::hardware_constructive_interference_size instead of hardcoded 64 for
> the cacheline_size.

It will definitely benefit. I am wondering if
std::hardware_constructive_interference_size is always guaranteed to be
the l2 cache line size?

Re: alignas c++20...

<idW8M.613646$5S78.524671@fx48.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=141&group=comp.lang.c%2B%2B#141

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.neodome.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
Subject: Re: alignas c++20...
Newsgroups: comp.lang.c++
References: <u391ei$3gmnh$1@dont-email.me> <ZGd8M.590313$Lfzc.111793@fx36.iad>
<u3u9iu$35r66$1@dont-email.me> <lmC8M.2869946$iU59.885057@fx14.iad>
<u4113s$3jv7m$2@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.15
MIME-Version: 1.0
In-Reply-To: <u4113s$3jv7m$2@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 102
Message-ID: <idW8M.613646$5S78.524671@fx48.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Wed, 17 May 2023 01:37:18 UTC
Date: Tue, 16 May 2023 21:37:08 -0400
X-Received-Bytes: 5083
 by: Pavel - Wed, 17 May 2023 01:37 UTC

Chris M. Thomasson wrote:
> On 5/15/2023 8:01 PM, Pavel wrote:
>> Chris M. Thomasson wrote:
>>> On 5/14/2023 3:56 PM, Pavel wrote:
>>>> Chris M. Thomasson wrote:
>>>>> I can get this working with C++20, can anybody else? Over
>>>>> allocating and aligning on a page size:
>>>>> _________________________
>>>> [snipped]
>>>>> _________________________
>>>>>
>>>>> I get:
>>>>>
>>>>> page = 0000017135410000
>>>>>
>>>>> as an output. I get no crap output, so to speak... ;^)
>>>>>
>>>> [snipped]
>>>> Seems to work for me as well
>>>>
>>>> g++ (GCC) 13.1.1 20230429
>>>>
>>>> $ ./a.out
>>>> page = 0x55f3f83da000
>>>> $
>>>>
>>>> g++ (GCC) 13.1.1 20230429 on x86_64 GNU/Linux
>>>
>>> Nice! I do not have that version installed. How does it respond to
>>> the program that uses a std::vector?
>> The vector prog's output is empty, so everything is good.
>
> Excellent. Thanks for taking the time to give it a go, Pavel. I really
> need to install a recent GCC. Stuck on MSVC right now for a project.
>
np, my pleasure.
>
>>> MSVC likes it and everything is padded and aligned. Iirc, std::vector
>>> should honor alignas, right?
>>>
>> I don's think it is the vector specifically that honors alignas; I
>> rather think the data structure of type ct_page, whether allocated by
>> vector or in any other legal way, can get aligned accordingly to its
>> alignment specifier (on my system, it's implementation specific as
>> alignof(std::max_align_t) is 16 so the alignments of 64 are "extended"
>> -- but happen to be supported.
>
> Remember those early hyperthreaded Pentium's? There was something called
> the aliasing problem that would make two hyperthreaded threads falsely
> share cache lines and would destroy performance? Iirc, the l2 cache
> lines were 128 bytes split into two 64 byte regions. The workaround was
> to offset the stacks of each thread using alloca.
I remember there was a problem with them simulated threads not having
cache of their own (don't recall whether it was L2 or L1) but don't
remember what exactly. The advice I remember was to not use
hyperthreading mode :-).

>
>
>> On a side note, see if your code benefits from using
>> std::hardware_constructive_interference_size instead of hardcoded 64
>> for the cacheline_size.
>
> It will definitely benefit. I am wondering if
> std::hardware_constructive_interference_size is always guaranteed to be
> the l2 cache line size?
Not in general, the Holy Standard definition is expectedly L-agnostic :-).

Gcc in particular implements both as L1 cache line size (at least for
architectures I care of):

Quote:
‘destructive-interference-size’
‘constructive-interference-size’
The values for the C++17 variables
‘std::hardware_destructive_interference_size’ and
‘std::hardware_constructive_interference_size’. The
destructive interference size is the minimum recommended
offset between two independent concurrently-accessed objects;
the constructive interference size is the maximum recommended
size of contiguous memory accessed together. Typically both
will be the size of an L1 cache line for the target, in bytes.
For a generic target covering a range of L1 cache line sizes,
typically the constructive interference size will be the small
end of the range and the destructive size will be the large
end.

The destructive interference size is intended to be used for
layout, and thus has ABI impact. The default value is not
expected to be stable, and on some targets varies with
‘-mtune’, so use of this variable in a context where ABI
stability is important, such as the public interface of a
library, is strongly discouraged; if it is used in that
context, users can stabilize the value using this option.

The constructive interference size is less sensitive, as it is
typically only used in a ‘static_assert’ to make sure that a
type fits within a cache line.
End-of-quote

HTH
-Pavel

Re: alignas c++20...

<u43usu$1e62$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=156&group=comp.lang.c%2B%2B#156

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: alignas c++20...
Date: Wed, 17 May 2023 18:26:55 -0700
Organization: A noiseless patient Spider
Lines: 117
Message-ID: <u43usu$1e62$1@dont-email.me>
References: <u391ei$3gmnh$1@dont-email.me> <ZGd8M.590313$Lfzc.111793@fx36.iad>
<u3u9iu$35r66$1@dont-email.me> <lmC8M.2869946$iU59.885057@fx14.iad>
<u4113s$3jv7m$2@dont-email.me> <idW8M.613646$5S78.524671@fx48.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 18 May 2023 01:26:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="19100c6aaa1f5c0d7af75a27f3dc718e";
logging-data="47298"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cwAuRcFOQ4Afzib5q+BLnO5/jT7HjdWY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:Lnkqfx3RHducU0dUxs3GuP235nY=
Content-Language: en-US
In-Reply-To: <idW8M.613646$5S78.524671@fx48.iad>
 by: Chris M. Thomasson - Thu, 18 May 2023 01:26 UTC

On 5/16/2023 6:37 PM, Pavel wrote:
> Chris M. Thomasson wrote:
>> On 5/15/2023 8:01 PM, Pavel wrote:
>>> Chris M. Thomasson wrote:
>>>> On 5/14/2023 3:56 PM, Pavel wrote:
>>>>> Chris M. Thomasson wrote:
>>>>>> I can get this working with C++20, can anybody else? Over
>>>>>> allocating and aligning on a page size:
>>>>>> _________________________
>>>>> [snipped]
>>>>>> _________________________
>>>>>>
>>>>>> I get:
>>>>>>
>>>>>> page = 0000017135410000
>>>>>>
>>>>>> as an output. I get no crap output, so to speak... ;^)
>>>>>>
>>>>> [snipped]
>>>>> Seems to work for me as well
>>>>>
>>>>> g++ (GCC) 13.1.1 20230429
>>>>>
>>>>> $ ./a.out
>>>>> page = 0x55f3f83da000
>>>>> $
>>>>>
>>>>> g++ (GCC) 13.1.1 20230429 on x86_64 GNU/Linux
>>>>
>>>> Nice! I do not have that version installed. How does it respond to
>>>> the program that uses a std::vector?
>>> The vector prog's output is empty, so everything is good.
>>
>> Excellent. Thanks for taking the time to give it a go, Pavel. I really
>> need to install a recent GCC. Stuck on MSVC right now for a project.
>>
> np, my pleasure.

:^)

>>>> MSVC likes it and everything is padded and aligned. Iirc,
>>>> std::vector should honor alignas, right?
>>>>
>>> I don's think it is the vector specifically that honors alignas; I
>>> rather think the data structure of type ct_page, whether allocated by
>>> vector or in any other legal way, can get aligned accordingly to its
>>> alignment specifier (on my system, it's implementation specific as
>>> alignof(std::max_align_t) is 16 so the alignments of 64 are
>>> "extended" -- but happen to be supported.
>>
>> Remember those early hyperthreaded Pentium's? There was something
>> called the aliasing problem that would make two hyperthreaded threads
>> falsely share cache lines and would destroy performance? Iirc, the l2
>> cache lines were 128 bytes split into two 64 byte regions. The
>> workaround was to offset the stacks of each thread using alloca.
> I remember there was a problem with them simulated threads not having
> cache of their own (don't recall whether it was L2 or L1) but don't
> remember what exactly. The advice I remember was to not use
> hyperthreading mode :-).
>
>>
>>
>>> On a side note, see if your code benefits from using
>>> std::hardware_constructive_interference_size instead of hardcoded 64
>>> for the cacheline_size.
>>
>> It will definitely benefit. I am wondering if
>> std::hardware_constructive_interference_size is always guaranteed to
>> be the l2 cache line size?
> Not in general, the Holy Standard definition is expectedly L-agnostic :-).
>
> Gcc in particular implements both as L1 cache line size (at least for
> architectures I care of):

I am trying to target the l2 cache line, and also allow for alignment on
a large boundary, ct_page. This is a basic requirement for some of my
previous memory allocators. I can do this manually with some math. I am
trying to explore c++'s ability to do this for me, without using some
hackish means for alignment. The fun part is that we can round any
address in the ct_page down to its artificially large boundary. A header
structure can be sitting right before the boundary. Perfect, and highly
efficient for certain types of high performance per-thread allocators.

>
> Quote:
>      ‘destructive-interference-size’
>      ‘constructive-interference-size’
>           The values for the C++17 variables
>           ‘std::hardware_destructive_interference_size’ and
>           ‘std::hardware_constructive_interference_size’.  The
>           destructive interference size is the minimum recommended
>           offset between two independent concurrently-accessed objects;
>           the constructive interference size is the maximum recommended
>           size of contiguous memory accessed together.  Typically both
>           will be the size of an L1 cache line for the target, in bytes.
>           For a generic target covering a range of L1 cache line sizes,
>           typically the constructive interference size will be the small
>           end of the range and the destructive size will be the large
>           end.
>
>           The destructive interference size is intended to be used for
>           layout, and thus has ABI impact.  The default value is not
>           expected to be stable, and on some targets varies with
>           ‘-mtune’, so use of this variable in a context where ABI
>           stability is important, such as the public interface of a
>           library, is strongly discouraged; if it is used in that
>           context, users can stabilize the value using this option.
>
>           The constructive interference size is less sensitive, as it is
>           typically only used in a ‘static_assert’ to make sure that a
>           type fits within a cache line.
> End-of-quote

Perfect. Okay. Targeting the l2 cache line is the main goal.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor