2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
29 #ifndef __KERNEL_STATS_HH__
30 #define __KERNEL_STATS_HH__
37 #include "base/statistics.hh"
38 #include "sim/serialize.hh"
39 #include "targetarch/isa_traits.hh"
44 // What does kernel stats expect is included?
51 enum cpu_mode { kernel, user, idle, interrupt, cpu_mode_num };
52 extern const char *modestr[];
61 // lisa's binning stuff
64 Stats::MainBin *myBin;
71 std::stack<fnCall *> callStack;
74 std::map<const std::string, Stats::MainBin *> fnBins;
75 std::map<const Addr, SWContext *> swCtxMap;
77 std::multimap<const std::string, std::string> callerMap;
78 void populateMap(std::string caller, std::string callee);
80 std::vector<FnEvent *> fnEvents;
82 Stats::Scalar<> fnCalls;
84 Stats::MainBin *getBin(const std::string &name);
85 bool findCaller(std::string, std::string) const;
87 SWContext *findContext(Addr pcb);
88 bool addContext(Addr pcb, SWContext *ctx)
90 return (swCtxMap.insert(std::make_pair(pcb, ctx))).second;
93 void remContext(Addr pcb)
98 void dumpState() const;
101 std::vector<std::string> binned_fns;
104 Stats::MainBin *modeBin[cpu_mode_num];
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);
117 Binning(System *sys);
120 const std::string name() const { return myname; }
121 void regStats(const std::string &name);
124 virtual void serialize(std::ostream &os);
125 virtual void unserialize(Checkpoint *cp, const std::string §ion);
128 class Statistics : public Serializable
130 friend class Binning;
141 void changeMode(cpu_mode newmode);
144 Stats::Scalar<> _arm;
145 Stats::Scalar<> _quiesce;
146 Stats::Scalar<> _ivlb;
147 Stats::Scalar<> _ivle;
148 Stats::Scalar<> _hwrei;
150 Stats::Vector<> _iplCount;
151 Stats::Vector<> _iplGood;
152 Stats::Vector<> _iplTicks;
153 Stats::Formula _iplUsed;
155 Stats::Vector<> _callpal;
156 Stats::Vector<> _syscall;
157 Stats::Vector<> _faults;
159 Stats::Vector<> _mode;
160 Stats::Vector<> _modeGood;
161 Stats::Formula _modeFraction;
162 Stats::Vector<> _modeTicks;
164 Stats::Scalar<> _swap_context;
171 Statistics(ExecContext *context);
173 const std::string name() const { return myname; }
174 void regStats(const std::string &name);
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);
188 void setIdleProcess(Addr idle);
191 virtual void serialize(std::ostream &os);
192 virtual void unserialize(Checkpoint *cp, const std::string §ion);
195 /* end namespace Kernel */ }
197 #endif // __KERNEL_STATS_HH__