PerfectSwitch.hh (11092:a51ef09e3a78) PerfectSwitch.hh (11093:8049ffff6d68)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * Perfect switch, of course it is perfect and no latency or what so
31 * ever. Every cycle it is woke up and perform all the necessary
32 * routings that must be done. Note, this switch also has number of
33 * input ports/output ports and has a routing table as well.
34 */
35
36#ifndef __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__
37#define __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__
38
39#include <iostream>
40#include <string>
41#include <vector>
42
43#include "mem/ruby/common/Consumer.hh"
44
45class MessageBuffer;
46class NetDest;
47class SimpleNetwork;
48class Switch;
49
50struct LinkOrder
51{
52 int m_link;
53 int m_value;
54};
55
56bool operator<(const LinkOrder& l1, const LinkOrder& l2);
57
58class PerfectSwitch : public Consumer
59{
60 public:
61 PerfectSwitch(SwitchID sid, Switch *, uint32_t);
62 ~PerfectSwitch();
63
64 std::string name()
65 { return csprintf("PerfectSwitch-%i", m_switch_id); }
66
67 void init(SimpleNetwork *);
68 void addInPort(const std::vector<MessageBuffer*>& in);
69 void addOutPort(const std::vector<MessageBuffer*>& out,
70 const NetDest& routing_table_entry);
71
72 int getInLinks() const { return m_in.size(); }
73 int getOutLinks() const { return m_out.size(); }
74
75 void wakeup();
76 void storeEventInfo(int info);
77
78 void clearStats();
79 void collateStats();
80 void print(std::ostream& out) const;
81
82 private:
83 // Private copy constructor and assignment operator
84 PerfectSwitch(const PerfectSwitch& obj);
85 PerfectSwitch& operator=(const PerfectSwitch& obj);
86
87 void operateVnet(int vnet);
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * Perfect switch, of course it is perfect and no latency or what so
31 * ever. Every cycle it is woke up and perform all the necessary
32 * routings that must be done. Note, this switch also has number of
33 * input ports/output ports and has a routing table as well.
34 */
35
36#ifndef __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__
37#define __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__
38
39#include <iostream>
40#include <string>
41#include <vector>
42
43#include "mem/ruby/common/Consumer.hh"
44
45class MessageBuffer;
46class NetDest;
47class SimpleNetwork;
48class Switch;
49
50struct LinkOrder
51{
52 int m_link;
53 int m_value;
54};
55
56bool operator<(const LinkOrder& l1, const LinkOrder& l2);
57
58class PerfectSwitch : public Consumer
59{
60 public:
61 PerfectSwitch(SwitchID sid, Switch *, uint32_t);
62 ~PerfectSwitch();
63
64 std::string name()
65 { return csprintf("PerfectSwitch-%i", m_switch_id); }
66
67 void init(SimpleNetwork *);
68 void addInPort(const std::vector<MessageBuffer*>& in);
69 void addOutPort(const std::vector<MessageBuffer*>& out,
70 const NetDest& routing_table_entry);
71
72 int getInLinks() const { return m_in.size(); }
73 int getOutLinks() const { return m_out.size(); }
74
75 void wakeup();
76 void storeEventInfo(int info);
77
78 void clearStats();
79 void collateStats();
80 void print(std::ostream& out) const;
81
82 private:
83 // Private copy constructor and assignment operator
84 PerfectSwitch(const PerfectSwitch& obj);
85 PerfectSwitch& operator=(const PerfectSwitch& obj);
86
87 void operateVnet(int vnet);
88 void operateMessageBuffer(MessageBuffer *b, int incoming, int vnet);
88
89 const SwitchID m_switch_id;
90 Switch * const m_switch;
91
92 // vector of queues from the components
93 std::vector<std::vector<MessageBuffer*> > m_in;
94 std::vector<std::vector<MessageBuffer*> > m_out;
95
96 std::vector<NetDest> m_routing_table;
97 std::vector<LinkOrder> m_link_order;
98
99 uint32_t m_virtual_networks;
100 int m_round_robin_start;
101 int m_wakeups_wo_switch;
102
103 SimpleNetwork* m_network_ptr;
104 std::vector<int> m_pending_message_count;
105};
106
107inline std::ostream&
108operator<<(std::ostream& out, const PerfectSwitch& obj)
109{
110 obj.print(out);
111 out << std::flush;
112 return out;
113}
114
115#endif // __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__
89
90 const SwitchID m_switch_id;
91 Switch * const m_switch;
92
93 // vector of queues from the components
94 std::vector<std::vector<MessageBuffer*> > m_in;
95 std::vector<std::vector<MessageBuffer*> > m_out;
96
97 std::vector<NetDest> m_routing_table;
98 std::vector<LinkOrder> m_link_order;
99
100 uint32_t m_virtual_networks;
101 int m_round_robin_start;
102 int m_wakeups_wo_switch;
103
104 SimpleNetwork* m_network_ptr;
105 std::vector<int> m_pending_message_count;
106};
107
108inline std::ostream&
109operator<<(std::ostream& out, const PerfectSwitch& obj)
110{
111 obj.print(out);
112 out << std::flush;
113 return out;
114}
115
116#endif // __MEM_RUBY_NETWORK_SIMPLE_PERFECTSWITCH_HH__