1- #include < dyad/residency/fcache.hpp>
21#include < dyad/utils/murmur3.h>
2+ #include < dyad/residency/fcache.hpp>
33
44#define DYAD_UTIL_LOGGER
55#include < dyad/common/dyad_logging.h>
66
7-
8- namespace dyad_residency {
7+ namespace dyad_residency
8+ {
99
1010// =============================================================================
1111// Associative Cache Set
1212// =============================================================================
1313
1414// -------------------------- LRU ------------------------
15- bool Set_LRU::lookup (const std::string& fname, id_iterator_t & it)
15+ bool Set_LRU::lookup (const std::string& fname, id_iterator_t & it)
1616{
1717 id_idx_t & index_id = boost::multi_index::get<id> (m_block_set);
1818 it = index_id.find (fname);
1919 return (it != index_id.end ());
2020}
2121
2222void Set_LRU::evict (void )
23- { // LRU
24- if (m_block_set.size () == 0 ) return ;
23+ { // LRU
24+ if (m_block_set.size () == 0 )
25+ return ;
2526 priority_idx_t & index_priority = boost::multi_index::get<priority> (m_block_set);
2627 if (!index_priority.empty ()) {
2728 priority_iterator_t it = index_priority.begin ();
28- DYAD_LOG_INFO (NULL , " %s evicts %s from set %u\n " , \
29- m_level.c_str (), it->m_id .c_str (), m_id);
29+ DYAD_LOG_INFO (NULL ,
30+ " %s evicts %s from set %u\n " ,
31+ m_level.c_str (),
32+ it->m_id .c_str (),
33+ m_id);
3034 index_priority.erase (it);
3135 }
3236}
@@ -35,8 +39,7 @@ void Set_LRU::load_and_access (const std::string& fname)
3539{
3640 m_num_miss++;
3741
38- DYAD_LOG_INFO (NULL , " %s adds %s to set %u\n " , \
39- m_level.c_str (), fname.c_str (), m_id);
42+ DYAD_LOG_INFO (NULL , " %s adds %s to set %u\n " , m_level.c_str (), fname.c_str (), m_id);
4043 if (m_size == m_block_set.size ()) {
4144 evict ();
4245 }
@@ -45,7 +48,7 @@ void Set_LRU::load_and_access (const std::string& fname)
4548 m_seqno++;
4649}
4750
48- void Set_LRU::access (id_iterator_t & it)
51+ void Set_LRU::access (id_iterator_t & it)
4952{
5053 Simple_Block blk = *it;
5154 m_block_set.erase (it);
@@ -56,12 +59,15 @@ void Set_LRU::access (id_iterator_t &it)
5659bool Set_LRU::access (const std::string& fname)
5760{
5861 id_iterator_t it;
59- if (lookup (fname, it)) { // hit
60- DYAD_LOG_INFO (NULL , " %s reuses %s from set %u\n " , \
61- m_level.c_str (), fname.c_str (), m_id);
62+ if (lookup (fname, it)) { // hit
63+ DYAD_LOG_INFO (NULL ,
64+ " %s reuses %s from set %u\n " ,
65+ m_level.c_str (),
66+ fname.c_str (),
67+ m_id);
6268 access (it);
6369 return true ;
64- } else { // miss
70+ } else { // miss
6571 load_and_access (fname);
6672 return false ;
6773 }
@@ -72,10 +78,10 @@ unsigned int Set_LRU::get_priority ()
7278 return m_seqno;
7379}
7480
75- std::ostream& Set_LRU::print (std::ostream & os) const
81+ std::ostream& Set_LRU::print (std::ostream& os) const
7682{
7783 os << " size : " << m_size << std::endl;
78- os << " num accesses : " << m_seqno<< std::endl;
84+ os << " num accesses : " << m_seqno << std::endl;
7985 os << " num misses : " << m_num_miss << std::endl;
8086 os << " blkId : " << std::endl;
8187
@@ -89,20 +95,25 @@ std::ostream& Set_LRU::print (std::ostream &os) const
8995 return os;
9096}
9197
92- std::ostream& operator <<(std::ostream& os, const Set_LRU & cc)
98+ std::ostream& operator << (std::ostream& os, const Set_LRU& cc)
9399{
94100 return cc.print (os);
95101}
96102
97103// -------------------------- MRU ------------------------
98104void Set_MRU::evict (void )
99- { // MRU
100- if (m_block_set.size () == 0 ) return ;
105+ { // MRU
106+ if (m_block_set.size () == 0 )
107+ return ;
101108 priority_idx_t & index_priority = boost::multi_index::get<priority> (m_block_set);
102109 if (!index_priority.empty ()) {
103- auto it = index_priority.end (); --it;
104- DYAD_LOG_INFO (NULL , " %s evicts %s from set %u\n " , \
105- m_level.c_str (), it->m_id .c_str (), m_id);
110+ auto it = index_priority.end ();
111+ --it;
112+ DYAD_LOG_INFO (NULL ,
113+ " %s evicts %s from set %u\n " ,
114+ m_level.c_str (),
115+ it->m_id .c_str (),
116+ m_id);
106117 index_priority.erase (it);
107118 }
108119}
@@ -112,15 +123,13 @@ bool Set_MRU::access (const std::string& fname)
112123 return Set_LRU::access (fname);
113124}
114125
115- std::ostream& operator <<(std::ostream& os, const Set_MRU & cc)
126+ std::ostream& operator << (std::ostream& os, const Set_MRU& cc)
116127{
117128 return cc.print (os);
118129}
119130
120-
121-
122131// -------------------------- Prioritied ------------------------
123- bool Set_Prioritized::lookup (const std::string& fname, id_iterator_t & it)
132+ bool Set_Prioritized::lookup (const std::string& fname, id_iterator_t & it)
124133{
125134 id_idx_t & index_id = boost::multi_index::get<id> (m_block_set);
126135 it = index_id.find (fname);
@@ -129,20 +138,23 @@ bool Set_Prioritized::lookup (const std::string& fname, id_iterator_t &it)
129138
130139void Set_Prioritized::evict (void )
131140{
132- if (m_block_set.size () == 0 ) return ;
141+ if (m_block_set.size () == 0 )
142+ return ;
133143 priority_idx_t & index_priority = boost::multi_index::get<priority> (m_block_set);
134144 priority_iterator_t it = index_priority.begin ();
135- DYAD_LOG_INFO (NULL , " %s evicts %s from set %u\n " , \
136- m_level.c_str (), it->m_id .c_str (), m_id);
145+ DYAD_LOG_INFO (NULL ,
146+ " %s evicts %s from set %u\n " ,
147+ m_level.c_str (),
148+ it->m_id .c_str (),
149+ m_id);
137150 index_priority.erase (it);
138151}
139152
140153void Set_Prioritized::load_and_access (const std::string& fname)
141154{
142155 m_num_miss++;
143156
144- DYAD_LOG_INFO (NULL , " %s adds %s to set %u\n " , \
145- m_level.c_str (), fname.c_str (), m_id);
157+ DYAD_LOG_INFO (NULL , " %s adds %s to set %u\n " , m_level.c_str (), fname.c_str (), m_id);
146158 if (m_size == m_block_set.size ()) {
147159 evict ();
148160 }
@@ -151,7 +163,7 @@ void Set_Prioritized::load_and_access (const std::string& fname)
151163 m_seqno++;
152164}
153165
154- void Set_Prioritized::access (id_iterator_t & it)
166+ void Set_Prioritized::access (id_iterator_t & it)
155167{
156168 Ranked_Block blk = *it;
157169 // reassigning the priority
@@ -164,12 +176,15 @@ void Set_Prioritized::access (id_iterator_t &it)
164176bool Set_Prioritized::access (const std::string& fname)
165177{
166178 id_iterator_t it;
167- if (lookup (fname, it)) { // hit
168- DYAD_LOG_INFO (NULL , " %s reuses %s from set %u\n " , \
169- m_level.c_str (), fname.c_str (), m_id);
179+ if (lookup (fname, it)) { // hit
180+ DYAD_LOG_INFO (NULL ,
181+ " %s reuses %s from set %u\n " ,
182+ m_level.c_str (),
183+ fname.c_str (),
184+ m_id);
170185 access (it);
171186 return true ;
172- } else { // miss
187+ } else { // miss
173188 load_and_access (fname);
174189 return false ;
175190 }
@@ -180,10 +195,10 @@ unsigned int Set_Prioritized::get_priority ()
180195 return m_seqno;
181196}
182197
183- std::ostream& Set_Prioritized::print (std::ostream & os) const
198+ std::ostream& Set_Prioritized::print (std::ostream& os) const
184199{
185200 os << " size : " << m_size << std::endl;
186- os << " num accesses : " << m_seqno<< std::endl;
201+ os << " num accesses : " << m_seqno << std::endl;
187202 os << " num misses : " << m_num_miss << std::endl;
188203 os << " priority blkId:" << std::endl;
189204
@@ -197,9 +212,9 @@ std::ostream& Set_Prioritized::print (std::ostream &os) const
197212 return os;
198213}
199214
200- std::ostream& operator <<(std::ostream& os, const Set_Prioritized& cc)
215+ std::ostream& operator << (std::ostream& os, const Set_Prioritized& cc)
201216{
202217 return cc.print (os);
203218}
204219
205- } // end of namespace dyad_residency
220+ } // end of namespace dyad_residency
0 commit comments