Throttle.hh revision 7054
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296145Snate@binkert.org/*
307054Snate@binkert.org * The class to implement bandwidth and latency throttle. An instance
317054Snate@binkert.org * of consumer class that can be woke up. It is only used to control
327054Snate@binkert.org * bandwidth at output port of a switch. And the throttle is added
337054Snate@binkert.org * *after* the output port, means the message is put in the output
347054Snate@binkert.org * port of the PerfectSwitch (a intermediateBuffers) first, then go
357054Snate@binkert.org * through the Throttle.
366145Snate@binkert.org */
376145Snate@binkert.org
387054Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_SIMPLE_THROTTLE_HH__
397054Snate@binkert.org#define __MEM_RUBY_NETWORK_SIMPLE_THROTTLE_HH__
406145Snate@binkert.org
416154Snate@binkert.org#include "mem/gems_common/Vector.hh"
426154Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
437054Snate@binkert.org#include "mem/ruby/common/Global.hh"
447054Snate@binkert.org#include "mem/ruby/network/Network.hh"
456154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
466285Snate@binkert.org#include "mem/ruby/system/System.hh"
476145Snate@binkert.org
486145Snate@binkert.orgclass MessageBuffer;
496145Snate@binkert.org
507054Snate@binkert.orgclass Throttle : public Consumer
517054Snate@binkert.org{
527054Snate@binkert.org  public:
537054Snate@binkert.org    Throttle(int sID, NodeID node, int link_latency,
547054Snate@binkert.org        int link_bandwidth_multiplier);
557054Snate@binkert.org    Throttle(NodeID node, int link_latency, int link_bandwidth_multiplier);
567054Snate@binkert.org    ~Throttle() {}
576145Snate@binkert.org
587054Snate@binkert.org    void addLinks(const Vector<MessageBuffer*>& in_vec,
597054Snate@binkert.org        const Vector<MessageBuffer*>& out_vec);
607054Snate@binkert.org    void wakeup();
616145Snate@binkert.org
627054Snate@binkert.org    void printStats(ostream& out) const;
637054Snate@binkert.org    void clearStats();
647054Snate@binkert.org    void printConfig(ostream& out) const;
657054Snate@binkert.org    // The average utilization (a percent) since last clearStats()
667054Snate@binkert.org    double getUtilization() const;
677054Snate@binkert.org    int
687054Snate@binkert.org    getLinkBandwidth() const
697054Snate@binkert.org    {
707054Snate@binkert.org        return RubySystem::getNetwork()->getEndpointBandwidth() *
717054Snate@binkert.org            m_link_bandwidth_multiplier;
727054Snate@binkert.org    }
737054Snate@binkert.org    int getLatency() const { return m_link_latency; }
746145Snate@binkert.org
757054Snate@binkert.org    const Vector<Vector<int> >&
767054Snate@binkert.org    getCounters() const
777054Snate@binkert.org    {
787054Snate@binkert.org        return m_message_counters;
797054Snate@binkert.org    }
806145Snate@binkert.org
817054Snate@binkert.org    void clear();
826145Snate@binkert.org
837054Snate@binkert.org    void print(ostream& out) const;
846145Snate@binkert.org
857054Snate@binkert.org  private:
867054Snate@binkert.org    void init(NodeID node, int link_latency, int link_bandwidth_multiplier);
877054Snate@binkert.org    void addVirtualNetwork(MessageBuffer* in_ptr, MessageBuffer* out_ptr);
887054Snate@binkert.org    void linkUtilized(double ratio) { m_links_utilized += ratio; }
896145Snate@binkert.org
907054Snate@binkert.org    // Private copy constructor and assignment operator
917054Snate@binkert.org    Throttle(const Throttle& obj);
927054Snate@binkert.org    Throttle& operator=(const Throttle& obj);
936145Snate@binkert.org
947054Snate@binkert.org    Vector<MessageBuffer*> m_in;
957054Snate@binkert.org    Vector<MessageBuffer*> m_out;
967054Snate@binkert.org    Vector<Vector<int> > m_message_counters;
977054Snate@binkert.org    int m_vnets;
987054Snate@binkert.org    Vector<int> m_units_remaining;
997054Snate@binkert.org    int m_sID;
1007054Snate@binkert.org    NodeID m_node;
1017054Snate@binkert.org    int m_link_bandwidth_multiplier;
1027054Snate@binkert.org    int m_link_latency;
1037054Snate@binkert.org    int m_wakeups_wo_switch;
1046145Snate@binkert.org
1057054Snate@binkert.org    // For tracking utilization
1067054Snate@binkert.org    Time m_ruby_start;
1077054Snate@binkert.org    double m_links_utilized;
1086145Snate@binkert.org};
1096145Snate@binkert.org
1107054Snate@binkert.orginline ostream&
1117054Snate@binkert.orgoperator<<(ostream& out, const Throttle& obj)
1126145Snate@binkert.org{
1137054Snate@binkert.org    obj.print(out);
1147054Snate@binkert.org    out << flush;
1157054Snate@binkert.org    return out;
1166145Snate@binkert.org}
1176145Snate@binkert.org
1187054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_THROTTLE_HH__
119