CheckTable.cc revision 11793
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
3011793Sbrandon.potter@amd.com#include "cpu/testers/rubytest/CheckTable.hh"
3111793Sbrandon.potter@amd.com
327056SN/A#include "base/intmath.hh"
3310348Sandreas.hansson@arm.com#include "base/random.hh"
347632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/Check.hh"
358232Snate@binkert.org#include "debug/RubyTest.hh"
366899SN/A
378932SBrad.Beckmann@amd.comCheckTable::CheckTable(int _num_writers, int _num_readers, RubyTester* _tester)
388932SBrad.Beckmann@amd.com    : m_num_writers(_num_writers), m_num_readers(_num_readers),
398932SBrad.Beckmann@amd.com      m_tester_ptr(_tester)
406899SN/A{
4111025Snilay@cs.wisc.edu    Addr physical = 0;
426899SN/A
437053SN/A    const int size1 = 32;
447053SN/A    const int size2 = 100;
456899SN/A
4611266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Adding false sharing checks\n");
477053SN/A    // The first set is to get some false sharing
487053SN/A    physical = 1000;
497053SN/A    for (int i = 0; i < size1; i++) {
507053SN/A        // Setup linear addresses
5111025Snilay@cs.wisc.edu        addCheck(physical);
527053SN/A        physical += CHECK_SIZE;
537053SN/A    }
546899SN/A
5511266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Adding cache conflict checks\n");
567053SN/A    // The next two sets are to get some limited false sharing and
577053SN/A    // cache conflicts
587053SN/A    physical = 1000;
597053SN/A    for (int i = 0; i < size2; i++) {
607053SN/A        // Setup linear addresses
6111025Snilay@cs.wisc.edu        addCheck(physical);
627053SN/A        physical += 256;
637053SN/A    }
646899SN/A
6511266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Adding cache conflict checks2\n");
667053SN/A    physical = 1000 + CHECK_SIZE;
677053SN/A    for (int i = 0; i < size2; i++) {
687053SN/A        // Setup linear addresses
6911025Snilay@cs.wisc.edu        addCheck(physical);
707053SN/A        physical += 256;
717053SN/A    }
726899SN/A}
736899SN/A
746899SN/ACheckTable::~CheckTable()
756899SN/A{
767053SN/A    int size = m_check_vector.size();
777053SN/A    for (int i = 0; i < size; i++)
787053SN/A        delete m_check_vector[i];
796899SN/A}
806899SN/A
817053SN/Avoid
8211025Snilay@cs.wisc.eduCheckTable::addCheck(Addr address)
836899SN/A{
847056SN/A    if (floorLog2(CHECK_SIZE) != 0) {
8511025Snilay@cs.wisc.edu        if (bitSelect(address, 0, CHECK_SIZE_BITS - 1) != 0) {
867805Snilay@cs.wisc.edu            panic("Check not aligned");
877053SN/A        }
886899SN/A    }
896899SN/A
907053SN/A    for (int i = 0; i < CHECK_SIZE; i++) {
9111025Snilay@cs.wisc.edu        if (m_lookup_map.count(address+i)) {
927053SN/A            // A mapping for this byte already existed, discard the
937053SN/A            // entire check
947053SN/A            return;
957053SN/A        }
966899SN/A    }
976899SN/A
9811266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Adding check for address: %s\n", address);
9911266SBrad.Beckmann@amd.com
10011025Snilay@cs.wisc.edu    Check* check_ptr = new Check(address, 100 + m_check_vector.size(),
1018932SBrad.Beckmann@amd.com                                 m_num_writers, m_num_readers, m_tester_ptr);
1027053SN/A    for (int i = 0; i < CHECK_SIZE; i++) {
1037053SN/A        // Insert it once per byte
10411025Snilay@cs.wisc.edu        m_lookup_map[address + i] = check_ptr;
1057053SN/A    }
1067454SN/A    m_check_vector.push_back(check_ptr);
1076899SN/A}
1086899SN/A
1097053SN/ACheck*
1107053SN/ACheckTable::getRandomCheck()
1116899SN/A{
1129108SBrad.Beckmann@amd.com    assert(m_check_vector.size() > 0);
11310348Sandreas.hansson@arm.com    return m_check_vector[random_mt.random<unsigned>(0, m_check_vector.size() - 1)];
1146899SN/A}
1156899SN/A
1167053SN/ACheck*
11711025Snilay@cs.wisc.eduCheckTable::getCheck(const Addr address)
1186899SN/A{
11911266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Looking for check by address: %s\n", address);
1206899SN/A
12111168Sandreas.hansson@arm.com    auto i = m_lookup_map.find(address);
1227455SN/A
1237455SN/A    if (i == m_lookup_map.end())
1247053SN/A        return NULL;
1257455SN/A
1267455SN/A    Check* check = i->second;
1277455SN/A    assert(check != NULL);
1287455SN/A    return check;
1296899SN/A}
1306899SN/A
1317053SN/Avoid
1327055SN/ACheckTable::print(std::ostream& out) const
1336899SN/A{
1346899SN/A}
135