activity.cc revision 9086
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 338229Snate@binkert.org#include "cpu/activity.hh" 347813Ssteve.reinhardt@amd.com#include "cpu/timebuf.hh" 358232Snate@binkert.org#include "debug/Activity.hh" 362325SN/A 375804Snate@binkert.orgusing namespace std; 385804Snate@binkert.org 395804Snate@binkert.orgActivityRecorder::ActivityRecorder(const string &name, int num_stages, 405804Snate@binkert.org int longest_latency, int activity) 415804Snate@binkert.org : _name(name), activityBuffer(longest_latency, 0), 425804Snate@binkert.org longestLatency(longest_latency), activityCount(activity), 435804Snate@binkert.org numStages(num_stages) 442325SN/A{ 452325SN/A stageActive = new bool[numStages]; 463918Ssaidi@eecs.umich.edu std::memset(stageActive, 0, numStages); 472325SN/A} 482325SN/A 499086Sandreas.hansson@arm.comActivityRecorder::~ActivityRecorder() 509086Sandreas.hansson@arm.com{ 519086Sandreas.hansson@arm.com delete[] stageActive; 529086Sandreas.hansson@arm.com} 539086Sandreas.hansson@arm.com 542325SN/Avoid 552325SN/AActivityRecorder::activity() 562325SN/A{ 572348SN/A // If we've already recorded activity for this cycle, we don't 582348SN/A // want to increment the count any more. 592325SN/A if (activityBuffer[0]) { 602325SN/A return; 612325SN/A } 622325SN/A 632325SN/A activityBuffer[0] = true; 642325SN/A 652325SN/A ++activityCount; 662325SN/A 672325SN/A DPRINTF(Activity, "Activity: %i\n", activityCount); 682325SN/A} 692325SN/A 702325SN/Avoid 712325SN/AActivityRecorder::advance() 722325SN/A{ 732348SN/A // If there's a 1 in the slot that is about to be erased once the 742348SN/A // time buffer advances, then decrement the activityCount. 752325SN/A if (activityBuffer[-longestLatency]) { 762325SN/A --activityCount; 772325SN/A 782325SN/A assert(activityCount >= 0); 792325SN/A 802325SN/A DPRINTF(Activity, "Activity: %i\n", activityCount); 812325SN/A 822325SN/A if (activityCount == 0) { 832325SN/A DPRINTF(Activity, "No activity left!\n"); 842325SN/A } 852325SN/A } 862325SN/A 872325SN/A activityBuffer.advance(); 882325SN/A} 892325SN/A 902325SN/Avoid 912325SN/AActivityRecorder::activateStage(const int idx) 922325SN/A{ 932348SN/A // Increment the activity count if this stage wasn't already active. 942325SN/A if (!stageActive[idx]) { 952325SN/A ++activityCount; 962325SN/A 972325SN/A stageActive[idx] = true; 982325SN/A 992325SN/A DPRINTF(Activity, "Activity: %i\n", activityCount); 1002325SN/A } else { 1012325SN/A DPRINTF(Activity, "Stage %i already active.\n", idx); 1022325SN/A } 1032325SN/A 1042325SN/A// assert(activityCount < longestLatency + numStages + 1); 1052325SN/A} 1062325SN/A 1072325SN/Avoid 1082325SN/AActivityRecorder::deactivateStage(const int idx) 1092325SN/A{ 1102348SN/A // Decrement the activity count if this stage was active. 1112325SN/A if (stageActive[idx]) { 1122325SN/A --activityCount; 1132325SN/A 1142325SN/A stageActive[idx] = false; 1152325SN/A 1162325SN/A DPRINTF(Activity, "Activity: %i\n", activityCount); 1172325SN/A } else { 1182325SN/A DPRINTF(Activity, "Stage %i already inactive.\n", idx); 1192325SN/A } 1202325SN/A 1212325SN/A assert(activityCount >= 0); 1222325SN/A} 1232325SN/A 1242325SN/Avoid 1252325SN/AActivityRecorder::reset() 1262325SN/A{ 1272325SN/A activityCount = 0; 1283918Ssaidi@eecs.umich.edu std::memset(stageActive, 0, numStages); 1292325SN/A for (int i = 0; i < longestLatency + 1; ++i) 1302325SN/A activityBuffer.advance(); 1312325SN/A} 1322325SN/A 1332325SN/Avoid 1342325SN/AActivityRecorder::dump() 1352325SN/A{ 1362325SN/A for (int i = 0; i <= longestLatency; ++i) { 1372325SN/A cprintf("[Idx:%i %i] ", i, activityBuffer[-i]); 1382325SN/A } 1392325SN/A 1402325SN/A cprintf("\n"); 1412325SN/A 1422325SN/A for (int i = 0; i < numStages; ++i) { 1432325SN/A cprintf("[Stage:%i %i]\n", i, stageActive[i]); 1442325SN/A } 1452325SN/A 1462325SN/A cprintf("\n"); 1472325SN/A 1482325SN/A cprintf("Activity count: %i\n", activityCount); 1492325SN/A} 1502325SN/A 1512325SN/Avoid 1522325SN/AActivityRecorder::validate() 1532325SN/A{ 1542325SN/A int count = 0; 1552325SN/A for (int i = 0; i <= longestLatency; ++i) { 1562325SN/A if (activityBuffer[-i]) { 1572325SN/A count++; 1582325SN/A } 1592325SN/A } 1602325SN/A 1612325SN/A for (int i = 0; i < numStages; ++i) { 1622325SN/A if (stageActive[i]) { 1632325SN/A count++; 1642325SN/A } 1652325SN/A } 1662325SN/A 1672325SN/A assert(count == activityCount); 1682325SN/A} 169