CheckTable.cc revision 11800
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/testers/rubytest/CheckTable.hh" 31 32#include "base/intmath.hh" 33#include "base/random.hh" 34#include "base/trace.hh" 35#include "cpu/testers/rubytest/Check.hh" 36#include "debug/RubyTest.hh" 37 38CheckTable::CheckTable(int _num_writers, int _num_readers, RubyTester* _tester) 39 : m_num_writers(_num_writers), m_num_readers(_num_readers), 40 m_tester_ptr(_tester) 41{ 42 Addr physical = 0; 43 44 const int size1 = 32; 45 const int size2 = 100; 46 47 DPRINTF(RubyTest, "Adding false sharing checks\n"); 48 // The first set is to get some false sharing 49 physical = 1000; 50 for (int i = 0; i < size1; i++) { 51 // Setup linear addresses 52 addCheck(physical); 53 physical += CHECK_SIZE; 54 } 55 56 DPRINTF(RubyTest, "Adding cache conflict checks\n"); 57 // The next two sets are to get some limited false sharing and 58 // cache conflicts 59 physical = 1000; 60 for (int i = 0; i < size2; i++) { 61 // Setup linear addresses 62 addCheck(physical); 63 physical += 256; 64 } 65 66 DPRINTF(RubyTest, "Adding cache conflict checks2\n"); 67 physical = 1000 + CHECK_SIZE; 68 for (int i = 0; i < size2; i++) { 69 // Setup linear addresses 70 addCheck(physical); 71 physical += 256; 72 } 73} 74 75CheckTable::~CheckTable() 76{ 77 int size = m_check_vector.size(); 78 for (int i = 0; i < size; i++) 79 delete m_check_vector[i]; 80} 81 82void 83CheckTable::addCheck(Addr address) 84{ 85 if (floorLog2(CHECK_SIZE) != 0) { 86 if (bitSelect(address, 0, CHECK_SIZE_BITS - 1) != 0) { 87 panic("Check not aligned"); 88 } 89 } 90 91 for (int i = 0; i < CHECK_SIZE; i++) { 92 if (m_lookup_map.count(address+i)) { 93 // A mapping for this byte already existed, discard the 94 // entire check 95 return; 96 } 97 } 98 99 DPRINTF(RubyTest, "Adding check for address: %s\n", address); 100 101 Check* check_ptr = new Check(address, 100 + m_check_vector.size(), 102 m_num_writers, m_num_readers, m_tester_ptr); 103 for (int i = 0; i < CHECK_SIZE; i++) { 104 // Insert it once per byte 105 m_lookup_map[address + i] = check_ptr; 106 } 107 m_check_vector.push_back(check_ptr); 108} 109 110Check* 111CheckTable::getRandomCheck() 112{ 113 assert(m_check_vector.size() > 0); 114 return m_check_vector[random_mt.random<unsigned>(0, m_check_vector.size() - 1)]; 115} 116 117Check* 118CheckTable::getCheck(const Addr address) 119{ 120 DPRINTF(RubyTest, "Looking for check by address: %s\n", address); 121 122 auto i = m_lookup_map.find(address); 123 124 if (i == m_lookup_map.end()) 125 return NULL; 126 127 Check* check = i->second; 128 assert(check != NULL); 129 return check; 130} 131 132void 133CheckTable::print(std::ostream& out) const 134{ 135} 136