kernel_stats.cc revision 4172
11689SN/A/* 22326SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Lisa Hsu 291689SN/A * Nathan Binkert 301689SN/A */ 311060SN/A 321060SN/A#include <map> 331689SN/A#include <stack> 341060SN/A#include <string> 351060SN/A 361060SN/A#include "arch/alpha/kernel_stats.hh" 371060SN/A#include "arch/alpha/osfpal.hh" 382292SN/A#include "base/trace.hh" 391717SN/A#include "cpu/thread_context.hh" 401060SN/A#include "kern/tru64/tru64_syscalls.hh" 411681SN/A#include "sim/system.hh" 422292SN/A 432873Sktlim@umich.eduusing namespace std; 441060SN/Ausing namespace Stats; 451061SN/A 462292SN/Anamespace AlphaISA { 472292SN/Anamespace Kernel { 482292SN/A 492292SN/Aconst char *modestr[] = { "kernel", "user", "idle" }; 502820Sktlim@umich.edu 512292SN/AStatistics::Statistics(System *system) 522820Sktlim@umich.edu : ::Kernel::Statistics(system), 532820Sktlim@umich.edu idleProcess((Addr)-1), themode(kernel), lastModeTick(0) 542307SN/A{ 552307SN/A} 561060SN/A 572292SN/Avoid 582292SN/AStatistics::regStats(const string &_name) 592292SN/A{ 601060SN/A ::Kernel::Statistics::regStats(_name); 611060SN/A 621060SN/A _callpal 631060SN/A .init(256) 641060SN/A .name(name() + ".callpal") 651060SN/A .desc("number of callpals executed") 661681SN/A .flags(total | pdf | nozero | nonan) 672292SN/A ; 681681SN/A 692292SN/A for (int i = 0; i < PAL::NumCodes; ++i) { 702292SN/A const char *str = PAL::name(i); 712292SN/A if (str) 722292SN/A _callpal.subname(i, str); 732292SN/A } 742935Sksewell@umich.edu 752292SN/A _hwrei 762292SN/A .name(name() + ".inst.hwrei") 772820Sktlim@umich.edu .desc("number of hwrei instructions executed") 782820Sktlim@umich.edu ; 792292SN/A 802292SN/A _mode 812820Sktlim@umich.edu .init(cpu_mode_num) 822820Sktlim@umich.edu .name(name() + ".mode_switch") 832292SN/A .desc("number of protection mode switches") 842292SN/A ; 852292SN/A 862292SN/A for (int i = 0; i < cpu_mode_num; ++i) 872292SN/A _mode.subname(i, modestr[i]); 882292SN/A 892292SN/A _modeGood 902292SN/A .init(cpu_mode_num) 911060SN/A .name(name() + ".mode_good") 921060SN/A ; 931681SN/A 941062SN/A for (int i = 0; i < cpu_mode_num; ++i) 952292SN/A _modeGood.subname(i, modestr[i]); 961062SN/A 972301SN/A _modeFraction 982301SN/A .name(name() + ".mode_switch_good") 991062SN/A .desc("fraction of useful protection mode switches") 1002727Sktlim@umich.edu .flags(total) 1011062SN/A ; 1021062SN/A 1031062SN/A for (int i = 0; i < cpu_mode_num; ++i) 1041062SN/A _modeFraction.subname(i, modestr[i]); 1051062SN/A 1061062SN/A _modeFraction = _modeGood / _mode; 1071062SN/A 1081062SN/A _modeTicks 1091062SN/A .init(cpu_mode_num) 1101062SN/A .name(name() + ".mode_ticks") 1111062SN/A .desc("number of ticks spent at the given mode") 1121062SN/A .flags(pdf) 1131062SN/A ; 1141062SN/A for (int i = 0; i < cpu_mode_num; ++i) 1151062SN/A _modeTicks.subname(i, modestr[i]); 1161062SN/A 1171062SN/A _swap_context 1181062SN/A .name(name() + ".swap_context") 1191062SN/A .desc("number of times the context was actually changed") 1201062SN/A ; 1211062SN/A} 1221062SN/A 1231062SN/Avoid 1241062SN/AStatistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc) 1251062SN/A{ 1261062SN/A assert(themode == kernel); 1271062SN/A idleProcess = idlepcbb; 1281062SN/A themode = idle; 1291062SN/A changeMode(themode, tc); 1301062SN/A} 1311062SN/A 1321062SN/Avoid 1331062SN/AStatistics::changeMode(cpu_mode newmode, ThreadContext *tc) 1341062SN/A{ 1351062SN/A _mode[newmode]++; 1361062SN/A 1371062SN/A if (newmode == themode) 1381062SN/A return; 1391062SN/A 1401062SN/A DPRINTF(Context, "old mode=%-8s new mode=%-8s\n", 1411062SN/A modestr[themode], modestr[newmode]); 1422292SN/A 1432292SN/A _modeGood[newmode]++; 1442292SN/A _modeTicks[themode] += curTick - lastModeTick; 1452292SN/A 1461062SN/A lastModeTick = curTick; 1471062SN/A themode = newmode; 1481062SN/A} 1491062SN/A 1501062SN/Avoid 1511062SN/AStatistics::mode(cpu_mode newmode, ThreadContext *tc) 1521062SN/A{ 1532292SN/A Addr pcbb = tc->readMiscRegNoEffect(AlphaISA::IPR_PALtemp23); 1542292SN/A 1552292SN/A if (newmode == kernel && pcbb == idleProcess) 1562292SN/A newmode = idle; 1572292SN/A 1582292SN/A changeMode(newmode, tc); 1592292SN/A} 1602292SN/A 1612292SN/Avoid 1622292SN/AStatistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc) 1632301SN/A{ 1642727Sktlim@umich.edu assert(themode != user); 1652353SN/A 1662727Sktlim@umich.edu _swap_context++; 1672727Sktlim@umich.edu changeMode(newpcbb == idleProcess ? idle : kernel, tc); 1682727Sktlim@umich.edu} 1692727Sktlim@umich.edu 1702353SN/Avoid 1712727Sktlim@umich.eduStatistics::callpal(int code, ThreadContext *tc) 1722727Sktlim@umich.edu{ 1732727Sktlim@umich.edu if (!PAL::name(code)) 1742727Sktlim@umich.edu return; 1752353SN/A 1762727Sktlim@umich.edu _callpal[code]++; 1772727Sktlim@umich.edu 1782727Sktlim@umich.edu switch (code) { 1792301SN/A case PAL::callsys: { 1802301SN/A int number = tc->readIntReg(0); 1812301SN/A if (SystemCalls<Tru64>::validSyscallNumber(number)) { 1822727Sktlim@umich.edu int cvtnum = SystemCalls<Tru64>::convert(number); 1832301SN/A _syscall[cvtnum]++; 1842727Sktlim@umich.edu } 1852301SN/A } break; 1862301SN/A } 1872301SN/A} 1882727Sktlim@umich.edu 1892301SN/Avoid 1902727Sktlim@umich.eduStatistics::serialize(ostream &os) 1912301SN/A{ 1922301SN/A ::Kernel::Statistics::serialize(os); 1932301SN/A int exemode = themode; 1942727Sktlim@umich.edu SERIALIZE_SCALAR(exemode); 1952301SN/A SERIALIZE_SCALAR(idleProcess); 1962727Sktlim@umich.edu SERIALIZE_SCALAR(lastModeTick); 1972301SN/A} 1982301SN/A 1992301SN/Avoid 2002727Sktlim@umich.eduStatistics::unserialize(Checkpoint *cp, const string §ion) 2012301SN/A{ 2022301SN/A ::Kernel::Statistics::unserialize(cp, section); 2032301SN/A int exemode; 2042301SN/A UNSERIALIZE_SCALAR(exemode); 2052727Sktlim@umich.edu UNSERIALIZE_SCALAR(idleProcess); 2062727Sktlim@umich.edu UNSERIALIZE_SCALAR(lastModeTick); 2072727Sktlim@umich.edu themode = (cpu_mode)exemode; 2082727Sktlim@umich.edu} 2092727Sktlim@umich.edu 2102727Sktlim@umich.edu} /* end namespace AlphaISA::Kernel */ 2112727Sktlim@umich.edu} /* end namespace AlphaISA */ 2122727Sktlim@umich.edu