@@ -19,29 +19,24 @@ CXLMemExpander::CXLMemExpander(int read_bw, int write_bw, int read_lat, int writ
1919 this ->latency .read = read_lat;
2020 this ->latency .write = write_lat;
2121}
22- double CXLMemExpander::calculate_latency (const std::tuple<int , int > &elem, double dramlatency) {
22+ double CXLMemExpander::calculate_latency (const std::vector<std:: tuple<int , int > > &elem, double dramlatency) {
2323
2424 return 60 ;
2525}
26- double CXLMemExpander::calculate_bandwidth (const std::tuple<int , int > &elem) {
26+ double CXLMemExpander::calculate_bandwidth (const std::vector<std:: tuple<int , int > > &elem) {
2727 // Iterate the map within the last 20ms
2828
2929 return this ->bandwidth .read + this ->bandwidth .write ;
3030}
3131void CXLMemExpander::delete_entry (uint64_t addr, uint64_t length) {
32- for (auto it1 = va_pa_map.begin (); it1 != va_pa_map.end ();) {
33- if (it1->second >= addr && it1->second <= addr + length) {
34- for (auto it = occupation.begin (); it != occupation.end ();) {
35- if (it->second == addr) {
36- it = occupation.erase (it);
37- } else {
38- ++it;
39- }
40- }
41- it1 = va_pa_map.erase (it1);
42- this ->counter .inc_load ();
32+ for (auto it = occupation.begin (); it != occupation.end ();) {
33+ if (it->second == addr) {
34+ it = occupation.erase (it);
35+ } else {
36+ ++it;
4337 }
4438 }
39+ this ->counter .inc_load ();
4540 // kernel mode access
4641 for (auto it = occupation.begin (); it != occupation.end ();) {
4742 if (it->second >= addr && it->second <= addr + length) {
@@ -61,12 +56,6 @@ int CXLMemExpander::insert(uint64_t timestamp, uint64_t tid, uint64_t phys_addr,
6156 last_timestamp = last_timestamp > timestamp ? last_timestamp : timestamp; // Update the last timestamp
6257 // Check if the address is already in the map)
6358 if (phys_addr != 0 ) {
64- if (va_pa_map.find (virt_addr) == va_pa_map.end ()) {
65- this ->va_pa_map .emplace (virt_addr, phys_addr);
66- } else {
67- this ->va_pa_map [virt_addr] = phys_addr;
68- SPDLOG_DEBUG (" virt:{} phys:{} conflict insertion detected\n " , virt_addr, phys_addr);
69- }
7059 for (auto it = this ->occupation .cbegin (); it != this ->occupation .cend (); it++) {
7160 if ((*it).second == phys_addr) {
7261 this ->occupation .erase (it);
@@ -95,24 +84,30 @@ int CXLMemExpander::insert(uint64_t timestamp, uint64_t tid, uint64_t phys_addr,
9584 return 0 ;
9685}
9786std::string CXLMemExpander::output () { return std::format (" CXLMemExpander {}" , this ->id ); }
98- std::tuple<int , int > CXLMemExpander::get_access (uint64_t timestamp) {
99- this ->last_read = this ->counter .load - this ->last_counter .load ;
100- this ->last_write = this ->counter .store - this ->last_counter .store ;
87+ std::vector<std::tuple<int , int >> CXLMemExpander::get_access (uint64_t timestamp) {
10188 last_counter = CXLMemExpanderEvent (counter);
102- return std::make_tuple (this ->last_read , this ->last_write );
89+ std::vector<std::tuple<int , int >> res;
90+ // Iterate the map within the last 100ns
91+ for (auto it = occupation.begin (); it != occupation.end ();) {
92+ if (it->first > timestamp - 100 ) {
93+ res.push_back (std::make_tuple (it->first , it->second ));
94+ } else {
95+ ++it;
96+ }
97+ }
98+ return res;
10399}
104100void CXLMemExpander::set_epoch (int epoch) { this ->epoch = epoch; }
105101void CXLMemExpander::free_stats (double size) {
106- std::vector<uint64_t > keys;
107- for (auto &it : this ->va_pa_map ) {
108- keys.push_back (it.first );
109- }
110- std::shuffle (keys.begin (), keys.end (), std::mt19937 (std::random_device ()()));
111- for (auto it = keys.begin (); it != keys.end (); ++it) {
112- if (this ->va_pa_map [*it] > size) {
113- this ->va_pa_map .erase (*it);
114- this ->occupation .erase (*it);
115- this ->counter .inc_load ();
102+ // 随机删除
103+ std::random_device rd;
104+ std::mt19937 gen (rd ());
105+ std::uniform_int_distribution<> dis (0 , 1 );
106+ for (auto it = occupation.begin (); it != occupation.end ();) {
107+ if (dis (gen) == 1 ) {
108+ it = occupation.erase (it);
109+ } else {
110+ ++it;
116111 }
117112 }
118113}
@@ -147,7 +142,7 @@ void CXLSwitch::delete_entry(uint64_t addr, uint64_t length) {
147142 }
148143}
149144CXLSwitch::CXLSwitch (int id) : id(id) {}
150- double CXLSwitch::calculate_latency (const std::tuple<int , int > &elem, double dramlatency) {
145+ double CXLSwitch::calculate_latency (const std::vector<std:: tuple<int , int > > &elem, double dramlatency) {
151146 double lat = 0.0 ;
152147 for (auto &expander : this ->expanders ) {
153148 lat += expander->calculate_latency (elem, dramlatency);
@@ -157,7 +152,7 @@ double CXLSwitch::calculate_latency(const std::tuple<int, int> &elem, double dra
157152 }
158153 return lat;
159154}
160- double CXLSwitch::calculate_bandwidth (const std::tuple<int , int > &elem) {
155+ double CXLSwitch::calculate_bandwidth (const std::vector<std:: tuple<int , int > > &elem) {
161156 double bw = 0.0 ;
162157 for (auto &expander : this ->expanders ) {
163158 bw += expander->calculate_bandwidth (elem);
@@ -197,19 +192,17 @@ std::tuple<double, std::vector<uint64_t>> CXLSwitch::calculate_congestion() {
197192 }
198193 return std::make_tuple (latency, congestion);
199194}
200- std::tuple<int , int > CXLSwitch::get_access (uint64_t timestamp) {
201- int read = 0 , write = 0 ;
195+ std::vector<std:: tuple<int , int > > CXLSwitch::get_access (uint64_t timestamp) {
196+ auto res = std::vector<std::tuple< int , int >>() ;
202197 for (auto &expander : this ->expanders ) {
203- auto [r, w] = expander->get_access (timestamp);
204- read += r;
205- write += w;
198+ auto tmp = expander->get_access (timestamp);
199+ res.insert (res.end (), tmp.begin (), tmp.end ());
206200 }
207201 for (auto &switch_ : this ->switches ) {
208- auto [r, w] = switch_->get_access (timestamp);
209- read += r;
210- write += w;
202+ auto tmp = switch_->get_access (timestamp);
203+ res.insert (res.end (), tmp.begin (), tmp.end ());
211204 }
212- return std::make_tuple (read, write) ;
205+ return res ;
213206}
214207void CXLSwitch::set_epoch (int epoch) { this ->epoch = epoch; }
215208void CXLSwitch::free_stats (double size) {
0 commit comments