CheckTable.cc revision 11266
111308Santhony.gutierrez@amd.com/* 211308Santhony.gutierrez@amd.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 311308Santhony.gutierrez@amd.com * Copyright (c) 2009 Advanced Micro Devices, Inc. 411308Santhony.gutierrez@amd.com * All rights reserved. 511308Santhony.gutierrez@amd.com * 611308Santhony.gutierrez@amd.com * Redistribution and use in source and binary forms, with or without 711308Santhony.gutierrez@amd.com * modification, are permitted provided that the following conditions are 811308Santhony.gutierrez@amd.com * met: redistributions of source code must retain the above copyright 911308Santhony.gutierrez@amd.com * notice, this list of conditions and the following disclaimer; 1011308Santhony.gutierrez@amd.com * redistributions in binary form must reproduce the above copyright 1111308Santhony.gutierrez@amd.com * notice, this list of conditions and the following disclaimer in the 1211308Santhony.gutierrez@amd.com * documentation and/or other materials provided with the distribution; 1311308Santhony.gutierrez@amd.com * neither the name of the copyright holders nor the names of its 1411308Santhony.gutierrez@amd.com * contributors may be used to endorse or promote products derived from 1511308Santhony.gutierrez@amd.com * this software without specific prior written permission. 1611308Santhony.gutierrez@amd.com * 1712697Santhony.gutierrez@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1812697Santhony.gutierrez@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1912697Santhony.gutierrez@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2011308Santhony.gutierrez@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2111308Santhony.gutierrez@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2211308Santhony.gutierrez@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2311308Santhony.gutierrez@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2411308Santhony.gutierrez@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2511308Santhony.gutierrez@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2611308Santhony.gutierrez@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2711308Santhony.gutierrez@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2811308Santhony.gutierrez@amd.com */ 2911308Santhony.gutierrez@amd.com 3011308Santhony.gutierrez@amd.com#include "base/intmath.hh" 3111308Santhony.gutierrez@amd.com#include "base/random.hh" 3211308Santhony.gutierrez@amd.com#include "cpu/testers/rubytest/Check.hh" 3312697Santhony.gutierrez@amd.com#include "cpu/testers/rubytest/CheckTable.hh" 3411308Santhony.gutierrez@amd.com#include "debug/RubyTest.hh" 3511308Santhony.gutierrez@amd.com 3612492Sodanrc@yahoo.com.brCheckTable::CheckTable(int _num_writers, int _num_readers, RubyTester* _tester) 3712492Sodanrc@yahoo.com.br : m_num_writers(_num_writers), m_num_readers(_num_readers), 3811308Santhony.gutierrez@amd.com m_tester_ptr(_tester) 3911308Santhony.gutierrez@amd.com{ 4011308Santhony.gutierrez@amd.com Addr physical = 0; 4111308Santhony.gutierrez@amd.com 4211308Santhony.gutierrez@amd.com const int size1 = 32; 4314184Sgabeblack@google.com const int size2 = 100; 4414184Sgabeblack@google.com 4514184Sgabeblack@google.com DPRINTF(RubyTest, "Adding false sharing checks\n"); 4611308Santhony.gutierrez@amd.com // The first set is to get some false sharing 4711308Santhony.gutierrez@amd.com physical = 1000; 4811308Santhony.gutierrez@amd.com for (int i = 0; i < size1; i++) { 4911308Santhony.gutierrez@amd.com // Setup linear addresses 5011308Santhony.gutierrez@amd.com addCheck(physical); 5111308Santhony.gutierrez@amd.com physical += CHECK_SIZE; 5211308Santhony.gutierrez@amd.com } 5311308Santhony.gutierrez@amd.com 5411308Santhony.gutierrez@amd.com DPRINTF(RubyTest, "Adding cache conflict checks\n"); 5511308Santhony.gutierrez@amd.com // The next two sets are to get some limited false sharing and 5611308Santhony.gutierrez@amd.com // cache conflicts 5711308Santhony.gutierrez@amd.com physical = 1000; 5811308Santhony.gutierrez@amd.com for (int i = 0; i < size2; i++) { 5911308Santhony.gutierrez@amd.com // Setup linear addresses 6011308Santhony.gutierrez@amd.com addCheck(physical); 6111308Santhony.gutierrez@amd.com physical += 256; 6211308Santhony.gutierrez@amd.com } 6311308Santhony.gutierrez@amd.com 6411308Santhony.gutierrez@amd.com DPRINTF(RubyTest, "Adding cache conflict checks2\n"); 6511308Santhony.gutierrez@amd.com physical = 1000 + CHECK_SIZE; 6611308Santhony.gutierrez@amd.com for (int i = 0; i < size2; i++) { 6711308Santhony.gutierrez@amd.com // Setup linear addresses 6811308Santhony.gutierrez@amd.com addCheck(physical); 6911308Santhony.gutierrez@amd.com physical += 256; 7011308Santhony.gutierrez@amd.com } 7111308Santhony.gutierrez@amd.com} 7211308Santhony.gutierrez@amd.com 7311308Santhony.gutierrez@amd.comCheckTable::~CheckTable() 7412492Sodanrc@yahoo.com.br{ 75 int size = m_check_vector.size(); 76 for (int i = 0; i < size; i++) 77 delete m_check_vector[i]; 78} 79 80void 81CheckTable::addCheck(Addr address) 82{ 83 if (floorLog2(CHECK_SIZE) != 0) { 84 if (bitSelect(address, 0, CHECK_SIZE_BITS - 1) != 0) { 85 panic("Check not aligned"); 86 } 87 } 88 89 for (int i = 0; i < CHECK_SIZE; i++) { 90 if (m_lookup_map.count(address+i)) { 91 // A mapping for this byte already existed, discard the 92 // entire check 93 return; 94 } 95 } 96 97 DPRINTF(RubyTest, "Adding check for address: %s\n", address); 98 99 Check* check_ptr = new Check(address, 100 + m_check_vector.size(), 100 m_num_writers, m_num_readers, m_tester_ptr); 101 for (int i = 0; i < CHECK_SIZE; i++) { 102 // Insert it once per byte 103 m_lookup_map[address + i] = check_ptr; 104 } 105 m_check_vector.push_back(check_ptr); 106} 107 108Check* 109CheckTable::getRandomCheck() 110{ 111 assert(m_check_vector.size() > 0); 112 return m_check_vector[random_mt.random<unsigned>(0, m_check_vector.size() - 1)]; 113} 114 115Check* 116CheckTable::getCheck(const Addr address) 117{ 118 DPRINTF(RubyTest, "Looking for check by address: %s\n", address); 119 120 auto i = m_lookup_map.find(address); 121 122 if (i == m_lookup_map.end()) 123 return NULL; 124 125 Check* check = i->second; 126 assert(check != NULL); 127 return check; 128} 129 130void 131CheckTable::print(std::ostream& out) const 132{ 133} 134