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
3211793Sbrandon.potter@amd.com#include "arch/alpha/kernel_stats.hh"
3311793Sbrandon.potter@amd.com
343560SN/A#include <map>
353560SN/A#include <stack>
363560SN/A#include <string>
373560SN/A
3811793Sbrandon.potter@amd.com#include "arch/alpha/osfpal.hh"
399329Sdam.sunwoo@arm.com#include "arch/generic/linux/threadinfo.hh"
403560SN/A#include "base/trace.hh"
413560SN/A#include "cpu/thread_context.hh"
428232Snate@binkert.org#include "debug/Context.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
5312181Sgabeblack@google.comStatistics::Statistics()
5412181Sgabeblack@google.com    : ::Kernel::Statistics(),
5512182Sgabeblack@google.com      idleProcess((Addr)-1), themode(kernel), lastModeTick(0),
5612182Sgabeblack@google.com      iplLast(0), iplLastTick(0)
573560SN/A{
583560SN/A}
593560SN/A
603560SN/Avoid
613560SN/AStatistics::regStats(const string &_name)
623560SN/A{
633560SN/A    ::Kernel::Statistics::regStats(_name);
643560SN/A
653560SN/A    _callpal
663560SN/A        .init(256)
673560SN/A        .name(name() + ".callpal")
683560SN/A        .desc("number of callpals executed")
693560SN/A        .flags(total | pdf | nozero | nonan)
703560SN/A        ;
713560SN/A
723560SN/A    for (int i = 0; i < PAL::NumCodes; ++i) {
733560SN/A        const char *str = PAL::name(i);
743560SN/A        if (str)
753560SN/A            _callpal.subname(i, str);
763560SN/A    }
773560SN/A
783560SN/A    _hwrei
793560SN/A        .name(name() + ".inst.hwrei")
803560SN/A        .desc("number of hwrei instructions executed")
813560SN/A        ;
823560SN/A
833560SN/A    _mode
843560SN/A        .init(cpu_mode_num)
853560SN/A        .name(name() + ".mode_switch")
863560SN/A        .desc("number of protection mode switches")
873560SN/A        ;
883560SN/A
893560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
903560SN/A        _mode.subname(i, modestr[i]);
913560SN/A
923560SN/A    _modeGood
933560SN/A        .init(cpu_mode_num)
943560SN/A        .name(name() + ".mode_good")
953560SN/A        ;
963560SN/A
973560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
983560SN/A        _modeGood.subname(i, modestr[i]);
993560SN/A
1003560SN/A    _modeFraction
1013560SN/A        .name(name() + ".mode_switch_good")
1023560SN/A        .desc("fraction of useful protection mode switches")
1033560SN/A        .flags(total)
1043560SN/A        ;
1053560SN/A
1063560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
1073560SN/A        _modeFraction.subname(i, modestr[i]);
1083560SN/A
1093560SN/A    _modeFraction = _modeGood / _mode;
1103560SN/A
1113560SN/A    _modeTicks
1123560SN/A        .init(cpu_mode_num)
1133560SN/A        .name(name() + ".mode_ticks")
1143560SN/A        .desc("number of ticks spent at the given mode")
1153560SN/A        .flags(pdf)
1163560SN/A        ;
1173560SN/A    for (int i = 0; i < cpu_mode_num; ++i)
1183560SN/A        _modeTicks.subname(i, modestr[i]);
1193560SN/A
1203560SN/A    _swap_context
1213560SN/A        .name(name() + ".swap_context")
1223560SN/A        .desc("number of times the context was actually changed")
1233560SN/A        ;
12412182Sgabeblack@google.com
12512182Sgabeblack@google.com    _iplCount
12612182Sgabeblack@google.com        .init(32)
12712182Sgabeblack@google.com        .name(name() + ".ipl_count")
12812182Sgabeblack@google.com        .desc("number of times we switched to this ipl")
12912182Sgabeblack@google.com        .flags(total | pdf | nozero | nonan)
13012182Sgabeblack@google.com        ;
13112182Sgabeblack@google.com
13212182Sgabeblack@google.com    _iplGood
13312182Sgabeblack@google.com        .init(32)
13412182Sgabeblack@google.com        .name(name() + ".ipl_good")
13512182Sgabeblack@google.com        .desc("number of times we switched to this ipl from a different ipl")
13612182Sgabeblack@google.com        .flags(total | pdf | nozero | nonan)
13712182Sgabeblack@google.com        ;
13812182Sgabeblack@google.com
13912182Sgabeblack@google.com    _iplTicks
14012182Sgabeblack@google.com        .init(32)
14112182Sgabeblack@google.com        .name(name() + ".ipl_ticks")
14212182Sgabeblack@google.com        .desc("number of cycles we spent at this ipl")
14312182Sgabeblack@google.com        .flags(total | pdf | nozero | nonan)
14412182Sgabeblack@google.com        ;
14512182Sgabeblack@google.com
14612182Sgabeblack@google.com    _iplUsed
14712182Sgabeblack@google.com        .name(name() + ".ipl_used")
14812182Sgabeblack@google.com        .desc("fraction of swpipl calls that actually changed the ipl")
14912182Sgabeblack@google.com        .flags(total | nozero | nonan)
15012182Sgabeblack@google.com        ;
15112182Sgabeblack@google.com
15212182Sgabeblack@google.com    _iplUsed = _iplGood / _iplCount;
1533560SN/A}
1543560SN/A
1553560SN/Avoid
1563560SN/AStatistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc)
1573560SN/A{
1583560SN/A    assert(themode == kernel);
1593560SN/A    idleProcess = idlepcbb;
1603560SN/A    themode = idle;
1613560SN/A    changeMode(themode, tc);
1623560SN/A}
1633560SN/A
1643560SN/Avoid
1653560SN/AStatistics::changeMode(cpu_mode newmode, ThreadContext *tc)
1663560SN/A{
1673560SN/A    _mode[newmode]++;
1683560SN/A
1693560SN/A    if (newmode == themode)
1703560SN/A        return;
1713560SN/A
1725191Ssaidi@eecs.umich.edu    DPRINTF(Context, "old mode=%s new mode=%s pid=%d\n",
1735191Ssaidi@eecs.umich.edu            modestr[themode], modestr[newmode],
1745191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc).curTaskPID());
1753560SN/A
1763560SN/A    _modeGood[newmode]++;
1777823Ssteve.reinhardt@amd.com    _modeTicks[themode] += curTick() - lastModeTick;
1783560SN/A
1797823Ssteve.reinhardt@amd.com    lastModeTick = curTick();
1803560SN/A    themode = newmode;
1813560SN/A}
1823560SN/A
1833560SN/Avoid
1843560SN/AStatistics::mode(cpu_mode newmode, ThreadContext *tc)
1853560SN/A{
1865568Snate@binkert.org    Addr pcbb = tc->readMiscRegNoEffect(IPR_PALtemp23);
1873560SN/A
1883560SN/A    if (newmode == kernel && pcbb == idleProcess)
1893560SN/A        newmode = idle;
1903560SN/A
1913560SN/A    changeMode(newmode, tc);
1923560SN/A}
1933560SN/A
1943560SN/Avoid
1953560SN/AStatistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
1963560SN/A{
1973560SN/A    assert(themode != user);
1983560SN/A
1993560SN/A    _swap_context++;
2003560SN/A    changeMode(newpcbb == idleProcess ? idle : kernel, tc);
2015191Ssaidi@eecs.umich.edu
2025191Ssaidi@eecs.umich.edu    DPRINTF(Context, "Context Switch old pid=%d new pid=%d\n",
2035191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc, oldpcbb).curTaskPID(),
2045191Ssaidi@eecs.umich.edu            Linux::ThreadInfo(tc, newpcbb).curTaskPID());
2053560SN/A}
2063560SN/A
2073560SN/Avoid
2083560SN/AStatistics::callpal(int code, ThreadContext *tc)
2093560SN/A{
2103560SN/A    if (!PAL::name(code))
2113560SN/A        return;
2123560SN/A
2133560SN/A    _callpal[code]++;
2143560SN/A}
2153560SN/A
2163560SN/Avoid
21712182Sgabeblack@google.comStatistics::swpipl(int ipl)
21812182Sgabeblack@google.com{
21912182Sgabeblack@google.com    assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n");
22012182Sgabeblack@google.com
22112182Sgabeblack@google.com    _iplCount[ipl]++;
22212182Sgabeblack@google.com
22312182Sgabeblack@google.com    if (ipl == iplLast)
22412182Sgabeblack@google.com        return;
22512182Sgabeblack@google.com
22612182Sgabeblack@google.com    _iplGood[ipl]++;
22712182Sgabeblack@google.com    _iplTicks[iplLast] += curTick() - iplLastTick;
22812182Sgabeblack@google.com    iplLastTick = curTick();
22912182Sgabeblack@google.com    iplLast = ipl;
23012182Sgabeblack@google.com}
23112182Sgabeblack@google.com
23212182Sgabeblack@google.comvoid
23310905Sandreas.sandberg@arm.comStatistics::serialize(CheckpointOut &cp) const
2343560SN/A{
23510905Sandreas.sandberg@arm.com    ::Kernel::Statistics::serialize(cp);
2363560SN/A    int exemode = themode;
2373560SN/A    SERIALIZE_SCALAR(exemode);
2383560SN/A    SERIALIZE_SCALAR(idleProcess);
2393560SN/A    SERIALIZE_SCALAR(lastModeTick);
24012182Sgabeblack@google.com    SERIALIZE_SCALAR(iplLast);
24112182Sgabeblack@google.com    SERIALIZE_SCALAR(iplLastTick);
2423560SN/A}
2433560SN/A
2443560SN/Avoid
24510905Sandreas.sandberg@arm.comStatistics::unserialize(CheckpointIn &cp)
2463560SN/A{
24710905Sandreas.sandberg@arm.com    ::Kernel::Statistics::unserialize(cp);
2483560SN/A    int exemode;
2493560SN/A    UNSERIALIZE_SCALAR(exemode);
2503560SN/A    UNSERIALIZE_SCALAR(idleProcess);
2513560SN/A    UNSERIALIZE_SCALAR(lastModeTick);
2523560SN/A    themode = (cpu_mode)exemode;
25312182Sgabeblack@google.com    UNSERIALIZE_SCALAR(iplLast);
25412182Sgabeblack@google.com    UNSERIALIZE_SCALAR(iplLastTick);
2553560SN/A}
2563560SN/A
2575568Snate@binkert.org} // namespace Kernel
2585568Snate@binkert.org} // namespace AlphaISA
259