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 417055Snate@binkert.org#include <iostream> 428229Snate@binkert.org#include <string> 437454Snate@binkert.org#include <vector> 447055Snate@binkert.org 456154Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 467054Snate@binkert.org#include "mem/ruby/network/Network.hh" 4711108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh" 486145Snate@binkert.org 496145Snate@binkert.orgclass MessageBuffer; 5011092Snilay@cs.wisc.educlass Switch; 516145Snate@binkert.org 527054Snate@binkert.orgclass Throttle : public Consumer 537054Snate@binkert.org{ 547054Snate@binkert.org public: 5510918Sbrandon.potter@amd.com Throttle(int sID, RubySystem *rs, NodeID node, Cycles link_latency, 569230Snilay@cs.wisc.edu int link_bandwidth_multiplier, int endpoint_bandwidth, 5711092Snilay@cs.wisc.edu Switch *em); 587054Snate@binkert.org ~Throttle() {} 596145Snate@binkert.org 608054Sksewell@umich.edu std::string name() 6111092Snilay@cs.wisc.edu { return csprintf("Throttle-%i", m_switch_id); } 628054Sksewell@umich.edu 6310370Snilay@cs.wisc.edu void addLinks(const std::vector<MessageBuffer*>& in_vec, 6410370Snilay@cs.wisc.edu const std::vector<MessageBuffer*>& out_vec); 657054Snate@binkert.org void wakeup(); 666145Snate@binkert.org 679863Snilay@cs.wisc.edu // The average utilization (a fraction) since last clearStats() 689863Snilay@cs.wisc.edu const Stats::Scalar & getUtilization() const 699863Snilay@cs.wisc.edu { return m_link_utilization; } 709863Snilay@cs.wisc.edu const Stats::Vector & getMsgCount(unsigned int type) const 719863Snilay@cs.wisc.edu { return m_msg_counts[type]; } 729863Snilay@cs.wisc.edu 739499Snilay@cs.wisc.edu int getLinkBandwidth() const 749499Snilay@cs.wisc.edu { return m_endpoint_bandwidth * m_link_bandwidth_multiplier; } 756145Snate@binkert.org 769499Snilay@cs.wisc.edu Cycles getLatency() const { return m_link_latency; } 776145Snate@binkert.org 789863Snilay@cs.wisc.edu void clearStats(); 799863Snilay@cs.wisc.edu void collateStats(); 809863Snilay@cs.wisc.edu void regStats(std::string name); 817055Snate@binkert.org void print(std::ostream& out) const; 826145Snate@binkert.org 837054Snate@binkert.org private: 849499Snilay@cs.wisc.edu void init(NodeID node, Cycles link_latency, int link_bandwidth_multiplier, 858259SBrad.Beckmann@amd.com int endpoint_bandwidth); 8610311Snilay@cs.wisc.edu void operateVnet(int vnet, int &bw_remainin, bool &schedule_wakeup, 8710311Snilay@cs.wisc.edu MessageBuffer *in, MessageBuffer *out); 886145Snate@binkert.org 897054Snate@binkert.org // Private copy constructor and assignment operator 907054Snate@binkert.org Throttle(const Throttle& obj); 917054Snate@binkert.org Throttle& operator=(const Throttle& obj); 926145Snate@binkert.org 9310370Snilay@cs.wisc.edu std::vector<MessageBuffer*> m_in; 9410370Snilay@cs.wisc.edu std::vector<MessageBuffer*> m_out; 9510370Snilay@cs.wisc.edu unsigned int m_vnets; 9610370Snilay@cs.wisc.edu std::vector<int> m_units_remaining; 9710311Snilay@cs.wisc.edu 9811092Snilay@cs.wisc.edu const int m_switch_id; 9911092Snilay@cs.wisc.edu Switch *m_switch; 1007054Snate@binkert.org NodeID m_node; 10111092Snilay@cs.wisc.edu 1027054Snate@binkert.org int m_link_bandwidth_multiplier; 1039499Snilay@cs.wisc.edu Cycles m_link_latency; 1047054Snate@binkert.org int m_wakeups_wo_switch; 1058259SBrad.Beckmann@amd.com int m_endpoint_bandwidth; 10610918Sbrandon.potter@amd.com RubySystem *m_ruby_system; 1076145Snate@binkert.org 1089863Snilay@cs.wisc.edu // Statistical variables 1099863Snilay@cs.wisc.edu Stats::Scalar m_link_utilization; 1109866Sjthestness@gmail.com Stats::Vector m_msg_counts[MessageSizeType_NUM]; 1119866Sjthestness@gmail.com Stats::Formula m_msg_bytes[MessageSizeType_NUM]; 1129863Snilay@cs.wisc.edu 1139863Snilay@cs.wisc.edu double m_link_utilization_proxy; 1146145Snate@binkert.org}; 1156145Snate@binkert.org 1167055Snate@binkert.orginline std::ostream& 1177055Snate@binkert.orgoperator<<(std::ostream& out, const Throttle& obj) 1186145Snate@binkert.org{ 1197054Snate@binkert.org obj.print(out); 1207055Snate@binkert.org out << std::flush; 1217054Snate@binkert.org return out; 1226145Snate@binkert.org} 1236145Snate@binkert.org 1247054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_THROTTLE_HH__ 125