CheckTable.cc revision 10348
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
312855Sgabeblack@google.com * Copyright (c) 2009 Advanced Micro Devices, Inc.
412855Sgabeblack@google.com * All rights reserved.
512855Sgabeblack@google.com *
612855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
712855Sgabeblack@google.com * modification, are permitted provided that the following conditions are
812855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
912855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1012855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1112855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1212855Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1312855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1412855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1512855Sgabeblack@google.com * this software without specific prior written permission.
1612855Sgabeblack@google.com *
1712855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812855Sgabeblack@google.com */
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com#include "base/intmath.hh"
3112855Sgabeblack@google.com#include "base/random.hh"
3212855Sgabeblack@google.com#include "cpu/testers/rubytest/Check.hh"
3312855Sgabeblack@google.com#include "cpu/testers/rubytest/CheckTable.hh"
3412855Sgabeblack@google.com#include "debug/RubyTest.hh"
3512855Sgabeblack@google.com
3612855Sgabeblack@google.comCheckTable::CheckTable(int _num_writers, int _num_readers, RubyTester* _tester)
3712855Sgabeblack@google.com    : m_num_writers(_num_writers), m_num_readers(_num_readers),
3812855Sgabeblack@google.com      m_tester_ptr(_tester)
3912855Sgabeblack@google.com{
4012855Sgabeblack@google.com    physical_address_t physical = 0;
4112855Sgabeblack@google.com    Address address;
4212855Sgabeblack@google.com
4312855Sgabeblack@google.com    const int size1 = 32;
4412855Sgabeblack@google.com    const int size2 = 100;
4512855Sgabeblack@google.com
4612855Sgabeblack@google.com    // The first set is to get some false sharing
4712855Sgabeblack@google.com    physical = 1000;
4812855Sgabeblack@google.com    for (int i = 0; i < size1; i++) {
4912855Sgabeblack@google.com        // Setup linear addresses
5012855Sgabeblack@google.com        address.setAddress(physical);
5112855Sgabeblack@google.com        addCheck(address);
5212855Sgabeblack@google.com        physical += CHECK_SIZE;
5312855Sgabeblack@google.com    }
5412855Sgabeblack@google.com
5512855Sgabeblack@google.com    // The next two sets are to get some limited false sharing and
5612855Sgabeblack@google.com    // cache conflicts
5712855Sgabeblack@google.com    physical = 1000;
5812855Sgabeblack@google.com    for (int i = 0; i < size2; i++) {
5912855Sgabeblack@google.com        // Setup linear addresses
6012855Sgabeblack@google.com        address.setAddress(physical);
6112855Sgabeblack@google.com        addCheck(address);
6212855Sgabeblack@google.com        physical += 256;
6312855Sgabeblack@google.com    }
6412855Sgabeblack@google.com
6512855Sgabeblack@google.com    physical = 1000 + CHECK_SIZE;
6612855Sgabeblack@google.com    for (int i = 0; i < size2; i++) {
6712855Sgabeblack@google.com        // Setup linear addresses
6812855Sgabeblack@google.com        address.setAddress(physical);
6912855Sgabeblack@google.com        addCheck(address);
70        physical += 256;
71    }
72}
73
74CheckTable::~CheckTable()
75{
76    int size = m_check_vector.size();
77    for (int i = 0; i < size; i++)
78        delete m_check_vector[i];
79}
80
81void
82CheckTable::addCheck(const Address& address)
83{
84    if (floorLog2(CHECK_SIZE) != 0) {
85        if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) {
86            panic("Check not aligned");
87        }
88    }
89
90    for (int i = 0; i < CHECK_SIZE; i++) {
91        if (m_lookup_map.count(Address(address.getAddress()+i))) {
92            // A mapping for this byte already existed, discard the
93            // entire check
94            return;
95        }
96    }
97
98    Check* check_ptr = new Check(address, Address(100 + m_check_vector.size()),
99                                 m_num_writers, m_num_readers, m_tester_ptr);
100    for (int i = 0; i < CHECK_SIZE; i++) {
101        // Insert it once per byte
102        m_lookup_map[Address(address.getAddress() + i)] = check_ptr;
103    }
104    m_check_vector.push_back(check_ptr);
105}
106
107Check*
108CheckTable::getRandomCheck()
109{
110    assert(m_check_vector.size() > 0);
111    return m_check_vector[random_mt.random<unsigned>(0, m_check_vector.size() - 1)];
112}
113
114Check*
115CheckTable::getCheck(const Address& address)
116{
117    DPRINTF(RubyTest, "Looking for check by address: %s", address);
118
119    m5::hash_map<Address, Check*>::iterator i = m_lookup_map.find(address);
120
121    if (i == m_lookup_map.end())
122        return NULL;
123
124    Check* check = i->second;
125    assert(check != NULL);
126    return check;
127}
128
129void
130CheckTable::print(std::ostream& out) const
131{
132}
133