[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-14 Thread raj.khem at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #11 from Khem Raj  ---
yes thanks. I have done so https://jira.mongodb.org/browse/SERVER-65664

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-14 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #10 from Andrew Pinski  ---
No. The issue is the two constants and cache line size are different. Basically
the whole code should not say cache line aligned but rather use them based on
what they mean.
Report the issue to the mongodb folks and have them fix their broken code. They
are using the constants in the wrong manner.

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-14 Thread raj.khem at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #9 from Khem Raj  ---
how does something like this look ?

#include 
#include 
#include 
#include 

#ifdef __cpp_lib_hardware_interference_size
using std::hardware_constructive_interference_size;
using std::hardware_destructive_interference_size;
#else
// 64 bytes on x86-64 │ L1_CACHE_BYTES │ L1_CACHE_SHIFT │
__cacheline_aligned │ ...
constexpr std::size_t hardware_constructive_interference_size = 64;
constexpr std::size_t hardware_destructive_interference_size = 64;
#endif

class NetworkCounter {

private:
template 
struct alignas(alignment) WithAlignment : T {
using T::T;
};

template 
using WithAlignmentAtLeast = WithAlignment;

// These two counters are always incremented at the same time, so
// we place them on the same cache line.
template 
using CacheAligned = WithAlignmentAtLeast;
struct Together {
long long logicalBytesIn{0};
long long requests{0};
};
CacheAligned _together{};
static_assert(sizeof(decltype(_together)) <=
hardware_destructive_interference_size,
  "cache line spill");
};

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-14 Thread raj.khem at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #8 from Khem Raj  ---
So in this case if I change

static_assert(sizeof(decltype(_together)) <=
hardware_constructive_interference_size,
  "cache line spill");


to 

static_assert(sizeof(decltype(_together)) <=
hardware_destructive_interference_size,
  "cache line spill");

should set it right

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-13 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #7 from Andrew Pinski  ---
mongodb is using these two values incorrectly and even misunderstanding what
they mean.

hardware_constructive_interference_size means the Minimum offset between two
objects which will avoid false sharing. So if you have two objects that are
that distant apart, then there will be NO false sharing at all (some offsets
smaller might also work too but it depends on the HW which is run on).

While hardware_constructive_interference_size says the maxium offset between
two obejcts which will promote true sharing.

That is if the two objects are within that alignment, there is a guarantee that
there will be sharing.

So if they want to guarantee true sharing, then they need to have it as aligned
to hardware_constructive_interference_size and make sure the size is smaller
than hardware_constructive_interference_size .

So In this case Together should be aligned to
hardware_constructive_interference_size .

The other CacheAligned cases need to be looked into make sure they are using
the correct values too. Depending on what they are trying to do.

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-13 Thread raj.khem at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #6 from Khem Raj  ---
this is from mongodb.

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-13 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #5 from Andrew Pinski  ---
(In reply to Khem Raj from comment #4)
> I dont think its a bug per-se, I am looking for fixing it right way. Should
> I pass a non-default value via gcc cmdline or adjust the size expectations
> in code.

Well adjusting the code is correct fix. But adjusting to what is more for the
developers of that code. Where does this code show up and that might help us
help you.

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-13 Thread raj.khem at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #4 from Khem Raj  ---
I dont think its a bug per-se, I am looking for fixing it right way. Should I
pass a non-default value via gcc cmdline or adjust the size expectations in
code.

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Andrew Pinski  ---
Why do you think this is a bug in GCC?
The definition:
hardware_destructive_interference_size:
Minimum offset between two objects to avoid false sharing

hardware_constructive_interference_size :
Maximum size of contiguous memory to promote true sharing

In aarch64, the sizes are defaulting to 256/64 as the max cache line size is
256 while the normal cache line size is 64.

I don't see this as a bug in GCC.
The code is assuming false definitions of these values.

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-12 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

--- Comment #2 from Jonathan Wakely  ---
(In reply to Khem Raj from comment #0)
> This testcase below fails to compile with gcc12 on aarch64 but works ok with
> gcc11
[...]
> #ifdef __cpp_lib_hardware_interference_size
> using std::hardware_constructive_interference_size;
> using std::hardware_destructive_interference_size;

Not a bug. This is defined for GCC 12, and your assumption about the
destructive size is wrong. It's 256 for aarch64.

See
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Winterference-size
for relevant options.

[Bug target/105251] static assert sizeof(decltype(_together)) <= hardware_constructive_interference_size fails with gcc12

2022-04-12 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105251

Andrew Pinski  changed:

   What|Removed |Added

  Component|c++ |target

--- Comment #1 from Andrew Pinski  ---
Right hardware_destructive_interference_size is 256 while
hardware_constructive_interference_size  is 64.