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"
3411800Sbrandon.potter@amd.com#include "base/trace.hh"
357632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/Check.hh"
368232Snate@binkert.org#include "debug/RubyTest.hh"
376899SN/A
388932SBrad.Beckmann@amd.comCheckTable::CheckTable(int _num_writers, int _num_readers, RubyTester* _tester)
398932SBrad.Beckmann@amd.com    : m_num_writers(_num_writers), m_num_readers(_num_readers),
408932SBrad.Beckmann@amd.com      m_tester_ptr(_tester)
416899SN/A{
4211025Snilay@cs.wisc.edu    Addr physical = 0;
436899SN/A
447053SN/A    const int size1 = 32;
457053SN/A    const int size2 = 100;
466899SN/A
4711266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Adding false sharing checks\n");
487053SN/A    // The first set is to get some false sharing
497053SN/A    physical = 1000;
507053SN/A    for (int i = 0; i < size1; i++) {
517053SN/A        // Setup linear addresses
5211025Snilay@cs.wisc.edu        addCheck(physical);
537053SN/A        physical += CHECK_SIZE;
547053SN/A    }
556899SN/A
5611266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Adding cache conflict checks\n");
577053SN/A    // The next two sets are to get some limited false sharing and
587053SN/A    // cache conflicts
597053SN/A    physical = 1000;
607053SN/A    for (int i = 0; i < size2; i++) {
617053SN/A        // Setup linear addresses
6211025Snilay@cs.wisc.edu        addCheck(physical);
637053SN/A        physical += 256;
647053SN/A    }
656899SN/A
6611266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Adding cache conflict checks2\n");
677053SN/A    physical = 1000 + CHECK_SIZE;
687053SN/A    for (int i = 0; i < size2; i++) {
697053SN/A        // Setup linear addresses
7011025Snilay@cs.wisc.edu        addCheck(physical);
717053SN/A        physical += 256;
727053SN/A    }
736899SN/A}
746899SN/A
756899SN/ACheckTable::~CheckTable()
766899SN/A{
777053SN/A    int size = m_check_vector.size();
787053SN/A    for (int i = 0; i < size; i++)
797053SN/A        delete m_check_vector[i];
806899SN/A}
816899SN/A
827053SN/Avoid
8311025Snilay@cs.wisc.eduCheckTable::addCheck(Addr address)
846899SN/A{
857056SN/A    if (floorLog2(CHECK_SIZE) != 0) {
8611025Snilay@cs.wisc.edu        if (bitSelect(address, 0, CHECK_SIZE_BITS - 1) != 0) {
877805Snilay@cs.wisc.edu            panic("Check not aligned");
887053SN/A        }
896899SN/A    }
906899SN/A
917053SN/A    for (int i = 0; i < CHECK_SIZE; i++) {
9211025Snilay@cs.wisc.edu        if (m_lookup_map.count(address+i)) {
937053SN/A            // A mapping for this byte already existed, discard the
947053SN/A            // entire check
957053SN/A            return;
967053SN/A        }
976899SN/A    }
986899SN/A
9911266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Adding check for address: %s\n", address);
10011266SBrad.Beckmann@amd.com
10111025Snilay@cs.wisc.edu    Check* check_ptr = new Check(address, 100 + m_check_vector.size(),
1028932SBrad.Beckmann@amd.com                                 m_num_writers, m_num_readers, m_tester_ptr);
1037053SN/A    for (int i = 0; i < CHECK_SIZE; i++) {
1047053SN/A        // Insert it once per byte
10511025Snilay@cs.wisc.edu        m_lookup_map[address + i] = check_ptr;
1067053SN/A    }
1077454SN/A    m_check_vector.push_back(check_ptr);
1086899SN/A}
1096899SN/A
1107053SN/ACheck*
1117053SN/ACheckTable::getRandomCheck()
1126899SN/A{
1139108SBrad.Beckmann@amd.com    assert(m_check_vector.size() > 0);
11410348Sandreas.hansson@arm.com    return m_check_vector[random_mt.random<unsigned>(0, m_check_vector.size() - 1)];
1156899SN/A}
1166899SN/A
1177053SN/ACheck*
11811025Snilay@cs.wisc.eduCheckTable::getCheck(const Addr address)
1196899SN/A{
12011266SBrad.Beckmann@amd.com    DPRINTF(RubyTest, "Looking for check by address: %s\n", address);
1216899SN/A
12211168Sandreas.hansson@arm.com    auto i = m_lookup_map.find(address);
1237455SN/A
1247455SN/A    if (i == m_lookup_map.end())
1257053SN/A        return NULL;
1267455SN/A
1277455SN/A    Check* check = i->second;
1287455SN/A    assert(check != NULL);
1297455SN/A    return check;
1306899SN/A}
1316899SN/A
1327053SN/Avoid
1337055SN/ACheckTable::print(std::ostream& out) const
1346899SN/A{
1356899SN/A}
136