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 "cpu/static_inst.hh"
42 // What does kernel stats expect is included?
48 enum cpu_mode { kernel, user, idle, interrupt, cpu_mode_num };
49 extern const char *modestr[];
54 typedef TheISA::Addr Addr;
60 // lisa's binning stuff
63 Stats::MainBin *myBin;
70 std::stack<fnCall *> callStack;
73 std::map<const std::string, Stats::MainBin *> fnBins;
74 std::map<const Addr, SWContext *> swCtxMap;
76 std::multimap<const std::string, std::string> callerMap;
77 void populateMap(std::string caller, std::string callee);
79 std::vector<FnEvent *> fnEvents;
81 Stats::Scalar<> fnCalls;
83 Stats::MainBin *getBin(const std::string &name);
84 bool findCaller(std::string, std::string) const;
86 SWContext *findContext(Addr pcb);
87 bool addContext(Addr pcb, SWContext *ctx)
89 return (swCtxMap.insert(std::make_pair(pcb, ctx))).second;
92 void remContext(Addr pcb)
97 void dumpState() const;
100 std::vector<std::string> binned_fns;
103 Stats::MainBin *modeBin[cpu_mode_num];
110 void palSwapContext(ExecContext *xc);
111 void execute(ExecContext *xc, StaticInstPtr inst);
112 void call(ExecContext *xc, Stats::MainBin *myBin);
113 void changeMode(cpu_mode mode);
116 Binning(System *sys);
119 const std::string name() const { return myname; }
120 void regStats(const std::string &name);
123 virtual void serialize(std::ostream &os);
124 virtual void unserialize(Checkpoint *cp, const std::string §ion);
127 class Statistics : public Serializable
130 typedef TheISA::Addr Addr;
132 friend class Binning;
143 void changeMode(cpu_mode newmode);
146 Stats::Scalar<> _arm;
147 Stats::Scalar<> _quiesce;
148 Stats::Scalar<> _ivlb;
149 Stats::Scalar<> _ivle;
150 Stats::Scalar<> _hwrei;
152 Stats::Vector<> _iplCount;
153 Stats::Vector<> _iplGood;
154 Stats::Vector<> _iplTicks;
155 Stats::Formula _iplUsed;
157 Stats::Vector<> _callpal;
158 Stats::Vector<> _syscall;
159 Stats::Vector<> _faults;
161 Stats::Vector<> _mode;
162 Stats::Vector<> _modeGood;
163 Stats::Formula _modeFraction;
164 Stats::Vector<> _modeTicks;
166 Stats::Scalar<> _swap_context;
173 Statistics(ExecContext *context);
175 const std::string name() const { return myname; }
176 void regStats(const std::string &name);
179 void arm() { _arm++; }
180 void quiesce() { _quiesce++; }
181 void ivlb() { _ivlb++; }
182 void ivle() { _ivle++; }
183 void hwrei() { _hwrei++; }
184 void fault(Fault * fault)
186 if(fault == NoFault) _faults[0]++;
187 else if(fault == MachineCheckFault) _faults[2]++;
188 else if(fault == AlignmentFault) _faults[7]++;
189 else _faults[fault->id]++;
190 }// FIXME: When there are no generic system fault objects, this will go back to _faults[fault]++; }
191 void swpipl(int ipl);
192 void mode(cpu_mode newmode);
193 void context(Addr oldpcbb, Addr newpcbb);
194 void callpal(int code);
196 void setIdleProcess(Addr idle);
199 virtual void serialize(std::ostream &os);
200 virtual void unserialize(Checkpoint *cp, const std::string §ion);
203 /* end namespace Kernel */ }
205 #endif // __KERNEL_STATS_HH__