CheckTable.cc revision 7455
12686Sksewell@umich.edu/*
22686Sksewell@umich.edu * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
32754Sksewell@umich.edu * Copyright (c) 2009 Advanced Micro Devices, Inc.
42706Sksewell@umich.edu * All rights reserved.
52706Sksewell@umich.edu *
62706Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
72706Sksewell@umich.edu * modification, are permitted provided that the following conditions are
82706Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
92706Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
102706Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
112706Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
122706Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
132706Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
142706Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
152706Sksewell@umich.edu * this software without specific prior written permission.
162706Sksewell@umich.edu *
172706Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182706Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192706Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202706Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212706Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222706Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232706Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242706Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252706Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262706Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272706Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282706Sksewell@umich.edu */
292706Sksewell@umich.edu
302706Sksewell@umich.edu#include "base/intmath.hh"
312686Sksewell@umich.edu#include "cpu/rubytest/Check.hh"
322686Sksewell@umich.edu#include "cpu/rubytest/CheckTable.hh"
334661Sksewell@umich.edu#include "cpu/rubytest/CheckTable.hh"
342686Sksewell@umich.edu
352686Sksewell@umich.eduCheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester)
362686Sksewell@umich.edu    : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
372686Sksewell@umich.edu{
382686Sksewell@umich.edu    physical_address_t physical = 0;
394661Sksewell@umich.edu    Address address;
402686Sksewell@umich.edu
412686Sksewell@umich.edu    const int size1 = 32;
422686Sksewell@umich.edu    const int size2 = 100;
432686Sksewell@umich.edu
444661Sksewell@umich.edu    // The first set is to get some false sharing
452686Sksewell@umich.edu    physical = 1000;
462686Sksewell@umich.edu    for (int i = 0; i < size1; i++) {
472686Sksewell@umich.edu        // Setup linear addresses
482686Sksewell@umich.edu        address.setAddress(physical);
492686Sksewell@umich.edu        addCheck(address);
502686Sksewell@umich.edu        physical += CHECK_SIZE;
512686Sksewell@umich.edu    }
524661Sksewell@umich.edu
532686Sksewell@umich.edu    // The next two sets are to get some limited false sharing and
542686Sksewell@umich.edu    // cache conflicts
552686Sksewell@umich.edu    physical = 1000;
562686Sksewell@umich.edu    for (int i = 0; i < size2; i++) {
572686Sksewell@umich.edu        // Setup linear addresses
584661Sksewell@umich.edu        address.setAddress(physical);
592686Sksewell@umich.edu        addCheck(address);
602686Sksewell@umich.edu        physical += 256;
612686Sksewell@umich.edu    }
622686Sksewell@umich.edu
632686Sksewell@umich.edu    physical = 1000 + CHECK_SIZE;
642686Sksewell@umich.edu    for (int i = 0; i < size2; i++) {
652686Sksewell@umich.edu        // Setup linear addresses
662686Sksewell@umich.edu        address.setAddress(physical);
674661Sksewell@umich.edu        addCheck(address);
684661Sksewell@umich.edu        physical += 256;
694661Sksewell@umich.edu    }
704661Sksewell@umich.edu}
714661Sksewell@umich.edu
724661Sksewell@umich.eduCheckTable::~CheckTable()
734661Sksewell@umich.edu{
744661Sksewell@umich.edu    int size = m_check_vector.size();
754661Sksewell@umich.edu    for (int i = 0; i < size; i++)
764661Sksewell@umich.edu        delete m_check_vector[i];
774661Sksewell@umich.edu}
784661Sksewell@umich.edu
794661Sksewell@umich.eduvoid
804661Sksewell@umich.eduCheckTable::addCheck(const Address& address)
814661Sksewell@umich.edu{
824661Sksewell@umich.edu    if (floorLog2(CHECK_SIZE) != 0) {
834661Sksewell@umich.edu        if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) {
844661Sksewell@umich.edu            ERROR_MSG("Check not aligned");
854661Sksewell@umich.edu        }
864661Sksewell@umich.edu    }
874661Sksewell@umich.edu
884661Sksewell@umich.edu    for (int i = 0; i < CHECK_SIZE; i++) {
892686Sksewell@umich.edu        if (m_lookup_map.count(Address(address.getAddress()+i))) {
902686Sksewell@umich.edu            // A mapping for this byte already existed, discard the
912686Sksewell@umich.edu            // entire check
922686Sksewell@umich.edu            return;
932686Sksewell@umich.edu        }
944661Sksewell@umich.edu    }
952686Sksewell@umich.edu
962686Sksewell@umich.edu    Check* check_ptr = new Check(address, Address(100 + m_check_vector.size()),
972686Sksewell@umich.edu                                 m_num_cpu_sequencers, m_tester_ptr);
982686Sksewell@umich.edu    for (int i = 0; i < CHECK_SIZE; i++) {
992686Sksewell@umich.edu        // Insert it once per byte
1002686Sksewell@umich.edu        m_lookup_map[Address(address.getAddress() + i)] = check_ptr;
1012686Sksewell@umich.edu    }
1022686Sksewell@umich.edu    m_check_vector.push_back(check_ptr);
1032686Sksewell@umich.edu}
1042686Sksewell@umich.edu
1052686Sksewell@umich.eduCheck*
1062686Sksewell@umich.eduCheckTable::getRandomCheck()
1074661Sksewell@umich.edu{
1084661Sksewell@umich.edu    return m_check_vector[random() % m_check_vector.size()];
1094661Sksewell@umich.edu}
1104661Sksewell@umich.edu
1114661Sksewell@umich.eduCheck*
1124661Sksewell@umich.eduCheckTable::getCheck(const Address& address)
1134661Sksewell@umich.edu{
1144661Sksewell@umich.edu    DEBUG_MSG(TESTER_COMP, MedPrio, "Looking for check by address");
1154661Sksewell@umich.edu    DEBUG_EXPR(TESTER_COMP, MedPrio, address);
1164661Sksewell@umich.edu
1174661Sksewell@umich.edu    m5::hash_map<Address, Check*>::iterator i = m_lookup_map.find(address);
1184661Sksewell@umich.edu
1194661Sksewell@umich.edu    if (i == m_lookup_map.end())
1204661Sksewell@umich.edu        return NULL;
1214661Sksewell@umich.edu
1224661Sksewell@umich.edu    Check* check = i->second;
1234661Sksewell@umich.edu    assert(check != NULL);
1244661Sksewell@umich.edu    return check;
1254661Sksewell@umich.edu}
1264661Sksewell@umich.edu
1274661Sksewell@umich.eduvoid
1284661Sksewell@umich.eduCheckTable::print(std::ostream& out) const
1294661Sksewell@umich.edu{
1304661Sksewell@umich.edu}
1314661Sksewell@umich.edu