working on L4
This commit is contained in:
@@ -1,27 +1,30 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="L4.EvictionRing"
|
// file="L4.EvictionRing.cs"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// obtaining a copy of this software and associated documentation
|
||||||
// in the Software without restriction, including without limitation the rights
|
// files (the “Software”), to deal in the Software without restriction,
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// including without limitation the rights to use, copy, modify, merge,
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
// furnished to do so, subject to the following conditions:
|
// and to permit persons to whom the Software is furnished to do so,
|
||||||
//
|
// subject to the following conditions:
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
//
|
||||||
// copies or substantial portions of the Software.
|
// The above copyright notice and
|
||||||
//
|
// this permission notice shall be included in all copies
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// or substantial portions of the Software.
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
//
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
// SOFTWARE.
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -45,9 +48,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
|
|
||||||
private nint[] _bucket;
|
private nint[] _bucket;
|
||||||
|
|
||||||
public void AddNode(
|
public void AddNode(CacheLineHead* node)
|
||||||
CacheLineHead* node
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
nint address = node->_address;
|
nint address = node->_address;
|
||||||
int hash = (int)(address % (nint)_bucket.Length);
|
int hash = (int)(address % (nint)_bucket.Length);
|
||||||
@@ -73,18 +74,6 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
internal int _refCount;
|
internal int _refCount;
|
||||||
internal nuint _address;
|
internal nuint _address;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void Unuse()
|
|
||||||
{
|
|
||||||
_ = Interlocked.Decrement(ref _refCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void Use()
|
|
||||||
{
|
|
||||||
_ = Interlocked.Increment(ref _refCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="L4"
|
// file="L4.cs"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload
|
// AuthorGroup: Nitload Space
|
||||||
// Copyright (c) Nitload. All rights reserved.
|
// Copyright (c) Nitload Space. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// obtaining a copy of this software and associated documentation
|
||||||
// in the Software without restriction, including without limitation the rights
|
// files (the “Software”), to deal in the Software without restriction,
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// including without limitation the rights to use, copy, modify, merge,
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||||
// furnished to do so, subject to the following conditions:
|
// and to permit persons to whom the Software is furnished to do so,
|
||||||
//
|
// subject to the following conditions:
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
//
|
||||||
// copies or substantial portions of the Software.
|
// The above copyright notice and
|
||||||
//
|
// this permission notice shall be included in all copies
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// or substantial portions of the Software.
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
//
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
// SOFTWARE.
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -43,7 +46,7 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
private const int CacheLineCount = 8192;
|
private const int CacheLineCount = 8192;
|
||||||
|
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
private int _activeCount;
|
||||||
private readonly nuint _baseAddress;
|
private readonly nuint _baseAddress;
|
||||||
|
|
||||||
private readonly SlabAllocator<CacheLineData> _cacheLineAllocator;
|
private readonly SlabAllocator<CacheLineData> _cacheLineAllocator;
|
||||||
@@ -82,17 +85,49 @@ namespace StgSharp.HighPerformance.Memory
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheLine Map(
|
public CacheLine Map(nuint origin)
|
||||||
nuint origin
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// Placeholder implementation; actual mapping logic would go here.
|
|
||||||
if (_map.TryGet(origin, out nuint entryHandle))
|
if (_map.TryGet(origin, out nuint entryHandle))
|
||||||
{
|
{
|
||||||
|
// cache hit
|
||||||
CacheLineHead* entry = (CacheLineHead*)entryHandle;
|
CacheLineHead* entry = (CacheLineHead*)entryHandle;
|
||||||
return new CacheLine(entryHandle);
|
return new CacheLine(entry->_address, ref _activeCount, ref entry->_refCount);
|
||||||
}
|
}
|
||||||
return origin;
|
|
||||||
|
// cache miss
|
||||||
|
/*
|
||||||
|
* post command
|
||||||
|
* then wait for completion
|
||||||
|
*/
|
||||||
|
return origin; //error now
|
||||||
|
}
|
||||||
|
|
||||||
|
public ref struct CacheLine : IDisposable
|
||||||
|
{
|
||||||
|
|
||||||
|
private ref int _activeCount;
|
||||||
|
private ref int _refCount;
|
||||||
|
private nuint _handle;
|
||||||
|
|
||||||
|
internal CacheLine(nuint handle, ref int activeCount, ref int cacheRefCount)
|
||||||
|
{
|
||||||
|
_handle = handle;
|
||||||
|
_refCount = ref cacheRefCount;
|
||||||
|
_activeCount = ref activeCount;
|
||||||
|
_ = Interlocked.Increment(ref _activeCount);
|
||||||
|
_ = Interlocked.Increment(ref _refCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_handle == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_handle = 0;
|
||||||
|
_ = Interlocked.Decrement(ref _activeCount);
|
||||||
|
_ = Interlocked.Decrement(ref _refCount);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct CacheLineData
|
private struct CacheLineData
|
||||||
|
|||||||
Reference in New Issue
Block a user