kernel_stats.cc revision 1070
111263Sandreas.sandberg@arm.com/* 211263Sandreas.sandberg@arm.com * Copyright (c) 2003 The Regents of The University of Michigan 311263Sandreas.sandberg@arm.com * All rights reserved. 411263Sandreas.sandberg@arm.com * 511263Sandreas.sandberg@arm.com * Redistribution and use in source and binary forms, with or without 611263Sandreas.sandberg@arm.com * modification, are permitted provided that the following conditions are 711263Sandreas.sandberg@arm.com * met: redistributions of source code must retain the above copyright 811263Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer; 911263Sandreas.sandberg@arm.com * redistributions in binary form must reproduce the above copyright 1011263Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer in the 1111263Sandreas.sandberg@arm.com * documentation and/or other materials provided with the distribution; 1211263Sandreas.sandberg@arm.com * neither the name of the copyright holders nor the names of its 1311263Sandreas.sandberg@arm.com * contributors may be used to endorse or promote products derived from 1411263Sandreas.sandberg@arm.com * this software without specific prior written permission. 1511263Sandreas.sandberg@arm.com * 1611263Sandreas.sandberg@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1711263Sandreas.sandberg@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811263Sandreas.sandberg@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1911263Sandreas.sandberg@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2011263Sandreas.sandberg@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2111263Sandreas.sandberg@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2211263Sandreas.sandberg@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2311263Sandreas.sandberg@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2411263Sandreas.sandberg@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2511263Sandreas.sandberg@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2611263Sandreas.sandberg@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2711263Sandreas.sandberg@arm.com */ 2811263Sandreas.sandberg@arm.com 2911263Sandreas.sandberg@arm.com#include <map> 3011263Sandreas.sandberg@arm.com#include <stack> 3111263Sandreas.sandberg@arm.com#include <string> 3211263Sandreas.sandberg@arm.com 3311263Sandreas.sandberg@arm.com#include "arch/alpha/osfpal.hh" 3411263Sandreas.sandberg@arm.com#include "base/trace.hh" 3511263Sandreas.sandberg@arm.com#include "base/statistics.hh" 3611263Sandreas.sandberg@arm.com#include "base/stats/bin.hh" 3711263Sandreas.sandberg@arm.com#include "cpu/exec_context.hh" 3811263Sandreas.sandberg@arm.com#include "cpu/pc_event.hh" 3911263Sandreas.sandberg@arm.com#include "cpu/static_inst.hh" 4011263Sandreas.sandberg@arm.com#include "kern/kernel_stats.hh" 4111263Sandreas.sandberg@arm.com#include "kern/linux/linux_syscalls.hh" 4211263Sandreas.sandberg@arm.com 4311263Sandreas.sandberg@arm.comusing namespace std; 4411263Sandreas.sandberg@arm.comusing namespace Stats; 4511263Sandreas.sandberg@arm.com 4611263Sandreas.sandberg@arm.comnamespace Kernel { 4711263Sandreas.sandberg@arm.com 4811263Sandreas.sandberg@arm.comconst char *modestr[] = { "kernel", "user", "idle" }; 4911263Sandreas.sandberg@arm.com 5011263Sandreas.sandberg@arm.comStatistics::Statistics(ExecContext *context) 5111317Sm.alian1369@gmail.com : xc(context), idleProcess((Addr)-1), themode(kernel), lastModeTick(0), 5211263Sandreas.sandberg@arm.com iplLast(0), iplLastTick(0) 5311263Sandreas.sandberg@arm.com{ 5411263Sandreas.sandberg@arm.com} 5511263Sandreas.sandberg@arm.com 5611263Sandreas.sandberg@arm.comvoid 5711263Sandreas.sandberg@arm.comStatistics::regStats(const string &_name) 5811263Sandreas.sandberg@arm.com{ 5911263Sandreas.sandberg@arm.com myname = _name; 6011263Sandreas.sandberg@arm.com 6111263Sandreas.sandberg@arm.com _arm 6211263Sandreas.sandberg@arm.com .name(name() + ".inst.arm") 6311263Sandreas.sandberg@arm.com .desc("number of arm instructions executed") 6411263Sandreas.sandberg@arm.com ; 6511263Sandreas.sandberg@arm.com 6611263Sandreas.sandberg@arm.com _quiesce 6711263Sandreas.sandberg@arm.com .name(name() + ".inst.quiesce") 6811263Sandreas.sandberg@arm.com .desc("number of quiesce instructions executed") 6911263Sandreas.sandberg@arm.com ; 7011263Sandreas.sandberg@arm.com 7111290Sgabor.dozsa@arm.com _ivlb 7211290Sgabor.dozsa@arm.com .name(name() + ".inst.ivlb") 7311290Sgabor.dozsa@arm.com .desc("number of ivlb instructions executed") 7411263Sandreas.sandberg@arm.com ; 7511263Sandreas.sandberg@arm.com 7611290Sgabor.dozsa@arm.com _ivle 7711290Sgabor.dozsa@arm.com .name(name() + ".inst.ivle") 7811290Sgabor.dozsa@arm.com .desc("number of ivle instructions executed") 7911263Sandreas.sandberg@arm.com ; 8011263Sandreas.sandberg@arm.com 8111263Sandreas.sandberg@arm.com _hwrei 8211263Sandreas.sandberg@arm.com .name(name() + ".inst.hwrei") 8311263Sandreas.sandberg@arm.com .desc("number of hwrei instructions executed") 8411263Sandreas.sandberg@arm.com ; 8511263Sandreas.sandberg@arm.com 8611263Sandreas.sandberg@arm.com _iplCount 8711263Sandreas.sandberg@arm.com .init(32) 8811263Sandreas.sandberg@arm.com .name(name() + ".ipl_count") 8911263Sandreas.sandberg@arm.com .desc("number of times we switched to this ipl") 9011263Sandreas.sandberg@arm.com .flags(total | pdf | nozero | nonan) 9111263Sandreas.sandberg@arm.com ; 9211263Sandreas.sandberg@arm.com 93 _iplGood 94 .init(32) 95 .name(name() + ".ipl_good") 96 .desc("number of times we switched to this ipl from a different ipl") 97 .flags(total | pdf | nozero | nonan) 98 ; 99 100 _iplTicks 101 .init(32) 102 .name(name() + ".ipl_ticks") 103 .desc("number of cycles we spent at this ipl") 104 .flags(total | pdf | nozero | nonan) 105 ; 106 107 _iplUsed 108 .name(name() + ".ipl_used") 109 .desc("fraction of swpipl calls that actually changed the ipl") 110 .flags(total | nozero | nonan) 111 ; 112 113 _iplUsed = _iplGood / _iplCount; 114 115 _callpal 116 .init(256) 117 .name(name() + ".callpal") 118 .desc("number of callpals executed") 119 .flags(total | pdf | nozero | nonan) 120 ; 121 122 for (int i = 0; i < PAL::NumCodes; ++i) { 123 const char *str = PAL::name(i); 124 if (str) 125 _callpal.subname(i, str); 126 } 127 128 _syscall 129 .init(SystemCalls<Tru64>::Number) 130 .name(name() + ".syscall") 131 .desc("number of syscalls executed") 132 .flags(total | pdf | nozero | nonan) 133 ; 134 135 for (int i = 0; i < SystemCalls<Tru64>::Number; ++i) { 136 const char *str = SystemCalls<Tru64>::name(i); 137 if (str) { 138 _syscall.subname(i, str); 139 } 140 } 141 142 _faults 143 .init(Num_Faults) 144 .name(name() + ".faults") 145 .desc("number of faults") 146 .flags(total | pdf | nozero | nonan) 147 ; 148 149 for (int i = 1; i < Num_Faults; ++i) { 150 const char *str = FaultName(i); 151 if (str) 152 _faults.subname(i, str); 153 } 154 155 _mode 156 .init(3) 157 .name(name() + ".mode_switch") 158 .desc("number of protection mode switches") 159 ; 160 161 for (int i = 0; i < 3; ++i) 162 _mode.subname(i, modestr[i]); 163 164 _modeGood 165 .init(3) 166 .name(name() + ".mode_good") 167 ; 168 169 for (int i = 0; i < 3; ++i) 170 _modeGood.subname(i, modestr[i]); 171 172 _modeFraction 173 .name(name() + ".mode_switch_good") 174 .desc("fraction of useful protection mode switches") 175 .flags(total) 176 ; 177 178 for (int i = 0; i < 3; ++i) 179 _modeFraction.subname(i, modestr[i]); 180 181 _modeFraction = _modeGood / _mode; 182 183 _modeTicks 184 .init(3) 185 .name(name() + ".mode_ticks") 186 .desc("number of ticks spent at the given mode") 187 .flags(pdf) 188 ; 189 for (int i = 0; i < 3; ++i) 190 _modeTicks.subname(i, modestr[i]); 191 192 _swap_context 193 .name(name() + ".swap_context") 194 .desc("number of times the context was actually changed") 195 ; 196} 197 198void 199Statistics::setIdleProcess(Addr idlepcbb) 200{ 201 assert(themode == kernel); 202 idleProcess = idlepcbb; 203 themode = idle; 204 changeMode(themode); 205} 206 207void 208Statistics::changeMode(cpu_mode newmode) 209{ 210 _mode[newmode]++; 211 212 if (newmode == themode) 213 return; 214 215 DPRINTF(Context, "old mode=%-8s new mode=%-8s\n", 216 modestr[themode], modestr[newmode]); 217 218 _modeGood[newmode]++; 219 _modeTicks[themode] += curTick - lastModeTick; 220 221 xc->system->kernelBinning->changeMode(newmode); 222 223 lastModeTick = curTick; 224 themode = newmode; 225} 226 227void 228Statistics::swpipl(int ipl) 229{ 230 assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n"); 231 232 _iplCount[ipl]++; 233 234 if (ipl == iplLast) 235 return; 236 237 _iplGood[ipl]++; 238 _iplTicks[iplLast] += curTick - iplLastTick; 239 iplLastTick = curTick; 240 iplLast = ipl; 241} 242 243void 244Statistics::mode(bool usermode) 245{ 246 Addr pcbb = xc->regs.ipr[AlphaISA::IPR_PALtemp23]; 247 248 cpu_mode newmode = usermode ? user : kernel; 249 if (newmode == kernel && pcbb == idleProcess) 250 newmode = idle; 251 252 changeMode(newmode); 253} 254 255void 256Statistics::context(Addr oldpcbb, Addr newpcbb) 257{ 258 assert(themode != user); 259 260 _swap_context++; 261 changeMode(newpcbb == idleProcess ? idle : kernel); 262} 263 264void 265Statistics::callpal(int code) 266{ 267 if (!PAL::name(code)) 268 return; 269 270 _callpal[code]++; 271 272 switch (code) { 273 case PAL::callsys: { 274 int number = xc->regs.intRegFile[0]; 275 if (SystemCalls<Tru64>::validSyscallNumber(number)) { 276 int cvtnum = SystemCalls<Tru64>::convert(number); 277 _syscall[cvtnum]++; 278 } 279 } break; 280 281 case PAL::swpctx: 282 if (xc->system->kernelBinning) 283 xc->system->kernelBinning->palSwapContext(xc); 284 break; 285 } 286} 287 288void 289Statistics::serialize(ostream &os) 290{ 291 int exemode = themode; 292 SERIALIZE_SCALAR(exemode); 293} 294 295void 296Statistics::unserialize(Checkpoint *cp, const string §ion) 297{ 298 int exemode; 299 UNSERIALIZE_SCALAR(exemode); 300 themode = (cpu_mode)exemode; 301} 302 303/* end namespace Kernel */ } 304