ChampSim
ptw.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 PTW_H
18 #define PTW_H
19 
20 #include <array>
21 #include <deque>
22 #include <string>
23 
24 #include "channel.h"
25 #include "operable.h"
26 #include "util/lru_table.h"
27 
28 class VirtualMemory;
30 {
31  struct pscl_entry {
32  uint64_t vaddr;
33  uint64_t ptw_addr;
34  std::size_t level;
35  };
36 
37  struct pscl_indexer {
38  std::size_t shamt;
39  auto operator()(const pscl_entry& entry) const { return entry.vaddr >> shamt; }
40  };
41 
46 
47  struct mshr_type {
48  uint64_t address = 0;
49  uint64_t v_address = 0;
50  uint64_t data = 0;
51 
52  std::vector<std::reference_wrapper<ooo_model_instr>> instr_depend_on_me{};
53  std::vector<std::deque<response_type>*> to_return{};
54 
55  uint64_t event_cycle = std::numeric_limits<uint64_t>::max();
56  uint32_t pf_metadata = 0;
57  uint32_t cpu = std::numeric_limits<uint32_t>::max();
58  uint8_t asid[2] = {std::numeric_limits<uint8_t>::max(), std::numeric_limits<uint8_t>::max()};
59 
60  std::size_t translation_level = 0;
61 
62  mshr_type(request_type req, std::size_t level);
63  };
64 
65  std::deque<mshr_type> MSHR;
66  std::deque<mshr_type> finished;
67  std::deque<mshr_type> completed;
68 
69  std::vector<channel_type*> upper_levels;
71 
72  std::optional<mshr_type> handle_read(const request_type& pkt, channel_type* ul);
73  std::optional<mshr_type> handle_fill(const mshr_type& pkt);
74  std::optional<mshr_type> step_translation(const mshr_type& source);
75 
76  void finish_packet(const response_type& packet);
77 
78 public:
79  const std::string NAME;
80  const uint32_t MSHR_SIZE;
81  const long int MAX_READ, MAX_FILL;
82  const uint64_t HIT_LATENCY;
83 
84  std::vector<pscl_type> pscl;
86 
87  const uint64_t CR3_addr;
88 
89  class Builder
90  {
91  std::string_view m_name{};
92  double m_freq_scale{};
93  uint32_t m_cpu{};
94  std::array<std::array<uint32_t, 3>, 16> m_pscl{}; // fixed size for now
95  uint32_t m_mshr_size{};
96  uint32_t m_max_tag_check{};
97  uint32_t m_max_fill{};
98  unsigned m_latency{};
99  std::vector<PageTableWalker::channel_type*> m_uls{};
102 
103  friend class PageTableWalker;
104 
105  public:
106  Builder& name(std::string_view name_)
107  {
108  m_name = name_;
109  return *this;
110  }
111  Builder& frequency(double freq_scale_)
112  {
113  m_freq_scale = freq_scale_;
114  return *this;
115  }
116  Builder& cpu(uint32_t cpu_)
117  {
118  m_cpu = cpu_;
119  return *this;
120  }
121  Builder& add_pscl(uint8_t lvl, uint32_t set, uint32_t way)
122  {
123  m_pscl.at(lvl) = {lvl, set, way};
124  return *this;
125  }
126  Builder& mshr_size(uint32_t mshr_size_)
127  {
128  m_mshr_size = mshr_size_;
129  return *this;
130  }
131  Builder& tag_bandwidth(uint32_t max_read_)
132  {
133  m_max_tag_check = max_read_;
134  return *this;
135  }
136  Builder& fill_bandwidth(uint32_t max_fill_)
137  {
138  m_max_fill = max_fill_;
139  return *this;
140  }
141  Builder& latency(unsigned latency_)
142  {
143  m_latency = latency_;
144  return *this;
145  }
146  Builder& upper_levels(std::vector<PageTableWalker::channel_type*>&& uls_)
147  {
148  m_uls = std::move(uls_);
149  return *this;
150  }
152  {
153  m_ll = ll_;
154  return *this;
155  }
157  {
158  m_vmem = vmem_;
159  return *this;
160  }
161  };
162 
163  explicit PageTableWalker(Builder builder);
164 
165  long operate() override final;
166 
167  void begin_phase() override final;
168  void print_deadlock() override final;
169 };
170 
171 #endif
Definition: ptw.h:90
unsigned m_latency
Definition: ptw.h:98
std::string_view m_name
Definition: ptw.h:91
uint32_t m_max_fill
Definition: ptw.h:97
uint32_t m_max_tag_check
Definition: ptw.h:96
Builder & latency(unsigned latency_)
Definition: ptw.h:141
Builder & cpu(uint32_t cpu_)
Definition: ptw.h:116
Builder & upper_levels(std::vector< PageTableWalker::channel_type * > &&uls_)
Definition: ptw.h:146
double m_freq_scale
Definition: ptw.h:92
Builder & virtual_memory(VirtualMemory *vmem_)
Definition: ptw.h:156
VirtualMemory * m_vmem
Definition: ptw.h:101
Builder & name(std::string_view name_)
Definition: ptw.h:106
uint32_t m_cpu
Definition: ptw.h:93
std::array< std::array< uint32_t, 3 >, 16 > m_pscl
Definition: ptw.h:94
Builder & mshr_size(uint32_t mshr_size_)
Definition: ptw.h:126
Builder & frequency(double freq_scale_)
Definition: ptw.h:111
std::vector< PageTableWalker::channel_type * > m_uls
Definition: ptw.h:99
Builder & fill_bandwidth(uint32_t max_fill_)
Definition: ptw.h:136
uint32_t m_mshr_size
Definition: ptw.h:95
Builder & lower_level(PageTableWalker::channel_type *ll_)
Definition: ptw.h:151
Builder & add_pscl(uint8_t lvl, uint32_t set, uint32_t way)
Definition: ptw.h:121
PageTableWalker::channel_type * m_ll
Definition: ptw.h:100
Builder & tag_bandwidth(uint32_t max_read_)
Definition: ptw.h:131
Definition: ptw.h:30
void begin_phase() override final
Definition: ptw.cc:200
const long int MAX_FILL
Definition: ptw.h:81
const uint32_t MSHR_SIZE
Definition: ptw.h:80
VirtualMemory * vmem
Definition: ptw.h:85
std::vector< pscl_type > pscl
Definition: ptw.h:84
typename channel_type::response_type response_type
Definition: ptw.h:45
void print_deadlock() override final
Definition: ptw.cc:210
std::deque< mshr_type > completed
Definition: ptw.h:67
typename channel_type::request_type request_type
Definition: ptw.h:44
const uint64_t HIT_LATENCY
Definition: ptw.h:82
long operate() override final
Definition: ptw.cc:112
std::vector< channel_type * > upper_levels
Definition: ptw.h:69
std::deque< mshr_type > MSHR
Definition: ptw.h:65
const std::string NAME
Definition: ptw.h:79
std::optional< mshr_type > handle_read(const request_type &pkt, channel_type *ul)
Definition: ptw.cc:49
const uint64_t CR3_addr
Definition: ptw.h:87
PageTableWalker(Builder builder)
Definition: ptw.cc:29
std::deque< mshr_type > finished
Definition: ptw.h:66
const long int MAX_READ
Definition: ptw.h:81
std::optional< mshr_type > step_translation(const mshr_type &source)
Definition: ptw.cc:92
void finish_packet(const response_type &packet)
Definition: ptw.cc:161
channel_type * lower_level
Definition: ptw.h:70
std::optional< mshr_type > handle_fill(const mshr_type &pkt)
Definition: ptw.cc:73
Definition: vmem.h:33
Definition: channel.h:64
response response_type
Definition: channel.h:109
request request_type
Definition: channel.h:110
Definition: lru_table.h:46
Definition: operable.h:24
Definition: ptw.h:47
uint64_t address
Definition: ptw.h:48
std::size_t translation_level
Definition: ptw.h:60
uint64_t event_cycle
Definition: ptw.h:55
uint32_t cpu
Definition: ptw.h:57
std::vector< std::deque< response_type > * > to_return
Definition: ptw.h:53
uint32_t pf_metadata
Definition: ptw.h:56
uint8_t asid[2]
Definition: ptw.h:58
uint64_t v_address
Definition: ptw.h:49
mshr_type(request_type req, std::size_t level)
Definition: ptw.cc:41
std::vector< std::reference_wrapper< ooo_model_instr > > instr_depend_on_me
Definition: ptw.h:52
uint64_t data
Definition: ptw.h:50
Definition: ptw.h:31
std::size_t level
Definition: ptw.h:34
uint64_t ptw_addr
Definition: ptw.h:33
uint64_t vaddr
Definition: ptw.h:32
Definition: ptw.h:37
std::size_t shamt
Definition: ptw.h:38
auto operator()(const pscl_entry &entry) const
Definition: ptw.h:39