kernel_stats.cc revision 1096
1/* 2 * Copyright (c) 2003 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 "base/statistics.hh" 36#include "base/stats/bin.hh" 37#include "cpu/exec_context.hh" 38#include "cpu/pc_event.hh" 39#include "cpu/static_inst.hh" 40#include "kern/kernel_stats.hh" 41#include "kern/linux/linux_syscalls.hh" 42 43using namespace std; 44using namespace Stats; 45 46namespace Kernel { 47 48const char *modestr[] = { "kernel", "user", "idle", "interrupt" }; 49 50Statistics::Statistics(ExecContext *context) 51 : xc(context), idleProcess((Addr)-1), themode(kernel), lastModeTick(0), 52 iplLast(0), iplLastTick(0) 53{ 54 bin_int = xc->system->params->bin_int; 55} 56 57void 58Statistics::regStats(const string &_name) 59{ 60 myname = _name; 61 62 _arm 63 .name(name() + ".inst.arm") 64 .desc("number of arm instructions executed") 65 ; 66 67 _quiesce 68 .name(name() + ".inst.quiesce") 69 .desc("number of quiesce instructions executed") 70 ; 71 72 _ivlb 73 .name(name() + ".inst.ivlb") 74 .desc("number of ivlb instructions executed") 75 ; 76 77 _ivle 78 .name(name() + ".inst.ivle") 79 .desc("number of ivle instructions executed") 80 ; 81 82 _hwrei 83 .name(name() + ".inst.hwrei") 84 .desc("number of hwrei instructions executed") 85 ; 86 87 _iplCount 88 .init(32) 89 .name(name() + ".ipl_count") 90 .desc("number of times we switched to this ipl") 91 .flags(total | pdf | nozero | nonan) 92 ; 93 94 _iplGood 95 .init(32) 96 .name(name() + ".ipl_good") 97 .desc("number of times we switched to this ipl from a different ipl") 98 .flags(total | pdf | nozero | nonan) 99 ; 100 101 _iplTicks 102 .init(32) 103 .name(name() + ".ipl_ticks") 104 .desc("number of cycles we spent at this ipl") 105 .flags(total | pdf | nozero | nonan) 106 ; 107 108 _iplUsed 109 .name(name() + ".ipl_used") 110 .desc("fraction of swpipl calls that actually changed the ipl") 111 .flags(total | nozero | nonan) 112 ; 113 114 _iplUsed = _iplGood / _iplCount; 115 116 _callpal 117 .init(256) 118 .name(name() + ".callpal") 119 .desc("number of callpals executed") 120 .flags(total | pdf | nozero | nonan) 121 ; 122 123 for (int i = 0; i < PAL::NumCodes; ++i) { 124 const char *str = PAL::name(i); 125 if (str) 126 _callpal.subname(i, str); 127 } 128 129 _syscall 130 .init(SystemCalls<Tru64>::Number) 131 .name(name() + ".syscall") 132 .desc("number of syscalls executed") 133 .flags(total | pdf | nozero | nonan) 134 ; 135 136 for (int i = 0; i < SystemCalls<Tru64>::Number; ++i) { 137 const char *str = SystemCalls<Tru64>::name(i); 138 if (str) { 139 _syscall.subname(i, str); 140 } 141 } 142 143 _faults 144 .init(Num_Faults) 145 .name(name() + ".faults") 146 .desc("number of faults") 147 .flags(total | pdf | nozero | nonan) 148 ; 149 150 for (int i = 1; i < Num_Faults; ++i) { 151 const char *str = FaultName(i); 152 if (str) 153 _faults.subname(i, str); 154 } 155 156 _mode 157 .init(cpu_mode_num) 158 .name(name() + ".mode_switch") 159 .desc("number of protection mode switches") 160 ; 161 162 for (int i = 0; i < cpu_mode_num; ++i) 163 _mode.subname(i, modestr[i]); 164 165 _modeGood 166 .init(cpu_mode_num) 167 .name(name() + ".mode_good") 168 ; 169 170 for (int i = 0; i < cpu_mode_num; ++i) 171 _modeGood.subname(i, modestr[i]); 172 173 _modeFraction 174 .name(name() + ".mode_switch_good") 175 .desc("fraction of useful protection mode switches") 176 .flags(total) 177 ; 178 179 for (int i = 0; i < cpu_mode_num; ++i) 180 _modeFraction.subname(i, modestr[i]); 181 182 _modeFraction = _modeGood / _mode; 183 184 _modeTicks 185 .init(cpu_mode_num) 186 .name(name() + ".mode_ticks") 187 .desc("number of ticks spent at the given mode") 188 .flags(pdf) 189 ; 190 for (int i = 0; i < cpu_mode_num; ++i) 191 _modeTicks.subname(i, modestr[i]); 192 193 _swap_context 194 .name(name() + ".swap_context") 195 .desc("number of times the context was actually changed") 196 ; 197} 198 199void 200Statistics::setIdleProcess(Addr idlepcbb) 201{ 202 assert(themode == kernel || themode == interrupt); 203 idleProcess = idlepcbb; 204 themode = idle; 205 changeMode(themode); 206} 207 208void 209Statistics::changeMode(cpu_mode newmode) 210{ 211 _mode[newmode]++; 212 213 if (newmode == themode) 214 return; 215 216 DPRINTF(Context, "old mode=%-8s new mode=%-8s\n", 217 modestr[themode], modestr[newmode]); 218 219 _modeGood[newmode]++; 220 _modeTicks[themode] += curTick - lastModeTick; 221 222 xc->system->kernelBinning->changeMode(newmode); 223 224 lastModeTick = curTick; 225 themode = newmode; 226} 227 228void 229Statistics::swpipl(int ipl) 230{ 231 assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n"); 232 233 _iplCount[ipl]++; 234 235 if (ipl == iplLast) 236 return; 237 238 _iplGood[ipl]++; 239 _iplTicks[iplLast] += curTick - iplLastTick; 240 iplLastTick = curTick; 241 iplLast = ipl; 242} 243 244void 245Statistics::mode(cpu_mode newmode) 246{ 247 Addr pcbb = xc->regs.ipr[AlphaISA::IPR_PALtemp23]; 248 249 if ((newmode == kernel || newmode == interrupt) && 250 pcbb == idleProcess) 251 newmode = idle; 252 253 if (bin_int == false && newmode == interrupt) 254 newmode = kernel; 255 256 changeMode(newmode); 257} 258 259void 260Statistics::context(Addr oldpcbb, Addr newpcbb) 261{ 262 assert(themode != user); 263 264 _swap_context++; 265 changeMode(newpcbb == idleProcess ? idle : kernel); 266} 267 268void 269Statistics::callpal(int code) 270{ 271 if (!PAL::name(code)) 272 return; 273 274 _callpal[code]++; 275 276 switch (code) { 277 case PAL::callsys: { 278 int number = xc->regs.intRegFile[0]; 279 if (SystemCalls<Tru64>::validSyscallNumber(number)) { 280 int cvtnum = SystemCalls<Tru64>::convert(number); 281 _syscall[cvtnum]++; 282 } 283 } break; 284 285 case PAL::swpctx: 286 if (xc->system->kernelBinning) 287 xc->system->kernelBinning->palSwapContext(xc); 288 break; 289 } 290} 291 292void 293Statistics::serialize(ostream &os) 294{ 295 int exemode = themode; 296 SERIALIZE_SCALAR(exemode); 297 SERIALIZE_SCALAR(idleProcess); 298} 299 300void 301Statistics::unserialize(Checkpoint *cp, const string §ion) 302{ 303 int exemode; 304 UNSERIALIZE_SCALAR(exemode); 305 UNSERIALIZE_SCALAR(idleProcess); 306 themode = (cpu_mode)exemode; 307} 308 309/* end namespace Kernel */ } 310