CheckTable.cc revision 7805
16899SN/A/* 26899SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36899SN/A * Copyright (c) 2009 Advanced Micro Devices, Inc. 46899SN/A * All rights reserved. 56899SN/A * 66899SN/A * Redistribution and use in source and binary forms, with or without 76899SN/A * modification, are permitted provided that the following conditions are 86899SN/A * met: redistributions of source code must retain the above copyright 96899SN/A * notice, this list of conditions and the following disclaimer; 106899SN/A * redistributions in binary form must reproduce the above copyright 116899SN/A * notice, this list of conditions and the following disclaimer in the 126899SN/A * documentation and/or other materials provided with the distribution; 136899SN/A * neither the name of the copyright holders nor the names of its 146899SN/A * contributors may be used to endorse or promote products derived from 156899SN/A * this software without specific prior written permission. 166899SN/A * 176899SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 186899SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 196899SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 206899SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 216899SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 226899SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 236899SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246899SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256899SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266899SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 276899SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286899SN/A */ 296899SN/A 307056SN/A#include "base/intmath.hh" 317632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/Check.hh" 327632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/CheckTable.hh" 337632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/CheckTable.hh" 346899SN/A 356899SN/ACheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester) 367053SN/A : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester) 376899SN/A{ 387053SN/A physical_address_t physical = 0; 397053SN/A Address address; 406899SN/A 417053SN/A const int size1 = 32; 427053SN/A const int size2 = 100; 436899SN/A 447053SN/A // The first set is to get some false sharing 457053SN/A physical = 1000; 467053SN/A for (int i = 0; i < size1; i++) { 477053SN/A // Setup linear addresses 487053SN/A address.setAddress(physical); 497053SN/A addCheck(address); 507053SN/A physical += CHECK_SIZE; 517053SN/A } 526899SN/A 537053SN/A // The next two sets are to get some limited false sharing and 547053SN/A // cache conflicts 557053SN/A physical = 1000; 567053SN/A for (int i = 0; i < size2; i++) { 577053SN/A // Setup linear addresses 587053SN/A address.setAddress(physical); 597053SN/A addCheck(address); 607053SN/A physical += 256; 617053SN/A } 626899SN/A 637053SN/A physical = 1000 + CHECK_SIZE; 647053SN/A for (int i = 0; i < size2; i++) { 657053SN/A // Setup linear addresses 667053SN/A address.setAddress(physical); 677053SN/A addCheck(address); 687053SN/A physical += 256; 697053SN/A } 706899SN/A} 716899SN/A 726899SN/ACheckTable::~CheckTable() 736899SN/A{ 747053SN/A int size = m_check_vector.size(); 757053SN/A for (int i = 0; i < size; i++) 767053SN/A delete m_check_vector[i]; 776899SN/A} 786899SN/A 797053SN/Avoid 807053SN/ACheckTable::addCheck(const Address& address) 816899SN/A{ 827056SN/A if (floorLog2(CHECK_SIZE) != 0) { 837053SN/A if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) { 847805Snilay@cs.wisc.edu panic("Check not aligned"); 857053SN/A } 866899SN/A } 876899SN/A 887053SN/A for (int i = 0; i < CHECK_SIZE; i++) { 897455SN/A if (m_lookup_map.count(Address(address.getAddress()+i))) { 907053SN/A // A mapping for this byte already existed, discard the 917053SN/A // entire check 927053SN/A return; 937053SN/A } 946899SN/A } 956899SN/A 967053SN/A Check* check_ptr = new Check(address, Address(100 + m_check_vector.size()), 977053SN/A m_num_cpu_sequencers, m_tester_ptr); 987053SN/A for (int i = 0; i < CHECK_SIZE; i++) { 997053SN/A // Insert it once per byte 1007455SN/A m_lookup_map[Address(address.getAddress() + i)] = check_ptr; 1017053SN/A } 1027454SN/A m_check_vector.push_back(check_ptr); 1036899SN/A} 1046899SN/A 1057053SN/ACheck* 1067053SN/ACheckTable::getRandomCheck() 1076899SN/A{ 1087053SN/A return m_check_vector[random() % m_check_vector.size()]; 1096899SN/A} 1106899SN/A 1117053SN/ACheck* 1127053SN/ACheckTable::getCheck(const Address& address) 1136899SN/A{ 1147780Snilay@cs.wisc.edu DPRINTF(RubyTest, "Looking for check by address: %s", address); 1156899SN/A 1167455SN/A m5::hash_map<Address, Check*>::iterator i = m_lookup_map.find(address); 1177455SN/A 1187455SN/A if (i == m_lookup_map.end()) 1197053SN/A return NULL; 1207455SN/A 1217455SN/A Check* check = i->second; 1227455SN/A assert(check != NULL); 1237455SN/A return check; 1246899SN/A} 1256899SN/A 1267053SN/Avoid 1277055SN/ACheckTable::print(std::ostream& out) const 1286899SN/A{ 1296899SN/A} 130