CheckTable.cc (8229:78bf55f23338) CheckTable.cc (8232:b28d06a175be)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * Copyright (c) 2009 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
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.
16 *
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.
28 */
29
30#include "base/intmath.hh"
31#include "cpu/testers/rubytest/Check.hh"
32#include "cpu/testers/rubytest/CheckTable.hh"
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * Copyright (c) 2009 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
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.
16 *
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.
28 */
29
30#include "base/intmath.hh"
31#include "cpu/testers/rubytest/Check.hh"
32#include "cpu/testers/rubytest/CheckTable.hh"
33#include "debug/RubyTest.hh"
33
34CheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester)
35 : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
36{
37 physical_address_t physical = 0;
38 Address address;
39
40 const int size1 = 32;
41 const int size2 = 100;
42
43 // The first set is to get some false sharing
44 physical = 1000;
45 for (int i = 0; i < size1; i++) {
46 // Setup linear addresses
47 address.setAddress(physical);
48 addCheck(address);
49 physical += CHECK_SIZE;
50 }
51
52 // The next two sets are to get some limited false sharing and
53 // cache conflicts
54 physical = 1000;
55 for (int i = 0; i < size2; i++) {
56 // Setup linear addresses
57 address.setAddress(physical);
58 addCheck(address);
59 physical += 256;
60 }
61
62 physical = 1000 + CHECK_SIZE;
63 for (int i = 0; i < size2; i++) {
64 // Setup linear addresses
65 address.setAddress(physical);
66 addCheck(address);
67 physical += 256;
68 }
69}
70
71CheckTable::~CheckTable()
72{
73 int size = m_check_vector.size();
74 for (int i = 0; i < size; i++)
75 delete m_check_vector[i];
76}
77
78void
79CheckTable::addCheck(const Address& address)
80{
81 if (floorLog2(CHECK_SIZE) != 0) {
82 if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) {
83 panic("Check not aligned");
84 }
85 }
86
87 for (int i = 0; i < CHECK_SIZE; i++) {
88 if (m_lookup_map.count(Address(address.getAddress()+i))) {
89 // A mapping for this byte already existed, discard the
90 // entire check
91 return;
92 }
93 }
94
95 Check* check_ptr = new Check(address, Address(100 + m_check_vector.size()),
96 m_num_cpu_sequencers, m_tester_ptr);
97 for (int i = 0; i < CHECK_SIZE; i++) {
98 // Insert it once per byte
99 m_lookup_map[Address(address.getAddress() + i)] = check_ptr;
100 }
101 m_check_vector.push_back(check_ptr);
102}
103
104Check*
105CheckTable::getRandomCheck()
106{
107 return m_check_vector[random() % m_check_vector.size()];
108}
109
110Check*
111CheckTable::getCheck(const Address& address)
112{
113 DPRINTF(RubyTest, "Looking for check by address: %s", address);
114
115 m5::hash_map<Address, Check*>::iterator i = m_lookup_map.find(address);
116
117 if (i == m_lookup_map.end())
118 return NULL;
119
120 Check* check = i->second;
121 assert(check != NULL);
122 return check;
123}
124
125void
126CheckTable::print(std::ostream& out) const
127{
128}
34
35CheckTable::CheckTable(int _num_cpu_sequencers, RubyTester* _tester)
36 : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
37{
38 physical_address_t physical = 0;
39 Address address;
40
41 const int size1 = 32;
42 const int size2 = 100;
43
44 // The first set is to get some false sharing
45 physical = 1000;
46 for (int i = 0; i < size1; i++) {
47 // Setup linear addresses
48 address.setAddress(physical);
49 addCheck(address);
50 physical += CHECK_SIZE;
51 }
52
53 // The next two sets are to get some limited false sharing and
54 // cache conflicts
55 physical = 1000;
56 for (int i = 0; i < size2; i++) {
57 // Setup linear addresses
58 address.setAddress(physical);
59 addCheck(address);
60 physical += 256;
61 }
62
63 physical = 1000 + CHECK_SIZE;
64 for (int i = 0; i < size2; i++) {
65 // Setup linear addresses
66 address.setAddress(physical);
67 addCheck(address);
68 physical += 256;
69 }
70}
71
72CheckTable::~CheckTable()
73{
74 int size = m_check_vector.size();
75 for (int i = 0; i < size; i++)
76 delete m_check_vector[i];
77}
78
79void
80CheckTable::addCheck(const Address& address)
81{
82 if (floorLog2(CHECK_SIZE) != 0) {
83 if (address.bitSelect(0, CHECK_SIZE_BITS - 1) != 0) {
84 panic("Check not aligned");
85 }
86 }
87
88 for (int i = 0; i < CHECK_SIZE; i++) {
89 if (m_lookup_map.count(Address(address.getAddress()+i))) {
90 // A mapping for this byte already existed, discard the
91 // entire check
92 return;
93 }
94 }
95
96 Check* check_ptr = new Check(address, Address(100 + m_check_vector.size()),
97 m_num_cpu_sequencers, m_tester_ptr);
98 for (int i = 0; i < CHECK_SIZE; i++) {
99 // Insert it once per byte
100 m_lookup_map[Address(address.getAddress() + i)] = check_ptr;
101 }
102 m_check_vector.push_back(check_ptr);
103}
104
105Check*
106CheckTable::getRandomCheck()
107{
108 return m_check_vector[random() % m_check_vector.size()];
109}
110
111Check*
112CheckTable::getCheck(const Address& address)
113{
114 DPRINTF(RubyTest, "Looking for check by address: %s", address);
115
116 m5::hash_map<Address, Check*>::iterator i = m_lookup_map.find(address);
117
118 if (i == m_lookup_map.end())
119 return NULL;
120
121 Check* check = i->second;
122 assert(check != NULL);
123 return check;
124}
125
126void
127CheckTable::print(std::ostream& out) const
128{
129}