MEM: Make CLREX a first class request operation and clear locks in caches when it...
[gem5.git] / src / mem / cache / tags / base.hh
1 /*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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: Erik Hallnor
29 * Ron Dreslinski
30 */
31
32 /**
33 * @file
34 * Declaration of a common base class for cache tagstore objects.
35 */
36
37 #ifndef __BASE_TAGS_HH__
38 #define __BASE_TAGS_HH__
39
40 #include <string>
41 #include "base/statistics.hh"
42 #include "base/callback.hh"
43
44 class BaseCache;
45
46 /**
47 * A common base class of Cache tagstore objects.
48 */
49 class BaseTags
50 {
51 protected:
52 /** Pointer to the parent cache. */
53 BaseCache *cache;
54
55 /** Local copy of the parent cache name. Used for DPRINTF. */
56 std::string objName;
57
58 /**
59 * The number of tags that need to be touched to meet the warmup
60 * percentage.
61 */
62 int warmupBound;
63 /** Marked true when the cache is warmed up. */
64 bool warmedUp;
65
66 /** the number of blocks in the cache */
67 unsigned numBlocks;
68
69 // Statistics
70 /**
71 * @addtogroup CacheStatistics
72 * @{
73 */
74
75 /** Number of replacements of valid blocks per thread. */
76 Stats::Vector replacements;
77 /** Per cycle average of the number of tags that hold valid data. */
78 Stats::Average tagsInUse;
79
80 /** The total number of references to a block before it is replaced. */
81 Stats::Scalar totalRefs;
82
83 /**
84 * The number of reference counts sampled. This is different from
85 * replacements because we sample all the valid blocks when the simulator
86 * exits.
87 */
88 Stats::Scalar sampledRefs;
89
90 /**
91 * Average number of references to a block before is was replaced.
92 * @todo This should change to an average stat once we have them.
93 */
94 Stats::Formula avgRefs;
95
96 /** The cycle that the warmup percentage was hit. */
97 Stats::Scalar warmupCycle;
98
99 /** Average occupancy of each context/cpu using the cache */
100 Stats::AverageVector occupancies;
101
102 /** Average occ % of each context/cpu using the cache */
103 Stats::Formula avgOccs;
104
105 /**
106 * @}
107 */
108
109 public:
110
111 /**
112 * Destructor.
113 */
114 virtual ~BaseTags() {}
115
116 /**
117 * Set the parent cache back pointer. Also copies the cache name to
118 * objName.
119 * @param _cache Pointer to parent cache.
120 */
121 void setCache(BaseCache *_cache);
122
123 /**
124 * Return the parent cache name.
125 * @return the parent cache name.
126 */
127 const std::string &name() const
128 {
129 return objName;
130 }
131
132 /**
133 * Register local statistics.
134 * @param name The name to preceed each statistic name.
135 */
136 void regStats(const std::string &name);
137
138 /**
139 * Average in the reference count for valid blocks when the simulation
140 * exits.
141 */
142 virtual void cleanupRefs() {}
143
144 /**
145 *iterated through all blocks and clear all locks
146 *Needed to clear all lock tracking at once
147 */
148 virtual void clearLocks() {}
149 };
150
151 class BaseTagsCallback : public Callback
152 {
153 BaseTags *tags;
154 public:
155 BaseTagsCallback(BaseTags *t) : tags(t) {}
156 virtual void process() { tags->cleanupRefs(); };
157 };
158
159 #endif //__BASE_TAGS_HH__