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