activity.hh 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 312325SN/A#ifndef __CPU_ACTIVITY_HH__ 322325SN/A#define __CPU_ACTIVITY_HH__ 332325SN/A 342325SN/A#include "base/timebuf.hh" 352325SN/A#include "base/trace.hh" 362325SN/A 372348SN/A/** 382348SN/A * ActivityRecorder helper class that informs the CPU if it can switch 392348SN/A * over to being idle or not. It works by having a time buffer as 402348SN/A * long as any time buffer in the CPU, and the CPU and all of its 412348SN/A * stages inform the ActivityRecorder when they write to any time 422348SN/A * buffer. The ActivityRecorder marks a 1 in the "0" slot of the time 432348SN/A * buffer any time a stage writes to a time buffer, and it advances 442348SN/A * its time buffer at the same time as all other stages. The 452348SN/A * ActivityRecorder also records if a stage has activity to do next 462348SN/A * cycle. The recorder keeps a count of these two. Thus any time the 472348SN/A * count is non-zero, there is either communication still in flight, 482348SN/A * or activity that still must be done, meaning that the CPU can not 492348SN/A * idle. If count is zero, then the CPU can safely idle as it has no 502348SN/A * more outstanding work to do. 512348SN/A */ 525804Snate@binkert.orgclass ActivityRecorder 535804Snate@binkert.org{ 542325SN/A public: 555804Snate@binkert.org ActivityRecorder(const std::string &name, int num_stages, 565804Snate@binkert.org int longest_latency, int count); 572325SN/A 582325SN/A /** Records that there is activity this cycle. */ 592325SN/A void activity(); 602348SN/A 612348SN/A /** Advances the activity buffer, decrementing the activityCount 622348SN/A * if active communication just left the time buffer, and 632348SN/A * determining if there is no activity. 642325SN/A */ 652325SN/A void advance(); 662348SN/A 672325SN/A /** Marks a stage as active. */ 682325SN/A void activateStage(const int idx); 692348SN/A 702325SN/A /** Deactivates a stage. */ 712325SN/A void deactivateStage(const int idx); 722325SN/A 732348SN/A /** Returns how many things are active within the recorder. */ 742325SN/A int getActivityCount() { return activityCount; } 752325SN/A 762348SN/A /** Sets the count to a starting value. Can be used to disable 772348SN/A * the idling option. 782348SN/A */ 792325SN/A void setActivityCount(int count) 802325SN/A { activityCount = count; } 812325SN/A 822348SN/A /** Returns if the CPU should be active. */ 832325SN/A bool active() { return activityCount; } 842325SN/A 852348SN/A /** Clears the time buffer and the activity count. */ 862325SN/A void reset(); 872325SN/A 882348SN/A /** Debug function to dump the contents of the time buffer. */ 892325SN/A void dump(); 902325SN/A 912348SN/A /** Debug function to ensure that the activity count matches the 922348SN/A * contents of the time buffer. 932348SN/A */ 942325SN/A void validate(); 952325SN/A 962325SN/A private: 975804Snate@binkert.org // provide name() for DPRINTF. 985804Snate@binkert.org std::string _name; 995804Snate@binkert.org const std::string &name() { return _name; } 1005804Snate@binkert.org 1012325SN/A /** Time buffer that tracks if any cycles has active communication 1022325SN/A * in them. It should be as long as the longest communication 1032325SN/A * latency in the system. Each time any time buffer is written, 1042325SN/A * the activity buffer should also be written to. The 1052325SN/A * activityBuffer is advanced along with all the other time 1062325SN/A * buffers, so it should have a 1 somewhere in it only if there 1072325SN/A * is active communication in a time buffer. 1082325SN/A */ 1092325SN/A TimeBuffer<bool> activityBuffer; 1102325SN/A 1112348SN/A /** Longest latency time buffer in the CPU. */ 1122325SN/A int longestLatency; 1132325SN/A 1142325SN/A /** Tracks how many stages and cycles of time buffer have 1152325SN/A * activity. Stages increment this count when they switch to 1162325SN/A * active, and decrement it when they switch to 1172325SN/A * inactive. Whenever a cycle that previously had no information 1182325SN/A * is written in the time buffer, this is incremented. When a 1192325SN/A * cycle that had information exits the time buffer due to age, 1202325SN/A * this count is decremented. When the count is 0, there is no 1212325SN/A * activity in the CPU, and it can be descheduled. 1222325SN/A */ 1232325SN/A int activityCount; 1242325SN/A 1252348SN/A /** Number of stages that can be marked as active or inactive. */ 1262325SN/A int numStages; 1272325SN/A 1282325SN/A /** Records which stages are active/inactive. */ 1292325SN/A bool *stageActive; 1302325SN/A}; 1312325SN/A 1322325SN/A#endif // __CPU_ACTIVITY_HH__ 133