kernel_stats.hh revision 1082
1/*
2 * Copyright (c) 2003 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
29#ifndef __KERNEL_STATS_HH__
30#define __KERNEL_STATS_HH__
31
32#include <map>
33#include <stack>
34#include <string>
35#include <vector>
36
37#include "base/statistics.hh"
38#include "sim/serialize.hh"
39#include "targetarch/isa_traits.hh"
40
41class BaseCPU;
42class ExecContext;
43class FnEvent;
44enum Fault;
45
46namespace Kernel {
47
48enum cpu_mode { kernel, user, idle, interrupt, cpu_mode_num };
49extern const char *modestr[];
50
51class Binning
52{
53  private:
54    std::string myname;
55    System *system;
56
57  private:
58    // lisa's binning stuff
59    struct fnCall
60    {
61        Stats::MainBin *myBin;
62        std::string name;
63    };
64
65    struct SWContext
66    {
67        Counter calls;
68        std::stack<fnCall *> callStack;
69    };
70
71    std::map<const std::string, Stats::MainBin *> fnBins;
72    std::map<const Addr, SWContext *> swCtxMap;
73
74    std::multimap<const std::string, std::string> callerMap;
75    void populateMap(std::string caller, std::string callee);
76
77    std::vector<FnEvent *> fnEvents;
78
79    Stats::Scalar<> fnCalls;
80
81    Stats::MainBin *getBin(const std::string &name);
82    bool findCaller(std::string, std::string) const;
83
84    SWContext *findContext(Addr pcb);
85    bool addContext(Addr pcb, SWContext *ctx)
86    {
87        return (swCtxMap.insert(std::make_pair(pcb, ctx))).second;
88    }
89
90    void remContext(Addr pcb)
91    {
92        swCtxMap.erase(pcb);
93    }
94
95    void dumpState() const;
96
97    SWContext *swctx;
98    std::vector<std::string> binned_fns;
99
100  private:
101    Stats::MainBin *modeBin[cpu_mode_num];
102
103  public:
104    const bool bin;
105    const bool fnbin;
106
107    cpu_mode themode;
108    void palSwapContext(ExecContext *xc);
109    void execute(ExecContext *xc, const StaticInstBase *inst);
110    void call(ExecContext *xc, Stats::MainBin *myBin);
111    void changeMode(cpu_mode mode);
112
113  public:
114    Binning(System *sys);
115    virtual ~Binning();
116
117    const std::string name() const { return myname; }
118    void regStats(const std::string &name);
119
120  public:
121    virtual void serialize(std::ostream &os);
122    virtual void unserialize(Checkpoint *cp, const std::string &section);
123};
124
125class Statistics : public Serializable
126{
127    friend class Binning;
128
129  private:
130    std::string myname;
131    ExecContext *xc;
132
133    Addr idleProcess;
134    cpu_mode themode;
135    Tick lastModeTick;
136    bool bin_int;
137
138    void changeMode(cpu_mode newmode);
139
140  private:
141    Stats::Scalar<> _arm;
142    Stats::Scalar<> _quiesce;
143    Stats::Scalar<> _ivlb;
144    Stats::Scalar<> _ivle;
145    Stats::Scalar<> _hwrei;
146
147    Stats::Vector<> _iplCount;
148    Stats::Vector<> _iplGood;
149    Stats::Vector<> _iplTicks;
150    Stats::Formula _iplUsed;
151
152    Stats::Vector<> _callpal;
153    Stats::Vector<> _syscall;
154    Stats::Vector<> _faults;
155
156    Stats::Vector<> _mode;
157    Stats::Vector<> _modeGood;
158    Stats::Formula _modeFraction;
159    Stats::Vector<> _modeTicks;
160
161    Stats::Scalar<> _swap_context;
162
163  private:
164    int iplLast;
165    Tick iplLastTick;
166
167  public:
168    Statistics(ExecContext *context);
169
170    const std::string name() const { return myname; }
171    void regStats(const std::string &name);
172
173  public:
174    void arm() { _arm++; }
175    void quiesce() { _quiesce++; }
176    void ivlb() { _ivlb++; }
177    void ivle() { _ivle++; }
178    void hwrei() { _hwrei++; }
179    void fault(Fault fault) { _faults[fault]++; }
180    void swpipl(int ipl);
181    void mode(cpu_mode newmode);
182    void context(Addr oldpcbb, Addr newpcbb);
183    void callpal(int code);
184
185    void setIdleProcess(Addr idle);
186
187  public:
188    virtual void serialize(std::ostream &os);
189    virtual void unserialize(Checkpoint *cp, const std::string &section);
190};
191
192/* end namespace Kernel */ }
193
194#endif // __KERNEL_STATS_HH__
195