Throttle.hh revision 7024:30883414ad10
19883Sandreas@sandberg.pp.se 29883Sandreas@sandberg.pp.se/* 39883Sandreas@sandberg.pp.se * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 49883Sandreas@sandberg.pp.se * All rights reserved. 59883Sandreas@sandberg.pp.se * 69883Sandreas@sandberg.pp.se * Redistribution and use in source and binary forms, with or without 79883Sandreas@sandberg.pp.se * modification, are permitted provided that the following conditions are 89883Sandreas@sandberg.pp.se * met: redistributions of source code must retain the above copyright 99883Sandreas@sandberg.pp.se * notice, this list of conditions and the following disclaimer; 109883Sandreas@sandberg.pp.se * redistributions in binary form must reproduce the above copyright 119883Sandreas@sandberg.pp.se * notice, this list of conditions and the following disclaimer in the 129883Sandreas@sandberg.pp.se * documentation and/or other materials provided with the distribution; 139883Sandreas@sandberg.pp.se * neither the name of the copyright holders nor the names of its 149883Sandreas@sandberg.pp.se * contributors may be used to endorse or promote products derived from 159883Sandreas@sandberg.pp.se * this software without specific prior written permission. 169883Sandreas@sandberg.pp.se * 179883Sandreas@sandberg.pp.se * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 189883Sandreas@sandberg.pp.se * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 199883Sandreas@sandberg.pp.se * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 209883Sandreas@sandberg.pp.se * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 219883Sandreas@sandberg.pp.se * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 229883Sandreas@sandberg.pp.se * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 239883Sandreas@sandberg.pp.se * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 249883Sandreas@sandberg.pp.se * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 259883Sandreas@sandberg.pp.se * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 269883Sandreas@sandberg.pp.se * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 279883Sandreas@sandberg.pp.se * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 289883Sandreas@sandberg.pp.se */ 299883Sandreas@sandberg.pp.se 309883Sandreas@sandberg.pp.se/* 319883Sandreas@sandberg.pp.se * $Id$ 329883Sandreas@sandberg.pp.se * 339883Sandreas@sandberg.pp.se * Description: The class to implement bandwidth and latency throttle. An 349883Sandreas@sandberg.pp.se * instance of consumer class that can be woke up. It is only used 359883Sandreas@sandberg.pp.se * to control bandwidth at output port of a switch. And the 369883Sandreas@sandberg.pp.se * throttle is added *after* the output port, means the message is 379883Sandreas@sandberg.pp.se * put in the output port of the PerfectSwitch (a 389883Sandreas@sandberg.pp.se * intermediateBuffers) first, then go through the Throttle. 399883Sandreas@sandberg.pp.se * 409883Sandreas@sandberg.pp.se */ 419883Sandreas@sandberg.pp.se 429883Sandreas@sandberg.pp.se#ifndef THROTTLE_H 439883Sandreas@sandberg.pp.se#define THROTTLE_H 449883Sandreas@sandberg.pp.se 459883Sandreas@sandberg.pp.se#include "mem/ruby/common/Global.hh" 469883Sandreas@sandberg.pp.se#include "mem/gems_common/Vector.hh" 479883Sandreas@sandberg.pp.se#include "mem/ruby/common/Consumer.hh" 489883Sandreas@sandberg.pp.se#include "mem/ruby/system/NodeID.hh" 499883Sandreas@sandberg.pp.se#include "mem/ruby/system/System.hh" 509883Sandreas@sandberg.pp.se#include "mem/ruby/network/Network.hh" 519883Sandreas@sandberg.pp.se 529883Sandreas@sandberg.pp.seclass MessageBuffer; 539883Sandreas@sandberg.pp.se 549883Sandreas@sandberg.pp.seclass Throttle : public Consumer { 559883Sandreas@sandberg.pp.sepublic: 569883Sandreas@sandberg.pp.se // Constructors 579883Sandreas@sandberg.pp.se Throttle(int sID, NodeID node, int link_latency, int link_bandwidth_multiplier); 589883Sandreas@sandberg.pp.se Throttle(NodeID node, int link_latency, int link_bandwidth_multiplier); 599883Sandreas@sandberg.pp.se 609883Sandreas@sandberg.pp.se // Destructor 619883Sandreas@sandberg.pp.se ~Throttle() {} 629883Sandreas@sandberg.pp.se 639883Sandreas@sandberg.pp.se // Public Methods 649883Sandreas@sandberg.pp.se void addLinks(const Vector<MessageBuffer*>& in_vec, const Vector<MessageBuffer*>& out_vec); 659883Sandreas@sandberg.pp.se void wakeup(); 669883Sandreas@sandberg.pp.se 679883Sandreas@sandberg.pp.se void printStats(ostream& out) const; 689883Sandreas@sandberg.pp.se void clearStats(); 699883Sandreas@sandberg.pp.se void printConfig(ostream& out) const; 709883Sandreas@sandberg.pp.se double getUtilization() const; // The average utilization (a percent) since last clearStats() 719883Sandreas@sandberg.pp.se int getLinkBandwidth() const { return RubySystem::getNetwork()->getEndpointBandwidth() * m_link_bandwidth_multiplier; } 729883Sandreas@sandberg.pp.se int getLatency() const { return m_link_latency; } 739883Sandreas@sandberg.pp.se 749883Sandreas@sandberg.pp.se const Vector<Vector<int> >& getCounters() const { return m_message_counters; } 759883Sandreas@sandberg.pp.se 769883Sandreas@sandberg.pp.se void clear(); 779883Sandreas@sandberg.pp.se 789883Sandreas@sandberg.pp.se void print(ostream& out) const; 799883Sandreas@sandberg.pp.se 809883Sandreas@sandberg.pp.seprivate: 819883Sandreas@sandberg.pp.se // Private Methods 829883Sandreas@sandberg.pp.se void init(NodeID node, int link_latency, int link_bandwidth_multiplier); 839883Sandreas@sandberg.pp.se void addVirtualNetwork(MessageBuffer* in_ptr, MessageBuffer* out_ptr); 849883Sandreas@sandberg.pp.se void linkUtilized(double ratio) { m_links_utilized += ratio; } 859883Sandreas@sandberg.pp.se 869883Sandreas@sandberg.pp.se // Private copy constructor and assignment operator 879883Sandreas@sandberg.pp.se Throttle(const Throttle& obj); 889883Sandreas@sandberg.pp.se Throttle& operator=(const Throttle& obj); 899883Sandreas@sandberg.pp.se 909883Sandreas@sandberg.pp.se // Data Members (m_ prefix) 919883Sandreas@sandberg.pp.se Vector<MessageBuffer*> m_in; 929883Sandreas@sandberg.pp.se Vector<MessageBuffer*> m_out; 939883Sandreas@sandberg.pp.se Vector<Vector<int> > m_message_counters; 949883Sandreas@sandberg.pp.se int m_vnets; 959883Sandreas@sandberg.pp.se Vector<int> m_units_remaining; 969883Sandreas@sandberg.pp.se int m_sID; 979883Sandreas@sandberg.pp.se NodeID m_node; 989883Sandreas@sandberg.pp.se int m_link_bandwidth_multiplier; 999883Sandreas@sandberg.pp.se int m_link_latency; 1009883Sandreas@sandberg.pp.se int m_wakeups_wo_switch; 1019883Sandreas@sandberg.pp.se 1029883Sandreas@sandberg.pp.se // For tracking utilization 1039883Sandreas@sandberg.pp.se Time m_ruby_start; 1049883Sandreas@sandberg.pp.se double m_links_utilized; 1059883Sandreas@sandberg.pp.se}; 1069883Sandreas@sandberg.pp.se 1079883Sandreas@sandberg.pp.se// Output operator declaration 1089883Sandreas@sandberg.pp.seostream& operator<<(ostream& out, const Throttle& obj); 1099883Sandreas@sandberg.pp.se 1109883Sandreas@sandberg.pp.se// ******************* Definitions ******************* 1119883Sandreas@sandberg.pp.se 1129883Sandreas@sandberg.pp.se// Output operator definition 1139883Sandreas@sandberg.pp.seextern inline 1149883Sandreas@sandberg.pp.seostream& operator<<(ostream& out, const Throttle& obj) 1159883Sandreas@sandberg.pp.se{ 1169883Sandreas@sandberg.pp.se obj.print(out); 1179883Sandreas@sandberg.pp.se out << flush; 1189883Sandreas@sandberg.pp.se return out; 1199883Sandreas@sandberg.pp.se} 1209883Sandreas@sandberg.pp.se 1219883Sandreas@sandberg.pp.se#endif //THROTTLE_H 1229883Sandreas@sandberg.pp.se