Deleted Added
sdiff udiff text old ( 12600:e670dd17c8cf ) new ( 12684:44ebd2bc020f )
full compact
1/**
2 * Copyright (c) 2018 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Daniel Carvalho
29 */
30
31#ifndef __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__
32#define __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__
33
34#include "mem/cache/base.hh"
35#include "mem/cache/blk.hh"
36#include "params/BaseReplacementPolicy.hh"
37#include "sim/sim_object.hh"
38
39/**
40 * Replacement candidates as chosen by the indexing policy.
41 *
42 * The base functions touch() and reset() must be called by all subclasses
43 * that override them.
44 *
45 * @todo
46 * Currently the replacement candidates are simply the cache blocks
47 * derived from the possible placement locations of an address, as
48 * defined by the getPossibleLocations() from BaseTags. In a future
49 * patch it should be an inheritable class to allow the replacement
50 * policies to be used with any table-like structure that needs to
51 * replace its entries.
52 */
53typedef std::vector<CacheBlk*> ReplacementCandidates;
54
55/**
56 * A common base class of cache replacement policy objects.
57 */
58class BaseReplacementPolicy : public SimObject
59{
60 public:
61 /**
62 * Convenience typedef.
63 */
64 typedef BaseReplacementPolicyParams Params;
65
66 /**
67 * Construct and initiliaze this replacement policy.
68 */
69 BaseReplacementPolicy(const Params *p);
70
71 /**
72 * Destructor.
73 */
74 virtual ~BaseReplacementPolicy() {}
75
76 /**
77 * Touch a block to update its replacement data.
78 * Updates number of references.
79 *
80 * This base function must be called by all subclasses that override it.
81 *
82 * @param blk Cache block to be touched.
83 */
84 virtual void touch(CacheBlk *blk);
85
86 /**
87 * Reset replacement data for a block. Used when a block is inserted.
88 * Sets the insertion tick, and update number of references.
89 *
90 * This base function must be called by all subclasses that override it.
91 *
92 * @param blk Cache block to be reset.
93 */
94 virtual void reset(CacheBlk *blk);
95
96 /**
97 * Find replacement victim among candidates.
98 *
99 * @param candidates Replacement candidates, selected by indexing policy.
100 * @return Cache block to be replaced.
101 */
102 virtual CacheBlk* getVictim(const ReplacementCandidates& candidates) = 0;
103};
104
105#endif // __MEM_CACHE_REPLACEMENT_POLICIES_BASE_HH__