89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using System;
|
|
|
|
namespace VMdemo.Core
|
|
{
|
|
[Serializable]
|
|
public class SimulationConfig
|
|
{
|
|
public const int FixedMachineBits = 32;
|
|
public const int FixedVaBits = 24;
|
|
public const int FixedPageSizeKB = 4;
|
|
public const int FixedPhysicalMemoryMB = 1;
|
|
public const int FixedTlbEntries = 8;
|
|
|
|
public int machineBits = FixedMachineBits;
|
|
public int vaBits = FixedVaBits;
|
|
public int pageSizeKB = FixedPageSizeKB;
|
|
public int physicalMemoryMB = FixedPhysicalMemoryMB;
|
|
public int tlbEntries = FixedTlbEntries;
|
|
public int accessCount = 100;
|
|
public int pageFaultPenalty = 100;
|
|
public AddressGenerationMode addressGenerationMode = AddressGenerationMode.SequentialArrayLoop;
|
|
public int arrayLengthBytes = 256;
|
|
public int arrayElementBytes = 4;
|
|
public int arrayBaseAddress = 0;
|
|
|
|
public void ApplyFixedCoreSpec()
|
|
{
|
|
machineBits = FixedMachineBits;
|
|
vaBits = FixedVaBits;
|
|
pageSizeKB = FixedPageSizeKB;
|
|
physicalMemoryMB = FixedPhysicalMemoryMB;
|
|
tlbEntries = FixedTlbEntries;
|
|
}
|
|
|
|
public ulong PageSizeBytes => pageSizeKB > 0 ? (ulong)pageSizeKB * 1024UL : 0UL;
|
|
|
|
public ulong PhysicalMemoryBytes => physicalMemoryMB > 0 ? (ulong)physicalMemoryMB * 1024UL * 1024UL : 0UL;
|
|
|
|
public int OffsetBits
|
|
{
|
|
get
|
|
{
|
|
return TryGetLog2(PageSizeBytes, out var bits) ? bits : -1;
|
|
}
|
|
}
|
|
|
|
public int VpnBits
|
|
{
|
|
get
|
|
{
|
|
var offsetBits = OffsetBits;
|
|
return offsetBits >= 0 ? vaBits - offsetBits : -1;
|
|
}
|
|
}
|
|
|
|
public ulong FrameCount
|
|
{
|
|
get
|
|
{
|
|
var pageSizeBytes = PageSizeBytes;
|
|
if (pageSizeBytes == 0UL)
|
|
{
|
|
return 0UL;
|
|
}
|
|
|
|
return PhysicalMemoryBytes / pageSizeBytes;
|
|
}
|
|
}
|
|
|
|
private static bool TryGetLog2(ulong value, out int bits)
|
|
{
|
|
bits = -1;
|
|
if (value == 0UL || (value & (value - 1UL)) != 0UL)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bits = 0;
|
|
while (value > 1UL)
|
|
{
|
|
value >>= 1;
|
|
bits++;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|