Topology.cc (9593:9441ca79f3c8) Topology.cc (9594:219ad5fe8c04)
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;

--- 19 unchanged lines hidden (view full) ---

28
29#include <cassert>
30
31#include "base/trace.hh"
32#include "debug/RubyNetwork.hh"
33#include "mem/protocol/MachineType.hh"
34#include "mem/ruby/common/NetDest.hh"
35#include "mem/ruby/network/BasicLink.hh"
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;

--- 19 unchanged lines hidden (view full) ---

28
29#include <cassert>
30
31#include "base/trace.hh"
32#include "debug/RubyNetwork.hh"
33#include "mem/protocol/MachineType.hh"
34#include "mem/ruby/common/NetDest.hh"
35#include "mem/ruby/network/BasicLink.hh"
36#include "mem/ruby/network/Network.hh"
37#include "mem/ruby/network/Topology.hh"
38#include "mem/ruby/slicc_interface/AbstractController.hh"
39
40using namespace std;
41
42const int INFINITE_LATENCY = 10000; // Yes, this is a big hack
43
44// Note: In this file, we use the first 2*m_nodes SwitchIDs to

--- 8 unchanged lines hidden (view full) ---

53 Matrix& inter_switches);
54Matrix shortest_path(const Matrix& weights, Matrix& latencies,
55 Matrix& inter_switches);
56bool link_is_shortest_path_to_node(SwitchID src, SwitchID next,
57 SwitchID final, const Matrix& weights, const Matrix& dist);
58NetDest shortest_path_to_node(SwitchID src, SwitchID next,
59 const Matrix& weights, const Matrix& dist);
60
36#include "mem/ruby/network/Topology.hh"
37#include "mem/ruby/slicc_interface/AbstractController.hh"
38
39using namespace std;
40
41const int INFINITE_LATENCY = 10000; // Yes, this is a big hack
42
43// Note: In this file, we use the first 2*m_nodes SwitchIDs to

--- 8 unchanged lines hidden (view full) ---

52 Matrix& inter_switches);
53Matrix shortest_path(const Matrix& weights, Matrix& latencies,
54 Matrix& inter_switches);
55bool link_is_shortest_path_to_node(SwitchID src, SwitchID next,
56 SwitchID final, const Matrix& weights, const Matrix& dist);
57NetDest shortest_path_to_node(SwitchID src, SwitchID next,
58 const Matrix& weights, const Matrix& dist);
59
61Topology::Topology(const Params *p)
62 : SimObject(p)
60Topology::Topology(uint32_t num_routers, vector<BasicExtLink *> ext_links,
61 vector<BasicIntLink *> int_links)
62 : m_number_of_switches(num_routers)
63{
63{
64 m_number_of_switches = p->num_routers;
65
66 // initialize component latencies record
67 m_component_latencies.resize(0);
68 m_component_inter_switches.resize(0);
69
70 // Total nodes/controllers in network
71 // Must make sure this is called after the State Machine constructors
72 m_nodes = MachineType_base_number(MachineType_NUM);
73 assert(m_nodes > 1);
74
64
65 // initialize component latencies record
66 m_component_latencies.resize(0);
67 m_component_inter_switches.resize(0);
68
69 // Total nodes/controllers in network
70 // Must make sure this is called after the State Machine constructors
71 m_nodes = MachineType_base_number(MachineType_NUM);
72 assert(m_nodes > 1);
73
75 if (m_nodes != params()->ext_links.size() &&
76 m_nodes != params()->ext_links.size()) {
74 if (m_nodes != ext_links.size()) {
77 fatal("m_nodes (%d) != ext_links vector length (%d)\n",
75 fatal("m_nodes (%d) != ext_links vector length (%d)\n",
78 m_nodes, params()->ext_links.size());
76 m_nodes, ext_links.size());
79 }
80
81 // analyze both the internal and external links, create data structures
82 // Note that the python created links are bi-directional, but that the
83 // topology and networks utilize uni-directional links. Thus each
84 // BasicLink is converted to two calls to add link, on for each direction
77 }
78
79 // analyze both the internal and external links, create data structures
80 // Note that the python created links are bi-directional, but that the
81 // topology and networks utilize uni-directional links. Thus each
82 // BasicLink is converted to two calls to add link, on for each direction
85 for (vector<BasicExtLink*>::const_iterator i = params()->ext_links.begin();
86 i != params()->ext_links.end(); ++i) {
83 for (vector::const_iterator i = ext_links.begin();
84 i != ext_links.end(); ++i) {
87 BasicExtLink *ext_link = (*i);
88 AbstractController *abs_cntrl = ext_link->params()->ext_node;
89 BasicRouter *router = ext_link->params()->int_node;
90
91 // Store the ExtLink pointers for later
92 m_ext_link_vector.push_back(ext_link);
93
94 int ext_idx1 = abs_cntrl->params()->cntrl_id;
95 int ext_idx2 = ext_idx1 + m_nodes;
96 int int_idx = router->params()->router_id + 2*m_nodes;
97
98 // create the internal uni-directional links in both directions
99 // the first direction is marked: In
100 addLink(ext_idx1, int_idx, ext_link, LinkDirection_In);
101 // the first direction is marked: Out
102 addLink(int_idx, ext_idx2, ext_link, LinkDirection_Out);
103 }
104
85 BasicExtLink *ext_link = (*i);
86 AbstractController *abs_cntrl = ext_link->params()->ext_node;
87 BasicRouter *router = ext_link->params()->int_node;
88
89 // Store the ExtLink pointers for later
90 m_ext_link_vector.push_back(ext_link);
91
92 int ext_idx1 = abs_cntrl->params()->cntrl_id;
93 int ext_idx2 = ext_idx1 + m_nodes;
94 int int_idx = router->params()->router_id + 2*m_nodes;
95
96 // create the internal uni-directional links in both directions
97 // the first direction is marked: In
98 addLink(ext_idx1, int_idx, ext_link, LinkDirection_In);
99 // the first direction is marked: Out
100 addLink(int_idx, ext_idx2, ext_link, LinkDirection_Out);
101 }
102
105 for (vector<BasicIntLink*>::const_iterator i = params()->int_links.begin();
106 i != params()->int_links.end(); ++i) {
103 for (vector::const_iterator i = int_links.begin();
104 i != int_links.end(); ++i) {
107 BasicIntLink *int_link = (*i);
108 BasicRouter *router_a = int_link->params()->node_a;
109 BasicRouter *router_b = int_link->params()->node_b;
110
111 // Store the IntLink pointers for later
112 m_int_link_vector.push_back(int_link);
113
114 int a = router_a->params()->router_id + 2*m_nodes;
115 int b = router_b->params()->router_id + 2*m_nodes;
116
117 // create the internal uni-directional links in both directions
118 // the first direction is marked: In
119 addLink(a, b, int_link, LinkDirection_In);
120 // the second direction is marked: Out
121 addLink(b, a, int_link, LinkDirection_Out);
122 }
123}
124
125void
105 BasicIntLink *int_link = (*i);
106 BasicRouter *router_a = int_link->params()->node_a;
107 BasicRouter *router_b = int_link->params()->node_b;
108
109 // Store the IntLink pointers for later
110 m_int_link_vector.push_back(int_link);
111
112 int a = router_a->params()->router_id + 2*m_nodes;
113 int b = router_b->params()->router_id + 2*m_nodes;
114
115 // create the internal uni-directional links in both directions
116 // the first direction is marked: In
117 addLink(a, b, int_link, LinkDirection_In);
118 // the second direction is marked: Out
119 addLink(b, a, int_link, LinkDirection_Out);
120 }
121}
122
123void
126Topology::init()
127{
128}
129
130
131void
132Topology::initNetworkPtr(Network* net_ptr)
133{
134 for (vector<BasicExtLink*>::const_iterator i = params()->ext_links.begin();
135 i != params()->ext_links.end(); ++i) {
136 BasicExtLink *ext_link = (*i);
137 AbstractController *abs_cntrl = ext_link->params()->ext_node;
138 abs_cntrl->initNetworkPtr(net_ptr);
139 }
140}
141
142void
143Topology::createLinks(Network *net, bool isReconfiguration)
144{
145 // Find maximum switchID
146 SwitchID max_switch_id = 0;
147 for (LinkMap::const_iterator i = m_link_map.begin();
148 i != m_link_map.end(); ++i) {
149 std::pair<int, int> src_dest = (*i).first;
150 max_switch_id = max(max_switch_id, src_dest.first);

--- 198 unchanged lines hidden (view full) ---

349 DPRINTF(RubyNetwork, "Returning shortest path\n"
350 "(src-(2*max_machines)): %d, (next-(2*max_machines)): %d, "
351 "src: %d, next: %d, result: %s\n",
352 (src-(2*max_machines)), (next-(2*max_machines)),
353 src, next, result);
354
355 return result;
356}
124Topology::createLinks(Network *net, bool isReconfiguration)
125{
126 // Find maximum switchID
127 SwitchID max_switch_id = 0;
128 for (LinkMap::const_iterator i = m_link_map.begin();
129 i != m_link_map.end(); ++i) {
130 std::pair<int, int> src_dest = (*i).first;
131 max_switch_id = max(max_switch_id, src_dest.first);

--- 198 unchanged lines hidden (view full) ---

330 DPRINTF(RubyNetwork, "Returning shortest path\n"
331 "(src-(2*max_machines)): %d, (next-(2*max_machines)): %d, "
332 "src: %d, next: %d, result: %s\n",
333 (src-(2*max_machines)), (next-(2*max_machines)),
334 src, next, result);
335
336 return result;
337}
357
358Topology *
359TopologyParams::create()
360{
361 return new Topology(this);
362}
363