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