gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MN_TBETable.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
39
40namespace gem5
41{
42
43namespace ruby
44{
45
46namespace CHI
47{
48
49// Based on the current set of TBEs, choose a new "distributor"
50// Can return null -> no distributor
51MiscNode_TBE*
53{
54 // Run over the current TBEs, gather information
55 std::vector<MiscNode_TBE*> ready_sync_tbes;
56 std::vector<MiscNode_TBE*> ready_nonsync_tbes;
57 std::vector<MiscNode_TBE*> potential_sync_dependency_tbes;
58 bool has_waiting_sync = false;
59 int waiting_count = 0;
60 for (auto& keyValuePair : m_map) {
61 MiscNode_TBE& tbe = keyValuePair.second;
62
63 switch (tbe.getstate()) {
64 case MiscNode_State_DvmSync_Distributing:
65 case MiscNode_State_DvmNonSync_Distributing:
66 // If something is still distributing, just return it
67 return &tbe;
68 case MiscNode_State_DvmSync_ReadyToDist:
69 ready_sync_tbes.push_back(&tbe);
70 break;
71 case MiscNode_State_DvmNonSync_ReadyToDist:
72 ready_nonsync_tbes.push_back(&tbe);
73 // Sync ops can potentially depend on not-executed NonSync ops
74 potential_sync_dependency_tbes.push_back(&tbe);
75 break;
76 case MiscNode_State_DvmSync_Waiting:
77 has_waiting_sync = true;
78 waiting_count++;
79 break;
80 case MiscNode_State_DvmNonSync_Waiting:
81 waiting_count++;
82 // Sync ops can potentially depend on not-finished NonSync ops
83 potential_sync_dependency_tbes.push_back(&tbe);
84 break;
85 default:
86 break;
87 }
88 }
89
90 // At most ~4 pending snoops at the RN-F
91 // => for safety we only allow 4 ops waiting + distributing at a time
92 // => if 4 are waiting currently, don't start distributing another one
93 assert(waiting_count <= 4);
94 if (waiting_count == 4) {
95 return nullptr;
96 }
97
98 // If there's a waiting Sync op, don't allow other Sync ops to start.
99 if (has_waiting_sync) {
100 ready_sync_tbes.clear();
101 }
102
103 // We need to handle NonSync -> Sync dependencies
104 // If we send CompDBIDResp for a Non-Sync that hasn't started,
105 // the RN-F can send a dependent Sync immediately afterwards.
106 // The Non-Sync must receive all responses before the Sync starts.
107 // => ignore Syncs which arrive after unfinished NonSyncs
108 auto hasNonSyncDependency = [&](const MiscNode_TBE* sync_tbe) {
109 for (const auto* potential_dep : potential_sync_dependency_tbes) {
110 if (sync_tbe->gettimestamp() > potential_dep->gettimestamp() &&
111 sync_tbe->getrequestor() == potential_dep->getrequestor()) {
112 // A NonSync from the same machine arrived before us
113 // => we have a dependency
114 return true;
115 }
116 }
117 return false;
118 };
119 // Erase-remove idiom to remove elements at arbitrary indices
120 // https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom
121 // This calls an O(n) function n times = O(n^2) worst case.
122 // TODO this should be improved if n grows > 16
123 ready_sync_tbes.erase(
124 std::remove_if(ready_sync_tbes.begin(), ready_sync_tbes.end(),
125 hasNonSyncDependency),
126 ready_sync_tbes.end()
127 );
128
129 // TODO shouldn't use age?
130
131 // Extend ready_nonsync_tbes with the contents of ready_sync_tbes
132 ready_nonsync_tbes.insert(ready_nonsync_tbes.end(),
133 ready_sync_tbes.begin(), ready_sync_tbes.end());
134
135 // Check if no candidates
136 if (ready_nonsync_tbes.empty())
137 return nullptr;
138
139 // Otherwise select the minimum timestamp = oldest element
140 auto it = std::min_element(
141 ready_nonsync_tbes.begin(), ready_nonsync_tbes.end(),
142 [](const MiscNode_TBE* a, const MiscNode_TBE* b) {
143 return a->gettimestamp() - b->gettimestamp();
144 }
145 );
146 assert(it != ready_nonsync_tbes.end());
147 return *it;
148}
149
150} // namespace CHI
151
152} // namespace ruby
153
154} // namespace gem5
MiscNode_TBE * chooseNewDistributor()
std::unordered_map< Addr, MiscNode_TBE > m_map
Definition TBETable.hh:87
STL vector class.
Definition stl.hh:37
Bitfield< 7 > b
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 17 > tbe
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36

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