includes: sort all includes
[gem5.git] / src / mem / ruby / network / garnet / fixed-pipeline / Switch_d.cc
1 /*
2 * Copyright (c) 2008 Princeton University
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 * Authors: Niket Agarwal
29 */
30
31 #include "base/stl_helpers.hh"
32 #include "mem/ruby/network/garnet/fixed-pipeline/OutputUnit_d.hh"
33 #include "mem/ruby/network/garnet/fixed-pipeline/Router_d.hh"
34 #include "mem/ruby/network/garnet/fixed-pipeline/Switch_d.hh"
35
36 using m5::stl_helpers::deletePointers;
37
38 Switch_d::Switch_d(Router_d *router)
39 {
40 m_router = router;
41 m_num_vcs = m_router->get_num_vcs();
42 m_crossbar_activity = 0;
43 }
44
45 Switch_d::~Switch_d()
46 {
47 deletePointers(m_switch_buffer);
48 }
49
50 void
51 Switch_d::init()
52 {
53 m_output_unit = m_router->get_outputUnit_ref();
54
55 m_num_inports = m_router->get_num_inports();
56 m_switch_buffer.resize(m_num_inports);
57 for (int i = 0; i < m_num_inports; i++) {
58 m_switch_buffer[i] = new flitBuffer_d();
59 }
60 }
61
62 void
63 Switch_d::wakeup()
64 {
65 DPRINTF(RubyNetwork, "Switch woke up at time: %lld\n",
66 g_eventQueue_ptr->getTime());
67
68 for (int inport = 0; inport < m_num_inports; inport++) {
69 if (!m_switch_buffer[inport]->isReady())
70 continue;
71 flit_d *t_flit = m_switch_buffer[inport]->peekTopFlit();
72 if (t_flit->is_stage(ST_)) {
73 int outport = t_flit->get_outport();
74 t_flit->advance_stage(LT_);
75 t_flit->set_time(g_eventQueue_ptr->getTime() + 1);
76
77 // This will take care of waking up the Network Link
78 m_output_unit[outport]->insert_flit(t_flit);
79 m_switch_buffer[inport]->getTopFlit();
80 m_crossbar_activity++;
81 }
82 }
83 check_for_wakeup();
84 }
85
86 void
87 Switch_d::check_for_wakeup()
88 {
89 for (int inport = 0; inport < m_num_inports; inport++) {
90 if (m_switch_buffer[inport]->isReadyForNext()) {
91 g_eventQueue_ptr->scheduleEvent(this, 1);
92 break;
93 }
94 }
95 }