CheckTable.cc revision 7055
19155SN/A/*
29155SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
39155SN/A * Copyright (c) 2009 Advanced Micro Devices, Inc.
49155SN/A * All rights reserved.
59155SN/A *
69155SN/A * Redistribution and use in source and binary forms, with or without
79155SN/A * modification, are permitted provided that the following conditions are
89155SN/A * met: redistributions of source code must retain the above copyright
99155SN/A * notice, this list of conditions and the following disclaimer;
109155SN/A * redistributions in binary form must reproduce the above copyright
119155SN/A * notice, this list of conditions and the following disclaimer in the
129155SN/A * documentation and/or other materials provided with the distribution;
139155SN/A * neither the name of the copyright holders nor the names of its
149155SN/A * contributors may be used to endorse or promote products derived from
159155SN/A * this software without specific prior written permission.
169155SN/A *
179155SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
189155SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
199155SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
209155SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
219155SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
229155SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
239155SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
249155SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
259155SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
269155SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
279155SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
289155SN/A */
299155SN/A
309155SN/A#include "cpu/rubytest/Check.hh"
319105SN/A#include "cpu/rubytest/CheckTable.hh"
329297SN/A#include "cpu/rubytest/CheckTable.hh"
3310301Snilay@cs.wisc.edu#include "mem/gems_common/Map.hh"
349297SN/A
359105SN/ACheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester)
369297SN/A    : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
3710919Sbrandon.potter@amd.com{
3810919Sbrandon.potter@amd.com    m_lookup_map_ptr = new Map<Address, Check*>;
399105SN/A    physical_address_t physical = 0;
409105SN/A    Address address;
419105SN/A
429105SN/A    const int size1 = 32;
439105SN/A    const int size2 = 100;
449105SN/A
459105SN/A    // The first set is to get some false sharing
469105SN/A    physical = 1000;
479105SN/A    for (int i = 0; i < size1; i++) {
489105SN/A        // Setup linear addresses
499105SN/A        address.setAddress(physical);
509105SN/A        addCheck(address);
519105SN/A        physical += CHECK_SIZE;
5210314Snilay@cs.wisc.edu    }
539105SN/A
549105SN/A    // The next two sets are to get some limited false sharing and
559105SN/A    // cache conflicts
569105SN/A    physical = 1000;
579105SN/A    for (int i = 0; i < size2; i++) {
589105SN/A        // Setup linear addresses
599105SN/A        address.setAddress(physical);
609297SN/A        addCheck(address);
619297SN/A        physical += 256;
629297SN/A    }
639105SN/A
649105SN/A    physical = 1000 + CHECK_SIZE;
659297SN/A    for (int i = 0; i < size2; i++) {
669297SN/A        // Setup linear addresses
679297SN/A        address.setAddress(physical);
689105SN/A        addCheck(address);
699105SN/A        physical += 256;
709105SN/A    }
719105SN/A}
729105SN/A
739297SN/ACheckTable::~CheckTable()
7410919Sbrandon.potter@amd.com{
759105SN/A    int size = m_check_vector.size();
769105SN/A    for (int i = 0; i < size; i++)
779105SN/A        delete m_check_vector[i];
789105SN/A    delete m_lookup_map_ptr;
799105SN/A}
8010314Snilay@cs.wisc.edu
819105SN/Avoid
829105SN/ACheckTable::addCheck(const Address& address)
839105SN/A{
849105SN/A    if (log_int(CHECK_SIZE) != 0) {
859105SN/A        if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) {
869105SN/A            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