예제 #1
0
        public Cache(int wordSize, int blockSize, int numBlocks, int numSets, IReplacementPolicy replacementPolicy, bool bit64, Cache nextLayer)
        {
            this.wordSize          = wordSize;
            this.blockSize         = blockSize;
            this.numBlocks         = numBlocks;
            this.numSets           = numSets;
            this.replacementPolicy = replacementPolicy;
            this.nextLayer         = nextLayer;

            entries    = mapEntries();
            offsetSize = (byte)Math.Round(Math.Log(wordSize, 2));
            indexSize  = (byte)Math.Round(Math.Log(numBlocks / numSets, 2));
            tagSize    = (byte)((bit64 ? 64 : 32) - (offsetSize + indexSize));
            count      = 0;
        }
예제 #2
0
        private void RunSimulation(object sender, RoutedEventArgs e)
        {
            int wordSize1    = int.Parse(((ComboBoxItem)lstWordSize.SelectedValue).Content.ToString());
            int blockSize1   = int.Parse(((ComboBoxItem)lstBlockSize.SelectedValue).Content.ToString());
            int numBlocks1   = int.Parse(((ComboBoxItem)lstNumBlocks.SelectedValue).Content.ToString());
            int mappingSize1 = int.Parse(((ComboBoxItem)lstMapSize.SelectedValue).Content.ToString());

            String             replacementString1 = ((ComboBoxItem)lstReplacementPolicy.SelectedValue).Content.ToString();
            IReplacementPolicy replacementPolicy1 = GetReplacementPolicyFromString(replacementString1);

            if (numCacheLevels > 2)
            {
                String             replacementString3 = ((ComboBoxItem)lstReplacementPolicy2.SelectedValue).Content.ToString();
                IReplacementPolicy replacementPolicy3 = GetReplacementPolicyFromString(replacementString3);

                int wordSize3    = int.Parse(((ComboBoxItem)lstWordSize3.SelectedValue).Content.ToString());
                int blockSize3   = int.Parse(((ComboBoxItem)lstBlockSize3.SelectedValue).Content.ToString());
                int numBlocks3   = int.Parse(((ComboBoxItem)lstNumBlocks3.SelectedValue).Content.ToString());
                int mappingSize3 = int.Parse(((ComboBoxItem)lstMapSize3.SelectedValue).Content.ToString());
                l3 = new Cache(wordSize3, blockSize3, numBlocks3, mappingSize3, replacementPolicy3, false, null);
            }
            else
            {
                l3 = null;
            }

            if (numCacheLevels > 1)
            {
                String             replacementString2 = ((ComboBoxItem)lstReplacementPolicy2.SelectedValue).Content.ToString();
                IReplacementPolicy replacementPolicy2 = GetReplacementPolicyFromString(replacementString2);

                int wordSize2    = int.Parse(((ComboBoxItem)lstWordSize2.SelectedValue).Content.ToString());
                int blockSize2   = int.Parse(((ComboBoxItem)lstBlockSize2.SelectedValue).Content.ToString());
                int numBlocks2   = int.Parse(((ComboBoxItem)lstNumBlocks2.SelectedValue).Content.ToString());
                int mappingSize2 = int.Parse(((ComboBoxItem)lstMapSize2.SelectedValue).Content.ToString());
                l2 = new Cache(wordSize2, blockSize2, numBlocks2, mappingSize2, replacementPolicy2, false, l3);
            }
            else
            {
                l2 = null;
            }

            l1 = new Cache(wordSize1, blockSize1, numBlocks1, mappingSize1, replacementPolicy1, false, l2);
            Tuple <Cache, StorageFile, int> t = Tuple.Create <Cache, StorageFile, int>(l1, logFile, numCacheLevels);

            Frame.Navigate(typeof(SimulationPage), t);
        }
예제 #3
0
        /// <summary>
        /// <para>Initialises this instance with the given components.</para>
        /// </summary>
        /// <param name="replacementPolicy">
        /// An <see cref="IReplacementPolicy"/>
        /// </param>
        /// <param name="backingStore">
        /// An <see cref="ICacheBackingStore"/>
        /// </param>
        /// <param name="defaultItemPolicy">
        /// An <see cref="IItemPolicy"/>
        /// </param>
        public EntityCacheBase(IReplacementPolicy replacementPolicy,
                               ICacheBackingStore backingStore,
                               IItemPolicy defaultItemPolicy)
        {
            _disposed = false;

            this.SyncRoot     = new ReaderWriterLockSlim();
            this.ItemPolicies = new Dictionary <IIdentity, IItemPolicy>();

            this.ReplacementPolicy = replacementPolicy;
            this.BackingStore      = backingStore;
            this.DefaultItemPolicy = defaultItemPolicy;

            this.CacheHit    += this.ReplacementPolicy.HandleCacheEvent;
            this.CacheMiss   += this.ReplacementPolicy.HandleCacheEvent;
            this.ItemAdded   += this.ReplacementPolicy.HandleCacheEvent;
            this.ItemRemoved += this.ReplacementPolicy.HandleCacheEvent;
        }
예제 #4
0
 /// <summary>
 /// <para>Initialises this instance, including a default item policy.</para>
 /// </summary>
 /// <param name="policy">
 /// A <see cref="IReplacementPolicy"/>
 /// </param>
 /// <param name="backingStore">
 /// A <see cref="ICacheBackingStore"/>
 /// </param>
 /// <param name="defaultItemPolicy">
 /// A <see cref="IItemPolicy"/>
 /// </param>
 public InlineEntityCache (IReplacementPolicy policy,
                           ICacheBackingStore backingStore,
                           IItemPolicy defaultItemPolicy) : base(policy, backingStore, defaultItemPolicy)
 {
   this.ItemAdded += HandleItemAdded;
 }
예제 #5
0
 /// <summary>
 /// <para>Initialises this instance.</para>
 /// </summary>
 /// <param name="policy">
 /// A <see cref="IReplacementPolicy"/>
 /// </param>
 /// <param name="backingStore">
 /// A <see cref="ICacheBackingStore"/>
 /// </param>
 public InlineEntityCache (IReplacementPolicy policy,
                           ICacheBackingStore backingStore) : this(policy, backingStore, null) {}
예제 #6
0
 /// <summary>
 /// <para>Initialises this instance, including a default item policy.</para>
 /// </summary>
 /// <param name="policy">
 /// A <see cref="IReplacementPolicy"/>
 /// </param>
 /// <param name="backingStore">
 /// A <see cref="ICacheBackingStore"/>
 /// </param>
 /// <param name="defaultItemPolicy">
 /// A <see cref="IItemPolicy"/>
 /// </param>
 public InlineEntityCache(IReplacementPolicy policy,
                          ICacheBackingStore backingStore,
                          IItemPolicy defaultItemPolicy) : base(policy, backingStore, defaultItemPolicy)
 {
     this.ItemAdded += HandleItemAdded;
 }
예제 #7
0
 /// <summary>
 /// <para>Initialises this instance.</para>
 /// </summary>
 /// <param name="policy">
 /// A <see cref="IReplacementPolicy"/>
 /// </param>
 /// <param name="backingStore">
 /// A <see cref="ICacheBackingStore"/>
 /// </param>
 public InlineEntityCache(IReplacementPolicy policy,
                          ICacheBackingStore backingStore) : this(policy, backingStore, null)
 {
 }
예제 #8
0
 /// <summary>
 /// <para>Initialises this instance with empty components.</para>
 /// </summary>
 /// <param name="replacementPolicy">
 /// An <see cref="IReplacementPolicy"/>
 /// </param>
 public EntityCacheBase(IReplacementPolicy replacementPolicy) : this(replacementPolicy, null, null)
 {
 }
예제 #9
0
 /// <summary>
 /// <para>Initialises this instance with the given components.</para>
 /// </summary>
 /// <param name="replacementPolicy">
 /// An <see cref="IReplacementPolicy"/>
 /// </param>
 /// <param name="backingStore">
 /// An <see cref="ICacheBackingStore"/>
 /// </param>
 /// <param name="defaultItemPolicy">
 /// An <see cref="IItemPolicy"/>
 /// </param>
 public EntityCacheBase (IReplacementPolicy replacementPolicy,
                         ICacheBackingStore backingStore,
                         IItemPolicy defaultItemPolicy)
 {
   _disposed = false;
   
   this.SyncRoot = new ReaderWriterLockSlim();
   this.ItemPolicies = new Dictionary<IIdentity, IItemPolicy>();
   
   this.ReplacementPolicy = replacementPolicy;
   this.BackingStore = backingStore;
   this.DefaultItemPolicy = defaultItemPolicy;
   
   this.CacheHit += this.ReplacementPolicy.HandleCacheEvent;
   this.CacheMiss += this.ReplacementPolicy.HandleCacheEvent;
   this.ItemAdded += this.ReplacementPolicy.HandleCacheEvent;
   this.ItemRemoved += this.ReplacementPolicy.HandleCacheEvent;
 }
예제 #10
0
 /// <summary>
 /// <para>Initialises this instance with empty components.</para>
 /// </summary>
 /// <param name="replacementPolicy">
 /// An <see cref="IReplacementPolicy"/>
 /// </param>
 public EntityCacheBase(IReplacementPolicy replacementPolicy) : this(replacementPolicy, null, null) {}