gem5  v22.1.0.0
ExpectedMap.hh
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 
38 #ifndef __MEM_RUBY_COMMON_EXPECTEDMAP_HH__
39 #define __MEM_RUBY_COMMON_EXPECTEDMAP_HH__
40 
41 #include <cassert>
42 #include <iostream>
43 #include <unordered_map>
44 
45 namespace gem5
46 {
47 
48 namespace ruby
49 {
50 
51 // ExpectedMap helper class is used to facilitate tracking of pending
52 // response and data messages in the CHI protocol. It offers additional
53 // functionality when compared to plain counters:
54 // - tracks the expected type for received messages
55 // - tracks segmented data messages (i.e. when a line transfer is split in
56 // multiple messages)
57 
58 template<typename RespType, typename DataType>
60 {
61  private:
62 
63  template<typename Type>
65  {
67  {
68  std::size_t operator()(Type t) const
69  {
70  return static_cast<std::size_t>(t);
71  }
72  };
73 
74  private:
75  // chunks is the number segmented messages we expect to receive
76  // before incrementing numReceived. This is tipically always 1 for all
77  // non-data messages
78  int chunks;
79  int currChunk;
81  std::unordered_map<Type, bool, EnumClassHash> expectedTypes;
82 
83  public:
85  :chunks(1), currChunk(0), numReceived(0)
86  {}
87 
88  void
89  clear(int msg_chunks)
90  {
91  chunks = msg_chunks;
92  currChunk = 0;
93  numReceived = 0;
94  expectedTypes.clear();
95  }
96 
97  void
99  {
100  expectedTypes[val] = false;
101  }
102 
103  int received() const { return numReceived; }
104 
105  bool
107  {
108  if (expectedTypes.find(val) == expectedTypes.end())
109  return false;
110 
111  expectedTypes[val] = true;
112  ++currChunk;
113  if (currChunk == chunks) {
114  ++numReceived;
115  currChunk = 0;
116  }
117 
118  return true;
119  }
120 
121  bool
122  receivedType(const Type &val) const
123  {
124  auto i = expectedTypes.find(val);
125  if (i != expectedTypes.end())
126  return i->second;
127  else
128  return false;
129  }
130  };
131 
135 
136  public:
139  {}
140 
141  // Clear the tracking state and specified the number of chunks are required
142  // to receive a complete data message
143  void
144  clear(int dataChunks)
145  {
146  expectedData.clear(dataChunks);
147  expectedResp.clear(1);
148  totalExpected = 0;
149  }
150 
151  // Register an expected response message type
152  void
153  addExpectedRespType(const RespType &val)
154  {
156  }
157 
158  // Register an expected data message type
159  void
160  addExpectedDataType(const DataType &val)
161  {
163  }
164 
165  // Set the number of expected messages
167 
169 
170  // Returns the number of messages received.
171  // Notice that a data message counts as received only after all of
172  // its chunks are received.
173  int
174  received() const
175  {
177  }
178 
179  // Returns the remaining number of expected messages
180  int expected() const { return totalExpected - received(); }
181 
182  // Has any expected message ?
183  bool hasExpected() const { return expected() != 0; }
184 
185  // Has received any data ?
186  bool hasReceivedData() const { return expectedData.received() != 0; }
187 
188  // Has received any response ?
189  bool hasReceivedResp() const { return expectedResp.received() != 0; }
190 
191 
192  // Notifies that a response message was received
193  bool
194  receiveResp(const RespType &val)
195  {
196  assert(received() < totalExpected);
198  }
199 
200  // Notifies that a data message chunk was received
201  bool
202  receiveData(const DataType &val)
203  {
204  assert(received() <= totalExpected);
206  }
207 
208  // Has received any data of the given type ?
209  bool
210  receivedDataType(const DataType &val) const
211  {
212  return expectedData.receivedType(val);
213  }
214 
215  // Has received any response of the given type ?
216  bool
217  receivedRespType(const RespType &val) const
218  {
219  return expectedResp.receivedType(val);
220  }
221 
222  void
223  print(std::ostream& out) const
224  {
225  out << expected();
226  }
227 };
228 
229 template<typename RespType, typename DataType>
230 inline std::ostream&
231 operator<<(std::ostream& out, const ExpectedMap<RespType,DataType>& obj)
232 {
233  obj.print(out);
234  return out;
235 }
236 
237 } // namespace ruby
238 } // namespace gem5
239 
240 #endif // __MEM_RUBY_COMMON_EXPECTEDMAP_HH__
ExpectedState< DataType > expectedData
Definition: ExpectedMap.hh:132
void print(std::ostream &out) const
Definition: ExpectedMap.hh:223
bool hasReceivedResp() const
Definition: ExpectedMap.hh:189
bool receivedRespType(const RespType &val) const
Definition: ExpectedMap.hh:217
void addExpectedCount(int val)
Definition: ExpectedMap.hh:168
void clear(int dataChunks)
Definition: ExpectedMap.hh:144
bool receivedDataType(const DataType &val) const
Definition: ExpectedMap.hh:210
void setExpectedCount(int val)
Definition: ExpectedMap.hh:166
void addExpectedDataType(const DataType &val)
Definition: ExpectedMap.hh:160
bool receiveResp(const RespType &val)
Definition: ExpectedMap.hh:194
bool hasReceivedData() const
Definition: ExpectedMap.hh:186
ExpectedState< RespType > expectedResp
Definition: ExpectedMap.hh:133
bool receiveData(const DataType &val)
Definition: ExpectedMap.hh:202
bool hasExpected() const
Definition: ExpectedMap.hh:183
void addExpectedRespType(const RespType &val)
Definition: ExpectedMap.hh:153
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 51 > t
Definition: pagetable.hh:56
Bitfield< 63 > val
Definition: misc.hh:776
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition: BoolVec.cc:49
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
void addExpectedType(const Type &val)
Definition: ExpectedMap.hh:98
bool receivedType(const Type &val) const
Definition: ExpectedMap.hh:122
std::unordered_map< Type, bool, EnumClassHash > expectedTypes
Definition: ExpectedMap.hh:81
bool increaseReceived(const Type &val)
Definition: ExpectedMap.hh:106

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