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 * Authors: Lisa Hsu 29 * Nathan Binkert 30 */ 31 32#include <map> 33#include <stack> 34#include <string> 35 36#include "arch/alpha/osfpal.hh" 37#include "base/trace.hh" 38#include "cpu/thread_context.hh" 39#include "kern/kernel_stats.hh" 40#include "kern/tru64/tru64_syscalls.hh" 41#include "sim/system.hh" 42 43using namespace std; 44using namespace Stats; 45 46namespace Kernel { 47
| 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 * Authors: Lisa Hsu 29 * Nathan Binkert 30 */ 31 32#include <map> 33#include <stack> 34#include <string> 35 36#include "arch/alpha/osfpal.hh" 37#include "base/trace.hh" 38#include "cpu/thread_context.hh" 39#include "kern/kernel_stats.hh" 40#include "kern/tru64/tru64_syscalls.hh" 41#include "sim/system.hh" 42 43using namespace std; 44using namespace Stats; 45 46namespace Kernel { 47
|
48const char *modestr[] = { "kernel", "user", "idle", "interrupt" };
| 48const char *modestr[] = { "kernel", "user", "idle" };
|
49 50Statistics::Statistics(System *system) 51 : idleProcess((Addr)-1), themode(kernel), lastModeTick(0), 52 iplLast(0), iplLastTick(0) 53{
| 49 50Statistics::Statistics(System *system) 51 : idleProcess((Addr)-1), themode(kernel), lastModeTick(0), 52 iplLast(0), iplLastTick(0) 53{
|
54 bin_int = 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 _mode 144 .init(cpu_mode_num) 145 .name(name() + ".mode_switch") 146 .desc("number of protection mode switches") 147 ; 148 149 for (int i = 0; i < cpu_mode_num; ++i) 150 _mode.subname(i, modestr[i]); 151 152 _modeGood 153 .init(cpu_mode_num) 154 .name(name() + ".mode_good") 155 ; 156 157 for (int i = 0; i < cpu_mode_num; ++i) 158 _modeGood.subname(i, modestr[i]); 159 160 _modeFraction 161 .name(name() + ".mode_switch_good") 162 .desc("fraction of useful protection mode switches") 163 .flags(total) 164 ; 165 166 for (int i = 0; i < cpu_mode_num; ++i) 167 _modeFraction.subname(i, modestr[i]); 168 169 _modeFraction = _modeGood / _mode; 170 171 _modeTicks 172 .init(cpu_mode_num) 173 .name(name() + ".mode_ticks") 174 .desc("number of ticks spent at the given mode") 175 .flags(pdf) 176 ; 177 for (int i = 0; i < cpu_mode_num; ++i) 178 _modeTicks.subname(i, modestr[i]); 179 180 _swap_context 181 .name(name() + ".swap_context") 182 .desc("number of times the context was actually changed") 183 ; 184} 185 186void 187Statistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc) 188{
| 54} 55 56void 57Statistics::regStats(const string &_name) 58{ 59 myname = _name; 60 61 _arm 62 .name(name() + ".inst.arm") 63 .desc("number of arm instructions executed") 64 ; 65 66 _quiesce 67 .name(name() + ".inst.quiesce") 68 .desc("number of quiesce instructions executed") 69 ; 70 71 _ivlb 72 .name(name() + ".inst.ivlb") 73 .desc("number of ivlb instructions executed") 74 ; 75 76 _ivle 77 .name(name() + ".inst.ivle") 78 .desc("number of ivle instructions executed") 79 ; 80 81 _hwrei 82 .name(name() + ".inst.hwrei") 83 .desc("number of hwrei instructions executed") 84 ; 85 86 _iplCount 87 .init(32) 88 .name(name() + ".ipl_count") 89 .desc("number of times we switched to this ipl") 90 .flags(total | pdf | nozero | nonan) 91 ; 92 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 _mode 143 .init(cpu_mode_num) 144 .name(name() + ".mode_switch") 145 .desc("number of protection mode switches") 146 ; 147 148 for (int i = 0; i < cpu_mode_num; ++i) 149 _mode.subname(i, modestr[i]); 150 151 _modeGood 152 .init(cpu_mode_num) 153 .name(name() + ".mode_good") 154 ; 155 156 for (int i = 0; i < cpu_mode_num; ++i) 157 _modeGood.subname(i, modestr[i]); 158 159 _modeFraction 160 .name(name() + ".mode_switch_good") 161 .desc("fraction of useful protection mode switches") 162 .flags(total) 163 ; 164 165 for (int i = 0; i < cpu_mode_num; ++i) 166 _modeFraction.subname(i, modestr[i]); 167 168 _modeFraction = _modeGood / _mode; 169 170 _modeTicks 171 .init(cpu_mode_num) 172 .name(name() + ".mode_ticks") 173 .desc("number of ticks spent at the given mode") 174 .flags(pdf) 175 ; 176 for (int i = 0; i < cpu_mode_num; ++i) 177 _modeTicks.subname(i, modestr[i]); 178 179 _swap_context 180 .name(name() + ".swap_context") 181 .desc("number of times the context was actually changed") 182 ; 183} 184 185void 186Statistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc) 187{
|
189 assert(themode == kernel || themode == interrupt);
| 188 assert(themode == kernel);
|
190 idleProcess = idlepcbb; 191 themode = idle; 192 changeMode(themode, tc); 193} 194 195void 196Statistics::changeMode(cpu_mode newmode, ThreadContext *tc) 197{ 198 _mode[newmode]++; 199 200 if (newmode == themode) 201 return; 202 203 DPRINTF(Context, "old mode=%-8s new mode=%-8s\n", 204 modestr[themode], modestr[newmode]); 205 206 _modeGood[newmode]++; 207 _modeTicks[themode] += curTick - lastModeTick; 208
| 189 idleProcess = idlepcbb; 190 themode = idle; 191 changeMode(themode, tc); 192} 193 194void 195Statistics::changeMode(cpu_mode newmode, ThreadContext *tc) 196{ 197 _mode[newmode]++; 198 199 if (newmode == themode) 200 return; 201 202 DPRINTF(Context, "old mode=%-8s new mode=%-8s\n", 203 modestr[themode], modestr[newmode]); 204 205 _modeGood[newmode]++; 206 _modeTicks[themode] += curTick - lastModeTick; 207
|
209 tc->getSystemPtr()->kernelBinning->changeMode(newmode); 210
| |
211 lastModeTick = curTick; 212 themode = newmode; 213} 214 215void 216Statistics::swpipl(int ipl) 217{ 218 assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n"); 219 220 _iplCount[ipl]++; 221 222 if (ipl == iplLast) 223 return; 224 225 _iplGood[ipl]++; 226 _iplTicks[iplLast] += curTick - iplLastTick; 227 iplLastTick = curTick; 228 iplLast = ipl; 229} 230 231void 232Statistics::mode(cpu_mode newmode, ThreadContext *tc) 233{ 234 Addr pcbb = tc->readMiscReg(AlphaISA::IPR_PALtemp23); 235
| 208 lastModeTick = curTick; 209 themode = newmode; 210} 211 212void 213Statistics::swpipl(int ipl) 214{ 215 assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n"); 216 217 _iplCount[ipl]++; 218 219 if (ipl == iplLast) 220 return; 221 222 _iplGood[ipl]++; 223 _iplTicks[iplLast] += curTick - iplLastTick; 224 iplLastTick = curTick; 225 iplLast = ipl; 226} 227 228void 229Statistics::mode(cpu_mode newmode, ThreadContext *tc) 230{ 231 Addr pcbb = tc->readMiscReg(AlphaISA::IPR_PALtemp23); 232
|
236 if ((newmode == kernel || newmode == interrupt) && 237 pcbb == idleProcess)
| 233 if (newmode == kernel && pcbb == idleProcess)
|
238 newmode = idle; 239
| 234 newmode = idle; 235
|
240 if (bin_int == false && newmode == interrupt) 241 newmode = kernel; 242
| |
243 changeMode(newmode, tc); 244} 245 246void 247Statistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc) 248{ 249 assert(themode != user); 250 251 _swap_context++; 252 changeMode(newpcbb == idleProcess ? idle : kernel, tc); 253} 254 255void 256Statistics::callpal(int code, ThreadContext *tc) 257{ 258 if (!PAL::name(code)) 259 return; 260 261 _callpal[code]++; 262 263 switch (code) { 264 case PAL::callsys: { 265 int number = tc->readIntReg(0); 266 if (SystemCalls<Tru64>::validSyscallNumber(number)) { 267 int cvtnum = SystemCalls<Tru64>::convert(number); 268 _syscall[cvtnum]++; 269 } 270 } break;
| 236 changeMode(newmode, tc); 237} 238 239void 240Statistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc) 241{ 242 assert(themode != user); 243 244 _swap_context++; 245 changeMode(newpcbb == idleProcess ? idle : kernel, tc); 246} 247 248void 249Statistics::callpal(int code, ThreadContext *tc) 250{ 251 if (!PAL::name(code)) 252 return; 253 254 _callpal[code]++; 255 256 switch (code) { 257 case PAL::callsys: { 258 int number = tc->readIntReg(0); 259 if (SystemCalls<Tru64>::validSyscallNumber(number)) { 260 int cvtnum = SystemCalls<Tru64>::convert(number); 261 _syscall[cvtnum]++; 262 } 263 } break;
|
271 272 case PAL::swpctx: 273 if (tc->getSystemPtr()->kernelBinning) 274 tc->getSystemPtr()->kernelBinning->palSwapContext(tc); 275 break;
| |
276 } 277} 278 279void 280Statistics::serialize(ostream &os) 281{ 282 int exemode = themode; 283 SERIALIZE_SCALAR(exemode); 284 SERIALIZE_SCALAR(idleProcess); 285 SERIALIZE_SCALAR(iplLast); 286 SERIALIZE_SCALAR(iplLastTick); 287 SERIALIZE_SCALAR(lastModeTick); 288} 289 290void 291Statistics::unserialize(Checkpoint *cp, const string §ion) 292{ 293 int exemode; 294 UNSERIALIZE_SCALAR(exemode); 295 UNSERIALIZE_SCALAR(idleProcess); 296 UNSERIALIZE_SCALAR(iplLast); 297 UNSERIALIZE_SCALAR(iplLastTick); 298 UNSERIALIZE_SCALAR(lastModeTick); 299 themode = (cpu_mode)exemode; 300} 301 302/* end namespace Kernel */ }
| 264 } 265} 266 267void 268Statistics::serialize(ostream &os) 269{ 270 int exemode = themode; 271 SERIALIZE_SCALAR(exemode); 272 SERIALIZE_SCALAR(idleProcess); 273 SERIALIZE_SCALAR(iplLast); 274 SERIALIZE_SCALAR(iplLastTick); 275 SERIALIZE_SCALAR(lastModeTick); 276} 277 278void 279Statistics::unserialize(Checkpoint *cp, const string §ion) 280{ 281 int exemode; 282 UNSERIALIZE_SCALAR(exemode); 283 UNSERIALIZE_SCALAR(idleProcess); 284 UNSERIALIZE_SCALAR(iplLast); 285 UNSERIALIZE_SCALAR(iplLastTick); 286 UNSERIALIZE_SCALAR(lastModeTick); 287 themode = (cpu_mode)exemode; 288} 289 290/* end namespace Kernel */ }
|