Throttle.hh revision 7024:30883414ad10
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/system/System.hh"
50#include "mem/ruby/network/Network.hh"
51
52class MessageBuffer;
53
54class Throttle : public Consumer {
55public:
56  // Constructors
57  Throttle(int sID, NodeID node, int link_latency, int link_bandwidth_multiplier);
58  Throttle(NodeID node, int link_latency, int link_bandwidth_multiplier);
59
60  // Destructor
61  ~Throttle() {}
62
63  // Public Methods
64  void addLinks(const Vector<MessageBuffer*>& in_vec, const Vector<MessageBuffer*>& out_vec);
65  void wakeup();
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 RubySystem::getNetwork()->getEndpointBandwidth() * 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_link_bandwidth_multiplier;
99  int m_link_latency;
100  int m_wakeups_wo_switch;
101
102  // For tracking utilization
103  Time m_ruby_start;
104  double m_links_utilized;
105};
106
107// Output operator declaration
108ostream& operator<<(ostream& out, const Throttle& obj);
109
110// ******************* Definitions *******************
111
112// Output operator definition
113extern inline
114ostream& operator<<(ostream& out, const Throttle& obj)
115{
116  obj.print(out);
117  out << flush;
118  return out;
119}
120
121#endif //THROTTLE_H
122