kernel_stats.hh revision 2665
1754SN/A/*
21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
3754SN/A * All rights reserved.
4754SN/A *
5754SN/A * Redistribution and use in source and binary forms, with or without
6754SN/A * modification, are permitted provided that the following conditions are
7754SN/A * met: redistributions of source code must retain the above copyright
8754SN/A * notice, this list of conditions and the following disclaimer;
9754SN/A * redistributions in binary form must reproduce the above copyright
10754SN/A * notice, this list of conditions and the following disclaimer in the
11754SN/A * documentation and/or other materials provided with the distribution;
12754SN/A * neither the name of the copyright holders nor the names of its
13754SN/A * contributors may be used to endorse or promote products derived from
14754SN/A * this software without specific prior written permission.
15754SN/A *
16754SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17754SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18754SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19754SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20754SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21754SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22754SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23754SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24754SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25754SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26754SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Lisa Hsu
292665Ssaidi@eecs.umich.edu *          Nathan Binkert
30754SN/A */
31754SN/A
32754SN/A#ifndef __KERNEL_STATS_HH__
33754SN/A#define __KERNEL_STATS_HH__
34754SN/A
351070SN/A#include <map>
361070SN/A#include <stack>
37754SN/A#include <string>
381070SN/A#include <vector>
39754SN/A
401917SN/A#include "cpu/static_inst.hh"
411917SN/A
421070SN/Aclass BaseCPU;
43754SN/Aclass ExecContext;
441070SN/Aclass FnEvent;
451681SN/A// What does kernel stats expect is included?
461681SN/Aclass System;
47754SN/A
481070SN/Anamespace Kernel {
491070SN/A
501082SN/Aenum cpu_mode { kernel, user, idle, interrupt, cpu_mode_num };
511070SN/Aextern const char *modestr[];
521070SN/A
531070SN/Aclass Binning
54754SN/A{
55754SN/A  private:
561070SN/A    std::string myname;
571070SN/A    System *system;
581070SN/A
591070SN/A  private:
601070SN/A    // lisa's binning stuff
611070SN/A    struct fnCall
621070SN/A    {
631070SN/A        Stats::MainBin *myBin;
641070SN/A        std::string name;
651070SN/A    };
661070SN/A
671070SN/A    struct SWContext
681070SN/A    {
691070SN/A        Counter calls;
701070SN/A        std::stack<fnCall *> callStack;
711070SN/A    };
721070SN/A
731070SN/A    std::map<const std::string, Stats::MainBin *> fnBins;
741070SN/A    std::map<const Addr, SWContext *> swCtxMap;
751070SN/A
761070SN/A    std::multimap<const std::string, std::string> callerMap;
771070SN/A    void populateMap(std::string caller, std::string callee);
781070SN/A
791070SN/A    std::vector<FnEvent *> fnEvents;
801070SN/A
811070SN/A    Stats::Scalar<> fnCalls;
821070SN/A
831070SN/A    Stats::MainBin *getBin(const std::string &name);
841070SN/A    bool findCaller(std::string, std::string) const;
851070SN/A
861070SN/A    SWContext *findContext(Addr pcb);
871070SN/A    bool addContext(Addr pcb, SWContext *ctx)
881070SN/A    {
891070SN/A        return (swCtxMap.insert(std::make_pair(pcb, ctx))).second;
901070SN/A    }
911070SN/A
921070SN/A    void remContext(Addr pcb)
931070SN/A    {
941070SN/A        swCtxMap.erase(pcb);
951070SN/A    }
961070SN/A
971070SN/A    void dumpState() const;
981070SN/A
991070SN/A    SWContext *swctx;
1001070SN/A    std::vector<std::string> binned_fns;
1011070SN/A
1021070SN/A  private:
1031082SN/A    Stats::MainBin *modeBin[cpu_mode_num];
104754SN/A
105754SN/A  public:
1061070SN/A    const bool bin;
1071070SN/A    const bool fnbin;
108754SN/A
1091070SN/A    cpu_mode themode;
1101070SN/A    void palSwapContext(ExecContext *xc);
1112107SN/A    void execute(ExecContext *xc, StaticInstPtr inst);
1121070SN/A    void call(ExecContext *xc, Stats::MainBin *myBin);
1131070SN/A    void changeMode(cpu_mode mode);
1141070SN/A
1151070SN/A  public:
1161070SN/A    Binning(System *sys);
1171070SN/A    virtual ~Binning();
1181070SN/A
1191070SN/A    const std::string name() const { return myname; }
120754SN/A    void regStats(const std::string &name);
121754SN/A
1221070SN/A  public:
1231070SN/A    virtual void serialize(std::ostream &os);
1241070SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
125754SN/A};
126754SN/A
1271070SN/Aclass Statistics : public Serializable
1281070SN/A{
1292107SN/A  private:
1301070SN/A    friend class Binning;
1311070SN/A
1321070SN/A  private:
1331070SN/A    std::string myname;
1341070SN/A
1351070SN/A    Addr idleProcess;
1361070SN/A    cpu_mode themode;
1371070SN/A    Tick lastModeTick;
1381082SN/A    bool bin_int;
1391070SN/A
1402190SN/A    void changeMode(cpu_mode newmode, ExecContext *xc);
1411070SN/A
1421070SN/A  private:
1431070SN/A    Stats::Scalar<> _arm;
1441070SN/A    Stats::Scalar<> _quiesce;
1451070SN/A    Stats::Scalar<> _ivlb;
1461070SN/A    Stats::Scalar<> _ivle;
1471070SN/A    Stats::Scalar<> _hwrei;
1481070SN/A
1491070SN/A    Stats::Vector<> _iplCount;
1501070SN/A    Stats::Vector<> _iplGood;
1511070SN/A    Stats::Vector<> _iplTicks;
1521070SN/A    Stats::Formula _iplUsed;
1531070SN/A
1541070SN/A    Stats::Vector<> _callpal;
1551070SN/A    Stats::Vector<> _syscall;
1562147SN/A//    Stats::Vector<> _faults;
1571070SN/A
1581070SN/A    Stats::Vector<> _mode;
1591070SN/A    Stats::Vector<> _modeGood;
1601070SN/A    Stats::Formula _modeFraction;
1611070SN/A    Stats::Vector<> _modeTicks;
1621070SN/A
1631070SN/A    Stats::Scalar<> _swap_context;
1641070SN/A
1651070SN/A  private:
1661070SN/A    int iplLast;
1671070SN/A    Tick iplLastTick;
1681070SN/A
1691070SN/A  public:
1702190SN/A    Statistics(System *system);
1711070SN/A
1721070SN/A    const std::string name() const { return myname; }
1731070SN/A    void regStats(const std::string &name);
1741070SN/A
1751070SN/A  public:
1761070SN/A    void arm() { _arm++; }
1771070SN/A    void quiesce() { _quiesce++; }
1781070SN/A    void ivlb() { _ivlb++; }
1791070SN/A    void ivle() { _ivle++; }
1801070SN/A    void hwrei() { _hwrei++; }
1811070SN/A    void swpipl(int ipl);
1822190SN/A    void mode(cpu_mode newmode, ExecContext *xc);
1832190SN/A    void context(Addr oldpcbb, Addr newpcbb, ExecContext *xc);
1842190SN/A    void callpal(int code, ExecContext *xc);
1851070SN/A
1862190SN/A    void setIdleProcess(Addr idle, ExecContext *xc);
1871070SN/A
1881070SN/A  public:
1891070SN/A    virtual void serialize(std::ostream &os);
1901070SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
1911070SN/A};
1921070SN/A
1931070SN/A/* end namespace Kernel */ }
1941070SN/A
195754SN/A#endif // __KERNEL_STATS_HH__
196