ChampSim
mocks.hpp
Go to the documentation of this file.
1 #include <deque>
2 #include <exception>
3 #include <functional>
4 #include <limits>
5 
6 #include "cache.h"
7 #include "operable.h"
8 
9 /*
10  * A MemoryRequestConsumer that simply returns all packets on the next cycle
11  */
13 {
15  {
16  uint64_t event_cycle = std::numeric_limits<uint64_t>::max();
17  };
18  std::deque<packet> packets, ready_packets;
19  uint64_t ret_data = 0x11111111;
20  const uint64_t latency = 0;
21 
22  public:
24  std::deque<uint64_t> addresses{};
25  do_nothing_MRC(uint64_t lat) : champsim::operable(1), latency(lat) {}
27 
28  long operate() override {
29  auto add_pkt = [&](auto pkt) {
30  packet to_insert{pkt};
31  to_insert.event_cycle = current_cycle + latency;
32  to_insert.data = ++ret_data;
33  addresses.push_back(to_insert.address);
34  packets.push_back(to_insert);
35  };
36 
37  std::for_each(std::begin(queues.RQ), std::end(queues.RQ), add_pkt);
38  std::for_each(std::begin(queues.WQ), std::end(queues.WQ), add_pkt);
39  std::for_each(std::begin(queues.PQ), std::end(queues.PQ), add_pkt);
40 
41  queues.RQ.clear();
42  queues.WQ.clear();
43  queues.PQ.clear();
44 
45  auto end = std::find_if_not(std::begin(packets), std::end(packets), [cycle=current_cycle](const auto &x){ return x.event_cycle <= cycle; });
46  std::move(std::begin(packets), end, std::back_inserter(ready_packets));
47  packets.erase(std::begin(packets), end);
48 
49  for (auto &pkt : ready_packets) {
50  if (pkt.response_requested)
52  }
53  ready_packets.clear();
54 
55  return 1; // never deadlock
56  }
57 
58  std::size_t packet_count() const { return std::size(addresses); }
59 };
60 
61 /*
62  * A MemoryRequestConsumer that returns only a particular address
63  */
65 {
67  {
68  uint64_t event_cycle = std::numeric_limits<uint64_t>::max();
69  };
70  std::deque<packet> packets, ready_packets;
71  const uint64_t ret_addr;
72  const uint64_t latency = 0;
73  std::size_t mpacket_count = 0;
74 
75  public:
77  filter_MRC(uint64_t ret_addr_, uint64_t lat) : champsim::operable(1), ret_addr(ret_addr_), latency(lat) {}
78  filter_MRC(uint64_t ret_addr_) : filter_MRC(ret_addr_, 0) {}
79 
80  long operate() override {
81  auto add_pkt = [&](auto pkt) {
82  if (pkt.address == ret_addr) {
83  packet to_insert{pkt};
84  to_insert.event_cycle = current_cycle + latency;
85  packets.push_back(to_insert);
86  ++mpacket_count;
87  }
88  };
89 
90  std::for_each(std::begin(queues.RQ), std::end(queues.RQ), add_pkt);
91  std::for_each(std::begin(queues.WQ), std::end(queues.WQ), add_pkt);
92  std::for_each(std::begin(queues.PQ), std::end(queues.PQ), add_pkt);
93 
94  queues.RQ.clear();
95  queues.WQ.clear();
96  queues.PQ.clear();
97 
98  auto end = std::find_if_not(std::begin(packets), std::end(packets), [cycle=current_cycle](const auto &x){ return x.event_cycle <= cycle; });
99  std::move(std::begin(packets), end, std::back_inserter(ready_packets));
100 
101  for (auto &pkt : ready_packets) {
102  if (pkt.response_requested)
104  }
105  ready_packets.clear();
106 
107  return 1; // never deadlock
108  }
109 
110  std::size_t packet_count() const { return mpacket_count; }
111 };
112 
113 /*
114  * A MemoryRequestConsumer that releases blocks when instructed to
115  */
117 {
118  std::deque<champsim::channel::request_type> packets;
119  std::size_t mpacket_count = 0;
120  uint64_t ret_data = 0x11111111;
121 
122  public:
125 
126  long operate() override {
127  auto add_pkt = [&](auto pkt) {
128  packets.push_back(pkt);
129  ++mpacket_count;
130  packets.back().data = ++ret_data;
131  };
132 
133  std::for_each(std::begin(queues.RQ), std::end(queues.RQ), add_pkt);
134  std::for_each(std::begin(queues.WQ), std::end(queues.WQ), add_pkt);
135  std::for_each(std::begin(queues.PQ), std::end(queues.PQ), add_pkt);
136 
137  queues.RQ.clear();
138  queues.WQ.clear();
139  queues.PQ.clear();
140 
141  return 1; // never deadlock
142  }
143 
144  std::size_t packet_count() const { return mpacket_count; }
145 
146  void release_all()
147  {
148  for (const auto &pkt : packets) {
149  if (pkt.response_requested)
151  }
152  packets.clear();
153  }
154 
155  void release(uint64_t addr)
156  {
157  auto pkt_it = std::partition(std::begin(packets), std::end(packets), [addr](auto x){ return x.address != addr; });
158  std::for_each(pkt_it, std::end(packets), [&](const auto& pkt) {
159  if (pkt.response_requested)
161  });
162  packets.erase(pkt_it, std::end(packets));
163  }
164 };
165 
166 /*
167  * A MemoryRequestProducer that counts how many returns it receives
168  */
170 {
171  std::deque<champsim::channel::response_type> returned{};
172 
173  std::size_t count = 0;
174 
175  long operate() {
176  count += std::size(returned);
177  returned.clear();
178 
179  return 1; // never deadlock
180  }
181 };
182 
184 {
187 
188  std::deque<response_type> returned{};
190 
191  struct result_data {
193  uint64_t issue_time;
194  uint64_t return_time;
195  };
196  std::deque<result_data> packets;
197 
198  using func_type = std::function<bool(request_type, response_type)>;
200 
201  queue_issue_MRP() : queue_issue_MRP([](auto x, auto y){ return x.address == y.address; }) {}
202  explicit queue_issue_MRP(func_type finder) : champsim::operable(1), top_finder(finder) {}
203 
204  long operate() override {
205  auto finder = [&](response_type to_find, result_data candidate) { return top_finder(candidate.pkt, to_find); };
206 
207  for (auto pkt : queues.returned) {
208  auto it = std::partition(std::begin(packets), std::end(packets), std::not_fn(std::bind(finder, pkt, std::placeholders::_1)));
209  if (it == std::end(packets))
210  throw std::invalid_argument{"Packet returned which was not sent"};
211  std::for_each(it, std::end(packets), [cycle=current_cycle](auto& x){ return x.return_time = cycle; });
212  }
213  queues.returned.clear();
214 
215  return 1; // never deadlock
216  }
217 };
218 
219 /*
220  * A MemoryRequestProducer that sends its packets to the write queue and notes when packets are returned
221  */
222 struct to_wq_MRP : public queue_issue_MRP
223 {
227  packets.push_back({pkt, current_cycle, 0});
228  return queues.add_wq(pkt);
229  }
230 };
231 
232 /*
233  * A MemoryRequestProducer that sends its packets to the read queue and notes when packets are returned
234  */
235 struct to_rq_MRP : public queue_issue_MRP
236 {
240  packets.push_back({pkt, current_cycle, 0});
241  return queues.add_rq(pkt);
242  }
243 };
244 
245 /*
246  * A MemoryRequestProducer that sends its packets to the read queue and notes when packets are returned
247  */
248 struct to_pq_MRP : public queue_issue_MRP
249 {
253  packets.push_back({pkt, current_cycle, 0});
254  return queues.add_pq(pkt);
255  }
256 };
257 
Definition: channel.h:64
bool add_wq(const request_type &packet)
Definition: channel.cc:155
response response_type
Definition: channel.h:109
bool add_rq(const request_type &packet)
Definition: channel.cc:141
std::deque< request_type > WQ
Definition: channel.h:113
bool add_pq(const request_type &packet)
Definition: channel.cc:169
std::deque< request_type > RQ
Definition: channel.h:113
std::deque< response_type > returned
Definition: channel.h:114
std::deque< request_type > PQ
Definition: channel.h:113
request request_type
Definition: channel.h:110
Definition: operable.h:24
uint64_t current_cycle
Definition: operable.h:29
operable(double scale)
Definition: operable.h:32
Definition: mocks.hpp:13
std::deque< packet > packets
Definition: mocks.hpp:18
champsim::channel queues
Definition: mocks.hpp:23
std::deque< uint64_t > addresses
Definition: mocks.hpp:24
do_nothing_MRC()
Definition: mocks.hpp:26
do_nothing_MRC(uint64_t lat)
Definition: mocks.hpp:25
long operate() override
Definition: mocks.hpp:28
uint64_t ret_data
Definition: mocks.hpp:19
const uint64_t latency
Definition: mocks.hpp:20
std::size_t packet_count() const
Definition: mocks.hpp:58
std::deque< packet > ready_packets
Definition: mocks.hpp:18
Definition: mocks.hpp:65
const uint64_t latency
Definition: mocks.hpp:72
long operate() override
Definition: mocks.hpp:80
std::deque< packet > packets
Definition: mocks.hpp:70
champsim::channel queues
Definition: mocks.hpp:76
const uint64_t ret_addr
Definition: mocks.hpp:71
std::size_t packet_count() const
Definition: mocks.hpp:110
filter_MRC(uint64_t ret_addr_, uint64_t lat)
Definition: mocks.hpp:77
std::deque< packet > ready_packets
Definition: mocks.hpp:70
std::size_t mpacket_count
Definition: mocks.hpp:73
filter_MRC(uint64_t ret_addr_)
Definition: mocks.hpp:78
Definition: mocks.hpp:117
std::size_t mpacket_count
Definition: mocks.hpp:119
std::deque< champsim::channel::request_type > packets
Definition: mocks.hpp:118
uint64_t ret_data
Definition: mocks.hpp:120
void release(uint64_t addr)
Definition: mocks.hpp:155
long operate() override
Definition: mocks.hpp:126
void release_all()
Definition: mocks.hpp:146
release_MRC()
Definition: mocks.hpp:124
champsim::channel queues
Definition: mocks.hpp:123
std::size_t packet_count() const
Definition: mocks.hpp:144
Definition: champsim.h:24
Definition: channel.h:65
Definition: channel.h:85
Definition: mocks.hpp:170
long operate()
Definition: mocks.hpp:175
std::size_t count
Definition: mocks.hpp:173
std::deque< champsim::channel::response_type > returned
Definition: mocks.hpp:171
Definition: mocks.hpp:15
uint64_t event_cycle
Definition: mocks.hpp:16
Definition: mocks.hpp:67
uint64_t event_cycle
Definition: mocks.hpp:68
Definition: mocks.hpp:191
request_type pkt
Definition: mocks.hpp:192
uint64_t issue_time
Definition: mocks.hpp:193
uint64_t return_time
Definition: mocks.hpp:194
Definition: mocks.hpp:184
std::deque< result_data > packets
Definition: mocks.hpp:196
champsim::channel queues
Definition: mocks.hpp:189
typename champsim::channel::response_type response_type
Definition: mocks.hpp:186
queue_issue_MRP()
Definition: mocks.hpp:201
typename champsim::channel::request_type request_type
Definition: mocks.hpp:185
queue_issue_MRP(func_type finder)
Definition: mocks.hpp:202
func_type top_finder
Definition: mocks.hpp:199
std::function< bool(request_type, response_type)> func_type
Definition: mocks.hpp:198
std::deque< response_type > returned
Definition: mocks.hpp:188
long operate() override
Definition: mocks.hpp:204
Definition: mocks.hpp:249
bool issue(const queue_issue_MRP::request_type &pkt)
Definition: mocks.hpp:252
Definition: mocks.hpp:236
bool issue(const queue_issue_MRP::request_type &pkt)
Definition: mocks.hpp:239
Definition: mocks.hpp:223
bool issue(const queue_issue_MRP::request_type &pkt)
Definition: mocks.hpp:226