ChampSim
dram_controller.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 DRAM_H
18 #define DRAM_H
19 
20 #include <array>
21 #include <cmath>
22 #include <limits>
23 #include <optional>
24 #include <string>
25 
26 #include "champsim_constants.h"
27 #include "channel.h"
28 #include "operable.h"
29 
30 struct dram_stats {
31  std::string name{};
33 
35 };
36 
37 struct DRAM_CHANNEL {
39  struct request_type {
40  bool scheduled = false;
41  bool forward_checked = false;
42 
43  uint8_t asid[2] = {std::numeric_limits<uint8_t>::max(), std::numeric_limits<uint8_t>::max()};
44 
45  uint32_t pf_metadata = 0;
46 
47  uint64_t address = 0;
48  uint64_t v_address = 0;
49  uint64_t data = 0;
50  uint64_t event_cycle = std::numeric_limits<uint64_t>::max();
51 
52  std::vector<std::reference_wrapper<ooo_model_instr>> instr_depend_on_me{};
53  std::vector<std::deque<response_type>*> to_return{};
54 
56  };
58  using queue_type = std::vector<std::optional<value_type>>;
59  queue_type WQ{DRAM_WQ_SIZE}, RQ{DRAM_RQ_SIZE};
60 
61  struct BANK_REQUEST {
62  bool valid = false, row_buffer_hit = false;
63 
64  std::size_t open_row = std::numeric_limits<uint32_t>::max();
65 
66  uint64_t event_cycle = 0;
67 
68  queue_type::iterator pkt;
69  };
70 
71  using request_array_type = std::array<BANK_REQUEST, DRAM_RANKS * DRAM_BANKS>;
73  request_array_type::iterator active_request = std::end(bank_request);
74 
75  bool write_mode = false;
76  uint64_t dbus_cycle_available = 0;
77 
80 
81  void check_collision();
82  void print_deadlock();
83 };
84 
86 {
90  std::vector<channel_type*> queues;
91 
92  // Latencies
94 
95  // these values control when to send out a burst of writes
96  constexpr static std::size_t DRAM_WRITE_HIGH_WM = ((DRAM_WQ_SIZE * 7) >> 3); // 7/8th
97  constexpr static std::size_t DRAM_WRITE_LOW_WM = ((DRAM_WQ_SIZE * 6) >> 3); // 6/8th
98  constexpr static std::size_t MIN_DRAM_WRITES_PER_SWITCH = ((DRAM_WQ_SIZE * 1) >> 2); // 1/4
99 
100  void initiate_requests();
101  bool add_rq(const request_type& pkt, champsim::channel* ul);
102  bool add_wq(const request_type& pkt);
103 
104 public:
105  std::array<DRAM_CHANNEL, DRAM_CHANNELS> channels;
106 
107  MEMORY_CONTROLLER(double freq_scale, int io_freq, double t_rp, double t_rcd, double t_cas, double turnaround, std::vector<channel_type*>&& ul);
108 
109  void initialize() override final;
110  long operate() override final;
111  void begin_phase() override final;
112  void end_phase(unsigned cpu) override final;
113  void print_deadlock() override final;
114 
115  std::size_t size() const;
116 
117  uint32_t dram_get_channel(uint64_t address);
118  uint32_t dram_get_rank(uint64_t address);
119  uint32_t dram_get_bank(uint64_t address);
120  uint32_t dram_get_row(uint64_t address);
121  uint32_t dram_get_column(uint64_t address);
122 };
123 
124 #endif
Definition: dram_controller.h:86
std::size_t size() const
Definition: dram_controller.cc:371
std::vector< channel_type * > queues
Definition: dram_controller.h:90
void begin_phase() override final
Definition: dram_controller.cc:197
typename channel_type::response_type response_type
Definition: dram_controller.h:89
bool add_wq(const request_type &pkt)
Definition: dram_controller.cc:318
uint32_t dram_get_rank(uint64_t address)
Definition: dram_controller.cc:359
void print_deadlock() override final
Definition: dram_controller.cc:374
const uint64_t DRAM_DBUS_TURN_AROUND_TIME
Definition: dram_controller.h:93
std::array< DRAM_CHANNEL, DRAM_CHANNELS > channels
Definition: dram_controller.h:105
long operate() override final
Definition: dram_controller.cc:44
void end_phase(unsigned cpu) override final
Definition: dram_controller.cc:213
uint32_t dram_get_channel(uint64_t address)
Definition: dram_controller.cc:341
const uint64_t tCAS
Definition: dram_controller.h:93
const uint64_t tRP
Definition: dram_controller.h:93
uint32_t dram_get_bank(uint64_t address)
Definition: dram_controller.cc:347
constexpr static std::size_t DRAM_WRITE_HIGH_WM
Definition: dram_controller.h:96
void initialize() override final
Definition: dram_controller.cc:186
typename channel_type::request_type request_type
Definition: dram_controller.h:88
bool add_rq(const request_type &pkt, champsim::channel *ul)
Definition: dram_controller.cc:299
constexpr static std::size_t DRAM_WRITE_LOW_WM
Definition: dram_controller.h:97
const uint64_t DRAM_DBUS_RETURN_TIME
Definition: dram_controller.h:93
uint32_t dram_get_column(uint64_t address)
Definition: dram_controller.cc:353
void initiate_requests()
Definition: dram_controller.cc:277
MEMORY_CONTROLLER(double freq_scale, int io_freq, double t_rp, double t_rcd, double t_cas, double turnaround, std::vector< channel_type * > &&ul)
Definition: dram_controller.cc:36
const uint64_t tRCD
Definition: dram_controller.h:93
uint32_t dram_get_row(uint64_t address)
Definition: dram_controller.cc:365
constexpr static std::size_t MIN_DRAM_WRITES_PER_SWITCH
Definition: dram_controller.h:98
Definition: channel.h:64
response response_type
Definition: channel.h:109
request request_type
Definition: channel.h:110
Definition: operable.h:24
Definition: dram_controller.h:61
queue_type::iterator pkt
Definition: dram_controller.h:68
bool valid
Definition: dram_controller.h:62
uint64_t event_cycle
Definition: dram_controller.h:66
std::size_t open_row
Definition: dram_controller.h:64
bool row_buffer_hit
Definition: dram_controller.h:62
Definition: dram_controller.h:39
bool forward_checked
Definition: dram_controller.h:41
uint32_t pf_metadata
Definition: dram_controller.h:45
uint64_t address
Definition: dram_controller.h:47
request_type(typename champsim::channel::request_type)
Definition: dram_controller.cc:292
uint8_t asid[2]
Definition: dram_controller.h:43
uint64_t data
Definition: dram_controller.h:49
std::vector< std::reference_wrapper< ooo_model_instr > > instr_depend_on_me
Definition: dram_controller.h:52
uint64_t event_cycle
Definition: dram_controller.h:50
uint64_t v_address
Definition: dram_controller.h:48
std::vector< std::deque< response_type > * > to_return
Definition: dram_controller.h:53
bool scheduled
Definition: dram_controller.h:40
Definition: dram_controller.h:37
stats_type sim_stats
Definition: dram_controller.h:79
queue_type WQ
Definition: dram_controller.h:59
request_array_type bank_request
Definition: dram_controller.h:72
void print_deadlock()
Definition: dram_controller.cc:383
std::vector< std::optional< value_type > > queue_type
Definition: dram_controller.h:58
uint64_t dbus_cycle_available
Definition: dram_controller.h:76
stats_type roi_stats
Definition: dram_controller.h:79
queue_type RQ
Definition: dram_controller.h:59
request_array_type::iterator active_request
Definition: dram_controller.h:73
typename champsim::channel::response_type response_type
Definition: dram_controller.h:38
void check_collision()
Definition: dram_controller.cc:220
std::array< BANK_REQUEST, DRAM_RANKS *DRAM_BANKS > request_array_type
Definition: dram_controller.h:71
bool write_mode
Definition: dram_controller.h:75
Definition: channel.h:65
Definition: dram_controller.h:30
unsigned WQ_ROW_BUFFER_MISS
Definition: dram_controller.h:34
unsigned RQ_ROW_BUFFER_MISS
Definition: dram_controller.h:34
uint64_t dbus_cycle_congested
Definition: dram_controller.h:32
uint64_t dbus_count_congested
Definition: dram_controller.h:32
unsigned WQ_ROW_BUFFER_HIT
Definition: dram_controller.h:34
unsigned RQ_ROW_BUFFER_HIT
Definition: dram_controller.h:34
std::string name
Definition: dram_controller.h:31
unsigned WQ_FULL
Definition: dram_controller.h:34