1/*
2 * Copyright (c) 2008 Princeton University
3 * Copyright (c) 2016 Georgia Institute of Technology
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 * Authors: Niket Agarwal
30 *          Tushar Krishna
31 */
32
33
34#ifndef __MEM_RUBY_NETWORK_GARNET2_0_INPUTUNIT_HH__
35#define __MEM_RUBY_NETWORK_GARNET2_0_INPUTUNIT_HH__
36
37#include <iostream>
38#include <vector>
39
40#include "mem/ruby/common/Consumer.hh"
41#include "mem/ruby/network/garnet2.0/CommonTypes.hh"
42#include "mem/ruby/network/garnet2.0/CreditLink.hh"
43#include "mem/ruby/network/garnet2.0/NetworkLink.hh"
44#include "mem/ruby/network/garnet2.0/Router.hh"
45#include "mem/ruby/network/garnet2.0/VirtualChannel.hh"
46#include "mem/ruby/network/garnet2.0/flitBuffer.hh"
47
48class InputUnit : public Consumer
49{
50  public:
51    InputUnit(int id, PortDirection direction, Router *router);
52    ~InputUnit();
53
54    void wakeup();
55    void print(std::ostream& out) const {};
56
57    inline PortDirection get_direction() { return m_direction; }
58
59    inline void
60    set_vc_idle(int vc, Cycles curTime)
61    {
62        m_vcs[vc]->set_idle(curTime);
63    }
64
65    inline void
66    set_vc_active(int vc, Cycles curTime)
67    {
68        m_vcs[vc]->set_active(curTime);
69    }
70
71    inline void
72    grant_outport(int vc, int outport)
73    {
74        m_vcs[vc]->set_outport(outport);
75    }
76
77    inline void
78    grant_outvc(int vc, int outvc)
79    {
80        m_vcs[vc]->set_outvc(outvc);
81    }
82
83    inline int
84    get_outport(int invc)
85    {
86        return m_vcs[invc]->get_outport();
87    }
88
89    inline int
90    get_outvc(int invc)
91    {
92        return m_vcs[invc]->get_outvc();
93    }
94
95    inline Cycles
96    get_enqueue_time(int invc)
97    {
98        return m_vcs[invc]->get_enqueue_time();
99    }
100
101    void increment_credit(int in_vc, bool free_signal, Cycles curTime);
102
103    inline flit*
104    peekTopFlit(int vc)
105    {
106        return m_vcs[vc]->peekTopFlit();
107    }
108
109    inline flit*
110    getTopFlit(int vc)
111    {
112        return m_vcs[vc]->getTopFlit();
113    }
114
115    inline bool
116    need_stage(int vc, flit_stage stage, Cycles time)
117    {
118        return m_vcs[vc]->need_stage(stage, time);
119    }
120
121    inline bool
122    isReady(int invc, Cycles curTime)
123    {
124        return m_vcs[invc]->isReady(curTime);
125    }
126
127    flitBuffer* getCreditQueue() { return creditQueue; }
128
129    inline void
130    set_in_link(NetworkLink *link)
131    {
132        m_in_link = link;
133    }
134
135    inline int get_inlink_id() { return m_in_link->get_id(); }
136
137    inline void
138    set_credit_link(CreditLink *credit_link)
139    {
140        m_credit_link = credit_link;
141    }
142
143    double get_buf_read_activity(unsigned int vnet) const
144    { return m_num_buffer_reads[vnet]; }
145    double get_buf_write_activity(unsigned int vnet) const
146    { return m_num_buffer_writes[vnet]; }
147
148    uint32_t functionalWrite(Packet *pkt);
149    void resetStats();
150
151  private:
152    int m_id;
153    PortDirection m_direction;
154    int m_num_vcs;
155    int m_vc_per_vnet;
156
157    Router *m_router;
158    NetworkLink *m_in_link;
159    CreditLink *m_credit_link;
160    flitBuffer *creditQueue;
161
162    // Input Virtual channels
163    std::vector<VirtualChannel *> m_vcs;
164
165    // Statistical variables
166    std::vector<double> m_num_buffer_writes;
167    std::vector<double> m_num_buffer_reads;
168};
169
170#endif // __MEM_RUBY_NETWORK_GARNET2_0_INPUTUNIT_HH__
171