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" };
50 Statistics::Statistics(System
*system
)
51 : idleProcess((Addr
)-1), themode(kernel
), lastModeTick(0),
52 iplLast(0), iplLastTick(0)
57 Statistics::regStats(const string
&_name
)
62 .name(name() + ".inst.arm")
63 .desc("number of arm instructions executed")
67 .name(name() + ".inst.quiesce")
68 .desc("number of quiesce instructions executed")
72 .name(name() + ".inst.hwrei")
73 .desc("number of hwrei instructions executed")
78 .name(name() + ".ipl_count")
79 .desc("number of times we switched to this ipl")
80 .flags(total
| pdf
| nozero
| nonan
)
85 .name(name() + ".ipl_good")
86 .desc("number of times we switched to this ipl from a different ipl")
87 .flags(total
| pdf
| nozero
| nonan
)
92 .name(name() + ".ipl_ticks")
93 .desc("number of cycles we spent at this ipl")
94 .flags(total
| pdf
| nozero
| nonan
)
98 .name(name() + ".ipl_used")
99 .desc("fraction of swpipl calls that actually changed the ipl")
100 .flags(total
| nozero
| nonan
)
103 _iplUsed
= _iplGood
/ _iplCount
;
107 .name(name() + ".callpal")
108 .desc("number of callpals executed")
109 .flags(total
| pdf
| nozero
| nonan
)
112 for (int i
= 0; i
< PAL::NumCodes
; ++i
) {
113 const char *str
= PAL::name(i
);
115 _callpal
.subname(i
, str
);
119 .init(SystemCalls
<Tru64
>::Number
)
120 .name(name() + ".syscall")
121 .desc("number of syscalls executed")
122 .flags(total
| pdf
| nozero
| nonan
)
125 for (int i
= 0; i
< SystemCalls
<Tru64
>::Number
; ++i
) {
126 const char *str
= SystemCalls
<Tru64
>::name(i
);
128 _syscall
.subname(i
, str
);
134 .name(name() + ".mode_switch")
135 .desc("number of protection mode switches")
138 for (int i
= 0; i
< cpu_mode_num
; ++i
)
139 _mode
.subname(i
, modestr
[i
]);
143 .name(name() + ".mode_good")
146 for (int i
= 0; i
< cpu_mode_num
; ++i
)
147 _modeGood
.subname(i
, modestr
[i
]);
150 .name(name() + ".mode_switch_good")
151 .desc("fraction of useful protection mode switches")
155 for (int i
= 0; i
< cpu_mode_num
; ++i
)
156 _modeFraction
.subname(i
, modestr
[i
]);
158 _modeFraction
= _modeGood
/ _mode
;
162 .name(name() + ".mode_ticks")
163 .desc("number of ticks spent at the given mode")
166 for (int i
= 0; i
< cpu_mode_num
; ++i
)
167 _modeTicks
.subname(i
, modestr
[i
]);
170 .name(name() + ".swap_context")
171 .desc("number of times the context was actually changed")
176 Statistics::setIdleProcess(Addr idlepcbb
, ThreadContext
*tc
)
178 assert(themode
== kernel
);
179 idleProcess
= idlepcbb
;
181 changeMode(themode
, tc
);
185 Statistics::changeMode(cpu_mode newmode
, ThreadContext
*tc
)
189 if (newmode
== themode
)
192 DPRINTF(Context
, "old mode=%-8s new mode=%-8s\n",
193 modestr
[themode
], modestr
[newmode
]);
195 _modeGood
[newmode
]++;
196 _modeTicks
[themode
] += curTick
- lastModeTick
;
198 lastModeTick
= curTick
;
203 Statistics::swpipl(int ipl
)
205 assert(ipl
>= 0 && ipl
<= 0x1f && "invalid IPL\n");
213 _iplTicks
[iplLast
] += curTick
- iplLastTick
;
214 iplLastTick
= curTick
;
219 Statistics::mode(cpu_mode newmode
, ThreadContext
*tc
)
221 Addr pcbb
= tc
->readMiscReg(AlphaISA::IPR_PALtemp23
);
223 if (newmode
== kernel
&& pcbb
== idleProcess
)
226 changeMode(newmode
, tc
);
230 Statistics::context(Addr oldpcbb
, Addr newpcbb
, ThreadContext
*tc
)
232 assert(themode
!= user
);
235 changeMode(newpcbb
== idleProcess
? idle
: kernel
, tc
);
239 Statistics::callpal(int code
, ThreadContext
*tc
)
241 if (!PAL::name(code
))
248 int number
= tc
->readIntReg(0);
249 if (SystemCalls
<Tru64
>::validSyscallNumber(number
)) {
250 int cvtnum
= SystemCalls
<Tru64
>::convert(number
);
258 Statistics::serialize(ostream
&os
)
260 int exemode
= themode
;
261 SERIALIZE_SCALAR(exemode
);
262 SERIALIZE_SCALAR(idleProcess
);
263 SERIALIZE_SCALAR(iplLast
);
264 SERIALIZE_SCALAR(iplLastTick
);
265 SERIALIZE_SCALAR(lastModeTick
);
269 Statistics::unserialize(Checkpoint
*cp
, const string
§ion
)
272 UNSERIALIZE_SCALAR(exemode
);
273 UNSERIALIZE_SCALAR(idleProcess
);
274 UNSERIALIZE_SCALAR(iplLast
);
275 UNSERIALIZE_SCALAR(iplLastTick
);
276 UNSERIALIZE_SCALAR(lastModeTick
);
277 themode
= (cpu_mode
)exemode
;
280 /* end namespace Kernel */ }