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