summaryrefslogtreecommitdiff
path: root/src/mem/ruby/system/AbstractReplacementPolicy.hh
blob: e8b504b8ab09bea3f7f8c8b59486619f59741b70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

#ifndef ABSTRACTREPLACEMENTPOLICY_H
#define ABSTRACTREPLACEMENTPOLICY_H

#include "mem/ruby/common/Global.hh"

class AbstractReplacementPolicy {

public:

  AbstractReplacementPolicy(Index num_sets, Index assoc);
  virtual ~AbstractReplacementPolicy();

  /* touch a block. a.k.a. update timestamp */
  virtual void touch(Index set, Index way, Time time) = 0;

  /* returns the way to replace */
  virtual Index getVictim(Index set) const = 0;

  /* get the time of the last access */
  Time getLastAccess(Index set, Index way);

 protected:
  unsigned int m_num_sets;       /** total number of sets */
  unsigned int m_assoc;          /** set associativity */
  Time **m_last_ref_ptr;         /** timestamp of last reference */
};

inline
AbstractReplacementPolicy::AbstractReplacementPolicy(Index num_sets, Index assoc)
{
  m_num_sets = num_sets;
  m_assoc = assoc;
  m_last_ref_ptr = new Time*[m_num_sets];
  for(unsigned int i = 0; i < m_num_sets; i++){
    m_last_ref_ptr[i] = new Time[m_assoc];
    for(unsigned int j = 0; j < m_assoc; j++){
      m_last_ref_ptr[i][j] = 0;
    }
  }
}

inline
AbstractReplacementPolicy::~AbstractReplacementPolicy()
{
  if(m_last_ref_ptr != NULL){
    for(unsigned int i = 0; i < m_num_sets; i++){
      if(m_last_ref_ptr[i] != NULL){
        delete[] m_last_ref_ptr[i];
      }
    }
    delete[] m_last_ref_ptr;
  }
}

inline
Time AbstractReplacementPolicy::getLastAccess(Index set, Index way)
{
  return m_last_ref_ptr[set][way];
}

#endif // ABSTRACTREPLACEMENTPOLICY_H