gem5  v22.1.0.0
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 
40 namespace gem5
41 {
42 
43 namespace ruby
44 {
45 
46 // Based on the current set of TBEs, choose a new "distributor"
47 // Can return null -> no distributor
48 MiscNode_TBE*
50 {
51  // Run over the current TBEs, gather information
52  std::vector<MiscNode_TBE*> ready_sync_tbes;
53  std::vector<MiscNode_TBE*> ready_nonsync_tbes;
54  std::vector<MiscNode_TBE*> potential_sync_dependency_tbes;
55  bool has_waiting_sync = false;
56  int waiting_count = 0;
57  for (auto& keyValuePair : m_map) {
58  MiscNode_TBE& tbe = keyValuePair.second;
59 
60  switch (tbe.getstate()) {
61  case MiscNode_State_DvmSync_Distributing:
62  case MiscNode_State_DvmNonSync_Distributing:
63  // If something is still distributing, just return it
64  return &tbe;
65  case MiscNode_State_DvmSync_ReadyToDist:
66  ready_sync_tbes.push_back(&tbe);
67  break;
68  case MiscNode_State_DvmNonSync_ReadyToDist:
69  ready_nonsync_tbes.push_back(&tbe);
70  // Sync ops can potentially depend on not-executed NonSync ops
71  potential_sync_dependency_tbes.push_back(&tbe);
72  break;
73  case MiscNode_State_DvmSync_Waiting:
74  has_waiting_sync = true;
75  waiting_count++;
76  break;
77  case MiscNode_State_DvmNonSync_Waiting:
78  waiting_count++;
79  // Sync ops can potentially depend on not-finished NonSync ops
80  potential_sync_dependency_tbes.push_back(&tbe);
81  break;
82  default:
83  break;
84  }
85  }
86 
87  // At most ~4 pending snoops at the RN-F
88  // => for safety we only allow 4 ops waiting + distributing at a time
89  // => if 4 are waiting currently, don't start distributing another one
90  assert(waiting_count <= 4);
91  if (waiting_count == 4) {
92  return nullptr;
93  }
94 
95  // If there's a waiting Sync op, don't allow other Sync ops to start.
96  if (has_waiting_sync) {
97  ready_sync_tbes.clear();
98  }
99 
100  // We need to handle NonSync -> Sync dependencies
101  // If we send CompDBIDResp for a Non-Sync that hasn't started,
102  // the RN-F can send a dependent Sync immediately afterwards.
103  // The Non-Sync must receive all responses before the Sync starts.
104  // => ignore Syncs which arrive after unfinished NonSyncs
105  auto hasNonSyncDependency = [&](const MiscNode_TBE* sync_tbe) {
106  for (const auto* potential_dep : potential_sync_dependency_tbes) {
107  if (sync_tbe->gettimestamp() > potential_dep->gettimestamp() &&
108  sync_tbe->getrequestor() == potential_dep->getrequestor()) {
109  // A NonSync from the same machine arrived before us
110  // => we have a dependency
111  return true;
112  }
113  }
114  return false;
115  };
116  // Erase-remove idiom to remove elements at arbitrary indices
117  // https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom
118  // This calls an O(n) function n times = O(n^2) worst case.
119  // TODO this should be improved if n grows > 16
120  ready_sync_tbes.erase(
121  std::remove_if(ready_sync_tbes.begin(), ready_sync_tbes.end(),
122  hasNonSyncDependency),
123  ready_sync_tbes.end()
124  );
125 
126  // TODO shouldn't use age?
127 
128  // Extend ready_nonsync_tbes with the contents of ready_sync_tbes
129  ready_nonsync_tbes.insert(ready_nonsync_tbes.end(),
130  ready_sync_tbes.begin(), ready_sync_tbes.end());
131 
132  // Check if no candidates
133  if (ready_nonsync_tbes.empty())
134  return nullptr;
135 
136  // Otherwise select the minimum timestamp = oldest element
137  auto it = std::min_element(
138  ready_nonsync_tbes.begin(), ready_nonsync_tbes.end(),
139  [](const MiscNode_TBE* a, const MiscNode_TBE* b) {
140  return a->gettimestamp() - b->gettimestamp();
141  }
142  );
143  assert(it != ready_nonsync_tbes.end());
144  return *it;
145 }
146 
147 } // namespace ruby
148 
149 } // namespace gem5
MiscNode_TBE * chooseNewDistributor()
Definition: MN_TBETable.cc:49
std::unordered_map< Addr, MiscNode_TBE > m_map
Definition: TBETable.hh:85
STL vector class.
Definition: stl.hh:37
Bitfield< 7 > b
Definition: misc_types.hh:388
Bitfield< 8 > a
Definition: misc_types.hh:66
Bitfield< 17 > tbe
Definition: mt_constants.hh:80
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....

Generated on Wed Dec 21 2022 10:22:38 for gem5 by doxygen 1.9.1