PerfectSwitch.hh revision 10370
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 * Perfect switch, of course it is perfect and no latency or what so
317054Snate@binkert.org * ever. Every cycle it is woke up and perform all the necessary
327054Snate@binkert.org * routings that must be done. Note, this switch also has number of
337054Snate@binkert.org * input ports/output ports and has a routing table as well.
346145Snate@binkert.org */
356145Snate@binkert.org
367054Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__
377054Snate@binkert.org#define __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__
386145Snate@binkert.org
397002Snate@binkert.org#include <iostream>
408229Snate@binkert.org#include <string>
417454Snate@binkert.org#include <vector>
427002Snate@binkert.org
436154Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
446145Snate@binkert.org
456145Snate@binkert.orgclass MessageBuffer;
466145Snate@binkert.orgclass NetDest;
476145Snate@binkert.orgclass SimpleNetwork;
489274Snilay@cs.wisc.educlass Switch;
496145Snate@binkert.org
507054Snate@binkert.orgstruct LinkOrder
517054Snate@binkert.org{
527054Snate@binkert.org    int m_link;
537054Snate@binkert.org    int m_value;
546145Snate@binkert.org};
556145Snate@binkert.org
569554Sandreas.hansson@arm.combool operator<(const LinkOrder& l1, const LinkOrder& l2);
579554Sandreas.hansson@arm.com
587054Snate@binkert.orgclass PerfectSwitch : public Consumer
597054Snate@binkert.org{
607054Snate@binkert.org  public:
619274Snilay@cs.wisc.edu    PerfectSwitch(SwitchID sid, Switch *, uint32_t);
627054Snate@binkert.org    ~PerfectSwitch();
636145Snate@binkert.org
648054Sksewell@umich.edu    std::string name()
658054Sksewell@umich.edu    { return csprintf("PerfectSwitch-%i", m_switch_id); }
668054Sksewell@umich.edu
679274Snilay@cs.wisc.edu    void init(SimpleNetwork *);
6810370Snilay@cs.wisc.edu    void addInPort(const std::vector<MessageBuffer*>& in);
6910370Snilay@cs.wisc.edu    void addOutPort(const std::vector<MessageBuffer*>& out,
709863Snilay@cs.wisc.edu                    const NetDest& routing_table_entry);
7110311Snilay@cs.wisc.edu
727054Snate@binkert.org    int getInLinks() const { return m_in.size(); }
737054Snate@binkert.org    int getOutLinks() const { return m_out.size(); }
746145Snate@binkert.org
757054Snate@binkert.org    void wakeup();
767973Snilay@cs.wisc.edu    void storeEventInfo(int info);
776145Snate@binkert.org
787054Snate@binkert.org    void clearStats();
799863Snilay@cs.wisc.edu    void collateStats();
807054Snate@binkert.org    void print(std::ostream& out) const;
816145Snate@binkert.org
827054Snate@binkert.org  private:
837054Snate@binkert.org    // Private copy constructor and assignment operator
847054Snate@binkert.org    PerfectSwitch(const PerfectSwitch& obj);
857054Snate@binkert.org    PerfectSwitch& operator=(const PerfectSwitch& obj);
866145Snate@binkert.org
8710312Snilay@cs.wisc.edu    void operateVnet(int vnet);
8810312Snilay@cs.wisc.edu
897054Snate@binkert.org    SwitchID m_switch_id;
906145Snate@binkert.org
917054Snate@binkert.org    // vector of queues from the components
9210370Snilay@cs.wisc.edu    std::vector<std::vector<MessageBuffer*> > m_in;
9310370Snilay@cs.wisc.edu    std::vector<std::vector<MessageBuffer*> > m_out;
9410311Snilay@cs.wisc.edu
957454Snate@binkert.org    std::vector<NetDest> m_routing_table;
967454Snate@binkert.org    std::vector<LinkOrder> m_link_order;
979274Snilay@cs.wisc.edu
989274Snilay@cs.wisc.edu    uint32_t m_virtual_networks;
997054Snate@binkert.org    int m_round_robin_start;
1007054Snate@binkert.org    int m_wakeups_wo_switch;
1019274Snilay@cs.wisc.edu
1027054Snate@binkert.org    SimpleNetwork* m_network_ptr;
1037973Snilay@cs.wisc.edu    std::vector<int> m_pending_message_count;
1046145Snate@binkert.org};
1056145Snate@binkert.org
1067054Snate@binkert.orginline std::ostream&
1077054Snate@binkert.orgoperator<<(std::ostream& out, const PerfectSwitch& obj)
1086145Snate@binkert.org{
1097054Snate@binkert.org    obj.print(out);
1107054Snate@binkert.org    out << std::flush;
1117054Snate@binkert.org    return out;
1126145Snate@binkert.org}
1136145Snate@binkert.org
1147054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__
115