kernel_stats.cc revision 8777
1754SN/A/*
21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
3754SN/A * All rights reserved.
4754SN/A *
5754SN/A * Redistribution and use in source and binary forms, with or without
6754SN/A * modification, are permitted provided that the following conditions are
7754SN/A * met: redistributions of source code must retain the above copyright
8754SN/A * notice, this list of conditions and the following disclaimer;
9754SN/A * redistributions in binary form must reproduce the above copyright
10754SN/A * notice, this list of conditions and the following disclaimer in the
11754SN/A * documentation and/or other materials provided with the distribution;
12754SN/A * neither the name of the copyright holders nor the names of its
13754SN/A * contributors may be used to endorse or promote products derived from
14754SN/A * this software without specific prior written permission.
15754SN/A *
16754SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17754SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18754SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19754SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20754SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21754SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22754SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23754SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24754SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25754SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26754SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Lisa Hsu
292665Ssaidi@eecs.umich.edu *          Nathan Binkert
30754SN/A */
31754SN/A
32754SN/A#include <string>
33754SN/A
341070SN/A#include "base/trace.hh"
352680Sktlim@umich.edu#include "cpu/thread_context.hh"
368777Sgblack@eecs.umich.edu#include "kern/kernel_stats.hh"
378777Sgblack@eecs.umich.edu#if THE_ISA == ALPHA_ISA
388229Snate@binkert.org#include "kern/tru64/tru64_syscalls.hh"
398777Sgblack@eecs.umich.edu#endif
402235SN/A#include "sim/system.hh"
41754SN/A
42754SN/Ausing namespace std;
43754SN/Ausing namespace Stats;
44754SN/A
451070SN/Anamespace Kernel {
461070SN/A
472190SN/AStatistics::Statistics(System *system)
483548SN/A    : iplLast(0), iplLastTick(0)
49754SN/A{
501070SN/A}
51754SN/A
52754SN/Avoid
531070SN/AStatistics::regStats(const string &_name)
54754SN/A{
551070SN/A    myname = _name;
56754SN/A
57754SN/A    _arm
581070SN/A        .name(name() + ".inst.arm")
59754SN/A        .desc("number of arm instructions executed")
60754SN/A        ;
61754SN/A
62754SN/A    _quiesce
631070SN/A        .name(name() + ".inst.quiesce")
64754SN/A        .desc("number of quiesce instructions executed")
65754SN/A        ;
66754SN/A
67754SN/A    _iplCount
68754SN/A        .init(32)
691070SN/A        .name(name() + ".ipl_count")
70754SN/A        .desc("number of times we switched to this ipl")
71754SN/A        .flags(total | pdf | nozero | nonan)
72754SN/A        ;
73754SN/A
74754SN/A    _iplGood
75754SN/A        .init(32)
761070SN/A        .name(name() + ".ipl_good")
77754SN/A        .desc("number of times we switched to this ipl from a different ipl")
78754SN/A        .flags(total | pdf | nozero | nonan)
79754SN/A        ;
80754SN/A
81754SN/A    _iplTicks
82754SN/A        .init(32)
831070SN/A        .name(name() + ".ipl_ticks")
84754SN/A        .desc("number of cycles we spent at this ipl")
85754SN/A        .flags(total | pdf | nozero | nonan)
86754SN/A        ;
87754SN/A
88754SN/A    _iplUsed
891070SN/A        .name(name() + ".ipl_used")
90754SN/A        .desc("fraction of swpipl calls that actually changed the ipl")
91754SN/A        .flags(total | nozero | nonan)
92754SN/A        ;
93754SN/A
94754SN/A    _iplUsed = _iplGood / _iplCount;
958777Sgblack@eecs.umich.edu#if THE_ISA == ALPHA_ISA
96754SN/A    _syscall
97754SN/A        .init(SystemCalls<Tru64>::Number)
981070SN/A        .name(name() + ".syscall")
99754SN/A        .desc("number of syscalls executed")
100754SN/A        .flags(total | pdf | nozero | nonan)
101754SN/A        ;
1028777Sgblack@eecs.umich.edu#endif
103754SN/A
1043563SN/A    //@todo This needs to get the names of syscalls from an appropriate place.
1053563SN/A#if 0
106754SN/A    for (int i = 0; i < SystemCalls<Tru64>::Number; ++i) {
1073563SN/A        const char *str = SystemCalls<Tru64>::name(i);
108754SN/A        if (str) {
109754SN/A            _syscall.subname(i, str);
110754SN/A        }
111754SN/A    }
1123563SN/A#endif
1131070SN/A}
114754SN/A
115754SN/Avoid
1161070SN/AStatistics::swpipl(int ipl)
117754SN/A{
118754SN/A    assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n");
119754SN/A
120754SN/A    _iplCount[ipl]++;
121754SN/A
122754SN/A    if (ipl == iplLast)
123754SN/A        return;
124754SN/A
125754SN/A    _iplGood[ipl]++;
1267823Ssteve.reinhardt@amd.com    _iplTicks[iplLast] += curTick() - iplLastTick;
1277823Ssteve.reinhardt@amd.com    iplLastTick = curTick();
128754SN/A    iplLast = ipl;
129754SN/A}
130754SN/A
131754SN/Avoid
1321070SN/AStatistics::serialize(ostream &os)
1331070SN/A{
1341097SN/A    SERIALIZE_SCALAR(iplLast);
1351097SN/A    SERIALIZE_SCALAR(iplLastTick);
1361070SN/A}
137754SN/A
1381070SN/Avoid
1391070SN/AStatistics::unserialize(Checkpoint *cp, const string &section)
1401070SN/A{
1411097SN/A    UNSERIALIZE_SCALAR(iplLast);
1421097SN/A    UNSERIALIZE_SCALAR(iplLastTick);
1431070SN/A}
144754SN/A
1457811Ssteve.reinhardt@amd.com} // namespace Kernel
146