2 * Copyright (c) 2003 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 "base/statistics.hh"
36 #include "base/stats/bin.hh"
37 #include "cpu/exec_context.hh"
38 #include "cpu/pc_event.hh"
39 #include "cpu/static_inst.hh"
40 #include "kern/kernel_stats.hh"
41 #include "kern/linux/linux_syscalls.hh"
42 #include "kern/tru64/tru64_syscalls.hh"
45 using namespace Stats
;
49 const char *modestr
[] = { "kernel", "user", "idle", "interrupt" };
51 Statistics::Statistics(ExecContext
*context
)
52 : xc(context
), idleProcess((Addr
)-1), themode(kernel
), lastModeTick(0),
53 iplLast(0), iplLastTick(0)
55 bin_int
= xc
->system
->params
->bin_int
;
59 Statistics::regStats(const string
&_name
)
64 .name(name() + ".inst.arm")
65 .desc("number of arm instructions executed")
69 .name(name() + ".inst.quiesce")
70 .desc("number of quiesce instructions executed")
74 .name(name() + ".inst.ivlb")
75 .desc("number of ivlb instructions executed")
79 .name(name() + ".inst.ivle")
80 .desc("number of ivle instructions executed")
84 .name(name() + ".inst.hwrei")
85 .desc("number of hwrei instructions executed")
90 .name(name() + ".ipl_count")
91 .desc("number of times we switched to this ipl")
92 .flags(total
| pdf
| nozero
| nonan
)
97 .name(name() + ".ipl_good")
98 .desc("number of times we switched to this ipl from a different ipl")
99 .flags(total
| pdf
| nozero
| nonan
)
104 .name(name() + ".ipl_ticks")
105 .desc("number of cycles we spent at this ipl")
106 .flags(total
| pdf
| nozero
| nonan
)
110 .name(name() + ".ipl_used")
111 .desc("fraction of swpipl calls that actually changed the ipl")
112 .flags(total
| nozero
| nonan
)
115 _iplUsed
= _iplGood
/ _iplCount
;
119 .name(name() + ".callpal")
120 .desc("number of callpals executed")
121 .flags(total
| pdf
| nozero
| nonan
)
124 for (int i
= 0; i
< PAL::NumCodes
; ++i
) {
125 const char *str
= PAL::name(i
);
127 _callpal
.subname(i
, str
);
131 .init(SystemCalls
<Tru64
>::Number
)
132 .name(name() + ".syscall")
133 .desc("number of syscalls executed")
134 .flags(total
| pdf
| nozero
| nonan
)
137 for (int i
= 0; i
< SystemCalls
<Tru64
>::Number
; ++i
) {
138 const char *str
= SystemCalls
<Tru64
>::name(i
);
140 _syscall
.subname(i
, str
);
146 .name(name() + ".faults")
147 .desc("number of faults")
148 .flags(total
| pdf
| nozero
| nonan
)
151 for (int i
= 1; i
< Num_Faults
; ++i
) {
152 const char *str
= FaultName(i
);
154 _faults
.subname(i
, str
);
159 .name(name() + ".mode_switch")
160 .desc("number of protection mode switches")
163 for (int i
= 0; i
< cpu_mode_num
; ++i
)
164 _mode
.subname(i
, modestr
[i
]);
168 .name(name() + ".mode_good")
171 for (int i
= 0; i
< cpu_mode_num
; ++i
)
172 _modeGood
.subname(i
, modestr
[i
]);
175 .name(name() + ".mode_switch_good")
176 .desc("fraction of useful protection mode switches")
180 for (int i
= 0; i
< cpu_mode_num
; ++i
)
181 _modeFraction
.subname(i
, modestr
[i
]);
183 _modeFraction
= _modeGood
/ _mode
;
187 .name(name() + ".mode_ticks")
188 .desc("number of ticks spent at the given mode")
191 for (int i
= 0; i
< cpu_mode_num
; ++i
)
192 _modeTicks
.subname(i
, modestr
[i
]);
195 .name(name() + ".swap_context")
196 .desc("number of times the context was actually changed")
201 Statistics::setIdleProcess(Addr idlepcbb
)
203 assert(themode
== kernel
|| themode
== interrupt
);
204 idleProcess
= idlepcbb
;
210 Statistics::changeMode(cpu_mode newmode
)
214 if (newmode
== themode
)
217 DPRINTF(Context
, "old mode=%-8s new mode=%-8s\n",
218 modestr
[themode
], modestr
[newmode
]);
220 _modeGood
[newmode
]++;
221 _modeTicks
[themode
] += curTick
- lastModeTick
;
223 xc
->system
->kernelBinning
->changeMode(newmode
);
225 lastModeTick
= curTick
;
230 Statistics::swpipl(int ipl
)
232 assert(ipl
>= 0 && ipl
<= 0x1f && "invalid IPL\n");
240 _iplTicks
[iplLast
] += curTick
- iplLastTick
;
241 iplLastTick
= curTick
;
246 Statistics::mode(cpu_mode newmode
)
248 Addr pcbb
= xc
->regs
.ipr
[AlphaISA::IPR_PALtemp23
];
250 if ((newmode
== kernel
|| newmode
== interrupt
) &&
254 if (bin_int
== false && newmode
== interrupt
)
261 Statistics::context(Addr oldpcbb
, Addr newpcbb
)
263 assert(themode
!= user
);
266 changeMode(newpcbb
== idleProcess
? idle
: kernel
);
270 Statistics::callpal(int code
)
272 if (!PAL::name(code
))
279 int number
= xc
->regs
.intRegFile
[0];
280 if (SystemCalls
<Tru64
>::validSyscallNumber(number
)) {
281 int cvtnum
= SystemCalls
<Tru64
>::convert(number
);
287 if (xc
->system
->kernelBinning
)
288 xc
->system
->kernelBinning
->palSwapContext(xc
);
294 Statistics::serialize(ostream
&os
)
296 int exemode
= themode
;
297 SERIALIZE_SCALAR(exemode
);
298 SERIALIZE_SCALAR(idleProcess
);
299 SERIALIZE_SCALAR(iplLast
);
300 SERIALIZE_SCALAR(iplLastTick
);
301 SERIALIZE_SCALAR(lastModeTick
);
305 Statistics::unserialize(Checkpoint
*cp
, const string
§ion
)
308 UNSERIALIZE_SCALAR(exemode
);
309 UNSERIALIZE_SCALAR(idleProcess
);
310 UNSERIALIZE_SCALAR(iplLast
);
311 UNSERIALIZE_SCALAR(iplLastTick
);
312 UNSERIALIZE_SCALAR(lastModeTick
);
313 themode
= (cpu_mode
)exemode
;
316 /* end namespace Kernel */ }