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/rubytest/Check.hh"
32 #include "cpu/rubytest/CheckTable.hh"
33 #include "cpu/rubytest/CheckTable.hh"
34 #include "mem/gems_common/Map.hh"
36 CheckTable::CheckTable(int _num_cpu_sequencers
, RubyTester
* _tester
)
37 : m_num_cpu_sequencers(_num_cpu_sequencers
), m_tester_ptr(_tester
)
39 m_lookup_map_ptr
= new Map
<Address
, Check
*>;
40 physical_address_t physical
= 0;
44 const int size2
= 100;
46 // The first set is to get some false sharing
48 for (int i
= 0; i
< size1
; i
++) {
49 // Setup linear addresses
50 address
.setAddress(physical
);
52 physical
+= CHECK_SIZE
;
55 // The next two sets are to get some limited false sharing and
58 for (int i
= 0; i
< size2
; i
++) {
59 // Setup linear addresses
60 address
.setAddress(physical
);
65 physical
= 1000 + CHECK_SIZE
;
66 for (int i
= 0; i
< size2
; i
++) {
67 // Setup linear addresses
68 address
.setAddress(physical
);
74 CheckTable::~CheckTable()
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
;
83 CheckTable::addCheck(const Address
& address
)
85 if (floorLog2(CHECK_SIZE
) != 0) {
86 if (address
.bitSelect(0, CHECK_SIZE_BITS
- 1) != 0) {
87 ERROR_MSG("Check not aligned");
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
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
);
105 m_check_vector
.insertAtBottom(check_ptr
);
109 CheckTable::getRandomCheck()
111 return m_check_vector
[random() % m_check_vector
.size()];
115 CheckTable::getCheck(const Address
& address
)
117 DEBUG_MSG(TESTER_COMP
, MedPrio
, "Looking for check by address");
118 DEBUG_EXPR(TESTER_COMP
, MedPrio
, address
);
120 if (m_lookup_map_ptr
->exist(address
)) {
121 Check
* check
= m_lookup_map_ptr
->lookup(address
);
122 assert(check
!= NULL
);
130 CheckTable::print(std::ostream
& out
) const