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.
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"
44 using namespace Stats
;
48 const char *modestr
[] = { "kernel", "user", "idle", "interrupt" };
50 Statistics::Statistics(System
*system
)
51 : idleProcess((Addr
)-1), themode(kernel
), lastModeTick(0),
52 iplLast(0), iplLastTick(0)
54 bin_int
= system
->params()->bin_int
;
58 Statistics::regStats(const string
&_name
)
63 .name(name() + ".inst.arm")
64 .desc("number of arm instructions executed")
68 .name(name() + ".inst.quiesce")
69 .desc("number of quiesce instructions executed")
73 .name(name() + ".inst.ivlb")
74 .desc("number of ivlb instructions executed")
78 .name(name() + ".inst.ivle")
79 .desc("number of ivle instructions executed")
83 .name(name() + ".inst.hwrei")
84 .desc("number of hwrei instructions executed")
89 .name(name() + ".ipl_count")
90 .desc("number of times we switched to this ipl")
91 .flags(total
| pdf
| nozero
| nonan
)
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
)
103 .name(name() + ".ipl_ticks")
104 .desc("number of cycles we spent at this ipl")
105 .flags(total
| pdf
| nozero
| nonan
)
109 .name(name() + ".ipl_used")
110 .desc("fraction of swpipl calls that actually changed the ipl")
111 .flags(total
| nozero
| nonan
)
114 _iplUsed
= _iplGood
/ _iplCount
;
118 .name(name() + ".callpal")
119 .desc("number of callpals executed")
120 .flags(total
| pdf
| nozero
| nonan
)
123 for (int i
= 0; i
< PAL::NumCodes
; ++i
) {
124 const char *str
= PAL::name(i
);
126 _callpal
.subname(i
, str
);
130 .init(SystemCalls
<Tru64
>::Number
)
131 .name(name() + ".syscall")
132 .desc("number of syscalls executed")
133 .flags(total
| pdf
| nozero
| nonan
)
136 for (int i
= 0; i
< SystemCalls
<Tru64
>::Number
; ++i
) {
137 const char *str
= SystemCalls
<Tru64
>::name(i
);
139 _syscall
.subname(i
, str
);
145 .name(name() + ".mode_switch")
146 .desc("number of protection mode switches")
149 for (int i
= 0; i
< cpu_mode_num
; ++i
)
150 _mode
.subname(i
, modestr
[i
]);
154 .name(name() + ".mode_good")
157 for (int i
= 0; i
< cpu_mode_num
; ++i
)
158 _modeGood
.subname(i
, modestr
[i
]);
161 .name(name() + ".mode_switch_good")
162 .desc("fraction of useful protection mode switches")
166 for (int i
= 0; i
< cpu_mode_num
; ++i
)
167 _modeFraction
.subname(i
, modestr
[i
]);
169 _modeFraction
= _modeGood
/ _mode
;
173 .name(name() + ".mode_ticks")
174 .desc("number of ticks spent at the given mode")
177 for (int i
= 0; i
< cpu_mode_num
; ++i
)
178 _modeTicks
.subname(i
, modestr
[i
]);
181 .name(name() + ".swap_context")
182 .desc("number of times the context was actually changed")
187 Statistics::setIdleProcess(Addr idlepcbb
, ThreadContext
*tc
)
189 assert(themode
== kernel
|| themode
== interrupt
);
190 idleProcess
= idlepcbb
;
192 changeMode(themode
, tc
);
196 Statistics::changeMode(cpu_mode newmode
, ThreadContext
*tc
)
200 if (newmode
== themode
)
203 DPRINTF(Context
, "old mode=%-8s new mode=%-8s\n",
204 modestr
[themode
], modestr
[newmode
]);
206 _modeGood
[newmode
]++;
207 _modeTicks
[themode
] += curTick
- lastModeTick
;
209 tc
->getSystemPtr()->kernelBinning
->changeMode(newmode
);
211 lastModeTick
= curTick
;
216 Statistics::swpipl(int ipl
)
218 assert(ipl
>= 0 && ipl
<= 0x1f && "invalid IPL\n");
226 _iplTicks
[iplLast
] += curTick
- iplLastTick
;
227 iplLastTick
= curTick
;
232 Statistics::mode(cpu_mode newmode
, ThreadContext
*tc
)
234 Addr pcbb
= tc
->readMiscReg(AlphaISA::IPR_PALtemp23
);
236 if ((newmode
== kernel
|| newmode
== interrupt
) &&
240 if (bin_int
== false && newmode
== interrupt
)
243 changeMode(newmode
, tc
);
247 Statistics::context(Addr oldpcbb
, Addr newpcbb
, ThreadContext
*tc
)
249 assert(themode
!= user
);
252 changeMode(newpcbb
== idleProcess
? idle
: kernel
, tc
);
256 Statistics::callpal(int code
, ThreadContext
*tc
)
258 if (!PAL::name(code
))
265 int number
= tc
->readIntReg(0);
266 if (SystemCalls
<Tru64
>::validSyscallNumber(number
)) {
267 int cvtnum
= SystemCalls
<Tru64
>::convert(number
);
273 if (tc
->getSystemPtr()->kernelBinning
)
274 tc
->getSystemPtr()->kernelBinning
->palSwapContext(tc
);
280 Statistics::serialize(ostream
&os
)
282 int exemode
= themode
;
283 SERIALIZE_SCALAR(exemode
);
284 SERIALIZE_SCALAR(idleProcess
);
285 SERIALIZE_SCALAR(iplLast
);
286 SERIALIZE_SCALAR(iplLastTick
);
287 SERIALIZE_SCALAR(lastModeTick
);
291 Statistics::unserialize(Checkpoint
*cp
, const string
§ion
)
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
;
302 /* end namespace Kernel */ }