Switch.hh revision 9274
111901Sjason@lowepower.com/*
211901Sjason@lowepower.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
311901Sjason@lowepower.com * All rights reserved.
411901Sjason@lowepower.com *
511901Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without
611901Sjason@lowepower.com * modification, are permitted provided that the following conditions are
711901Sjason@lowepower.com * met: redistributions of source code must retain the above copyright
811901Sjason@lowepower.com * notice, this list of conditions and the following disclaimer;
911901Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright
1011901Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the
1111901Sjason@lowepower.com * documentation and/or other materials provided with the distribution;
1211901Sjason@lowepower.com * neither the name of the copyright holders nor the names of its
1311901Sjason@lowepower.com * contributors may be used to endorse or promote products derived from
1411901Sjason@lowepower.com * this software without specific prior written permission.
1511901Sjason@lowepower.com *
1611901Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1711901Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1811901Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1911901Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2011901Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2111901Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2211901Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2311901Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2411901Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2511901Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2611901Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711901Sjason@lowepower.com */
2811901Sjason@lowepower.com
2911901Sjason@lowepower.com/*
3011901Sjason@lowepower.com * The actual modelled switch. It use the perfect switch and a
3111901Sjason@lowepower.com * Throttle object to control and bandwidth and timing *only for the
3211901Sjason@lowepower.com * output port*. So here we have un-realistic modelling, since the
3311901Sjason@lowepower.com * order of PerfectSwitch and Throttle objects get woke up affect the
3411901Sjason@lowepower.com * message timing. A more accurate model would be having two set of
3511901Sjason@lowepower.com * system states, one for this cycle, one for next cycle. And on the
3611901Sjason@lowepower.com * cycle boundary swap the two set of states.
3711901Sjason@lowepower.com */
3811901Sjason@lowepower.com
3911901Sjason@lowepower.com#ifndef __MEM_RUBY_NETWORK_SIMPLE_SWITCH_HH__
4011901Sjason@lowepower.com#define __MEM_RUBY_NETWORK_SIMPLE_SWITCH_HH__
4111901Sjason@lowepower.com
4211901Sjason@lowepower.com#include <iostream>
4311901Sjason@lowepower.com#include <vector>
4411901Sjason@lowepower.com
4511901Sjason@lowepower.com#include "mem/ruby/network/BasicRouter.hh"
4611901Sjason@lowepower.com#include "params/Switch.hh"
4711901Sjason@lowepower.com
4811901Sjason@lowepower.comclass MessageBuffer;
4911901Sjason@lowepower.comclass PerfectSwitch;
5011901Sjason@lowepower.comclass NetDest;
5111901Sjason@lowepower.comclass SimpleNetwork;
5211901Sjason@lowepower.comclass Throttle;
5311901Sjason@lowepower.com
5411901Sjason@lowepower.comclass Switch : public BasicRouter
5511901Sjason@lowepower.com{
5611901Sjason@lowepower.com  public:
5711901Sjason@lowepower.com    typedef SwitchParams Params;
5811901Sjason@lowepower.com    Switch(const Params *p);
5911901Sjason@lowepower.com    ~Switch();
6011901Sjason@lowepower.com
6111901Sjason@lowepower.com    void init();
6211901Sjason@lowepower.com    void addInPort(const std::vector<MessageBuffer*>& in);
6311901Sjason@lowepower.com    void addOutPort(const std::vector<MessageBuffer*>& out,
6411901Sjason@lowepower.com        const NetDest& routing_table_entry, int link_latency,
6511901Sjason@lowepower.com        int bw_multiplier);
6611901Sjason@lowepower.com    const Throttle* getThrottle(LinkID link_number) const;
6711901Sjason@lowepower.com    const std::vector<Throttle*>* getThrottles() const;
6811901Sjason@lowepower.com    void clearRoutingTables();
6911901Sjason@lowepower.com    void clearBuffers();
7011901Sjason@lowepower.com    void reconfigureOutPort(const NetDest& routing_table_entry);
7111901Sjason@lowepower.com
7211901Sjason@lowepower.com    void printStats(std::ostream& out) const;
7311901Sjason@lowepower.com    void clearStats();
7411901Sjason@lowepower.com    void print(std::ostream& out) const;
7511901Sjason@lowepower.com    void init_net_ptr(SimpleNetwork* net_ptr) { m_network_ptr = net_ptr; }
7611901Sjason@lowepower.com
7711901Sjason@lowepower.com  private:
7811901Sjason@lowepower.com    // Private copy constructor and assignment operator
7911901Sjason@lowepower.com    Switch(const Switch& obj);
8011901Sjason@lowepower.com    Switch& operator=(const Switch& obj);
8111901Sjason@lowepower.com
8211901Sjason@lowepower.com    PerfectSwitch* m_perfect_switch_ptr;
8311901Sjason@lowepower.com    SimpleNetwork* m_network_ptr;
8411901Sjason@lowepower.com    std::vector<Throttle*> m_throttles;
8511901Sjason@lowepower.com    std::vector<MessageBuffer*> m_buffers_to_free;
8611901Sjason@lowepower.com};
8711901Sjason@lowepower.com
8811901Sjason@lowepower.cominline std::ostream&
8911901Sjason@lowepower.comoperator<<(std::ostream& out, const Switch& obj)
9011901Sjason@lowepower.com{
9111901Sjason@lowepower.com    obj.print(out);
9211901Sjason@lowepower.com    out << std::flush;
9311901Sjason@lowepower.com    return out;
9411901Sjason@lowepower.com}
9511901Sjason@lowepower.com
9611901Sjason@lowepower.com#endif // __MEM_RUBY_NETWORK_SIMPLE_SWITCH_HH__
9711901Sjason@lowepower.com