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/kernel_stats.hh"
37 #include "arch/alpha/osfpal.hh"
38 #include "base/trace.hh"
39 #include "cpu/thread_context.hh"
40 #include "kern/tru64/tru64_syscalls.hh"
41 #include "sim/system.hh"
44 using namespace Stats
;
49 const char *modestr
[] = { "kernel", "user", "idle" };
51 Statistics::Statistics(System
*system
)
52 : ::Kernel::Statistics(system
),
53 idleProcess((Addr
)-1), themode(kernel
), lastModeTick(0)
58 Statistics::regStats(const string
&_name
)
60 ::Kernel::Statistics::regStats(_name
);
64 .name(name() + ".callpal")
65 .desc("number of callpals executed")
66 .flags(total
| pdf
| nozero
| nonan
)
69 for (int i
= 0; i
< PAL::NumCodes
; ++i
) {
70 const char *str
= PAL::name(i
);
72 _callpal
.subname(i
, str
);
76 .name(name() + ".inst.hwrei")
77 .desc("number of hwrei instructions executed")
82 .name(name() + ".mode_switch")
83 .desc("number of protection mode switches")
86 for (int i
= 0; i
< cpu_mode_num
; ++i
)
87 _mode
.subname(i
, modestr
[i
]);
91 .name(name() + ".mode_good")
94 for (int i
= 0; i
< cpu_mode_num
; ++i
)
95 _modeGood
.subname(i
, modestr
[i
]);
98 .name(name() + ".mode_switch_good")
99 .desc("fraction of useful protection mode switches")
103 for (int i
= 0; i
< cpu_mode_num
; ++i
)
104 _modeFraction
.subname(i
, modestr
[i
]);
106 _modeFraction
= _modeGood
/ _mode
;
110 .name(name() + ".mode_ticks")
111 .desc("number of ticks spent at the given mode")
114 for (int i
= 0; i
< cpu_mode_num
; ++i
)
115 _modeTicks
.subname(i
, modestr
[i
]);
118 .name(name() + ".swap_context")
119 .desc("number of times the context was actually changed")
124 Statistics::setIdleProcess(Addr idlepcbb
, ThreadContext
*tc
)
126 assert(themode
== kernel
);
127 idleProcess
= idlepcbb
;
129 changeMode(themode
, tc
);
133 Statistics::changeMode(cpu_mode newmode
, ThreadContext
*tc
)
137 if (newmode
== themode
)
140 DPRINTF(Context
, "old mode=%-8s new mode=%-8s\n",
141 modestr
[themode
], modestr
[newmode
]);
143 _modeGood
[newmode
]++;
144 _modeTicks
[themode
] += curTick
- lastModeTick
;
146 lastModeTick
= curTick
;
151 Statistics::mode(cpu_mode newmode
, ThreadContext
*tc
)
153 Addr pcbb
= tc
->readMiscReg(AlphaISA::IPR_PALtemp23
);
155 if (newmode
== kernel
&& pcbb
== idleProcess
)
158 changeMode(newmode
, tc
);
162 Statistics::context(Addr oldpcbb
, Addr newpcbb
, ThreadContext
*tc
)
164 assert(themode
!= user
);
167 changeMode(newpcbb
== idleProcess
? idle
: kernel
, tc
);
171 Statistics::callpal(int code
, ThreadContext
*tc
)
173 if (!PAL::name(code
))
180 int number
= tc
->readIntReg(0);
181 if (SystemCalls
<Tru64
>::validSyscallNumber(number
)) {
182 int cvtnum
= SystemCalls
<Tru64
>::convert(number
);
190 Statistics::serialize(ostream
&os
)
192 ::Kernel::Statistics::serialize(os
);
193 int exemode
= themode
;
194 SERIALIZE_SCALAR(exemode
);
195 SERIALIZE_SCALAR(idleProcess
);
196 SERIALIZE_SCALAR(lastModeTick
);
200 Statistics::unserialize(Checkpoint
*cp
, const string
§ion
)
202 ::Kernel::Statistics::unserialize(cp
, section
);
204 UNSERIALIZE_SCALAR(exemode
);
205 UNSERIALIZE_SCALAR(idleProcess
);
206 UNSERIALIZE_SCALAR(lastModeTick
);
207 themode
= (cpu_mode
)exemode
;
210 } /* end namespace AlphaISA::Kernel */
211 } /* end namespace AlphaISA */