Made Addr a global type
[gem5.git] / kern / kernel_stats.hh
1 /*
2 * Copyright (c) 2004-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
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 "cpu/static_inst.hh"
38
39 class BaseCPU;
40 class ExecContext;
41 class FnEvent;
42 // What does kernel stats expect is included?
43 class System;
44 class Fault;
45
46 namespace Kernel {
47
48 enum cpu_mode { kernel, user, idle, interrupt, cpu_mode_num };
49 extern const char *modestr[];
50
51 class 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, StaticInstPtr 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
125 class Statistics : public Serializable
126 {
127 private:
128 friend class Binning;
129
130 private:
131 std::string myname;
132 ExecContext *xc;
133
134 Addr idleProcess;
135 cpu_mode themode;
136 Tick lastModeTick;
137 bool bin_int;
138
139 void changeMode(cpu_mode newmode);
140
141 private:
142 Stats::Scalar<> _arm;
143 Stats::Scalar<> _quiesce;
144 Stats::Scalar<> _ivlb;
145 Stats::Scalar<> _ivle;
146 Stats::Scalar<> _hwrei;
147
148 Stats::Vector<> _iplCount;
149 Stats::Vector<> _iplGood;
150 Stats::Vector<> _iplTicks;
151 Stats::Formula _iplUsed;
152
153 Stats::Vector<> _callpal;
154 Stats::Vector<> _syscall;
155 Stats::Vector<> _faults;
156
157 Stats::Vector<> _mode;
158 Stats::Vector<> _modeGood;
159 Stats::Formula _modeFraction;
160 Stats::Vector<> _modeTicks;
161
162 Stats::Scalar<> _swap_context;
163
164 private:
165 int iplLast;
166 Tick iplLastTick;
167
168 public:
169 Statistics(ExecContext *context);
170
171 const std::string name() const { return myname; }
172 void regStats(const std::string &name);
173
174 public:
175 void arm() { _arm++; }
176 void quiesce() { _quiesce++; }
177 void ivlb() { _ivlb++; }
178 void ivle() { _ivle++; }
179 void hwrei() { _hwrei++; }
180 void fault(Fault * fault)
181 {
182 if(fault == NoFault) _faults[0]++;
183 else if(fault == MachineCheckFault) _faults[2]++;
184 else if(fault == AlignmentFault) _faults[7]++;
185 else _faults[fault->id]++;
186 }// FIXME: When there are no generic system fault objects, this will go back to _faults[fault]++; }
187 void swpipl(int ipl);
188 void mode(cpu_mode newmode);
189 void context(Addr oldpcbb, Addr newpcbb);
190 void callpal(int code);
191
192 void setIdleProcess(Addr idle);
193
194 public:
195 virtual void serialize(std::ostream &os);
196 virtual void unserialize(Checkpoint *cp, const std::string &section);
197 };
198
199 /* end namespace Kernel */ }
200
201 #endif // __KERNEL_STATS_HH__