CheckTable.cc revision 7454
112841Sgabeblack@google.com/*
212841Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
312841Sgabeblack@google.com * Copyright (c) 2009 Advanced Micro Devices, Inc.
412841Sgabeblack@google.com * All rights reserved.
512841Sgabeblack@google.com *
612841Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
712841Sgabeblack@google.com * modification, are permitted provided that the following conditions are
812841Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
912841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1012841Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1112841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1212841Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1312841Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1412841Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1512841Sgabeblack@google.com * this software without specific prior written permission.
1612841Sgabeblack@google.com *
1712841Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812841Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912841Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012841Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112841Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212841Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312841Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412841Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512841Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612841Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712841Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812841Sgabeblack@google.com */
2912841Sgabeblack@google.com
3012841Sgabeblack@google.com#include "base/intmath.hh"
3112841Sgabeblack@google.com#include "cpu/rubytest/Check.hh"
3212841Sgabeblack@google.com#include "cpu/rubytest/CheckTable.hh"
3312841Sgabeblack@google.com#include "cpu/rubytest/CheckTable.hh"
3412841Sgabeblack@google.com#include "mem/gems_common/Map.hh"
3512841Sgabeblack@google.com
3612841Sgabeblack@google.comCheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester)
3712841Sgabeblack@google.com    : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
3812841Sgabeblack@google.com{
3912841Sgabeblack@google.com    m_lookup_map_ptr = new Map<Address, Check*>;
4012841Sgabeblack@google.com    physical_address_t physical = 0;
4112841Sgabeblack@google.com    Address address;
4212841Sgabeblack@google.com
4312841Sgabeblack@google.com    const int size1 = 32;
4412841Sgabeblack@google.com    const int size2 = 100;
4512841Sgabeblack@google.com
4612841Sgabeblack@google.com    // The first set is to get some false sharing
4712841Sgabeblack@google.com    physical = 1000;
4812841Sgabeblack@google.com    for (int i = 0; i < size1; i++) {
4912841Sgabeblack@google.com        // Setup linear addresses
5012841Sgabeblack@google.com        address.setAddress(physical);
5112841Sgabeblack@google.com        addCheck(address);
5212841Sgabeblack@google.com        physical += CHECK_SIZE;
5312841Sgabeblack@google.com    }
5412841Sgabeblack@google.com
5512841Sgabeblack@google.com    // The next two sets are to get some limited false sharing and
5612841Sgabeblack@google.com    // cache conflicts
57    physical = 1000;
58    for (int i = 0; i < size2; i++) {
59        // Setup linear addresses
60        address.setAddress(physical);
61        addCheck(address);
62        physical += 256;
63    }
64
65    physical = 1000 + CHECK_SIZE;
66    for (int i = 0; i < size2; i++) {
67        // Setup linear addresses
68        address.setAddress(physical);
69        addCheck(address);
70        physical += 256;
71    }
72}
73
74CheckTable::~CheckTable()
75{
76    int size = m_check_vector.size();
77    for (int i = 0; i < size; i++)
78        delete m_check_vector[i];
79    delete m_lookup_map_ptr;
80}
81
82void
83CheckTable::addCheck(const Address& address)
84{
85    if (floorLog2(CHECK_SIZE) != 0) {
86        if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) {
87            ERROR_MSG("Check not aligned");
88        }
89    }
90
91    for (int i = 0; i < CHECK_SIZE; i++) {
92        if (m_lookup_map_ptr->exist(Address(address.getAddress()+i))) {
93            // A mapping for this byte already existed, discard the
94            // entire check
95            return;
96        }
97    }
98
99    Check* check_ptr = new Check(address, Address(100 + m_check_vector.size()),
100                                 m_num_cpu_sequencers, m_tester_ptr);
101    for (int i = 0; i < CHECK_SIZE; i++) {
102        // Insert it once per byte
103        m_lookup_map_ptr->add(Address(address.getAddress() + i), check_ptr);
104    }
105    m_check_vector.push_back(check_ptr);
106}
107
108Check*
109CheckTable::getRandomCheck()
110{
111    return m_check_vector[random() % m_check_vector.size()];
112}
113
114Check*
115CheckTable::getCheck(const Address& address)
116{
117    DEBUG_MSG(TESTER_COMP, MedPrio, "Looking for check by address");
118    DEBUG_EXPR(TESTER_COMP, MedPrio, address);
119
120    if (m_lookup_map_ptr->exist(address)) {
121        Check* check = m_lookup_map_ptr->lookup(address);
122        assert(check != NULL);
123        return check;
124    } else {
125        return NULL;
126    }
127}
128
129void
130CheckTable::print(std::ostream& out) const
131{
132}
133