kernel_stats.cc revision 2235
1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <map> 30#include <stack> 31#include <string> 32 33#include "arch/alpha/osfpal.hh" 34#include "base/trace.hh" 35#include "cpu/exec_context.hh" 36#include "kern/kernel_stats.hh" 37#include "kern/tru64/tru64_syscalls.hh" 38#include "sim/system.hh" 39 40using namespace std; 41using namespace Stats; 42 43namespace Kernel { 44 45const char *modestr[] = { "kernel", "user", "idle", "interrupt" }; 46 47Statistics::Statistics(System *system) 48 : idleProcess((Addr)-1), themode(kernel), lastModeTick(0), 49 iplLast(0), iplLastTick(0) 50{ 51 bin_int = system->params()->bin_int; 52} 53 54void 55Statistics::regStats(const string &_name) 56{ 57 myname = _name; 58 59 _arm 60 .name(name() + ".inst.arm") 61 .desc("number of arm instructions executed") 62 ; 63 64 _quiesce 65 .name(name() + ".inst.quiesce") 66 .desc("number of quiesce instructions executed") 67 ; 68 69 _ivlb 70 .name(name() + ".inst.ivlb") 71 .desc("number of ivlb instructions executed") 72 ; 73 74 _ivle 75 .name(name() + ".inst.ivle") 76 .desc("number of ivle instructions executed") 77 ; 78 79 _hwrei 80 .name(name() + ".inst.hwrei") 81 .desc("number of hwrei instructions executed") 82 ; 83 84 _iplCount 85 .init(32) 86 .name(name() + ".ipl_count") 87 .desc("number of times we switched to this ipl") 88 .flags(total | pdf | nozero | nonan) 89 ; 90 91 _iplGood 92 .init(32) 93 .name(name() + ".ipl_good") 94 .desc("number of times we switched to this ipl from a different ipl") 95 .flags(total | pdf | nozero | nonan) 96 ; 97 98 _iplTicks 99 .init(32) 100 .name(name() + ".ipl_ticks") 101 .desc("number of cycles we spent at this ipl") 102 .flags(total | pdf | nozero | nonan) 103 ; 104 105 _iplUsed 106 .name(name() + ".ipl_used") 107 .desc("fraction of swpipl calls that actually changed the ipl") 108 .flags(total | nozero | nonan) 109 ; 110 111 _iplUsed = _iplGood / _iplCount; 112 113 _callpal 114 .init(256) 115 .name(name() + ".callpal") 116 .desc("number of callpals executed") 117 .flags(total | pdf | nozero | nonan) 118 ; 119 120 for (int i = 0; i < PAL::NumCodes; ++i) { 121 const char *str = PAL::name(i); 122 if (str) 123 _callpal.subname(i, str); 124 } 125 126 _syscall 127 .init(SystemCalls<Tru64>::Number) 128 .name(name() + ".syscall") 129 .desc("number of syscalls executed") 130 .flags(total | pdf | nozero | nonan) 131 ; 132 133 for (int i = 0; i < SystemCalls<Tru64>::Number; ++i) { 134 const char *str = SystemCalls<Tru64>::name(i); 135 if (str) { 136 _syscall.subname(i, str); 137 } 138 } 139 140/* _faults 141 .init(NumFaults) 142 .name(name() + ".faults") 143 .desc("number of faults") 144 .flags(total | pdf | nozero | nonan) 145 ; 146 147 for (int i = 1; i < NumFaults; ++i) { 148 const char *str = (*ListOfFaults[i])->name; 149 if (str) 150 _faults.subname(i, str); 151 }*/ 152 153 _mode 154 .init(cpu_mode_num) 155 .name(name() + ".mode_switch") 156 .desc("number of protection mode switches") 157 ; 158 159 for (int i = 0; i < cpu_mode_num; ++i) 160 _mode.subname(i, modestr[i]); 161 162 _modeGood 163 .init(cpu_mode_num) 164 .name(name() + ".mode_good") 165 ; 166 167 for (int i = 0; i < cpu_mode_num; ++i) 168 _modeGood.subname(i, modestr[i]); 169 170 _modeFraction 171 .name(name() + ".mode_switch_good") 172 .desc("fraction of useful protection mode switches") 173 .flags(total) 174 ; 175 176 for (int i = 0; i < cpu_mode_num; ++i) 177 _modeFraction.subname(i, modestr[i]); 178 179 _modeFraction = _modeGood / _mode; 180 181 _modeTicks 182 .init(cpu_mode_num) 183 .name(name() + ".mode_ticks") 184 .desc("number of ticks spent at the given mode") 185 .flags(pdf) 186 ; 187 for (int i = 0; i < cpu_mode_num; ++i) 188 _modeTicks.subname(i, modestr[i]); 189 190 _swap_context 191 .name(name() + ".swap_context") 192 .desc("number of times the context was actually changed") 193 ; 194} 195 196void 197Statistics::setIdleProcess(Addr idlepcbb, ExecContext *xc) 198{ 199 assert(themode == kernel || themode == interrupt); 200 idleProcess = idlepcbb; 201 themode = idle; 202 changeMode(themode, xc); 203} 204 205void 206Statistics::changeMode(cpu_mode newmode, ExecContext *xc) 207{ 208 _mode[newmode]++; 209 210 if (newmode == themode) 211 return; 212 213 DPRINTF(Context, "old mode=%-8s new mode=%-8s\n", 214 modestr[themode], modestr[newmode]); 215 216 _modeGood[newmode]++; 217 _modeTicks[themode] += curTick - lastModeTick; 218 219 xc->getSystemPtr()->kernelBinning->changeMode(newmode); 220 221 lastModeTick = curTick; 222 themode = newmode; 223} 224 225void 226Statistics::swpipl(int ipl) 227{ 228 assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n"); 229 230 _iplCount[ipl]++; 231 232 if (ipl == iplLast) 233 return; 234 235 _iplGood[ipl]++; 236 _iplTicks[iplLast] += curTick - iplLastTick; 237 iplLastTick = curTick; 238 iplLast = ipl; 239} 240 241void 242Statistics::mode(cpu_mode newmode, ExecContext *xc) 243{ 244 Addr pcbb = xc->readMiscReg(AlphaISA::IPR_PALtemp23); 245 246 if ((newmode == kernel || newmode == interrupt) && 247 pcbb == idleProcess) 248 newmode = idle; 249 250 if (bin_int == false && newmode == interrupt) 251 newmode = kernel; 252 253 changeMode(newmode, xc); 254} 255 256void 257Statistics::context(Addr oldpcbb, Addr newpcbb, ExecContext *xc) 258{ 259 assert(themode != user); 260 261 _swap_context++; 262 changeMode(newpcbb == idleProcess ? idle : kernel, xc); 263} 264 265void 266Statistics::callpal(int code, ExecContext *xc) 267{ 268 if (!PAL::name(code)) 269 return; 270 271 _callpal[code]++; 272 273 switch (code) { 274 case PAL::callsys: { 275 int number = xc->readIntReg(0); 276 if (SystemCalls<Tru64>::validSyscallNumber(number)) { 277 int cvtnum = SystemCalls<Tru64>::convert(number); 278 _syscall[cvtnum]++; 279 } 280 } break; 281 282 case PAL::swpctx: 283 if (xc->getSystemPtr()->kernelBinning) 284 xc->getSystemPtr()->kernelBinning->palSwapContext(xc); 285 break; 286 } 287} 288 289void 290Statistics::serialize(ostream &os) 291{ 292 int exemode = themode; 293 SERIALIZE_SCALAR(exemode); 294 SERIALIZE_SCALAR(idleProcess); 295 SERIALIZE_SCALAR(iplLast); 296 SERIALIZE_SCALAR(iplLastTick); 297 SERIALIZE_SCALAR(lastModeTick); 298} 299 300void 301Statistics::unserialize(Checkpoint *cp, const string §ion) 302{ 303 int exemode; 304 UNSERIALIZE_SCALAR(exemode); 305 UNSERIALIZE_SCALAR(idleProcess); 306 UNSERIALIZE_SCALAR(iplLast); 307 UNSERIALIZE_SCALAR(iplLastTick); 308 UNSERIALIZE_SCALAR(lastModeTick); 309 themode = (cpu_mode)exemode; 310} 311 312/* end namespace Kernel */ } 313