PerfectCacheMemory.hh revision 10441:5377550e1e15
112027Sjungma@eit.uni-kl.de/*
212027Sjungma@eit.uni-kl.de * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
312027Sjungma@eit.uni-kl.de * All rights reserved.
412027Sjungma@eit.uni-kl.de *
512027Sjungma@eit.uni-kl.de * Redistribution and use in source and binary forms, with or without
612027Sjungma@eit.uni-kl.de * modification, are permitted provided that the following conditions are
712027Sjungma@eit.uni-kl.de * met: redistributions of source code must retain the above copyright
812027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer;
912027Sjungma@eit.uni-kl.de * redistributions in binary form must reproduce the above copyright
1012027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer in the
1112027Sjungma@eit.uni-kl.de * documentation and/or other materials provided with the distribution;
1212027Sjungma@eit.uni-kl.de * neither the name of the copyright holders nor the names of its
1312027Sjungma@eit.uni-kl.de * contributors may be used to endorse or promote products derived from
1412027Sjungma@eit.uni-kl.de * this software without specific prior written permission.
1512027Sjungma@eit.uni-kl.de *
1612027Sjungma@eit.uni-kl.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712027Sjungma@eit.uni-kl.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812027Sjungma@eit.uni-kl.de * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912027Sjungma@eit.uni-kl.de * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012027Sjungma@eit.uni-kl.de * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112027Sjungma@eit.uni-kl.de * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212027Sjungma@eit.uni-kl.de * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312027Sjungma@eit.uni-kl.de * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412027Sjungma@eit.uni-kl.de * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512027Sjungma@eit.uni-kl.de * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612027Sjungma@eit.uni-kl.de * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712027Sjungma@eit.uni-kl.de */
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de#ifndef __MEM_RUBY_STRUCTURES_PERFECTCACHEMEMORY_HH__
3012027Sjungma@eit.uni-kl.de#define __MEM_RUBY_STRUCTURES_PERFECTCACHEMEMORY_HH__
3112027Sjungma@eit.uni-kl.de
3212027Sjungma@eit.uni-kl.de#include "base/hashmap.hh"
3312027Sjungma@eit.uni-kl.de#include "mem/protocol/AccessPermission.hh"
3412027Sjungma@eit.uni-kl.de#include "mem/ruby/common/Address.hh"
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.detemplate<class ENTRY>
3712027Sjungma@eit.uni-kl.destruct PerfectCacheLineState
3812027Sjungma@eit.uni-kl.de{
3912027Sjungma@eit.uni-kl.de    PerfectCacheLineState() { m_permission = AccessPermission_NUM; }
4012027Sjungma@eit.uni-kl.de    AccessPermission m_permission;
4112027Sjungma@eit.uni-kl.de    ENTRY m_entry;
4212027Sjungma@eit.uni-kl.de};
4312027Sjungma@eit.uni-kl.de
4412027Sjungma@eit.uni-kl.detemplate<class ENTRY>
4512027Sjungma@eit.uni-kl.deinline std::ostream&
4612027Sjungma@eit.uni-kl.deoperator<<(std::ostream& out, const PerfectCacheLineState<ENTRY>& obj)
4712027Sjungma@eit.uni-kl.de{
4812027Sjungma@eit.uni-kl.de    return out;
4912027Sjungma@eit.uni-kl.de}
5012027Sjungma@eit.uni-kl.de
5112027Sjungma@eit.uni-kl.detemplate<class ENTRY>
5212027Sjungma@eit.uni-kl.declass PerfectCacheMemory
5312027Sjungma@eit.uni-kl.de{
5412027Sjungma@eit.uni-kl.de  public:
5512027Sjungma@eit.uni-kl.de    PerfectCacheMemory();
5612027Sjungma@eit.uni-kl.de
5712027Sjungma@eit.uni-kl.de    // tests to see if an address is present in the cache
5812027Sjungma@eit.uni-kl.de    bool isTagPresent(const Address& address) const;
5912027Sjungma@eit.uni-kl.de
6012027Sjungma@eit.uni-kl.de    // Returns true if there is:
6112027Sjungma@eit.uni-kl.de    //   a) a tag match on this address or there is
6212027Sjungma@eit.uni-kl.de    //   b) an Invalid line in the same cache "way"
6312027Sjungma@eit.uni-kl.de    bool cacheAvail(const Address& address) const;
6412027Sjungma@eit.uni-kl.de
6512027Sjungma@eit.uni-kl.de    // find an Invalid entry and sets the tag appropriate for the address
6612027Sjungma@eit.uni-kl.de    void allocate(const Address& address);
6712027Sjungma@eit.uni-kl.de
6812027Sjungma@eit.uni-kl.de    void deallocate(const Address& address);
6912027Sjungma@eit.uni-kl.de
7012027Sjungma@eit.uni-kl.de    // Returns with the physical address of the conflicting cache line
7112027Sjungma@eit.uni-kl.de    Address cacheProbe(const Address& newAddress) const;
7212027Sjungma@eit.uni-kl.de
7312027Sjungma@eit.uni-kl.de    // looks an address up in the cache
7412027Sjungma@eit.uni-kl.de    ENTRY& lookup(const Address& address);
7512027Sjungma@eit.uni-kl.de    const ENTRY& lookup(const Address& address) const;
7612027Sjungma@eit.uni-kl.de
7712027Sjungma@eit.uni-kl.de    // Get/Set permission of cache block
7812027Sjungma@eit.uni-kl.de    AccessPermission getPermission(const Address& address) const;
7912027Sjungma@eit.uni-kl.de    void changePermission(const Address& address, AccessPermission new_perm);
8012027Sjungma@eit.uni-kl.de
8112027Sjungma@eit.uni-kl.de    // Print cache contents
8212027Sjungma@eit.uni-kl.de    void print(std::ostream& out) const;
8312027Sjungma@eit.uni-kl.de
8412027Sjungma@eit.uni-kl.de  private:
8512027Sjungma@eit.uni-kl.de    // Private copy constructor and assignment operator
8612027Sjungma@eit.uni-kl.de    PerfectCacheMemory(const PerfectCacheMemory& obj);
8712027Sjungma@eit.uni-kl.de    PerfectCacheMemory& operator=(const PerfectCacheMemory& obj);
8812027Sjungma@eit.uni-kl.de
8912027Sjungma@eit.uni-kl.de    // Data Members (m_prefix)
9012027Sjungma@eit.uni-kl.de    m5::hash_map<Address, PerfectCacheLineState<ENTRY> > m_map;
9112027Sjungma@eit.uni-kl.de};
9212027Sjungma@eit.uni-kl.de
9312027Sjungma@eit.uni-kl.detemplate<class ENTRY>
9412027Sjungma@eit.uni-kl.deinline std::ostream&
9512027Sjungma@eit.uni-kl.deoperator<<(std::ostream& out, const PerfectCacheMemory<ENTRY>& obj)
9612027Sjungma@eit.uni-kl.de{
9712027Sjungma@eit.uni-kl.de    obj.print(out);
9812027Sjungma@eit.uni-kl.de    out << std::flush;
9912027Sjungma@eit.uni-kl.de    return out;
10012027Sjungma@eit.uni-kl.de}
10112027Sjungma@eit.uni-kl.de
10212027Sjungma@eit.uni-kl.detemplate<class ENTRY>
10312027Sjungma@eit.uni-kl.deinline
10412027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::PerfectCacheMemory()
10512027Sjungma@eit.uni-kl.de{
10612027Sjungma@eit.uni-kl.de}
10712027Sjungma@eit.uni-kl.de
10812027Sjungma@eit.uni-kl.de// tests to see if an address is present in the cache
10912027Sjungma@eit.uni-kl.detemplate<class ENTRY>
11012027Sjungma@eit.uni-kl.deinline bool
11112027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::isTagPresent(const Address& address) const
11212027Sjungma@eit.uni-kl.de{
11312027Sjungma@eit.uni-kl.de    return m_map.count(line_address(address)) > 0;
11412027Sjungma@eit.uni-kl.de}
11512027Sjungma@eit.uni-kl.de
11612027Sjungma@eit.uni-kl.detemplate<class ENTRY>
11712027Sjungma@eit.uni-kl.deinline bool
11812027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::cacheAvail(const Address& address) const
11912027Sjungma@eit.uni-kl.de{
12012027Sjungma@eit.uni-kl.de    return true;
12112027Sjungma@eit.uni-kl.de}
12212027Sjungma@eit.uni-kl.de
12312027Sjungma@eit.uni-kl.de// find an Invalid or already allocated entry and sets the tag
12412027Sjungma@eit.uni-kl.de// appropriate for the address
12512027Sjungma@eit.uni-kl.detemplate<class ENTRY>
12612027Sjungma@eit.uni-kl.deinline void
12712027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::allocate(const Address& address)
12812027Sjungma@eit.uni-kl.de{
12912027Sjungma@eit.uni-kl.de    PerfectCacheLineState<ENTRY> line_state;
13012027Sjungma@eit.uni-kl.de    line_state.m_permission = AccessPermission_Invalid;
13112027Sjungma@eit.uni-kl.de    line_state.m_entry = ENTRY();
13212027Sjungma@eit.uni-kl.de    m_map[line_address(address)] = line_state;
13312027Sjungma@eit.uni-kl.de}
13412027Sjungma@eit.uni-kl.de
13512027Sjungma@eit.uni-kl.de// deallocate entry
13612027Sjungma@eit.uni-kl.detemplate<class ENTRY>
13712027Sjungma@eit.uni-kl.deinline void
13812027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::deallocate(const Address& address)
13912027Sjungma@eit.uni-kl.de{
14012027Sjungma@eit.uni-kl.de    m_map.erase(line_address(address));
14112027Sjungma@eit.uni-kl.de}
14212027Sjungma@eit.uni-kl.de
14312027Sjungma@eit.uni-kl.de// Returns with the physical address of the conflicting cache line
14412027Sjungma@eit.uni-kl.detemplate<class ENTRY>
14512027Sjungma@eit.uni-kl.deinline Address
14612027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::cacheProbe(const Address& newAddress) const
14712027Sjungma@eit.uni-kl.de{
14812027Sjungma@eit.uni-kl.de    panic("cacheProbe called in perfect cache");
14912027Sjungma@eit.uni-kl.de    return newAddress;
15012027Sjungma@eit.uni-kl.de}
15112027Sjungma@eit.uni-kl.de
15212027Sjungma@eit.uni-kl.de// looks an address up in the cache
15312027Sjungma@eit.uni-kl.detemplate<class ENTRY>
15412027Sjungma@eit.uni-kl.deinline ENTRY&
15512027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::lookup(const Address& address)
15612027Sjungma@eit.uni-kl.de{
15712027Sjungma@eit.uni-kl.de    return m_map[line_address(address)].m_entry;
15812027Sjungma@eit.uni-kl.de}
15912027Sjungma@eit.uni-kl.de
16012027Sjungma@eit.uni-kl.de// looks an address up in the cache
16112027Sjungma@eit.uni-kl.detemplate<class ENTRY>
16212027Sjungma@eit.uni-kl.deinline const ENTRY&
16312027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::lookup(const Address& address) const
16412027Sjungma@eit.uni-kl.de{
16512027Sjungma@eit.uni-kl.de    return m_map[line_address(address)].m_entry;
16612027Sjungma@eit.uni-kl.de}
16712027Sjungma@eit.uni-kl.de
16812027Sjungma@eit.uni-kl.detemplate<class ENTRY>
16912027Sjungma@eit.uni-kl.deinline AccessPermission
17012027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::getPermission(const Address& address) const
17112027Sjungma@eit.uni-kl.de{
17212027Sjungma@eit.uni-kl.de    return m_map[line_address(address)].m_permission;
17312027Sjungma@eit.uni-kl.de}
17412027Sjungma@eit.uni-kl.de
17512027Sjungma@eit.uni-kl.detemplate<class ENTRY>
17612027Sjungma@eit.uni-kl.deinline void
17712027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::changePermission(const Address& address,
17812027Sjungma@eit.uni-kl.de                                            AccessPermission new_perm)
17912027Sjungma@eit.uni-kl.de{
18012027Sjungma@eit.uni-kl.de    Address line_address = address;
18112027Sjungma@eit.uni-kl.de    line_address.makeLineAddress();
18212027Sjungma@eit.uni-kl.de    PerfectCacheLineState<ENTRY>& line_state = m_map[line_address];
18312027Sjungma@eit.uni-kl.de    line_state.m_permission = new_perm;
18412027Sjungma@eit.uni-kl.de}
18512027Sjungma@eit.uni-kl.de
18612027Sjungma@eit.uni-kl.detemplate<class ENTRY>
18712027Sjungma@eit.uni-kl.deinline void
18812027Sjungma@eit.uni-kl.dePerfectCacheMemory<ENTRY>::print(std::ostream& out) const
18912027Sjungma@eit.uni-kl.de{
19012027Sjungma@eit.uni-kl.de}
19112027Sjungma@eit.uni-kl.de
19212027Sjungma@eit.uni-kl.de#endif // __MEM_RUBY_STRUCTURES_PERFECTCACHEMEMORY_HH__
19312027Sjungma@eit.uni-kl.de