kernel_stats.cc revision 9329
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
369329Sdam.sunwoo@arm.com#include "arch/generic/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"
418232Snate@binkert.org#include "debug/Context.hh"
423560SN/A#include "kern/tru64/tru64_syscalls.hh"
433560SN/A#include "sim/system.hh"
443560SN/A
453560SN/Ausing namespace std;
463560SN/Ausing namespace Stats;
473560SN/A
483560SN/Anamespace AlphaISA {
493560SN/Anamespace Kernel {
503560SN/A
513560SN/Aconst char *modestr[] = { "kernel", "user", "idle" };
523560SN/A
533560SN/AStatistics::Statistics(System *system)
543560SN/A    : ::Kernel::Statistics(system),
553560SN/A      idleProcess((Addr)-1), themode(kernel), lastModeTick(0)
563560SN/A{
573560SN/A}
583560SN/A
593560SN/Avoid
603560SN/AStatistics::regStats(const string &_name)
613560SN/A{
623560SN/A    ::Kernel::Statistics::regStats(_name);
633560SN/A
643560SN/A    _callpal
653560SN/A        .init(256)
663560SN/A        .name(name() + ".callpal")
673560SN/A        .desc("number of callpals executed")
683560SN/A        .flags(total | pdf | nozero | nonan)
693560SN/A        ;
703560SN/A
713560SN/A    for (int i = 0; i < PAL::NumCodes; ++i) {
723560SN/A        const char *str = PAL::name(i);
733560SN/A        if (str)
743560SN/A            _callpal.subname(i, str);
753560SN/A    }
763560SN/A
773560SN/A    _hwrei
783560SN/A        .name(name() + ".inst.hwrei")
793560SN/A        .desc("number of hwrei instructions executed")
803560SN/A        ;
813560SN/A
823560SN/A    _mode
833560SN/A        .init(cpu_mode_num)
843560SN/A        .name(name() + ".mode_switch")
853560SN/A        .desc("number of protection mode switches")
863560SN/A        ;
873560SN/A
883560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
893560SN/A        _mode.subname(i, modestr[i]);
903560SN/A
913560SN/A    _modeGood
923560SN/A        .init(cpu_mode_num)
933560SN/A        .name(name() + ".mode_good")
943560SN/A        ;
953560SN/A
963560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
973560SN/A        _modeGood.subname(i, modestr[i]);
983560SN/A
993560SN/A    _modeFraction
1003560SN/A        .name(name() + ".mode_switch_good")
1013560SN/A        .desc("fraction of useful protection mode switches")
1023560SN/A        .flags(total)
1033560SN/A        ;
1043560SN/A
1053560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
1063560SN/A        _modeFraction.subname(i, modestr[i]);
1073560SN/A
1083560SN/A    _modeFraction = _modeGood / _mode;
1093560SN/A
1103560SN/A    _modeTicks
1113560SN/A        .init(cpu_mode_num)
1123560SN/A        .name(name() + ".mode_ticks")
1133560SN/A        .desc("number of ticks spent at the given mode")
1143560SN/A        .flags(pdf)
1153560SN/A        ;
1163560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
1173560SN/A        _modeTicks.subname(i, modestr[i]);
1183560SN/A
1193560SN/A    _swap_context
1203560SN/A        .name(name() + ".swap_context")
1213560SN/A        .desc("number of times the context was actually changed")
1223560SN/A        ;
1233560SN/A}
1243560SN/A
1253560SN/Avoid
1263560SN/AStatistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc)
1273560SN/A{
1283560SN/A    assert(themode == kernel);
1293560SN/A    idleProcess = idlepcbb;
1303560SN/A    themode = idle;
1313560SN/A    changeMode(themode, tc);
1323560SN/A}
1333560SN/A
1343560SN/Avoid
1353560SN/AStatistics::changeMode(cpu_mode newmode, ThreadContext *tc)
1363560SN/A{
1373560SN/A    _mode[newmode]++;
1383560SN/A
1393560SN/A    if (newmode == themode)
1403560SN/A        return;
1413560SN/A
1425191Ssaidi@eecs.umich.edu    DPRINTF(Context, "old mode=%s new mode=%s pid=%d\n",
1435191Ssaidi@eecs.umich.edu            modestr[themode], modestr[newmode],
1445191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc).curTaskPID());
1453560SN/A
1463560SN/A    _modeGood[newmode]++;
1477823Ssteve.reinhardt@amd.com    _modeTicks[themode] += curTick() - lastModeTick;
1483560SN/A
1497823Ssteve.reinhardt@amd.com    lastModeTick = curTick();
1503560SN/A    themode = newmode;
1513560SN/A}
1523560SN/A
1533560SN/Avoid
1543560SN/AStatistics::mode(cpu_mode newmode, ThreadContext *tc)
1553560SN/A{
1565568Snate@binkert.org    Addr pcbb = tc->readMiscRegNoEffect(IPR_PALtemp23);
1573560SN/A
1583560SN/A    if (newmode == kernel && pcbb == idleProcess)
1593560SN/A        newmode = idle;
1603560SN/A
1613560SN/A    changeMode(newmode, tc);
1623560SN/A}
1633560SN/A
1643560SN/Avoid
1653560SN/AStatistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
1663560SN/A{
1673560SN/A    assert(themode != user);
1683560SN/A
1693560SN/A    _swap_context++;
1703560SN/A    changeMode(newpcbb == idleProcess ? idle : kernel, tc);
1715191Ssaidi@eecs.umich.edu
1725191Ssaidi@eecs.umich.edu    DPRINTF(Context, "Context Switch old pid=%d new pid=%d\n",
1735191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc, oldpcbb).curTaskPID(),
1745191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc, newpcbb).curTaskPID());
1753560SN/A}
1763560SN/A
1773560SN/Avoid
1783560SN/AStatistics::callpal(int code, ThreadContext *tc)
1793560SN/A{
1803560SN/A    if (!PAL::name(code))
1813560SN/A        return;
1823560SN/A
1833560SN/A    _callpal[code]++;
1843560SN/A
1853560SN/A    switch (code) {
1863560SN/A      case PAL::callsys: {
1873560SN/A          int number = tc->readIntReg(0);
1883560SN/A          if (SystemCalls<Tru64>::validSyscallNumber(number)) {
1893560SN/A              int cvtnum = SystemCalls<Tru64>::convert(number);
1903560SN/A              _syscall[cvtnum]++;
1913560SN/A          }
1923560SN/A      } break;
1933560SN/A    }
1943560SN/A}
1953560SN/A
1963560SN/Avoid
1973560SN/AStatistics::serialize(ostream &os)
1983560SN/A{
1993560SN/A    ::Kernel::Statistics::serialize(os);
2003560SN/A    int exemode = themode;
2013560SN/A    SERIALIZE_SCALAR(exemode);
2023560SN/A    SERIALIZE_SCALAR(idleProcess);
2033560SN/A    SERIALIZE_SCALAR(lastModeTick);
2043560SN/A}
2053560SN/A
2063560SN/Avoid
2073560SN/AStatistics::unserialize(Checkpoint *cp, const string &section)
2083560SN/A{
2093560SN/A    ::Kernel::Statistics::unserialize(cp, section);
2103560SN/A    int exemode;
2113560SN/A    UNSERIALIZE_SCALAR(exemode);
2123560SN/A    UNSERIALIZE_SCALAR(idleProcess);
2133560SN/A    UNSERIALIZE_SCALAR(lastModeTick);
2143560SN/A    themode = (cpu_mode)exemode;
2153560SN/A}
2163560SN/A
2175568Snate@binkert.org} // namespace Kernel
2185568Snate@binkert.org} // namespace AlphaISA
219