Network.hh revision 6372:f1a41ea3bbab
1
2/*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * Network.hh
32 *
33 * Description: The Network class is the base class for classes that
34 * implement the interconnection network between components
35 * (processor/cache components and memory/directory components).  The
36 * interconnection network as described here is not a physical
37 * network, but a programming concept used to implement all
38 * communication between components.  Thus parts of this 'network'
39 * will model the on-chip connections between cache controllers and
40 * directory controllers as well as the links between chip and network
41 * switches.
42 *
43 * $Id$
44 * */
45
46#ifndef NETWORK_H
47#define NETWORK_H
48
49#include "mem/ruby/common/Global.hh"
50#include "mem/ruby/system/NodeID.hh"
51#include "mem/protocol/MessageSizeType.hh"
52#include "mem/ruby/system/System.hh"
53
54class NetDest;
55class MessageBuffer;
56class Throttle;
57class Topology;
58
59class Network {
60public:
61  // Constructors
62  Network(const string & name);
63  virtual void init(const vector<string> & argv);
64
65  // Destructor
66  virtual ~Network() {}
67
68  // Public Methods
69  int getBufferSize() { return m_buffer_size; }
70  int getNumberOfVirtualNetworks() { return m_virtual_networks; }
71  int getEndpointBandwidth() { return m_endpoint_bandwidth; }
72  bool getAdaptiveRouting() {return m_adaptive_routing; }
73  int getLinkLatency() { return m_link_latency; }
74
75  // returns the queue requested for the given component
76  virtual MessageBuffer* getToNetQueue(NodeID id, bool ordered, int netNumber) = 0;
77  virtual MessageBuffer* getFromNetQueue(NodeID id, bool ordered, int netNumber) = 0;
78  virtual const Vector<Throttle*>* getThrottles(NodeID id) const { return NULL; }
79
80  virtual int getNumNodes() {return 1;}
81
82  virtual void makeOutLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) = 0;
83  virtual void makeInLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int bw_multiplier, bool isReconfiguration) = 0;
84  virtual void makeInternalLink(SwitchID src, NodeID dest, const NetDest& routing_table_entry, int link_latency, int link_weight, int bw_multiplier, bool isReconfiguration) = 0;
85
86  virtual void reset() = 0;
87
88  virtual void printStats(ostream& out) const = 0;
89  virtual void clearStats() = 0;
90  virtual void printConfig(ostream& out) const = 0;
91  virtual void print(ostream& out) const = 0;
92
93protected:
94
95  // Private Methods
96  // Private copy constructor and assignment operator
97  Network(const Network& obj);
98  Network& operator=(const Network& obj);
99
100  // Data Members (m_ prefix)
101protected:
102  const string m_name;
103  int m_nodes;
104  int m_virtual_networks;
105  int m_buffer_size;
106  int m_endpoint_bandwidth;
107  Topology* m_topology_ptr;
108  bool m_adaptive_routing;
109  int m_link_latency;
110};
111
112// Output operator declaration
113ostream& operator<<(ostream& out, const Network& obj);
114
115// ******************* Definitions *******************
116
117// Output operator definition
118extern inline
119ostream& operator<<(ostream& out, const Network& obj)
120{
121  obj.print(out);
122  out << flush;
123  return out;
124}
125
126// Code to map network message size types to an integer number of bytes
127const int CONTROL_MESSAGE_SIZE = 8;
128const int DATA_MESSAGE_SIZE = (RubySystem::getBlockSizeBytes()+8);
129
130extern inline
131int MessageSizeType_to_int(MessageSizeType size_type)
132{
133  switch(size_type) {
134  case MessageSizeType_Undefined:
135    ERROR_MSG("Can't convert Undefined MessageSizeType to integer");
136    break;
137  case MessageSizeType_Control:
138  case MessageSizeType_Request_Control:
139  case MessageSizeType_Reissue_Control:
140  case MessageSizeType_Response_Control:
141  case MessageSizeType_Writeback_Control:
142  case MessageSizeType_Forwarded_Control:
143  case MessageSizeType_Invalidate_Control:
144  case MessageSizeType_Unblock_Control:
145  case MessageSizeType_Persistent_Control:
146  case MessageSizeType_Completion_Control:
147    return CONTROL_MESSAGE_SIZE;
148    break;
149  case MessageSizeType_Data:
150  case MessageSizeType_Response_Data:
151  case MessageSizeType_ResponseLocal_Data:
152  case MessageSizeType_ResponseL2hit_Data:
153  case MessageSizeType_Writeback_Data:
154    return DATA_MESSAGE_SIZE;
155    break;
156  default:
157    ERROR_MSG("Invalid range for type MessageSizeType");
158    break;
159  }
160  return 0;
161}
162
163#endif //NETWORK_H
164