HLSf use nuint rather than long, L4 now uses hlsf rather than array to alloc cache line.
This commit is contained in:
@@ -44,7 +44,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
}
|
||||
IL4Predict predict = CurrentPredict;
|
||||
int predictIndex = CurrentPredictIndex;
|
||||
Span<CacheLinePrediction> span = new(_prediction, PredictionCount);
|
||||
Span<CacheLineDescription> span = new(_prediction, PredictionCount);
|
||||
PredictResult result = predict.Predict(span, out int actualCount);
|
||||
if ((result & PredictResult.Exhausted) != 0) {
|
||||
_exhausted = !TryGetNextPredict();
|
||||
@@ -58,7 +58,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
AgeAll();
|
||||
for (int i = 0; i < actualCount; i++)
|
||||
{
|
||||
ref CacheLinePrediction handle = ref span[i];
|
||||
ref CacheLineDescription handle = ref span[i];
|
||||
nuint address = handle.Address;
|
||||
if (!_map.TryGet(address, out _))
|
||||
{
|
||||
@@ -75,34 +75,34 @@ namespace StgSharp.HighPerformance.Memory
|
||||
for (int i = 0; i < missIndex; i++)
|
||||
{
|
||||
CacheLineHead* head;
|
||||
ref CacheLinePrediction pHandle = ref span[i];
|
||||
ref CacheLineDescription pHandle = ref span[i];
|
||||
nuint address = pHandle.Address;
|
||||
int index;
|
||||
if (_map.TryGet(address, out nuint handle))
|
||||
{
|
||||
head = (CacheLineHead*)handle;
|
||||
index = head->_id;
|
||||
index = head->Id;
|
||||
(*_eviction)[index] = 0; // reset eviction counter
|
||||
|
||||
#region update predictor belonging
|
||||
|
||||
int predictId = head->_predictor;
|
||||
int predictId = head->Predictor;
|
||||
IL4Predict belong = predictorSpan[predictId];
|
||||
|
||||
// TODO 由于L4的缓存行改为“可变长度”缓存行,需要调整缓存行复用策略
|
||||
// This branch performs resident-line adoption rather than a simple policy
|
||||
// equality check. Returning true means the current predictor can keep using
|
||||
// the existing cache bytes without a write-back plus re-prefetch cycle.
|
||||
if (predict.IsSamePolicy(head->_profile, belong))
|
||||
if (predict.IsSamePolicy(head->Profile, belong))
|
||||
{
|
||||
head->_predictor = (short)predictIndex;
|
||||
head->Predictor = (short)predictIndex;
|
||||
} else
|
||||
{
|
||||
// Compatibility failed, so the old owner must first flush its view of
|
||||
// the line before the new predictor rematerializes the cache bytes.
|
||||
belong.WriteBack(head->_origin, head->_profile, new ReadOnlySpan<byte>((byte*)head->_address, head->_size));
|
||||
head->_profile = pHandle.MapPolicy;
|
||||
predict.Prefetch(head->_origin, head->_profile, new Span<byte>((byte*)head->_address, head->_size));
|
||||
belong.WriteBack(head->Origin, head->Profile, new ReadOnlySpan<byte>((byte*)head->Address, (int)head->Size));
|
||||
head->Profile = pHandle.MapPolicy;
|
||||
predict.Prefetch(head->Origin, head->Profile, new Span<byte>((byte*)head->Address, (int)head->Size));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -112,8 +112,7 @@ namespace StgSharp.HighPerformance.Memory
|
||||
|
||||
int retryCount = 0, remain = missIndex - i;
|
||||
const int maxRetry = 1024;
|
||||
HlsfHandle hlsfHandle;
|
||||
while (!TryGetEmptyLine(pHandle.Size, out index, out hlsfHandle))
|
||||
while (!TryGetEmptyLine(pHandle.Size, out index))
|
||||
{
|
||||
remain = Evict(remain);
|
||||
retryCount++;
|
||||
@@ -126,15 +125,13 @@ namespace StgSharp.HighPerformance.Memory
|
||||
}
|
||||
head = &_head[index];
|
||||
head->_id = index;
|
||||
head->_origin = address;
|
||||
head->_profile = pHandle.MapPolicy;
|
||||
head->_refCount = 0;
|
||||
head->_predictor = (short)predictIndex;
|
||||
head->_address = (nuint)hlsfHandle.Pointer;
|
||||
head->_size = pHandle.Size;
|
||||
head->Origin = address;
|
||||
head->Profile = pHandle.MapPolicy;
|
||||
head->RefCount = 0;
|
||||
head->Predictor = (short)predictIndex;
|
||||
|
||||
// pre fetch them here
|
||||
predict.Prefetch(head->_origin, head->_profile, new Span<byte>((byte*)head->_address, (int)head->_size));
|
||||
predict.Prefetch(head->Origin, head->Profile, new Span<byte>((byte*)head->Address, (int)head->Size));
|
||||
_ = _map.TryAddOrSet(address, (nuint)head, out _);
|
||||
}
|
||||
_ = Interlocked.Add(ref _aheadCount, actualCount);
|
||||
|
||||
Reference in New Issue
Block a user