Deleted Added
sdiff udiff text old ( 2632:1bb2f91485ea ) new ( 2665:a124942bacb8 )
full compact
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
29#include <map>
30#include <stack>
31#include <string>
32
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"
39
40using namespace std;
41using namespace Stats;
42
43namespace Kernel {
44
45const char *modestr[] = { "kernel", "user", "idle", "interrupt" };
46
47Statistics::Statistics(System *system)
48 : idleProcess((Addr)-1), themode(kernel), lastModeTick(0),
49 iplLast(0), iplLastTick(0)
50{
51 bin_int = system->params()->bin_int;
52}
53
54void
55Statistics::regStats(const string &_name)
56{
57 myname = _name;
58
59 _arm
60 .name(name() + ".inst.arm")
61 .desc("number of arm instructions executed")
62 ;
63
64 _quiesce
65 .name(name() + ".inst.quiesce")
66 .desc("number of quiesce instructions executed")
67 ;
68
69 _ivlb
70 .name(name() + ".inst.ivlb")
71 .desc("number of ivlb instructions executed")
72 ;
73
74 _ivle
75 .name(name() + ".inst.ivle")
76 .desc("number of ivle instructions executed")
77 ;
78
79 _hwrei
80 .name(name() + ".inst.hwrei")
81 .desc("number of hwrei instructions executed")
82 ;
83
84 _iplCount
85 .init(32)
86 .name(name() + ".ipl_count")
87 .desc("number of times we switched to this ipl")
88 .flags(total | pdf | nozero | nonan)
89 ;
90
91 _iplGood
92 .init(32)
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)
96 ;
97
98 _iplTicks
99 .init(32)
100 .name(name() + ".ipl_ticks")
101 .desc("number of cycles we spent at this ipl")
102 .flags(total | pdf | nozero | nonan)
103 ;
104
105 _iplUsed
106 .name(name() + ".ipl_used")
107 .desc("fraction of swpipl calls that actually changed the ipl")
108 .flags(total | nozero | nonan)
109 ;
110
111 _iplUsed = _iplGood / _iplCount;
112
113 _callpal
114 .init(256)
115 .name(name() + ".callpal")
116 .desc("number of callpals executed")
117 .flags(total | pdf | nozero | nonan)
118 ;
119
120 for (int i = 0; i < PAL::NumCodes; ++i) {
121 const char *str = PAL::name(i);
122 if (str)
123 _callpal.subname(i, str);
124 }
125
126 _syscall
127 .init(SystemCalls<Tru64>::Number)
128 .name(name() + ".syscall")
129 .desc("number of syscalls executed")
130 .flags(total | pdf | nozero | nonan)
131 ;
132
133 for (int i = 0; i < SystemCalls<Tru64>::Number; ++i) {
134 const char *str = SystemCalls<Tru64>::name(i);
135 if (str) {
136 _syscall.subname(i, str);
137 }
138 }
139
140 _mode
141 .init(cpu_mode_num)
142 .name(name() + ".mode_switch")
143 .desc("number of protection mode switches")
144 ;
145
146 for (int i = 0; i < cpu_mode_num; ++i)
147 _mode.subname(i, modestr[i]);
148
149 _modeGood
150 .init(cpu_mode_num)
151 .name(name() + ".mode_good")
152 ;
153
154 for (int i = 0; i < cpu_mode_num; ++i)
155 _modeGood.subname(i, modestr[i]);
156
157 _modeFraction
158 .name(name() + ".mode_switch_good")
159 .desc("fraction of useful protection mode switches")
160 .flags(total)
161 ;
162
163 for (int i = 0; i < cpu_mode_num; ++i)
164 _modeFraction.subname(i, modestr[i]);
165
166 _modeFraction = _modeGood / _mode;
167
168 _modeTicks
169 .init(cpu_mode_num)
170 .name(name() + ".mode_ticks")
171 .desc("number of ticks spent at the given mode")
172 .flags(pdf)
173 ;
174 for (int i = 0; i < cpu_mode_num; ++i)
175 _modeTicks.subname(i, modestr[i]);
176
177 _swap_context
178 .name(name() + ".swap_context")
179 .desc("number of times the context was actually changed")
180 ;
181}
182
183void
184Statistics::setIdleProcess(Addr idlepcbb, ExecContext *xc)
185{
186 assert(themode == kernel || themode == interrupt);
187 idleProcess = idlepcbb;
188 themode = idle;
189 changeMode(themode, xc);
190}
191
192void
193Statistics::changeMode(cpu_mode newmode, ExecContext *xc)
194{
195 _mode[newmode]++;
196
197 if (newmode == themode)
198 return;
199
200 DPRINTF(Context, "old mode=%-8s new mode=%-8s\n",
201 modestr[themode], modestr[newmode]);
202
203 _modeGood[newmode]++;
204 _modeTicks[themode] += curTick - lastModeTick;
205
206 xc->getSystemPtr()->kernelBinning->changeMode(newmode);
207
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, ExecContext *xc)
230{
231 Addr pcbb = xc->readMiscReg(AlphaISA::IPR_PALtemp23);
232
233 if ((newmode == kernel || newmode == interrupt) &&
234 pcbb == idleProcess)
235 newmode = idle;
236
237 if (bin_int == false && newmode == interrupt)
238 newmode = kernel;
239
240 changeMode(newmode, xc);
241}
242
243void
244Statistics::context(Addr oldpcbb, Addr newpcbb, ExecContext *xc)
245{
246 assert(themode != user);
247
248 _swap_context++;
249 changeMode(newpcbb == idleProcess ? idle : kernel, xc);
250}
251
252void
253Statistics::callpal(int code, ExecContext *xc)
254{
255 if (!PAL::name(code))
256 return;
257
258 _callpal[code]++;
259
260 switch (code) {
261 case PAL::callsys: {
262 int number = xc->readIntReg(0);
263 if (SystemCalls<Tru64>::validSyscallNumber(number)) {
264 int cvtnum = SystemCalls<Tru64>::convert(number);
265 _syscall[cvtnum]++;
266 }
267 } break;
268
269 case PAL::swpctx:
270 if (xc->getSystemPtr()->kernelBinning)
271 xc->getSystemPtr()->kernelBinning->palSwapContext(xc);
272 break;
273 }
274}
275
276void
277Statistics::serialize(ostream &os)
278{
279 int exemode = themode;
280 SERIALIZE_SCALAR(exemode);
281 SERIALIZE_SCALAR(idleProcess);
282 SERIALIZE_SCALAR(iplLast);
283 SERIALIZE_SCALAR(iplLastTick);
284 SERIALIZE_SCALAR(lastModeTick);
285}
286
287void
288Statistics::unserialize(Checkpoint *cp, const string &section)
289{
290 int exemode;
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;
297}
298
299/* end namespace Kernel */ }