gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CheckTable.cc
Go to the documentation of this file.
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
31
32#include "base/intmath.hh"
33#include "base/trace.hh"
35#include "debug/RubyTest.hh"
36
37namespace gem5
38{
39
40CheckTable::CheckTable(int _num_writers, int _num_readers, RubyTester* _tester)
41 : m_num_writers(_num_writers), m_num_readers(_num_readers),
42 m_tester_ptr(_tester)
43{
44 Addr physical = 0;
45
46 const int size1 = 32;
47 const int size2 = 100;
48
49 DPRINTF(RubyTest, "Adding false sharing checks\n");
50 // The first set is to get some false sharing
51 physical = 1000;
52 for (int i = 0; i < size1; i++) {
53 // Setup linear addresses
54 addCheck(physical);
55 physical += CHECK_SIZE;
56 }
57
58 DPRINTF(RubyTest, "Adding cache conflict checks\n");
59 // The next two sets are to get some limited false sharing and
60 // cache conflicts
61 physical = 1000;
62 for (int i = 0; i < size2; i++) {
63 // Setup linear addresses
64 addCheck(physical);
65 physical += 256;
66 }
67
68 DPRINTF(RubyTest, "Adding cache conflict checks2\n");
69 physical = 1000 + CHECK_SIZE;
70 for (int i = 0; i < size2; i++) {
71 // Setup linear addresses
72 addCheck(physical);
73 physical += 256;
74 }
75}
76
78{
79 int size = m_check_vector.size();
80 for (int i = 0; i < size; i++)
81 delete m_check_vector[i];
82}
83
84void
86{
87 if (floorLog2(CHECK_SIZE) != 0) {
88 if (ruby::bitSelect(address, 0, CHECK_SIZE_BITS - 1) != 0) {
89 panic("Check not aligned");
90 }
91 }
92
93 for (int i = 0; i < CHECK_SIZE; i++) {
94 if (m_lookup_map.count(address+i)) {
95 // A mapping for this byte already existed, discard the
96 // entire check
97 return;
98 }
99 }
100
101 DPRINTF(RubyTest, "Adding check for address: %s\n", address);
102
103 Check* check_ptr = new Check(address, 100 + m_check_vector.size(),
105 for (int i = 0; i < CHECK_SIZE; i++) {
106 // Insert it once per byte
107 m_lookup_map[address + i] = check_ptr;
108 }
109 m_check_vector.push_back(check_ptr);
110}
111
112Check*
114{
115 assert(m_check_vector.size() > 0);
116 return m_check_vector[rng->random<unsigned>(0, m_check_vector.size() - 1)];
117}
118
119Check*
121{
122 DPRINTF(RubyTest, "Looking for check by address: %s\n", address);
123
124 auto i = m_lookup_map.find(address);
125
126 if (i == m_lookup_map.end())
127 return NULL;
128
129 Check* check = i->second;
130 assert(check != NULL);
131 return check;
132}
133
134void
135CheckTable::print(std::ostream& out) const
136{
137}
138
139} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
RubyTester * m_tester_ptr
Definition CheckTable.hh:74
Check * getRandomCheck()
void print(std::ostream &out) const
std::unordered_map< Addr, Check * > m_lookup_map
Definition CheckTable.hh:70
std::vector< Check * > m_check_vector
Definition CheckTable.hh:69
Check * getCheck(Addr address)
Random::RandomPtr rng
Definition CheckTable.hh:75
void addCheck(Addr address)
Definition CheckTable.cc:85
CheckTable(int _num_writers, int _num_readers, RubyTester *_tester)
Definition CheckTable.cc:40
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition intmath.hh:59
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 7 > i
Definition misc_types.hh:67
Addr bitSelect(Addr addr, unsigned int small, unsigned int big)
Definition Address.cc:41
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
const int CHECK_SIZE_BITS
Definition Check.hh:49
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
const int CHECK_SIZE
Definition Check.hh:50

Generated on Mon Jan 13 2025 04:28:32 for gem5 by doxygen 1.9.8