Throttle.hh revision 6154:6bb54dcb940e
1 2/* 3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30/* 31 * $Id$ 32 * 33 * Description: The class to implement bandwidth and latency throttle. An 34 * instance of consumer class that can be woke up. It is only used 35 * to control bandwidth at output port of a switch. And the 36 * throttle is added *after* the output port, means the message is 37 * put in the output port of the PerfectSwitch (a 38 * intermediateBuffers) first, then go through the Throttle. 39 * 40 */ 41 42#ifndef THROTTLE_H 43#define THROTTLE_H 44 45#include "mem/ruby/common/Global.hh" 46#include "mem/gems_common/Vector.hh" 47#include "mem/ruby/common/Consumer.hh" 48#include "mem/ruby/system/NodeID.hh" 49#include "mem/ruby/config/RubyConfig.hh" 50 51class MessageBuffer; 52 53class Throttle : public Consumer { 54public: 55 // Constructors 56 Throttle(int sID, NodeID node, int link_latency, int link_bandwidth_multiplier); 57 Throttle(NodeID node, int link_latency, int link_bandwidth_multiplier); 58 59 // Destructor 60 ~Throttle() {} 61 62 // Public Methods 63 void addLinks(const Vector<MessageBuffer*>& in_vec, const Vector<MessageBuffer*>& out_vec); 64 void wakeup(); 65 bool broadcastBandwidthAvailable(int rand) const; 66 67 void printStats(ostream& out) const; 68 void clearStats(); 69 void printConfig(ostream& out) const; 70 double getUtilization() const; // The average utilization (a percent) since last clearStats() 71 int getLinkBandwidth() const { return g_endpoint_bandwidth * m_link_bandwidth_multiplier; } 72 int getLatency() const { return m_link_latency; } 73 74 const Vector<Vector<int> >& getCounters() const { return m_message_counters; } 75 76 void clear(); 77 78 void print(ostream& out) const; 79 80private: 81 // Private Methods 82 void init(NodeID node, int link_latency, int link_bandwidth_multiplier); 83 void addVirtualNetwork(MessageBuffer* in_ptr, MessageBuffer* out_ptr); 84 void linkUtilized(double ratio) { m_links_utilized += ratio; } 85 86 // Private copy constructor and assignment operator 87 Throttle(const Throttle& obj); 88 Throttle& operator=(const Throttle& obj); 89 90 // Data Members (m_ prefix) 91 Vector<MessageBuffer*> m_in; 92 Vector<MessageBuffer*> m_out; 93 Vector<Vector<int> > m_message_counters; 94 int m_vnets; 95 Vector<int> m_units_remaining; 96 int m_sID; 97 NodeID m_node; 98 int m_bash_counter; 99 int m_bandwidth_since_sample; 100 Time m_last_bandwidth_sample; 101 int m_link_bandwidth_multiplier; 102 int m_link_latency; 103 int m_wakeups_wo_switch; 104 105 // For tracking utilization 106 Time m_ruby_start; 107 double m_links_utilized; 108}; 109 110// Output operator declaration 111ostream& operator<<(ostream& out, const Throttle& obj); 112 113// ******************* Definitions ******************* 114 115// Output operator definition 116extern inline 117ostream& operator<<(ostream& out, const Throttle& obj) 118{ 119 obj.print(out); 120 out << flush; 121 return out; 122} 123 124#endif //THROTTLE_H 125