PerfectCacheMemory.hh revision 7805
12817Sksewell@umich.edu/*
22817Sksewell@umich.edu * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
32817Sksewell@umich.edu * All rights reserved.
42817Sksewell@umich.edu *
52817Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
62817Sksewell@umich.edu * modification, are permitted provided that the following conditions are
72817Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
82817Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
92817Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
102817Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
112817Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
122817Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
132817Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
142817Sksewell@umich.edu * this software without specific prior written permission.
152817Sksewell@umich.edu *
162817Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172817Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182817Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192817Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202817Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212817Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222817Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232817Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242817Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252817Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262817Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272817Sksewell@umich.edu */
282817Sksewell@umich.edu
292817Sksewell@umich.edu#ifndef __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__
302817Sksewell@umich.edu#define __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__
312817Sksewell@umich.edu
322817Sksewell@umich.edu#include "base/hashmap.hh"
332834Sksewell@umich.edu#include "mem/protocol/AccessPermission.hh"
342817Sksewell@umich.edu#include "mem/ruby/common/Address.hh"
352817Sksewell@umich.edu#include "mem/ruby/common/Global.hh"
362817Sksewell@umich.edu
372817Sksewell@umich.edutemplate<class ENTRY>
382817Sksewell@umich.edustruct PerfectCacheLineState
392817Sksewell@umich.edu{
402817Sksewell@umich.edu    PerfectCacheLineState() { m_permission = AccessPermission_NUM; }
412817Sksewell@umich.edu    AccessPermission m_permission;
422817Sksewell@umich.edu    ENTRY m_entry;
432817Sksewell@umich.edu};
442817Sksewell@umich.edu
452817Sksewell@umich.edutemplate<class ENTRY>
462817Sksewell@umich.eduinline std::ostream&
472817Sksewell@umich.eduoperator<<(std::ostream& out, const PerfectCacheLineState<ENTRY>& obj)
482817Sksewell@umich.edu{
492817Sksewell@umich.edu    return out;
502817Sksewell@umich.edu}
512817Sksewell@umich.edu
522817Sksewell@umich.edutemplate<class ENTRY>
532817Sksewell@umich.educlass PerfectCacheMemory
542817Sksewell@umich.edu{
552817Sksewell@umich.edu  public:
562817Sksewell@umich.edu    PerfectCacheMemory();
573126Sktlim@umich.edu
582817Sksewell@umich.edu    static void printConfig(std::ostream& out);
592817Sksewell@umich.edu
602817Sksewell@umich.edu    // perform a cache access and see if we hit or not.  Return true
612817Sksewell@umich.edu    // on a hit.
622817Sksewell@umich.edu    bool tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry);
632817Sksewell@umich.edu
642817Sksewell@umich.edu    // tests to see if an address is present in the cache
652817Sksewell@umich.edu    bool isTagPresent(const Address& address) const;
662817Sksewell@umich.edu
672817Sksewell@umich.edu    // Returns true if there is:
682817Sksewell@umich.edu    //   a) a tag match on this address or there is
692817Sksewell@umich.edu    //   b) an Invalid line in the same cache "way"
702817Sksewell@umich.edu    bool cacheAvail(const Address& address) const;
712817Sksewell@umich.edu
722817Sksewell@umich.edu    // find an Invalid entry and sets the tag appropriate for the address
732817Sksewell@umich.edu    void allocate(const Address& address);
742817Sksewell@umich.edu
752817Sksewell@umich.edu    void deallocate(const Address& address);
762817Sksewell@umich.edu
772817Sksewell@umich.edu    // Returns with the physical address of the conflicting cache line
782817Sksewell@umich.edu    Address cacheProbe(const Address& newAddress) const;
792817Sksewell@umich.edu
802817Sksewell@umich.edu    // looks an address up in the cache
812817Sksewell@umich.edu    ENTRY& lookup(const Address& address);
822817Sksewell@umich.edu    const ENTRY& lookup(const Address& address) const;
832817Sksewell@umich.edu
842817Sksewell@umich.edu    // Get/Set permission of cache block
852817Sksewell@umich.edu    AccessPermission getPermission(const Address& address) const;
862817Sksewell@umich.edu    void changePermission(const Address& address, AccessPermission new_perm);
872817Sksewell@umich.edu
882817Sksewell@umich.edu    // Print cache contents
892817Sksewell@umich.edu    void print(std::ostream& out) const;
902817Sksewell@umich.edu
912817Sksewell@umich.edu  private:
922817Sksewell@umich.edu    // Private copy constructor and assignment operator
932817Sksewell@umich.edu    PerfectCacheMemory(const PerfectCacheMemory& obj);
942817Sksewell@umich.edu    PerfectCacheMemory& operator=(const PerfectCacheMemory& obj);
952817Sksewell@umich.edu
962817Sksewell@umich.edu    // Data Members (m_prefix)
972817Sksewell@umich.edu    m5::hash_map<Address, PerfectCacheLineState<ENTRY> > m_map;
982817Sksewell@umich.edu};
992817Sksewell@umich.edu
1002817Sksewell@umich.edutemplate<class ENTRY>
1012817Sksewell@umich.eduinline std::ostream&
1022817Sksewell@umich.eduoperator<<(std::ostream& out, const PerfectCacheMemory<ENTRY>& obj)
1032817Sksewell@umich.edu{
1042817Sksewell@umich.edu    obj.print(out);
1052817Sksewell@umich.edu    out << std::flush;
1062817Sksewell@umich.edu    return out;
1072817Sksewell@umich.edu}
1082817Sksewell@umich.edu
1092817Sksewell@umich.edutemplate<class ENTRY>
1102817Sksewell@umich.eduinline
1112817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::PerfectCacheMemory()
1122817Sksewell@umich.edu{
1132817Sksewell@umich.edu}
1142817Sksewell@umich.edu
1152817Sksewell@umich.edutemplate<class ENTRY>
1162875Sksewell@umich.eduinline void
1172875Sksewell@umich.eduPerfectCacheMemory<ENTRY>::printConfig(std::ostream& out)
1182817Sksewell@umich.edu{
1192817Sksewell@umich.edu}
1202817Sksewell@umich.edu
1212817Sksewell@umich.edutemplate<class ENTRY>
1222817Sksewell@umich.eduinline bool
1232817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::tryCacheAccess(const CacheMsg& msg,
1242817Sksewell@umich.edu                                          bool& block_stc, ENTRY*& entry)
1252817Sksewell@umich.edu{
1262817Sksewell@umich.edu    panic("not implemented");
1272817Sksewell@umich.edu}
1282817Sksewell@umich.edu
1292817Sksewell@umich.edu// tests to see if an address is present in the cache
1302817Sksewell@umich.edutemplate<class ENTRY>
1312817Sksewell@umich.eduinline bool
1322817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::isTagPresent(const Address& address) const
1332817Sksewell@umich.edu{
1342817Sksewell@umich.edu    return m_map.count(line_address(address)) > 0;
1352817Sksewell@umich.edu}
1362817Sksewell@umich.edu
1372817Sksewell@umich.edutemplate<class ENTRY>
1382817Sksewell@umich.eduinline bool
1392817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::cacheAvail(const Address& address) const
1402817Sksewell@umich.edu{
1412875Sksewell@umich.edu    return true;
1422875Sksewell@umich.edu}
1432817Sksewell@umich.edu
1442817Sksewell@umich.edu// find an Invalid or already allocated entry and sets the tag
1452817Sksewell@umich.edu// appropriate for the address
1462817Sksewell@umich.edutemplate<class ENTRY>
1472817Sksewell@umich.eduinline void
1482817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::allocate(const Address& address)
1492817Sksewell@umich.edu{
1502817Sksewell@umich.edu    PerfectCacheLineState<ENTRY> line_state;
1512817Sksewell@umich.edu    line_state.m_permission = AccessPermission_Busy;
1522817Sksewell@umich.edu    line_state.m_entry = ENTRY();
1532817Sksewell@umich.edu    m_map[line_address(address)] = line_state;
1542817Sksewell@umich.edu}
1552817Sksewell@umich.edu
1562817Sksewell@umich.edu// deallocate entry
1572817Sksewell@umich.edutemplate<class ENTRY>
1582817Sksewell@umich.eduinline void
1592817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::deallocate(const Address& address)
1602817Sksewell@umich.edu{
1612817Sksewell@umich.edu    m_map.erase(line_address(address));
1622817Sksewell@umich.edu}
1632817Sksewell@umich.edu
1642817Sksewell@umich.edu// Returns with the physical address of the conflicting cache line
1652817Sksewell@umich.edutemplate<class ENTRY>
1662875Sksewell@umich.eduinline Address
1672817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::cacheProbe(const Address& newAddress) const
1683221Sktlim@umich.edu{
1693221Sktlim@umich.edu    panic("cacheProbe called in perfect cache");
1702817Sksewell@umich.edu}
1712817Sksewell@umich.edu
1722817Sksewell@umich.edu// looks an address up in the cache
1732817Sksewell@umich.edutemplate<class ENTRY>
1742817Sksewell@umich.eduinline ENTRY&
1753221Sktlim@umich.eduPerfectCacheMemory<ENTRY>::lookup(const Address& address)
1762817Sksewell@umich.edu{
1772817Sksewell@umich.edu    return m_map[line_address(address)].m_entry;
1782817Sksewell@umich.edu}
1792817Sksewell@umich.edu
1802817Sksewell@umich.edu// looks an address up in the cache
1812817Sksewell@umich.edutemplate<class ENTRY>
1822875Sksewell@umich.eduinline const ENTRY&
1832875Sksewell@umich.eduPerfectCacheMemory<ENTRY>::lookup(const Address& address) const
1842817Sksewell@umich.edu{
1852817Sksewell@umich.edu    return m_map[line_address(address)].m_entry;
1862817Sksewell@umich.edu}
1872817Sksewell@umich.edu
1882817Sksewell@umich.edutemplate<class ENTRY>
1892817Sksewell@umich.eduinline AccessPermission
1902817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::getPermission(const Address& address) const
1912817Sksewell@umich.edu{
1922817Sksewell@umich.edu    return m_map[line_address(address)].m_permission;
1932817Sksewell@umich.edu}
1942817Sksewell@umich.edu
1952817Sksewell@umich.edutemplate<class ENTRY>
1962817Sksewell@umich.eduinline void
1972817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::changePermission(const Address& address,
1982817Sksewell@umich.edu                                            AccessPermission new_perm)
1992817Sksewell@umich.edu{
2002817Sksewell@umich.edu    Address line_address = address;
2012817Sksewell@umich.edu    line_address.makeLineAddress();
2022817Sksewell@umich.edu    PerfectCacheLineState<ENTRY>& line_state = m_map[line_address];
2032817Sksewell@umich.edu    AccessPermission old_perm = line_state.m_permission;
2042817Sksewell@umich.edu    line_state.m_permission = new_perm;
2052817Sksewell@umich.edu}
2062817Sksewell@umich.edu
2072817Sksewell@umich.edutemplate<class ENTRY>
2082817Sksewell@umich.eduinline void
2092817Sksewell@umich.eduPerfectCacheMemory<ENTRY>::print(std::ostream& out) const
2102817Sksewell@umich.edu{
2112817Sksewell@umich.edu}
2122817Sksewell@umich.edu
2132817Sksewell@umich.edu#endif // __MEM_RUBY_SYSTEM_PERFECTCACHEMEMORY_HH__
2142817Sksewell@umich.edu