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.ivlb")
73 .desc("number of ivlb instructions executed")
77 .name(name() + ".inst.ivle")
78 .desc("number of ivle instructions executed")
82 .name(name() + ".inst.hwrei")
83 .desc("number of hwrei instructions executed")
88 .name(name() + ".ipl_count")
89 .desc("number of times we switched to this ipl")
90 .flags(total
| pdf
| nozero
| nonan
)
95 .name(name() + ".ipl_good")
96 .desc("number of times we switched to this ipl from a different ipl")
97 .flags(total
| pdf
| nozero
| nonan
)
102 .name(name() + ".ipl_ticks")
103 .desc("number of cycles we spent at this ipl")
104 .flags(total
| pdf
| nozero
| nonan
)
108 .name(name() + ".ipl_used")
109 .desc("fraction of swpipl calls that actually changed the ipl")
110 .flags(total
| nozero
| nonan
)
113 _iplUsed
= _iplGood
/ _iplCount
;
117 .name(name() + ".callpal")
118 .desc("number of callpals executed")
119 .flags(total
| pdf
| nozero
| nonan
)
122 for (int i
= 0; i
< PAL::NumCodes
; ++i
) {
123 const char *str
= PAL::name(i
);
125 _callpal
.subname(i
, str
);
129 .init(SystemCalls
<Tru64
>::Number
)
130 .name(name() + ".syscall")
131 .desc("number of syscalls executed")
132 .flags(total
| pdf
| nozero
| nonan
)
135 for (int i
= 0; i
< SystemCalls
<Tru64
>::Number
; ++i
) {
136 const char *str
= SystemCalls
<Tru64
>::name(i
);
138 _syscall
.subname(i
, str
);
144 .name(name() + ".mode_switch")
145 .desc("number of protection mode switches")
148 for (int i
= 0; i
< cpu_mode_num
; ++i
)
149 _mode
.subname(i
, modestr
[i
]);
153 .name(name() + ".mode_good")
156 for (int i
= 0; i
< cpu_mode_num
; ++i
)
157 _modeGood
.subname(i
, modestr
[i
]);
160 .name(name() + ".mode_switch_good")
161 .desc("fraction of useful protection mode switches")
165 for (int i
= 0; i
< cpu_mode_num
; ++i
)
166 _modeFraction
.subname(i
, modestr
[i
]);
168 _modeFraction
= _modeGood
/ _mode
;
172 .name(name() + ".mode_ticks")
173 .desc("number of ticks spent at the given mode")
176 for (int i
= 0; i
< cpu_mode_num
; ++i
)
177 _modeTicks
.subname(i
, modestr
[i
]);
180 .name(name() + ".swap_context")
181 .desc("number of times the context was actually changed")
186 Statistics::setIdleProcess(Addr idlepcbb
, ThreadContext
*tc
)
188 assert(themode
== kernel
);
189 idleProcess
= idlepcbb
;
191 changeMode(themode
, tc
);
195 Statistics::changeMode(cpu_mode newmode
, ThreadContext
*tc
)
199 if (newmode
== themode
)
202 DPRINTF(Context
, "old mode=%-8s new mode=%-8s\n",
203 modestr
[themode
], modestr
[newmode
]);
205 _modeGood
[newmode
]++;
206 _modeTicks
[themode
] += curTick
- lastModeTick
;
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
, ThreadContext
*tc
)
231 Addr pcbb
= tc
->readMiscReg(AlphaISA::IPR_PALtemp23
);
233 if (newmode
== kernel
&& pcbb
== idleProcess
)
236 changeMode(newmode
, tc
);
240 Statistics::context(Addr oldpcbb
, Addr newpcbb
, ThreadContext
*tc
)
242 assert(themode
!= user
);
245 changeMode(newpcbb
== idleProcess
? idle
: kernel
, tc
);
249 Statistics::callpal(int code
, ThreadContext
*tc
)
251 if (!PAL::name(code
))
258 int number
= tc
->readIntReg(0);
259 if (SystemCalls
<Tru64
>::validSyscallNumber(number
)) {
260 int cvtnum
= SystemCalls
<Tru64
>::convert(number
);
268 Statistics::serialize(ostream
&os
)
270 int exemode
= themode
;
271 SERIALIZE_SCALAR(exemode
);
272 SERIALIZE_SCALAR(idleProcess
);
273 SERIALIZE_SCALAR(iplLast
);
274 SERIALIZE_SCALAR(iplLastTick
);
275 SERIALIZE_SCALAR(lastModeTick
);
279 Statistics::unserialize(Checkpoint
*cp
, const string
§ion
)
282 UNSERIALIZE_SCALAR(exemode
);
283 UNSERIALIZE_SCALAR(idleProcess
);
284 UNSERIALIZE_SCALAR(iplLast
);
285 UNSERIALIZE_SCALAR(iplLastTick
);
286 UNSERIALIZE_SCALAR(lastModeTick
);
287 themode
= (cpu_mode
)exemode
;
290 /* end namespace Kernel */ }