2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * Copyright (c) 2009 Advanced Micro Devices, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "base/intmath.hh"
31 #include "cpu/testers/rubytest/Check.hh"
32 #include "cpu/testers/rubytest/CheckTable.hh"
33 #include "debug/RubyTest.hh"
35 CheckTable::CheckTable(int _num_writers
, int _num_readers
, RubyTester
* _tester
)
36 : m_num_writers(_num_writers
), m_num_readers(_num_readers
),
39 physical_address_t physical
= 0;
43 const int size2
= 100;
45 // The first set is to get some false sharing
47 for (int i
= 0; i
< size1
; i
++) {
48 // Setup linear addresses
49 address
.setAddress(physical
);
51 physical
+= CHECK_SIZE
;
54 // The next two sets are to get some limited false sharing and
57 for (int i
= 0; i
< size2
; i
++) {
58 // Setup linear addresses
59 address
.setAddress(physical
);
64 physical
= 1000 + CHECK_SIZE
;
65 for (int i
= 0; i
< size2
; i
++) {
66 // Setup linear addresses
67 address
.setAddress(physical
);
73 CheckTable::~CheckTable()
75 int size
= m_check_vector
.size();
76 for (int i
= 0; i
< size
; i
++)
77 delete m_check_vector
[i
];
81 CheckTable::addCheck(const Address
& address
)
83 if (floorLog2(CHECK_SIZE
) != 0) {
84 if (address
.bitSelect(0, CHECK_SIZE_BITS
- 1) != 0) {
85 panic("Check not aligned");
89 for (int i
= 0; i
< CHECK_SIZE
; i
++) {
90 if (m_lookup_map
.count(Address(address
.getAddress()+i
))) {
91 // A mapping for this byte already existed, discard the
97 Check
* check_ptr
= new Check(address
, Address(100 + m_check_vector
.size()),
98 m_num_writers
, m_num_readers
, m_tester_ptr
);
99 for (int i
= 0; i
< CHECK_SIZE
; i
++) {
100 // Insert it once per byte
101 m_lookup_map
[Address(address
.getAddress() + i
)] = check_ptr
;
103 m_check_vector
.push_back(check_ptr
);
107 CheckTable::getRandomCheck()
109 assert(m_check_vector
.size() > 0);
110 return m_check_vector
[random() % m_check_vector
.size()];
114 CheckTable::getCheck(const Address
& address
)
116 DPRINTF(RubyTest
, "Looking for check by address: %s", address
);
118 m5::hash_map
<Address
, Check
*>::iterator i
= m_lookup_map
.find(address
);
120 if (i
== m_lookup_map
.end())
123 Check
* check
= i
->second
;
124 assert(check
!= NULL
);
129 CheckTable::print(std::ostream
& out
) const