activity.cc revision 5804
12348SN/A/*
22348SN/A * Copyright (c) 2006 The Regents of The University of Michigan
32348SN/A * All rights reserved.
42348SN/A *
52348SN/A * Redistribution and use in source and binary forms, with or without
62348SN/A * modification, are permitted provided that the following conditions are
72348SN/A * met: redistributions of source code must retain the above copyright
82348SN/A * notice, this list of conditions and the following disclaimer;
92348SN/A * redistributions in binary form must reproduce the above copyright
102348SN/A * notice, this list of conditions and the following disclaimer in the
112348SN/A * documentation and/or other materials provided with the distribution;
122348SN/A * neither the name of the copyright holders nor the names of its
132348SN/A * contributors may be used to endorse or promote products derived from
142348SN/A * this software without specific prior written permission.
152348SN/A *
162348SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172348SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182348SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192348SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202348SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212348SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222348SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232348SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242348SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252348SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262348SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272689Sktlim@umich.edu *
282689Sktlim@umich.edu * Authors: Kevin Lim
292348SN/A */
302325SN/A
315804Snate@binkert.org#include <string>
323918Ssaidi@eecs.umich.edu
332325SN/A#include "base/timebuf.hh"
342325SN/A#include "cpu/activity.hh"
352325SN/A
365804Snate@binkert.orgusing namespace std;
375804Snate@binkert.org
385804Snate@binkert.orgActivityRecorder::ActivityRecorder(const string &name, int num_stages,
395804Snate@binkert.org    int longest_latency, int activity)
405804Snate@binkert.org    : _name(name), activityBuffer(longest_latency, 0),
415804Snate@binkert.org      longestLatency(longest_latency), activityCount(activity),
425804Snate@binkert.org      numStages(num_stages)
432325SN/A{
442325SN/A    stageActive = new bool[numStages];
453918Ssaidi@eecs.umich.edu    std::memset(stageActive, 0, numStages);
462325SN/A}
472325SN/A
482325SN/Avoid
492325SN/AActivityRecorder::activity()
502325SN/A{
512348SN/A    // If we've already recorded activity for this cycle, we don't
522348SN/A    // want to increment the count any more.
532325SN/A    if (activityBuffer[0]) {
542325SN/A        return;
552325SN/A    }
562325SN/A
572325SN/A    activityBuffer[0] = true;
582325SN/A
592325SN/A    ++activityCount;
602325SN/A
612325SN/A    DPRINTF(Activity, "Activity: %i\n", activityCount);
622325SN/A}
632325SN/A
642325SN/Avoid
652325SN/AActivityRecorder::advance()
662325SN/A{
672348SN/A    // If there's a 1 in the slot that is about to be erased once the
682348SN/A    // time buffer advances, then decrement the activityCount.
692325SN/A    if (activityBuffer[-longestLatency]) {
702325SN/A        --activityCount;
712325SN/A
722325SN/A        assert(activityCount >= 0);
732325SN/A
742325SN/A        DPRINTF(Activity, "Activity: %i\n", activityCount);
752325SN/A
762325SN/A        if (activityCount == 0) {
772325SN/A            DPRINTF(Activity, "No activity left!\n");
782325SN/A        }
792325SN/A    }
802325SN/A
812325SN/A    activityBuffer.advance();
822325SN/A}
832325SN/A
842325SN/Avoid
852325SN/AActivityRecorder::activateStage(const int idx)
862325SN/A{
872348SN/A    // Increment the activity count if this stage wasn't already active.
882325SN/A    if (!stageActive[idx]) {
892325SN/A        ++activityCount;
902325SN/A
912325SN/A        stageActive[idx] = true;
922325SN/A
932325SN/A        DPRINTF(Activity, "Activity: %i\n", activityCount);
942325SN/A    } else {
952325SN/A        DPRINTF(Activity, "Stage %i already active.\n", idx);
962325SN/A    }
972325SN/A
982325SN/A//    assert(activityCount < longestLatency + numStages + 1);
992325SN/A}
1002325SN/A
1012325SN/Avoid
1022325SN/AActivityRecorder::deactivateStage(const int idx)
1032325SN/A{
1042348SN/A    // Decrement the activity count if this stage was active.
1052325SN/A    if (stageActive[idx]) {
1062325SN/A        --activityCount;
1072325SN/A
1082325SN/A        stageActive[idx] = false;
1092325SN/A
1102325SN/A        DPRINTF(Activity, "Activity: %i\n", activityCount);
1112325SN/A    } else {
1122325SN/A        DPRINTF(Activity, "Stage %i already inactive.\n", idx);
1132325SN/A    }
1142325SN/A
1152325SN/A    assert(activityCount >= 0);
1162325SN/A}
1172325SN/A
1182325SN/Avoid
1192325SN/AActivityRecorder::reset()
1202325SN/A{
1212325SN/A    activityCount = 0;
1223918Ssaidi@eecs.umich.edu    std::memset(stageActive, 0, numStages);
1232325SN/A    for (int i = 0; i < longestLatency + 1; ++i)
1242325SN/A        activityBuffer.advance();
1252325SN/A}
1262325SN/A
1272325SN/Avoid
1282325SN/AActivityRecorder::dump()
1292325SN/A{
1302325SN/A    for (int i = 0; i <= longestLatency; ++i) {
1312325SN/A        cprintf("[Idx:%i %i] ", i, activityBuffer[-i]);
1322325SN/A    }
1332325SN/A
1342325SN/A    cprintf("\n");
1352325SN/A
1362325SN/A    for (int i = 0; i < numStages; ++i) {
1372325SN/A        cprintf("[Stage:%i %i]\n", i, stageActive[i]);
1382325SN/A    }
1392325SN/A
1402325SN/A    cprintf("\n");
1412325SN/A
1422325SN/A    cprintf("Activity count: %i\n", activityCount);
1432325SN/A}
1442325SN/A
1452325SN/Avoid
1462325SN/AActivityRecorder::validate()
1472325SN/A{
1482325SN/A    int count = 0;
1492325SN/A    for (int i = 0; i <= longestLatency; ++i) {
1502325SN/A        if (activityBuffer[-i]) {
1512325SN/A            count++;
1522325SN/A        }
1532325SN/A    }
1542325SN/A
1552325SN/A    for (int i = 0; i < numStages; ++i) {
1562325SN/A        if (stageActive[i]) {
1572325SN/A            count++;
1582325SN/A        }
1592325SN/A    }
1602325SN/A
1612325SN/A    assert(count == activityCount);
1622325SN/A}
163