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