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/linux/threadinfo.hh"
37 #include "arch/alpha/kernel_stats.hh"
38 #include "arch/alpha/osfpal.hh"
39 #include "base/trace.hh"
40 #include "cpu/thread_context.hh"
41 #include "kern/tru64/tru64_syscalls.hh"
42 #include "sim/system.hh"
45 using namespace Stats
;
50 const char *modestr
[] = { "kernel", "user", "idle" };
52 Statistics::Statistics(System
*system
)
53 : ::Kernel::Statistics(system
),
54 idleProcess((Addr
)-1), themode(kernel
), lastModeTick(0)
59 Statistics::regStats(const string
&_name
)
61 ::Kernel::Statistics::regStats(_name
);
65 .name(name() + ".callpal")
66 .desc("number of callpals executed")
67 .flags(total
| pdf
| nozero
| nonan
)
70 for (int i
= 0; i
< PAL::NumCodes
; ++i
) {
71 const char *str
= PAL::name(i
);
73 _callpal
.subname(i
, str
);
77 .name(name() + ".inst.hwrei")
78 .desc("number of hwrei instructions executed")
83 .name(name() + ".mode_switch")
84 .desc("number of protection mode switches")
87 for (int i
= 0; i
< cpu_mode_num
; ++i
)
88 _mode
.subname(i
, modestr
[i
]);
92 .name(name() + ".mode_good")
95 for (int i
= 0; i
< cpu_mode_num
; ++i
)
96 _modeGood
.subname(i
, modestr
[i
]);
99 .name(name() + ".mode_switch_good")
100 .desc("fraction of useful protection mode switches")
104 for (int i
= 0; i
< cpu_mode_num
; ++i
)
105 _modeFraction
.subname(i
, modestr
[i
]);
107 _modeFraction
= _modeGood
/ _mode
;
111 .name(name() + ".mode_ticks")
112 .desc("number of ticks spent at the given mode")
115 for (int i
= 0; i
< cpu_mode_num
; ++i
)
116 _modeTicks
.subname(i
, modestr
[i
]);
119 .name(name() + ".swap_context")
120 .desc("number of times the context was actually changed")
125 Statistics::setIdleProcess(Addr idlepcbb
, ThreadContext
*tc
)
127 assert(themode
== kernel
);
128 idleProcess
= idlepcbb
;
130 changeMode(themode
, tc
);
134 Statistics::changeMode(cpu_mode newmode
, ThreadContext
*tc
)
138 if (newmode
== themode
)
141 DPRINTF(Context
, "old mode=%s new mode=%s pid=%d\n",
142 modestr
[themode
], modestr
[newmode
],
143 Linux::ThreadInfo(tc
).curTaskPID());
145 _modeGood
[newmode
]++;
146 _modeTicks
[themode
] += curTick
- lastModeTick
;
148 lastModeTick
= curTick
;
153 Statistics::mode(cpu_mode newmode
, ThreadContext
*tc
)
155 Addr pcbb
= tc
->readMiscRegNoEffect(IPR_PALtemp23
);
157 if (newmode
== kernel
&& pcbb
== idleProcess
)
160 changeMode(newmode
, tc
);
164 Statistics::context(Addr oldpcbb
, Addr newpcbb
, ThreadContext
*tc
)
166 assert(themode
!= user
);
169 changeMode(newpcbb
== idleProcess
? idle
: kernel
, tc
);
171 DPRINTF(Context
, "Context Switch old pid=%d new pid=%d\n",
172 Linux::ThreadInfo(tc
, oldpcbb
).curTaskPID(),
173 Linux::ThreadInfo(tc
, newpcbb
).curTaskPID());
177 Statistics::callpal(int code
, ThreadContext
*tc
)
179 if (!PAL::name(code
))
186 int number
= tc
->readIntReg(0);
187 if (SystemCalls
<Tru64
>::validSyscallNumber(number
)) {
188 int cvtnum
= SystemCalls
<Tru64
>::convert(number
);
196 Statistics::serialize(ostream
&os
)
198 ::Kernel::Statistics::serialize(os
);
199 int exemode
= themode
;
200 SERIALIZE_SCALAR(exemode
);
201 SERIALIZE_SCALAR(idleProcess
);
202 SERIALIZE_SCALAR(lastModeTick
);
206 Statistics::unserialize(Checkpoint
*cp
, const string
§ion
)
208 ::Kernel::Statistics::unserialize(cp
, section
);
210 UNSERIALIZE_SCALAR(exemode
);
211 UNSERIALIZE_SCALAR(idleProcess
);
212 UNSERIALIZE_SCALAR(lastModeTick
);
213 themode
= (cpu_mode
)exemode
;
216 } // namespace Kernel
217 } // namespace AlphaISA