CheckTable.cc revision 7055
112837Sgabeblack@google.com/*
212837Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
312837Sgabeblack@google.com * Copyright (c) 2009 Advanced Micro Devices, Inc.
412837Sgabeblack@google.com * All rights reserved.
512837Sgabeblack@google.com *
612837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
712837Sgabeblack@google.com * modification, are permitted provided that the following conditions are
812837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
912837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1012837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1112837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1212837Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1312837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1412837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1512837Sgabeblack@google.com * this software without specific prior written permission.
1612837Sgabeblack@google.com *
1712837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812837Sgabeblack@google.com */
2912837Sgabeblack@google.com
3012837Sgabeblack@google.com#include "cpu/rubytest/Check.hh"
3112837Sgabeblack@google.com#include "cpu/rubytest/CheckTable.hh"
3212837Sgabeblack@google.com#include "cpu/rubytest/CheckTable.hh"
3312837Sgabeblack@google.com#include "mem/gems_common/Map.hh"
3412837Sgabeblack@google.com
3512837Sgabeblack@google.comCheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester)
3612837Sgabeblack@google.com    : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
3712837Sgabeblack@google.com{
3812837Sgabeblack@google.com    m_lookup_map_ptr = new Map<Address, Check*>;
3912837Sgabeblack@google.com    physical_address_t physical = 0;
4012837Sgabeblack@google.com    Address address;
4112837Sgabeblack@google.com
4212837Sgabeblack@google.com    const int size1 = 32;
4312837Sgabeblack@google.com    const int size2 = 100;
4412837Sgabeblack@google.com
4512837Sgabeblack@google.com    // The first set is to get some false sharing
4612837Sgabeblack@google.com    physical = 1000;
4712837Sgabeblack@google.com    for (int i = 0; i < size1; i++) {
4812837Sgabeblack@google.com        // Setup linear addresses
4912837Sgabeblack@google.com        address.setAddress(physical);
5012837Sgabeblack@google.com        addCheck(address);
5112837Sgabeblack@google.com        physical += CHECK_SIZE;
5212837Sgabeblack@google.com    }
5312837Sgabeblack@google.com
5412837Sgabeblack@google.com    // The next two sets are to get some limited false sharing and
5512837Sgabeblack@google.com    // cache conflicts
5612837Sgabeblack@google.com    physical = 1000;
5712837Sgabeblack@google.com    for (int i = 0; i < size2; i++) {
5812837Sgabeblack@google.com        // Setup linear addresses
5912837Sgabeblack@google.com        address.setAddress(physical);
6012837Sgabeblack@google.com        addCheck(address);
6112837Sgabeblack@google.com        physical += 256;
6212837Sgabeblack@google.com    }
6312837Sgabeblack@google.com
6412837Sgabeblack@google.com    physical = 1000 + CHECK_SIZE;
6512837Sgabeblack@google.com    for (int i = 0; i < size2; i++) {
6612837Sgabeblack@google.com        // Setup linear addresses
6712837Sgabeblack@google.com        address.setAddress(physical);
6812837Sgabeblack@google.com        addCheck(address);
6912837Sgabeblack@google.com        physical += 256;
7012837Sgabeblack@google.com    }
7112837Sgabeblack@google.com}
7212837Sgabeblack@google.com
7312837Sgabeblack@google.comCheckTable::~CheckTable()
7412837Sgabeblack@google.com{
7512837Sgabeblack@google.com    int size = m_check_vector.size();
7612837Sgabeblack@google.com    for (int i = 0; i < size; i++)
7712837Sgabeblack@google.com        delete m_check_vector[i];
7812837Sgabeblack@google.com    delete m_lookup_map_ptr;
7912837Sgabeblack@google.com}
8012837Sgabeblack@google.com
8112837Sgabeblack@google.comvoid
8212837Sgabeblack@google.comCheckTable::addCheck(const Address& address)
8312837Sgabeblack@google.com{
8412837Sgabeblack@google.com    if (log_int(CHECK_SIZE) != 0) {
8512837Sgabeblack@google.com        if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) {
8612837Sgabeblack@google.com            ERROR_MSG("Check not aligned");
8712837Sgabeblack@google.com        }
8812837Sgabeblack@google.com    }
8912837Sgabeblack@google.com
9012837Sgabeblack@google.com    for (int i = 0; i < CHECK_SIZE; i++) {
9112837Sgabeblack@google.com        if (m_lookup_map_ptr->exist(Address(address.getAddress()+i))) {
9212837Sgabeblack@google.com            // A mapping for this byte already existed, discard the
9312837Sgabeblack@google.com            // entire check
9412837Sgabeblack@google.com            return;
9512837Sgabeblack@google.com        }
9612837Sgabeblack@google.com    }
9712837Sgabeblack@google.com
9812837Sgabeblack@google.com    Check* check_ptr = new Check(address, Address(100 + m_check_vector.size()),
9912837Sgabeblack@google.com                                 m_num_cpu_sequencers, m_tester_ptr);
10012837Sgabeblack@google.com    for (int i = 0; i < CHECK_SIZE; i++) {
10112837Sgabeblack@google.com        // Insert it once per byte
10212837Sgabeblack@google.com        m_lookup_map_ptr->add(Address(address.getAddress() + i), check_ptr);
10312837Sgabeblack@google.com    }
10412837Sgabeblack@google.com    m_check_vector.insertAtBottom(check_ptr);
10512837Sgabeblack@google.com}
10612837Sgabeblack@google.com
10712837Sgabeblack@google.comCheck*
10812837Sgabeblack@google.comCheckTable::getRandomCheck()
10912837Sgabeblack@google.com{
11012837Sgabeblack@google.com    return m_check_vector[random() % m_check_vector.size()];
11112837Sgabeblack@google.com}
11212837Sgabeblack@google.com
11312837Sgabeblack@google.comCheck*
11412837Sgabeblack@google.comCheckTable::getCheck(const Address& address)
11512837Sgabeblack@google.com{
11612837Sgabeblack@google.com    DEBUG_MSG(TESTER_COMP, MedPrio, "Looking for check by address");
11712837Sgabeblack@google.com    DEBUG_EXPR(TESTER_COMP, MedPrio, address);
11812837Sgabeblack@google.com
11912837Sgabeblack@google.com    if (m_lookup_map_ptr->exist(address)) {
12012837Sgabeblack@google.com        Check* check = m_lookup_map_ptr->lookup(address);
12112837Sgabeblack@google.com        assert(check != NULL);
12212837Sgabeblack@google.com        return check;
12312837Sgabeblack@google.com    } else {
12412860Sgabeblack@google.com        return NULL;
12512860Sgabeblack@google.com    }
12612860Sgabeblack@google.com}
12712860Sgabeblack@google.com
12812860Sgabeblack@google.comvoid
12912860Sgabeblack@google.comCheckTable::print(std::ostream& out) const
13012860Sgabeblack@google.com{
13112860Sgabeblack@google.com}
13212860Sgabeblack@google.com