base.hh revision 2810
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
44class BaseCache;
45
46/**
47 * A common base class of Cache tagstore objects.
48 */
49class 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    // Statistics
67    /**
68     * @addtogroup CacheStatistics
69     * @{
70     */
71
72    /** Number of replacements of valid blocks per thread. */
73    Stats::Vector<> replacements;
74    /** Per cycle average of the number of tags that hold valid data. */
75    Stats::Average<> tagsInUse;
76
77    /** The total number of references to a block before it is replaced. */
78    Stats::Scalar<> totalRefs;
79
80    /**
81     * The number of reference counts sampled. This is different from
82     * replacements because we sample all the valid blocks when the simulator
83     * exits.
84     */
85    Stats::Scalar<> sampledRefs;
86
87    /**
88     * Average number of references to a block before is was replaced.
89     * @todo This should change to an average stat once we have them.
90     */
91    Stats::Formula avgRefs;
92
93    /** The cycle that the warmup percentage was hit. */
94    Stats::Scalar<> warmupCycle;
95    /**
96     * @}
97     */
98
99  public:
100
101    /**
102     * Destructor.
103     */
104    virtual ~BaseTags() {}
105
106    /**
107     * Set the parent cache back pointer. Also copies the cache name to
108     * objName.
109     * @param _cache Pointer to parent cache.
110     */
111    void setCache(BaseCache *_cache);
112
113    /**
114     * Return the parent cache name.
115     * @return the parent cache name.
116     */
117    const std::string &name() const
118    {
119        return objName;
120    }
121
122    /**
123     * Register local statistics.
124     * @param name The name to preceed each statistic name.
125     */
126    void regStats(const std::string &name);
127
128    /**
129     * Average in the reference count for valid blocks when the simulation
130     * exits.
131     */
132    virtual void cleanupRefs() {}
133};
134
135class BaseTagsCallback : public Callback
136{
137    BaseTags *tags;
138  public:
139    BaseTagsCallback(BaseTags *t) : tags(t) {}
140    virtual void process() { tags->cleanupRefs(); };
141};
142
143#endif //__BASE_TAGS_HH__
144