public void RegMHandle() { //var x = new Lazy<int>(() => 2); //var tt = x.GetType(); //dynamic nn= Activator.CreateInstance(tt); //var vv = nn.Value; //Assert.AreEqual(vv, 2); using (var mmap = new MemMap()) { RegDataMHandle._MemMap = mmap; var reg = new RegDataMHandle() { _name = regroot }; reg.Fillit(); var mh = mmap.AddData(reg); var ret = (RegDataMHandle)mmap.GetData(mh, reg.GetType()); foreach (var m in ret._childNodes) { var ch = mmap.GetData(m, reg.GetType()); } Assert.IsTrue(reg.CompareTo(ret) == 0, "not eq cnt = {0}", RegDataMHandle._cnt); } }
public MemAddr inst_wnd_head_addr() { ulong block_addr = inst_wnd.head(); ulong paddr = block_addr << Config.proc.block_size_bits; MemAddr addr = MemMap.Translate(paddr); return(addr); }
public void TestListNest() { for (int i = 0; i < 10000; i++) { var x1x = new MemMap(); } MapFileList <NestClass> mfList = null; int iLoop = 0; try { var bigstr = new string('a', 10000); uint nInst = 1 << 25; // 2^26 = 67,108,864 nInst = 16777214; nInst = 10000; using (mfList = new MapFileList <NestClass>()) { var xx = new NestClass() { _nNum = 1, _stack = null }; mfList.Add(xx); var ret = mfList[mfList.Count - 1]; Assert.AreEqual(ret._nNum, mfList.Count); Assert.IsNull(ret._stack, "ret stack should be null"); mfList.Clear(); for (int i = 1; i < nInst; i++) { var testInstance = DataClass.MakeInstance((ulong)i); testInstance.str5 = bigstr; var x = new NestClass() { _nNum = i, _stack = testInstance }; mfList.Add(x); var retrievedInstance = mfList[(int)i - 1]; Assert.AreEqual(bigstr, retrievedInstance._stack.str5, "objects not equal Count=" + mfList.Count.ToString()); // Assert.AreEqual(testInstance, retrievedInstance, "objects not equal Count=" + mfList.Count.ToString()); } mfList.VerifyNoLeaks(); } } catch (Exception ex) { Assert.Fail("exception lp={0} cnt={1} {2}\r\n{3}", iLoop, mfList.Count, mfList._MemMap._stats.ToString(), ex.ToString()); throw; } }
public MapFileList( ulong ulInitialSize = 0, MapMemTypes mapfileType = MapMemTypes.MapMemTypePageFile, ulong ulGrowDynamicallyThreshold = 0, MemMap memMapToUse = null, uint uiViewSize = MemMap.AllocationGranularity ) { _MemMap = memMapToUse; if (_MemMap == null) { _MemMap = new MemMap( ulInitialSize, mapfileType, ulGrowDynamicallyThreshold, uiViewSize ); } _listInternal = new List <MHandle>(); }
public void DelegateTest() { var dummy = 0; var x = new Action(() => { dummy = 1; }); using (var mfd = new MemMap()) { var loc = mfd.AddData(x); var ret = (Action)mfd.GetData(loc, x.GetType()); ret.Invoke(); Assert.AreEqual(dummy, 1); // Assert.IsTrue(ret.CompareTo(root) == 0, "not equal!"); } }
public MapFileDict( IEqualityComparer <TKey> comparer = null, ulong ulInitialSize = 0, MapMemTypes mapfileType = MapMemTypes.MapMemTypePageFile, ulong ulGrowDynamicallyThreshold = 0, MemMap memMapToUse = null, uint uiViewSize = MemMap.AllocationGranularity ) { _MemMap = memMapToUse; _comparer = comparer ?? EqualityComparer <TKey> .Default; if (_MemMap == null) { _MemMap = new MemMap( ulInitialSize, mapfileType, ulGrowDynamicallyThreshold, uiViewSize ); } }
public void Set(int pid, ReqType type, ulong paddr) { // state Pid = pid; Type = type; // address TracePaddr = paddr; if (Config.mctrl.page_randomize) { Paddr = Prand.get_paddr(paddr); } else if (Config.mctrl.page_sequence) { Paddr = Pseq.get_paddr(paddr); } else if (Config.mctrl.page_contiguous) { Paddr = Pcontig.get_paddr(paddr); } else { Paddr = paddr; } BlockAddr = Paddr >> Config.proc.block_size_bits; Addr = MemMap.Translate(Paddr); Stat.procs[pid].allocated_physical_pages.collect(); reset_timing(); // Word offset ulong pwo = (Paddr & (63)) >> 2; Dbg.AssertPrint(pwo == ((paddr & (63)) >> 2), "Word offset should be the same for both virtual and physical addresses."); Dbg.AssertPrint(pwo < 16, "There should be only 8 words in a cacheline=" + pwo); WordOffset = (int)pwo; }
public ProcessMemory() { //mUsage = new List<Dictionary<string, string>>(); memUsagepList = new MemMap(); }
/// <param name="args"></param> static void Main(string[] args) { string name; string message; StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; // Create a new SerialPort object with default settings. _serialPort = new SerialPort(); // Allow the user to set the appropriate properties. _serialPort.PortName = "COM6"; _serialPort.BaudRate = 9600; _serialPort.Parity = Parity.None; _serialPort.DataBits = 8; _serialPort.StopBits = StopBits.One; _serialPort.Encoding = System.Text.ASCIIEncoding.ASCII; _serialPort.Handshake = Handshake.None; // Set the read/write timeouts _serialPort.ReadTimeout = 500; _serialPort.WriteTimeout = 500; _serialPort.ReadBufferSize = 10000; _serialPort.WriteBufferSize = 10000; _serialPort.DataReceived += _serialPort_DataReceived; _serialPort.Open(); _continue = true; Console.WriteLine("Type QUIT to exit"); while (_continue) { message = Console.ReadLine(); if (stringComparer.Equals("quit", message)) { _continue = false; } if (stringComparer.Equals("U", message)) { _serialPort.Write("U"); } if (stringComparer.Equals("reset", message)) { Reset(); } if (stringComparer.Equals("read", message)) { ReadData(0x00); } if (stringComparer.Equals("gc", message)) { //I'm too lazy to figure this out, so I'll flatten it. byte[] valArray = new byte[256]; int add = 0; for (int i = 0; i < 32; i++) { for (int k = 0; k < 8; k++) { valArray[add] = readValues[i, k]; add++; } } //Open our text file. string file = System.IO.File.ReadAllText("memtable.txt"); using (StreamWriter writer = File.CreateText("MemMap.cs")) { writer.Write(@"using System; using System.Collections.Generic; using System.IO.Ports; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; public class MemMap { private byte[] valArray; public MemMap(byte[] vals) { valArray = vals; } "); string[] lines = file.Split('\n'); foreach (string line in lines) { //Console.WriteLine(line); string[] cols = line.Split('\t'); if (cols.Length > 5) { //foreach (string col in cols) //{ // Console.WriteLine(col); //} writer.WriteLine("/// <summary>"); writer.WriteLine("/// " + cols[4]); writer.WriteLine("/// </summary>"); string type = "UNKNOWN"; int length = Convert.ToInt32(cols[3]); switch (length) { case 1: { type = "byte"; break; } case 2: { type = "UInt16"; break; } case 4: { type = "UInt32"; break; } } writer.WriteLine("public {0} {1}", type, cols[2]); writer.WriteLine("{"); writer.WriteLine("\tget{"); switch (length) { case 1: { writer.WriteLine("return valArray[{0}];", cols[0]); break; } case 2: { writer.WriteLine("return BitConverter.ToUInt16(valArray, {0});", cols[0]); break; } case 4: { writer.WriteLine("return BitConverter.ToUInt32(valArray, {0});", cols[0]); break; } } writer.WriteLine("\t}"); writer.WriteLine("}"); } } writer.WriteLine("}"); writer.Flush(); writer.Close(); } } if (stringComparer.Equals("rst", message)) { _serialPort.Write(new byte[] { 0x00 }, 0, 1); } if (stringComparer.Equals("dspb", message)) { int add = 0; for (int i = 0; i < 32; i++) { for (int k = 0; k < 8; k++) { Console.WriteLine(String.Format("Add {0} value {1}", add, (int)readValues[i, k])); add++; } } } if (stringComparer.Equals("mm", message)) { byte[] valArray = new byte[256]; int add = 0; for (int i = 0; i < 32; i++) { for (int k = 0; k < 8; k++) { valArray[add] = readValues[i, k]; add++; } } MemMap map = new MemMap(valArray); } if (stringComparer.Equals("readAllBytes", message)) { for (int i = 0; i < 240; i = i + 8) { ReadData((byte)i); reset = false; int j = 0; while (!reset) { Thread.Sleep(10); j++; if (j > 1500) //15second timeout... I think, I don't math. { reset = true; } } } } } _serialPort.Close(); }
public void Initialize() { Stat = new Stat(); // Crossbar Xbar = new Xbar(); // ddr3 DDR3DRAM ddr3 = new DDR3DRAM(Config.mem.ddr3_type, Config.mem.clock_factor, Config.mem.tRTRS, Config.mem.tWR, Config.mem.tWTR, Config.mem.tBL, Config.mem.bank_max, Config.mem.subarray_max, Config.mem.col_max, Config.mem.tRA, Config.mem.tWA, Config.mem.tREFI, Config.mem.tRFC, Config.mem.tRP, Config.mem.tRCD); uint cmax = Config.mem.chan_max; uint rmax = Config.mem.rank_max; // randomized page table const ulong page_size = 4 * 1024; PageRandomizer prand = new PageRandomizer(page_size, ddr3.ROW_MAX); Req.Prand = prand; // sequential page table PageSequencer pseq = new PageSequencer(page_size, cmax, rmax, ddr3.BANK_MAX); Req.Pseq = pseq; // Contiguous physical page allocation ContiguousAllocator pcontig = new ContiguousAllocator(page_size, cmax * rmax * ddr3.ROW_MAX * ddr3.DEVICE_WIDTH); Req.Pcontig = pcontig; // memory mapping MemMap.Init(Config.mem.map_type, Config.mem.chan_max, Config.mem.rank_max, Config.mem.col_per_subrow, ddr3); // Cache hierarchy if (Config.proc.cache_enabled) { Caches = new CacheHierarchy(Config.N); } // processors Procs = new Proc.Proc[Config.N]; for (int p = 0; p < Config.N; p++) { Procs[p] = new Proc.Proc(Config.traceFileNames[p], Caches); } // memory controllers Mctrls = new MemCtrl.MemCtrl[cmax]; for (int i = 0; i < Mctrls.Length; i++) { Mctrls[i] = new MemCtrl.MemCtrl(rmax, ddr3); // Add ref handles to processors for (int p = 0; p < Config.N; p++) { Procs[p].mctrls[i] = Mctrls[i]; Mctrls[i].ProcHandles[p] = Procs[p]; } } // memory schedulers MemSched.MemSched[] rscheds = new MemSched.MemSched[cmax]; for (int i = 0; i < cmax; i++) { Object[] args = { Mctrls[i], Mctrls }; rscheds[i] = Activator.CreateInstance(Config.sched.typeof_sched_algo, args) as MemSched.MemSched; } MemSched.MemSched[] wscheds = new MemSched.MemSched[cmax]; for (int i = 0; i < cmax; i++) { Object[] args = { Mctrls[i], Mctrls }; wscheds[i] = Activator.CreateInstance(Config.sched.typeof_wbsched_algo, args) as MemSched.MemSched; } for (int i = 0; i < cmax; i++) { Mctrls[i].Rsched = rscheds[i]; Mctrls[i].Wsched = wscheds[i]; rscheds[i].Initialize(); wscheds[i].Initialize(); } // WB mode Mwbmode = Activator.CreateInstance(Config.mctrl.typeof_wbmode_algo, new Object[] { Mctrls }) as MemWBMode.MemWBMode; for (int i = 0; i < cmax; i++) { Mctrls[i].Mwbmode = Mwbmode; } // BLP tracker Blptracker = new BLPTracker(Mctrls); }