Throttle.hh (6154:6bb54dcb940e) Throttle.hh (6285:ce086eca1ede)
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"
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"
49#include "mem/ruby/system/System.hh"
50#include "mem/ruby/network/Network.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()
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 bool broadcastBandwidthAvailable(int rand) const;
67
68 void printStats(ostream& out) const;
69 void clearStats();
70 void printConfig(ostream& out) const;
71 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 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_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
73 int getLatency() const { return m_link_latency; }
74
75 const Vector<Vector<int> >& getCounters() const { return m_message_counters; }
76
77 void clear();
78
79 void print(ostream& out) const;
80
81private:
82 // Private Methods
83 void init(NodeID node, int link_latency, int link_bandwidth_multiplier);
84 void addVirtualNetwork(MessageBuffer* in_ptr, MessageBuffer* out_ptr);
85 void linkUtilized(double ratio) { m_links_utilized += ratio; }
86
87 // Private copy constructor and assignment operator
88 Throttle(const Throttle& obj);
89 Throttle& operator=(const Throttle& obj);
90
91 // Data Members (m_ prefix)
92 Vector<MessageBuffer*> m_in;
93 Vector<MessageBuffer*> m_out;
94 Vector<Vector<int> > m_message_counters;
95 int m_vnets;
96 Vector<int> m_units_remaining;
97 int m_sID;
98 NodeID m_node;
99 int m_bash_counter;
100 int m_bandwidth_since_sample;
101 Time m_last_bandwidth_sample;
102 int m_link_bandwidth_multiplier;
103 int m_link_latency;
104 int m_wakeups_wo_switch;
105
106 // For tracking utilization
107 Time m_ruby_start;
108 double m_links_utilized;
109};
110
111// Output operator declaration
112ostream& operator<<(ostream& out, const Throttle& obj);
113
114// ******************* Definitions *******************
115
116// Output operator definition
117extern inline
118ostream& operator<<(ostream& out, const Throttle& obj)
119{
120 obj.print(out);
121 out << flush;
122 return out;
123}
124
125#endif //THROTTLE_H