ChampSim
channel.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 The ChampSim Contributors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CHANNEL_H
18 #define CHANNEL_H
19 
20 #include <array>
21 #include <cstdint>
22 #include <deque>
23 #include <functional>
24 #include <limits>
25 #include <vector>
26 
27 #include <string_view>
28 
29 struct ooo_model_instr;
30 
31 enum class access_type : unsigned {
32  LOAD = 0,
33  RFO,
34  PREFETCH,
35  WRITE,
37  NUM_TYPES,
38 };
39 
40 using namespace std::literals::string_view_literals;
41 inline constexpr std::array<std::string_view, static_cast<std::size_t>(access_type::NUM_TYPES)> access_type_names{"LOAD"sv, "RFO"sv, "PREFETCH"sv, "WRITE"sv,
42  "TRANSLATION"};
43 
44 namespace champsim
45 {
46 
48  uint64_t RQ_ACCESS = 0;
49  uint64_t RQ_MERGED = 0;
50  uint64_t RQ_FULL = 0;
51  uint64_t RQ_TO_CACHE = 0;
52  uint64_t PQ_ACCESS = 0;
53  uint64_t PQ_MERGED = 0;
54  uint64_t PQ_FULL = 0;
55  uint64_t PQ_TO_CACHE = 0;
56  uint64_t WQ_ACCESS = 0;
57  uint64_t WQ_MERGED = 0;
58  uint64_t WQ_FULL = 0;
59  uint64_t WQ_TO_CACHE = 0;
60  uint64_t WQ_FORWARD = 0;
61 };
62 
63 class channel
64 {
65  struct request {
66  bool forward_checked = false;
67  bool is_translated = true;
68  bool response_requested = true;
69 
70  uint8_t asid[2] = {std::numeric_limits<uint8_t>::max(), std::numeric_limits<uint8_t>::max()};
72 
73  uint32_t pf_metadata = 0;
74  uint32_t cpu = std::numeric_limits<uint32_t>::max();
75 
76  uint64_t address = 0;
77  uint64_t v_address = 0;
78  uint64_t data = 0;
79  uint64_t instr_id = 0;
80  uint64_t ip = 0;
81 
82  std::vector<std::reference_wrapper<ooo_model_instr>> instr_depend_on_me{};
83  };
84 
85  struct response {
86  uint64_t address;
87  uint64_t v_address;
88  uint64_t data;
89  uint32_t pf_metadata = 0;
90  std::vector<std::reference_wrapper<ooo_model_instr>> instr_depend_on_me{};
91 
92  response(uint64_t addr, uint64_t v_addr, uint64_t data_, uint32_t pf_meta, std::vector<std::reference_wrapper<ooo_model_instr>> deps)
93  : address(addr), v_address(v_addr), data(data_), pf_metadata(pf_meta), instr_depend_on_me(deps)
94  {
95  }
96  explicit response(request req) : response(req.address, req.v_address, req.data, req.pf_metadata, req.instr_depend_on_me) {}
97  };
98 
99  template <typename R>
100  bool do_add_queue(R& queue, std::size_t queue_size, const typename R::value_type& packet);
101 
102  std::size_t RQ_SIZE = std::numeric_limits<std::size_t>::max();
103  std::size_t PQ_SIZE = std::numeric_limits<std::size_t>::max();
104  std::size_t WQ_SIZE = std::numeric_limits<std::size_t>::max();
105  unsigned OFFSET_BITS = 0;
106  bool match_offset_bits = false;
107 
108 public:
112 
113  std::deque<request_type> RQ{}, PQ{}, WQ{};
114  std::deque<response_type> returned{};
115 
116  stats_type sim_stats{}, roi_stats{};
117 
118  channel() = default;
119  channel(std::size_t rq_size, std::size_t pq_size, std::size_t wq_size, unsigned offset_bits, bool match_offset);
120 
121  bool add_rq(const request_type& packet);
122  bool add_wq(const request_type& packet);
123  bool add_pq(const request_type& packet);
124 
125  std::size_t rq_occupancy() const;
126  std::size_t wq_occupancy() const;
127  std::size_t pq_occupancy() const;
128 
129  std::size_t rq_size() const;
130  std::size_t wq_size() const;
131  std::size_t pq_size() const;
132 
133  void check_collision();
134 };
135 } // namespace champsim
136 
137 #endif
constexpr std::array< std::string_view, static_cast< std::size_t >access_type::NUM_TYPES)> access_type_names
Definition: channel.h:41
access_type
Definition: channel.h:31
Definition: channel.h:64
Definition: champsim.h:24
Definition: channel.h:47
Definition: channel.h:65
Definition: channel.h:85
response(request req)
Definition: channel.h:96
uint64_t v_address
Definition: channel.h:87
uint64_t address
Definition: channel.h:86
response(uint64_t addr, uint64_t v_addr, uint64_t data_, uint32_t pf_meta, std::vector< std::reference_wrapper< ooo_model_instr >> deps)
Definition: channel.h:92
uint64_t data
Definition: channel.h:88
Definition: instruction.h:41