CheckTable.cc revision 7055
1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * Copyright (c) 2009 Advanced Micro Devices, Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30#include "cpu/rubytest/Check.hh" 31#include "cpu/rubytest/CheckTable.hh" 32#include "cpu/rubytest/CheckTable.hh" 33#include "mem/gems_common/Map.hh" 34 35CheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester) 36 : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester) 37{ 38 m_lookup_map_ptr = new Map<Address, Check*>; 39 physical_address_t physical = 0; 40 Address address; 41 42 const int size1 = 32; 43 const int size2 = 100; 44 45 // The first set is to get some false sharing 46 physical = 1000; 47 for (int i = 0; i < size1; i++) { 48 // Setup linear addresses 49 address.setAddress(physical); 50 addCheck(address); 51 physical += CHECK_SIZE; 52 } 53 54 // The next two sets are to get some limited false sharing and 55 // cache conflicts 56 physical = 1000; 57 for (int i = 0; i < size2; i++) { 58 // Setup linear addresses 59 address.setAddress(physical); 60 addCheck(address); 61 physical += 256; 62 } 63 64 physical = 1000 + CHECK_SIZE; 65 for (int i = 0; i < size2; i++) { 66 // Setup linear addresses 67 address.setAddress(physical); 68 addCheck(address); 69 physical += 256; 70 } 71} 72 73CheckTable::~CheckTable() 74{ 75 int size = m_check_vector.size(); 76 for (int i = 0; i < size; i++) 77 delete m_check_vector[i]; 78 delete m_lookup_map_ptr; 79} 80 81void 82CheckTable::addCheck(const Address& address) 83{ 84 if (log_int(CHECK_SIZE) != 0) { 85 if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) { 86 ERROR_MSG("Check not aligned"); 87 } 88 } 89 90 for (int i = 0; i < CHECK_SIZE; i++) { 91 if (m_lookup_map_ptr->exist(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_cpu_sequencers, m_tester_ptr); 100 for (int i = 0; i < CHECK_SIZE; i++) { 101 // Insert it once per byte 102 m_lookup_map_ptr->add(Address(address.getAddress() + i), check_ptr); 103 } 104 m_check_vector.insertAtBottom(check_ptr); 105} 106 107Check* 108CheckTable::getRandomCheck() 109{ 110 return m_check_vector[random() % m_check_vector.size()]; 111} 112 113Check* 114CheckTable::getCheck(const Address& address) 115{ 116 DEBUG_MSG(TESTER_COMP, MedPrio, "Looking for check by address"); 117 DEBUG_EXPR(TESTER_COMP, MedPrio, address); 118 119 if (m_lookup_map_ptr->exist(address)) { 120 Check* check = m_lookup_map_ptr->lookup(address); 121 assert(check != NULL); 122 return check; 123 } else { 124 return NULL; 125 } 126} 127 128void 129CheckTable::print(std::ostream& out) const 130{ 131} 132