kernel_stats.cc revision 5191
13560SN/A/*
23560SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
33560SN/A * All rights reserved.
43560SN/A *
53560SN/A * Redistribution and use in source and binary forms, with or without
63560SN/A * modification, are permitted provided that the following conditions are
73560SN/A * met: redistributions of source code must retain the above copyright
83560SN/A * notice, this list of conditions and the following disclaimer;
93560SN/A * redistributions in binary form must reproduce the above copyright
103560SN/A * notice, this list of conditions and the following disclaimer in the
113560SN/A * documentation and/or other materials provided with the distribution;
123560SN/A * neither the name of the copyright holders nor the names of its
133560SN/A * contributors may be used to endorse or promote products derived from
143560SN/A * this software without specific prior written permission.
153560SN/A *
163560SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173560SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183560SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193560SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203560SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213560SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223560SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233560SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243560SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253560SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263560SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273560SN/A *
283560SN/A * Authors: Lisa Hsu
293560SN/A *          Nathan Binkert
303560SN/A */
313560SN/A
323560SN/A#include <map>
333560SN/A#include <stack>
343560SN/A#include <string>
353560SN/A
365191Ssaidi@eecs.umich.edu#include "arch/alpha/linux/threadinfo.hh"
373565Sgblack@eecs.umich.edu#include "arch/alpha/kernel_stats.hh"
383560SN/A#include "arch/alpha/osfpal.hh"
393560SN/A#include "base/trace.hh"
403560SN/A#include "cpu/thread_context.hh"
413560SN/A#include "kern/tru64/tru64_syscalls.hh"
423560SN/A#include "sim/system.hh"
433560SN/A
443560SN/Ausing namespace std;
453560SN/Ausing namespace Stats;
463560SN/A
473560SN/Anamespace AlphaISA {
483560SN/Anamespace Kernel {
493560SN/A
503560SN/Aconst char *modestr[] = { "kernel", "user", "idle" };
513560SN/A
523560SN/AStatistics::Statistics(System *system)
533560SN/A    : ::Kernel::Statistics(system),
543560SN/A      idleProcess((Addr)-1), themode(kernel), lastModeTick(0)
553560SN/A{
563560SN/A}
573560SN/A
583560SN/Avoid
593560SN/AStatistics::regStats(const string &_name)
603560SN/A{
613560SN/A    ::Kernel::Statistics::regStats(_name);
623560SN/A
633560SN/A    _callpal
643560SN/A        .init(256)
653560SN/A        .name(name() + ".callpal")
663560SN/A        .desc("number of callpals executed")
673560SN/A        .flags(total | pdf | nozero | nonan)
683560SN/A        ;
693560SN/A
703560SN/A    for (int i = 0; i < PAL::NumCodes; ++i) {
713560SN/A        const char *str = PAL::name(i);
723560SN/A        if (str)
733560SN/A            _callpal.subname(i, str);
743560SN/A    }
753560SN/A
763560SN/A    _hwrei
773560SN/A        .name(name() + ".inst.hwrei")
783560SN/A        .desc("number of hwrei instructions executed")
793560SN/A        ;
803560SN/A
813560SN/A    _mode
823560SN/A        .init(cpu_mode_num)
833560SN/A        .name(name() + ".mode_switch")
843560SN/A        .desc("number of protection mode switches")
853560SN/A        ;
863560SN/A
873560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
883560SN/A        _mode.subname(i, modestr[i]);
893560SN/A
903560SN/A    _modeGood
913560SN/A        .init(cpu_mode_num)
923560SN/A        .name(name() + ".mode_good")
933560SN/A        ;
943560SN/A
953560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
963560SN/A        _modeGood.subname(i, modestr[i]);
973560SN/A
983560SN/A    _modeFraction
993560SN/A        .name(name() + ".mode_switch_good")
1003560SN/A        .desc("fraction of useful protection mode switches")
1013560SN/A        .flags(total)
1023560SN/A        ;
1033560SN/A
1043560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
1053560SN/A        _modeFraction.subname(i, modestr[i]);
1063560SN/A
1073560SN/A    _modeFraction = _modeGood / _mode;
1083560SN/A
1093560SN/A    _modeTicks
1103560SN/A        .init(cpu_mode_num)
1113560SN/A        .name(name() + ".mode_ticks")
1123560SN/A        .desc("number of ticks spent at the given mode")
1133560SN/A        .flags(pdf)
1143560SN/A        ;
1153560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
1163560SN/A        _modeTicks.subname(i, modestr[i]);
1173560SN/A
1183560SN/A    _swap_context
1193560SN/A        .name(name() + ".swap_context")
1203560SN/A        .desc("number of times the context was actually changed")
1213560SN/A        ;
1223560SN/A}
1233560SN/A
1243560SN/Avoid
1253560SN/AStatistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc)
1263560SN/A{
1273560SN/A    assert(themode == kernel);
1283560SN/A    idleProcess = idlepcbb;
1293560SN/A    themode = idle;
1303560SN/A    changeMode(themode, tc);
1313560SN/A}
1323560SN/A
1333560SN/Avoid
1343560SN/AStatistics::changeMode(cpu_mode newmode, ThreadContext *tc)
1353560SN/A{
1363560SN/A    _mode[newmode]++;
1373560SN/A
1383560SN/A    if (newmode == themode)
1393560SN/A        return;
1403560SN/A
1415191Ssaidi@eecs.umich.edu    DPRINTF(Context, "old mode=%s new mode=%s pid=%d\n",
1425191Ssaidi@eecs.umich.edu            modestr[themode], modestr[newmode],
1435191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc).curTaskPID());
1443560SN/A
1453560SN/A    _modeGood[newmode]++;
1463560SN/A    _modeTicks[themode] += curTick - lastModeTick;
1473560SN/A
1483560SN/A    lastModeTick = curTick;
1493560SN/A    themode = newmode;
1503560SN/A}
1513560SN/A
1523560SN/Avoid
1533560SN/AStatistics::mode(cpu_mode newmode, ThreadContext *tc)
1543560SN/A{
1554172Ssaidi@eecs.umich.edu    Addr pcbb = tc->readMiscRegNoEffect(AlphaISA::IPR_PALtemp23);
1563560SN/A
1573560SN/A    if (newmode == kernel && pcbb == idleProcess)
1583560SN/A        newmode = idle;
1593560SN/A
1603560SN/A    changeMode(newmode, tc);
1613560SN/A}
1623560SN/A
1633560SN/Avoid
1643560SN/AStatistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
1653560SN/A{
1663560SN/A    assert(themode != user);
1673560SN/A
1683560SN/A    _swap_context++;
1693560SN/A    changeMode(newpcbb == idleProcess ? idle : kernel, tc);
1705191Ssaidi@eecs.umich.edu
1715191Ssaidi@eecs.umich.edu    DPRINTF(Context, "Context Switch old pid=%d new pid=%d\n",
1725191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc, oldpcbb).curTaskPID(),
1735191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc, newpcbb).curTaskPID());
1743560SN/A}
1753560SN/A
1763560SN/Avoid
1773560SN/AStatistics::callpal(int code, ThreadContext *tc)
1783560SN/A{
1793560SN/A    if (!PAL::name(code))
1803560SN/A        return;
1813560SN/A
1823560SN/A    _callpal[code]++;
1833560SN/A
1843560SN/A    switch (code) {
1853560SN/A      case PAL::callsys: {
1863560SN/A          int number = tc->readIntReg(0);
1873560SN/A          if (SystemCalls<Tru64>::validSyscallNumber(number)) {
1883560SN/A              int cvtnum = SystemCalls<Tru64>::convert(number);
1893560SN/A              _syscall[cvtnum]++;
1903560SN/A          }
1913560SN/A      } break;
1923560SN/A    }
1933560SN/A}
1943560SN/A
1953560SN/Avoid
1963560SN/AStatistics::serialize(ostream &os)
1973560SN/A{
1983560SN/A    ::Kernel::Statistics::serialize(os);
1993560SN/A    int exemode = themode;
2003560SN/A    SERIALIZE_SCALAR(exemode);
2013560SN/A    SERIALIZE_SCALAR(idleProcess);
2023560SN/A    SERIALIZE_SCALAR(lastModeTick);
2033560SN/A}
2043560SN/A
2053560SN/Avoid
2063560SN/AStatistics::unserialize(Checkpoint *cp, const string &section)
2073560SN/A{
2083560SN/A    ::Kernel::Statistics::unserialize(cp, section);
2093560SN/A    int exemode;
2103560SN/A    UNSERIALIZE_SCALAR(exemode);
2113560SN/A    UNSERIALIZE_SCALAR(idleProcess);
2123560SN/A    UNSERIALIZE_SCALAR(lastModeTick);
2133560SN/A    themode = (cpu_mode)exemode;
2143560SN/A}
2153560SN/A
2163560SN/A} /* end namespace AlphaISA::Kernel */
2173560SN/A} /* end namespace AlphaISA */
218