-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CompareExchange_long benchmark sometimes reports very long execution time on x86 #1497
Comments
21 tasks
Here's a repro... issue is lock cmpxchg8 splitting a cache line, so it requires a particular data alignment. The code below has a 50/50 chance that one of those public class X
{
int x;
long l1;
long l2;
long l3;
long l4;
long l5;
long l6;
long l7;
long l8;
[Benchmark]
public long CompareExchange_long1() => Interlocked.CompareExchange(ref l1, 1, 0);
[Benchmark]
public long CompareExchange_long2() => Interlocked.CompareExchange(ref l2, 1, 0);
[Benchmark]
public long CompareExchange_long3() => Interlocked.CompareExchange(ref l3, 1, 0);
[Benchmark]
public long CompareExchange_long4() => Interlocked.CompareExchange(ref l4, 1, 0);
[Benchmark]
public long CompareExchange_long5() => Interlocked.CompareExchange(ref l5, 1, 0);
[Benchmark]
public long CompareExchange_long6() => Interlocked.CompareExchange(ref l6, 1, 0);
[Benchmark]
public long CompareExchange_long7() => Interlocked.CompareExchange(ref l7, 1, 0);
[Benchmark]
public long CompareExchange_long8() => Interlocked.CompareExchange(ref l8, 1, 0);
} Sample data
|
Also explains why we don't see this on x64, because classes there are 8 byte aligned. On x86, classes are only 4 byte aligned. |
13 tasks
10 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By looking at the data I got for x86 the
CompareExchange_long
benchmark typically reports time around10ns
, but sometimes it's evenx100
more.It's either a very weird hardware issue or a BenchmarkDotNet bug, possibly: dotnet/BenchmarkDotNet#837
The problem is that I can't reproduce it locally... so if anyone ever faces this problem please copy-paste the content of BDN
.log
file here.The text was updated successfully, but these errors were encountered: