2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
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"
41 using namespace Stats
;
45 const char *modestr
[] = { "kernel", "user", "idle", "interrupt" };
47 Statistics::Statistics(System
*system
)
48 : idleProcess((Addr
)-1), themode(kernel
), lastModeTick(0),
49 iplLast(0), iplLastTick(0)
51 bin_int
= system
->params()->bin_int
;
55 Statistics::regStats(const string
&_name
)
60 .name(name() + ".inst.arm")
61 .desc("number of arm instructions executed")
65 .name(name() + ".inst.quiesce")
66 .desc("number of quiesce instructions executed")
70 .name(name() + ".inst.ivlb")
71 .desc("number of ivlb instructions executed")
75 .name(name() + ".inst.ivle")
76 .desc("number of ivle instructions executed")
80 .name(name() + ".inst.hwrei")
81 .desc("number of hwrei instructions executed")
86 .name(name() + ".ipl_count")
87 .desc("number of times we switched to this ipl")
88 .flags(total
| pdf
| nozero
| nonan
)
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
)
100 .name(name() + ".ipl_ticks")
101 .desc("number of cycles we spent at this ipl")
102 .flags(total
| pdf
| nozero
| nonan
)
106 .name(name() + ".ipl_used")
107 .desc("fraction of swpipl calls that actually changed the ipl")
108 .flags(total
| nozero
| nonan
)
111 _iplUsed
= _iplGood
/ _iplCount
;
115 .name(name() + ".callpal")
116 .desc("number of callpals executed")
117 .flags(total
| pdf
| nozero
| nonan
)
120 for (int i
= 0; i
< PAL::NumCodes
; ++i
) {
121 const char *str
= PAL::name(i
);
123 _callpal
.subname(i
, str
);
127 .init(SystemCalls
<Tru64
>::Number
)
128 .name(name() + ".syscall")
129 .desc("number of syscalls executed")
130 .flags(total
| pdf
| nozero
| nonan
)
133 for (int i
= 0; i
< SystemCalls
<Tru64
>::Number
; ++i
) {
134 const char *str
= SystemCalls
<Tru64
>::name(i
);
136 _syscall
.subname(i
, str
);
142 .name(name() + ".mode_switch")
143 .desc("number of protection mode switches")
146 for (int i
= 0; i
< cpu_mode_num
; ++i
)
147 _mode
.subname(i
, modestr
[i
]);
151 .name(name() + ".mode_good")
154 for (int i
= 0; i
< cpu_mode_num
; ++i
)
155 _modeGood
.subname(i
, modestr
[i
]);
158 .name(name() + ".mode_switch_good")
159 .desc("fraction of useful protection mode switches")
163 for (int i
= 0; i
< cpu_mode_num
; ++i
)
164 _modeFraction
.subname(i
, modestr
[i
]);
166 _modeFraction
= _modeGood
/ _mode
;
170 .name(name() + ".mode_ticks")
171 .desc("number of ticks spent at the given mode")
174 for (int i
= 0; i
< cpu_mode_num
; ++i
)
175 _modeTicks
.subname(i
, modestr
[i
]);
178 .name(name() + ".swap_context")
179 .desc("number of times the context was actually changed")
184 Statistics::setIdleProcess(Addr idlepcbb
, ExecContext
*xc
)
186 assert(themode
== kernel
|| themode
== interrupt
);
187 idleProcess
= idlepcbb
;
189 changeMode(themode
, xc
);
193 Statistics::changeMode(cpu_mode newmode
, ExecContext
*xc
)
197 if (newmode
== themode
)
200 DPRINTF(Context
, "old mode=%-8s new mode=%-8s\n",
201 modestr
[themode
], modestr
[newmode
]);
203 _modeGood
[newmode
]++;
204 _modeTicks
[themode
] += curTick
- lastModeTick
;
206 xc
->getSystemPtr()->kernelBinning
->changeMode(newmode
);
208 lastModeTick
= curTick
;
213 Statistics::swpipl(int ipl
)
215 assert(ipl
>= 0 && ipl
<= 0x1f && "invalid IPL\n");
223 _iplTicks
[iplLast
] += curTick
- iplLastTick
;
224 iplLastTick
= curTick
;
229 Statistics::mode(cpu_mode newmode
, ExecContext
*xc
)
231 Addr pcbb
= xc
->readMiscReg(AlphaISA::IPR_PALtemp23
);
233 if ((newmode
== kernel
|| newmode
== interrupt
) &&
237 if (bin_int
== false && newmode
== interrupt
)
240 changeMode(newmode
, xc
);
244 Statistics::context(Addr oldpcbb
, Addr newpcbb
, ExecContext
*xc
)
246 assert(themode
!= user
);
249 changeMode(newpcbb
== idleProcess
? idle
: kernel
, xc
);
253 Statistics::callpal(int code
, ExecContext
*xc
)
255 if (!PAL::name(code
))
262 int number
= xc
->readIntReg(0);
263 if (SystemCalls
<Tru64
>::validSyscallNumber(number
)) {
264 int cvtnum
= SystemCalls
<Tru64
>::convert(number
);
270 if (xc
->getSystemPtr()->kernelBinning
)
271 xc
->getSystemPtr()->kernelBinning
->palSwapContext(xc
);
277 Statistics::serialize(ostream
&os
)
279 int exemode
= themode
;
280 SERIALIZE_SCALAR(exemode
);
281 SERIALIZE_SCALAR(idleProcess
);
282 SERIALIZE_SCALAR(iplLast
);
283 SERIALIZE_SCALAR(iplLastTick
);
284 SERIALIZE_SCALAR(lastModeTick
);
288 Statistics::unserialize(Checkpoint
*cp
, const string
§ion
)
291 UNSERIALIZE_SCALAR(exemode
);
292 UNSERIALIZE_SCALAR(idleProcess
);
293 UNSERIALIZE_SCALAR(iplLast
);
294 UNSERIALIZE_SCALAR(iplLastTick
);
295 UNSERIALIZE_SCALAR(lastModeTick
);
296 themode
= (cpu_mode
)exemode
;
299 /* end namespace Kernel */ }