Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

mscorlib cache padding for 128 byte lines #13102

Merged
merged 2 commits into from
Aug 24, 2017

Conversation

sdmaclea
Copy link

No description provided.

@sdmaclea
Copy link
Author

@dotnet/arm64-contrib @stephentoub @kouvel PTAL coreclr equivalent of dotnet/corefx#22724

@@ -1111,10 +1111,10 @@ internal struct Slot

/// <summary>Padded head and tail indices, to avoid false sharing between producers and consumers.</summary>
[DebuggerDisplay("Head = {Head}, Tail = {Tail}")]
[StructLayout(LayoutKind.Explicit, Size = 192)] // padding before/between/after fields based on typical cache line size of 64
[StructLayout(LayoutKind.Explicit, Size = 384)] // padding before/between/after fields based on worst case cache line size of 128
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we may want to make this change ARM64 specific (put it under #if ARM64)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janvorli Done

@sdmaclea sdmaclea force-pushed the PR-ConcurrentQueue-128 branch from 31b21b2 to a946aab Compare August 1, 2017 19:20
@@ -1109,12 +1109,23 @@ internal struct Slot
}
}

/// <summary>A placeholder class for common padding constants and eventually routines.</summary>
internal static class PaddedHelper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have two places where we define the cache line size (at the other place, we use just the 128 bytes for all platforms). I wonder if we should unify it and put it e.g. to System.Environment.
@jkotas, would the System.Environment be the right place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Environment is a dumping ground for everything. It may be better to keep it as a small type with a constant. It does not really matter because of it has to be internal in the current shape, and thus we can change it anytime.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas @janvorli Sounds like the Cache Line related helpers should move to a common file. How about

Internal.CacheHelpers @ src/mscorlib/src/Internal/CacheHelpers.cs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas @janvorli ping. I can also just make the pre-existing cache size definition conditional on ARM64. Then refer to it where it is. Then rename and relocation can be a separate task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdmaclea the location sounds reasonable to me, but @jkotas knows the structure of mscorlib much better, so he should provide a better feedback on that than me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/mscorlib/src/Internal/CacheHelpers.cs

Sounds good to me.

@sdmaclea sdmaclea force-pushed the PR-ConcurrentQueue-128 branch from a946aab to 9641c9d Compare August 23, 2017 20:00
Copy link
Author

@sdmaclea sdmaclea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas @janvorli This should address outstanding issues

@@ -356,6 +356,7 @@
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\Augments\EnvironmentAugments.cs" />
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\Augments\RuntimeThread.cs" />
<Compile Include="$(BclSourcesRoot)\Internal\Console.cs" />
<Compile Include="$(BclSourcesRoot)\Internal\Padding.cs" />
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the filename Padding.cs because I noticed corefx used that name for the equivalent file.

[StructLayout(LayoutKind.Explicit, Size = PaddingHelpers.CACHE_LINE_SIZE - sizeof(int))]
internal struct PaddingFor32
{
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left these structure pretty much intact because that matches corefx.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas
Copy link
Member

jkotas commented Aug 24, 2017

@dotnet-bot test OSX10.12 x64 Checked Build and Test please
@dotnet-bot test Windows_NT x64 Release Priority 1 Build and Test please

@sdmaclea
Copy link
Author

@jkotas Thanks. Tests are clean. This can be merged.

@jkotas jkotas merged commit ad29b87 into dotnet:master Aug 24, 2017
@karelz karelz modified the milestone: 2.1.0 Aug 28, 2017
@sdmaclea sdmaclea deleted the PR-ConcurrentQueue-128 branch December 4, 2017 16:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants