ChampSim
vmem.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 VMEM_H
18 #define VMEM_H
19 
20 #include <cstdint>
21 #include <map>
22 
23 #include "champsim_constants.h"
24 
25 class MEMORY_CONTROLLER;
26 
27 // reserve 1MB or one page of space
28 inline constexpr auto VMEM_RESERVE_CAPACITY = std::max<uint64_t>(PAGE_SIZE, 1ull << 20);
29 
30 inline constexpr std::size_t PTE_BYTES = 8;
31 
33 {
34 private:
35  std::map<std::pair<uint32_t, uint64_t>, uint64_t> vpage_to_ppage_map;
36  std::map<std::tuple<uint32_t, uint64_t, uint32_t>, uint64_t> page_table;
37 
38  uint64_t next_pte_page = 0;
39 
40  uint64_t next_ppage;
41  uint64_t last_ppage;
42 
43  uint64_t ppage_front() const;
44  void ppage_pop();
45 
46 public:
47  const uint64_t minor_fault_penalty;
48  const std::size_t pt_levels;
49  const uint64_t pte_page_size; // Size of a PTE page
50 
51  // capacity and pg_size are measured in bytes, and capacity must be a multiple of pg_size
52  VirtualMemory(uint64_t pg_size, std::size_t page_table_levels, uint64_t minor_penalty, MEMORY_CONTROLLER& dram);
53  uint64_t shamt(std::size_t level) const;
54  uint64_t get_offset(uint64_t vaddr, std::size_t level) const;
55  std::size_t available_ppages() const;
56  std::pair<uint64_t, uint64_t> va_to_pa(uint32_t cpu_num, uint64_t vaddr);
57  std::pair<uint64_t, uint64_t> get_pte_pa(uint32_t cpu_num, uint64_t vaddr, std::size_t level);
58 };
59 
60 #endif
Definition: dram_controller.h:86
Definition: vmem.h:33
uint64_t get_offset(uint64_t vaddr, std::size_t level) const
Definition: vmem.cc:43
uint64_t next_ppage
Definition: vmem.h:40
std::map< std::pair< uint32_t, uint64_t >, uint64_t > vpage_to_ppage_map
Definition: vmem.h:35
std::map< std::tuple< uint32_t, uint64_t, uint32_t >, uint64_t > page_table
Definition: vmem.h:36
uint64_t next_pte_page
Definition: vmem.h:38
const uint64_t pte_page_size
Definition: vmem.h:49
std::pair< uint64_t, uint64_t > get_pte_pa(uint32_t cpu_num, uint64_t vaddr, std::size_t level)
Definition: vmem.cc:74
uint64_t last_ppage
Definition: vmem.h:41
uint64_t ppage_front() const
Definition: vmem.cc:48
VirtualMemory(uint64_t pg_size, std::size_t page_table_levels, uint64_t minor_penalty, MEMORY_CONTROLLER &dram)
Definition: vmem.cc:26
void ppage_pop()
Definition: vmem.cc:54
uint64_t shamt(std::size_t level) const
Definition: vmem.cc:41
std::size_t available_ppages() const
Definition: vmem.cc:56
std::pair< uint64_t, uint64_t > va_to_pa(uint32_t cpu_num, uint64_t vaddr)
Definition: vmem.cc:58
const std::size_t pt_levels
Definition: vmem.h:48
const uint64_t minor_fault_penalty
Definition: vmem.h:47
constexpr std::size_t PTE_BYTES
Definition: vmem.h:30
constexpr auto VMEM_RESERVE_CAPACITY
Definition: vmem.h:28