CacheMemory.hh revision 8174
12155SN/A/* 22155SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 32155SN/A * All rights reserved. 42155SN/A * 52155SN/A * Redistribution and use in source and binary forms, with or without 62155SN/A * modification, are permitted provided that the following conditions are 72155SN/A * met: redistributions of source code must retain the above copyright 82155SN/A * notice, this list of conditions and the following disclaimer; 92155SN/A * redistributions in binary form must reproduce the above copyright 102155SN/A * notice, this list of conditions and the following disclaimer in the 112155SN/A * documentation and/or other materials provided with the distribution; 122155SN/A * neither the name of the copyright holders nor the names of its 132155SN/A * contributors may be used to endorse or promote products derived from 142155SN/A * this software without specific prior written permission. 152155SN/A * 162155SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172155SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182155SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192155SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202155SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212155SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222155SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232155SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242155SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252155SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262155SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272155SN/A */ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu#ifndef __MEM_RUBY_SYSTEM_CACHEMEMORY_HH__ 302155SN/A#define __MEM_RUBY_SYSTEM_CACHEMEMORY_HH__ 314202Sbinkertn@umich.edu 322155SN/A#include <iostream> 332178SN/A#include <string> 342178SN/A#include <vector> 352178SN/A 362178SN/A#include "base/hashmap.hh" 372178SN/A#include "mem/protocol/AccessPermission.hh" 382178SN/A#include "mem/protocol/RubyRequest.hh" 392178SN/A#include "mem/protocol/RubyRequestType.hh" 402178SN/A#include "mem/protocol/GenericRequestType.hh" 412178SN/A#include "mem/protocol/MachineType.hh" 422178SN/A#include "mem/ruby/common/Address.hh" 432178SN/A#include "mem/ruby/common/DataBlock.hh" 442178SN/A#include "mem/ruby/common/Global.hh" 452155SN/A#include "mem/ruby/profiler/CacheProfiler.hh" 462178SN/A#include "mem/ruby/recorder/CacheRecorder.hh" 472155SN/A#include "mem/ruby/slicc_interface/AbstractCacheEntry.hh" 482155SN/A#include "mem/ruby/slicc_interface/AbstractController.hh" 492178SN/A#include "mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh" 502155SN/A#include "mem/ruby/system/LRUPolicy.hh" 515865Sksewell@umich.edu#include "mem/ruby/system/PseudoLRUPolicy.hh" 526181Sksewell@umich.edu#include "mem/ruby/system/System.hh" 536181Sksewell@umich.edu#include "params/RubyCache.hh" 545865Sksewell@umich.edu#include "sim/sim_object.hh" 553918Ssaidi@eecs.umich.edu 565865Sksewell@umich.educlass CacheMemory : public SimObject 572623SN/A{ 583918Ssaidi@eecs.umich.edu public: 592155SN/A typedef RubyCacheParams Params; 602155SN/A CacheMemory(const Params *p); 612292SN/A ~CacheMemory(); 626181Sksewell@umich.edu 636181Sksewell@umich.edu void init(); 643918Ssaidi@eecs.umich.edu 652292SN/A // Public Methods 662292SN/A void printConfig(std::ostream& out); 672292SN/A 683918Ssaidi@eecs.umich.edu // perform a cache access and see if we hit or not. Return true on a hit. 692292SN/A bool tryCacheAccess(const Address& address, RubyRequestType type, 702292SN/A DataBlock*& data_ptr); 712766Sktlim@umich.edu 722766Sktlim@umich.edu // similar to above, but doesn't require full access check 732766Sktlim@umich.edu bool testCacheAccess(const Address& address, RubyRequestType type, 742921Sktlim@umich.edu DataBlock*& data_ptr); 752921Sktlim@umich.edu 762766Sktlim@umich.edu // tests to see if an address is present in the cache 772766Sktlim@umich.edu bool isTagPresent(const Address& address) const; 785529Snate@binkert.org 792766Sktlim@umich.edu // Returns true if there is: 804762Snate@binkert.org // a) a tag match on this address or there is 812155SN/A // b) an unused line in the same cache "way" 822155SN/A bool cacheAvail(const Address& address) const; 832155SN/A 842155SN/A // find an unused entry and sets the tag appropriate for the address 852155SN/A AbstractCacheEntry* allocate(const Address& address, AbstractCacheEntry* new_entry); 862155SN/A 872766Sktlim@umich.edu // Explicitly free up this address 882155SN/A void deallocate(const Address& address); 895865Sksewell@umich.edu 902155SN/A // Returns with the physical address of the conflicting cache line 912155SN/A Address cacheProbe(const Address& address) const; 922155SN/A 932155SN/A // looks an address up in the cache 942178SN/A AbstractCacheEntry* lookup(const Address& address); 952178SN/A const AbstractCacheEntry* lookup(const Address& address) const; 962178SN/A 972766Sktlim@umich.edu int getLatency() const { return m_latency; } 982178SN/A 992178SN/A // Hook for checkpointing the contents of the cache 1002178SN/A void recordCacheContents(CacheRecorder& tr) const; 1012178SN/A void 1022766Sktlim@umich.edu setAsInstructionCache(bool is_icache) 1032766Sktlim@umich.edu { 1042766Sktlim@umich.edu m_is_instruction_only_cache = is_icache; 1052788Sktlim@umich.edu } 1062178SN/A 1072733Sktlim@umich.edu // Set this address to most recently used 1082733Sktlim@umich.edu void setMRU(const Address& address); 1092817Sksewell@umich.edu 1102733Sktlim@umich.edu void profileMiss(const RubyRequest & msg); 1114486Sbinkertn@umich.edu 1124486Sbinkertn@umich.edu void profileGenericRequest(GenericRequestType requestType, 1134776Sgblack@eecs.umich.edu RubyAccessMode accessType, 1144776Sgblack@eecs.umich.edu PrefetchBit pfBit); 1156365Sgblack@eecs.umich.edu 1164486Sbinkertn@umich.edu void getMemoryValue(const Address& addr, char* value, 1174202Sbinkertn@umich.edu unsigned int size_in_bytes); 1184202Sbinkertn@umich.edu void setMemoryValue(const Address& addr, char* value, 1194202Sbinkertn@umich.edu unsigned int size_in_bytes); 1204202Sbinkertn@umich.edu 1214202Sbinkertn@umich.edu void setLocked (const Address& addr, int context); 1224776Sgblack@eecs.umich.edu void clearLocked (const Address& addr); 1236365Sgblack@eecs.umich.edu bool isLocked (const Address& addr, int context); 1244202Sbinkertn@umich.edu // Print cache contents 1254202Sbinkertn@umich.edu void print(std::ostream& out) const; 1264202Sbinkertn@umich.edu void printData(std::ostream& out) const; 1274202Sbinkertn@umich.edu 1285217Ssaidi@eecs.umich.edu void clearStats() const; 1294202Sbinkertn@umich.edu void printStats(std::ostream& out) const; 1302155SN/A 1314202Sbinkertn@umich.edu private: 1324486Sbinkertn@umich.edu // convert a Address to its location in the cache 1334486Sbinkertn@umich.edu Index addressToCacheSet(const Address& address) const; 1344202Sbinkertn@umich.edu 1354202Sbinkertn@umich.edu // Given a cache tag: returns the index of the tag in a set. 1362821Sktlim@umich.edu // returns -1 if the tag is not found. 1374776Sgblack@eecs.umich.edu int findTagInSet(Index line, const Address& tag) const; 1384776Sgblack@eecs.umich.edu int findTagInSetIgnorePermissions(Index cacheSet, 1394776Sgblack@eecs.umich.edu const Address& tag) const; 1404776Sgblack@eecs.umich.edu 1412766Sktlim@umich.edu // Private copy constructor and assignment operator 1424202Sbinkertn@umich.edu CacheMemory(const CacheMemory& obj); 1435192Ssaidi@eecs.umich.edu CacheMemory& operator=(const CacheMemory& obj); 1442733Sktlim@umich.edu 1452733Sktlim@umich.edu private: 1462733Sktlim@umich.edu const std::string m_cache_name; 1472733Sktlim@umich.edu int m_latency; 1482733Sktlim@umich.edu 1492874Sktlim@umich.edu // Data Members (m_prefix) 1502874Sktlim@umich.edu bool m_is_instruction_only_cache; 1512874Sktlim@umich.edu bool m_is_data_only_cache; 1524202Sbinkertn@umich.edu 1532733Sktlim@umich.edu // The first index is the # of cache lines. 1545192Ssaidi@eecs.umich.edu // The second index is the the amount associativity. 1555192Ssaidi@eecs.umich.edu m5::hash_map<Address, int> m_tag_index; 1565192Ssaidi@eecs.umich.edu std::vector<std::vector<AbstractCacheEntry*> > m_cache; 1575217Ssaidi@eecs.umich.edu 1585192Ssaidi@eecs.umich.edu AbstractReplacementPolicy *m_replacementPolicy_ptr; 1595192Ssaidi@eecs.umich.edu 1605192Ssaidi@eecs.umich.edu CacheProfiler* m_profiler_ptr; 1615192Ssaidi@eecs.umich.edu 1625192Ssaidi@eecs.umich.edu int m_cache_size; 1636667Ssteve.reinhardt@amd.com std::string m_policy; 1645192Ssaidi@eecs.umich.edu int m_cache_num_sets; 1655192Ssaidi@eecs.umich.edu int m_cache_num_set_bits; 1665192Ssaidi@eecs.umich.edu int m_cache_assoc; 1675192Ssaidi@eecs.umich.edu int m_start_index_bit; 1685192Ssaidi@eecs.umich.edu}; 1695192Ssaidi@eecs.umich.edu 1705192Ssaidi@eecs.umich.edu#endif // __MEM_RUBY_SYSTEM_CACHEMEMORY_HH__ 1715192Ssaidi@eecs.umich.edu 1725784Sgblack@eecs.umich.edu