PerfectCacheMemory.hh revision 7055
112854Sgabeblack@google.com/* 212854Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 312854Sgabeblack@google.com * All rights reserved. 412854Sgabeblack@google.com * 512854Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612854Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712854Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812854Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912854Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012854Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112854Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212854Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312854Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412854Sgabeblack@google.com * this software without specific prior written permission. 1512854Sgabeblack@google.com * 1612854Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712854Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812854Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912854Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012854Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112854Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212854Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312854Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412854Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512854Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612854Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712854Sgabeblack@google.com */ 2812854Sgabeblack@google.com 2912854Sgabeblack@google.com#ifndef __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__ 3012854Sgabeblack@google.com#define __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__ 3112854Sgabeblack@google.com 3212854Sgabeblack@google.com#include "mem/gems_common/Map.hh" 3312854Sgabeblack@google.com#include "mem/protocol/AccessPermission.hh" 3412854Sgabeblack@google.com#include "mem/ruby/common/Address.hh" 3512854Sgabeblack@google.com#include "mem/ruby/common/Global.hh" 3612854Sgabeblack@google.com 3712854Sgabeblack@google.comtemplate<class ENTRY> 3812854Sgabeblack@google.comstruct PerfectCacheLineState 3912854Sgabeblack@google.com{ 4012854Sgabeblack@google.com PerfectCacheLineState() { m_permission = AccessPermission_NUM; } 4112854Sgabeblack@google.com AccessPermission m_permission; 4212854Sgabeblack@google.com ENTRY m_entry; 4312854Sgabeblack@google.com}; 4412854Sgabeblack@google.com 4512854Sgabeblack@google.comtemplate<class ENTRY> 4612854Sgabeblack@google.cominline std::ostream& 4712854Sgabeblack@google.comoperator<<(std::ostream& out, const PerfectCacheLineState<ENTRY>& obj) 4812854Sgabeblack@google.com{ 4912854Sgabeblack@google.com return out; 5012854Sgabeblack@google.com} 5112854Sgabeblack@google.com 5212854Sgabeblack@google.comtemplate<class ENTRY> 5312854Sgabeblack@google.comclass PerfectCacheMemory 5412854Sgabeblack@google.com{ 5512854Sgabeblack@google.com public: 5612854Sgabeblack@google.com PerfectCacheMemory(); 5712854Sgabeblack@google.com 5812854Sgabeblack@google.com static void printConfig(std::ostream& out); 5912854Sgabeblack@google.com 6012854Sgabeblack@google.com // perform a cache access and see if we hit or not. Return true 6112854Sgabeblack@google.com // on a hit. 6212854Sgabeblack@google.com bool tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry); 6312854Sgabeblack@google.com 6412854Sgabeblack@google.com // tests to see if an address is present in the cache 6512854Sgabeblack@google.com bool isTagPresent(const Address& address) const; 6612854Sgabeblack@google.com 67 // Returns true if there is: 68 // a) a tag match on this address or there is 69 // b) an Invalid line in the same cache "way" 70 bool cacheAvail(const Address& address) const; 71 72 // find an Invalid entry and sets the tag appropriate for the address 73 void allocate(const Address& address); 74 75 void deallocate(const Address& address); 76 77 // Returns with the physical address of the conflicting cache line 78 Address cacheProbe(const Address& newAddress) const; 79 80 // looks an address up in the cache 81 ENTRY& lookup(const Address& address); 82 const ENTRY& lookup(const Address& address) const; 83 84 // Get/Set permission of cache block 85 AccessPermission getPermission(const Address& address) const; 86 void changePermission(const Address& address, AccessPermission new_perm); 87 88 // Print cache contents 89 void print(std::ostream& out) const; 90 91 private: 92 // Private copy constructor and assignment operator 93 PerfectCacheMemory(const PerfectCacheMemory& obj); 94 PerfectCacheMemory& operator=(const PerfectCacheMemory& obj); 95 96 // Data Members (m_prefix) 97 Map<Address, PerfectCacheLineState<ENTRY> > m_map; 98}; 99 100template<class ENTRY> 101inline std::ostream& 102operator<<(std::ostream& out, const PerfectCacheMemory<ENTRY>& obj) 103{ 104 obj.print(out); 105 out << std::flush; 106 return out; 107} 108 109template<class ENTRY> 110inline 111PerfectCacheMemory<ENTRY>::PerfectCacheMemory() 112{ 113} 114 115template<class ENTRY> 116inline void 117PerfectCacheMemory<ENTRY>::printConfig(std::ostream& out) 118{ 119} 120 121template<class ENTRY> 122inline bool 123PerfectCacheMemory<ENTRY>::tryCacheAccess(const CacheMsg& msg, 124 bool& block_stc, ENTRY*& entry) 125{ 126 ERROR_MSG("not implemented"); 127} 128 129// tests to see if an address is present in the cache 130template<class ENTRY> 131inline bool 132PerfectCacheMemory<ENTRY>::isTagPresent(const Address& address) const 133{ 134 return m_map.exist(line_address(address)); 135} 136 137template<class ENTRY> 138inline bool 139PerfectCacheMemory<ENTRY>::cacheAvail(const Address& address) const 140{ 141 return true; 142} 143 144// find an Invalid or already allocated entry and sets the tag 145// appropriate for the address 146template<class ENTRY> 147inline void 148PerfectCacheMemory<ENTRY>::allocate(const Address& address) 149{ 150 PerfectCacheLineState<ENTRY> line_state; 151 line_state.m_permission = AccessPermission_Busy; 152 line_state.m_entry = ENTRY(); 153 m_map.add(line_address(address), line_state); 154} 155 156// deallocate entry 157template<class ENTRY> 158inline void 159PerfectCacheMemory<ENTRY>::deallocate(const Address& address) 160{ 161 m_map.erase(line_address(address)); 162} 163 164// Returns with the physical address of the conflicting cache line 165template<class ENTRY> 166inline Address 167PerfectCacheMemory<ENTRY>::cacheProbe(const Address& newAddress) const 168{ 169 ERROR_MSG("cacheProbe called in perfect cache"); 170} 171 172// looks an address up in the cache 173template<class ENTRY> 174inline ENTRY& 175PerfectCacheMemory<ENTRY>::lookup(const Address& address) 176{ 177 return m_map.lookup(line_address(address)).m_entry; 178} 179 180// looks an address up in the cache 181template<class ENTRY> 182inline const ENTRY& 183PerfectCacheMemory<ENTRY>::lookup(const Address& address) const 184{ 185 return m_map.lookup(line_address(address)).m_entry; 186} 187 188template<class ENTRY> 189inline AccessPermission 190PerfectCacheMemory<ENTRY>::getPermission(const Address& address) const 191{ 192 return m_map.lookup(line_address(address)).m_permission; 193} 194 195template<class ENTRY> 196inline void 197PerfectCacheMemory<ENTRY>::changePermission(const Address& address, 198 AccessPermission new_perm) 199{ 200 Address line_address = address; 201 line_address.makeLineAddress(); 202 PerfectCacheLineState<ENTRY>& line_state = m_map.lookup(line_address); 203 AccessPermission old_perm = line_state.m_permission; 204 line_state.m_permission = new_perm; 205} 206 207template<class ENTRY> 208inline void 209PerfectCacheMemory<ENTRY>::print(std::ostream& out) const 210{ 211} 212 213#endif // __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__ 214