flit.hh revision 12492
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_FLIT_HH__
35#define __MEM_RUBY_NETWORK_GARNET2_0_FLIT_HH__
36
37#include <cassert>
38#include <iostream>
39
40#include "base/types.hh"
41#include "mem/ruby/network/garnet2.0/CommonTypes.hh"
42#include "mem/ruby/slicc_interface/Message.hh"
43
44class flit
45{
46  public:
47    flit() {}
48    flit(int id, int vc, int vnet, RouteInfo route, int size,
49         MsgPtr msg_ptr, Cycles curTime);
50
51    int get_outport() {return m_outport; }
52    int get_size() { return m_size; }
53    Cycles get_enqueue_time() { return m_enqueue_time; }
54    Cycles get_dequeue_time() { return m_dequeue_time; }
55    int get_id() { return m_id; }
56    Cycles get_time() { return m_time; }
57    int get_vnet() { return m_vnet; }
58    int get_vc() { return m_vc; }
59    RouteInfo get_route() { return m_route; }
60    MsgPtr& get_msg_ptr() { return m_msg_ptr; }
61    flit_type get_type() { return m_type; }
62    std::pair<flit_stage, Cycles> get_stage() { return m_stage; }
63    Cycles get_src_delay() { return src_delay; }
64
65    void set_outport(int port) { m_outport = port; }
66    void set_time(Cycles time) { m_time = time; }
67    void set_vc(int vc) { m_vc = vc; }
68    void set_route(RouteInfo route) { m_route = route; }
69    void set_src_delay(Cycles delay) { src_delay = delay; }
70    void set_dequeue_time(Cycles time) { m_dequeue_time = time; }
71
72    void increment_hops() { m_route.hops_traversed++; }
73    void print(std::ostream& out) const;
74
75    bool
76    is_stage(flit_stage stage, Cycles time)
77    {
78        return (stage == m_stage.first &&
79                time >= m_stage.second);
80    }
81
82    void
83    advance_stage(flit_stage t_stage, Cycles newTime)
84    {
85        m_stage.first = t_stage;
86        m_stage.second = newTime;
87    }
88
89    static bool
90    greater(flit* n1, flit* n2)
91    {
92        if (n1->get_time() == n2->get_time()) {
93            //assert(n1->flit_id != n2->flit_id);
94            return (n1->get_id() > n2->get_id());
95        } else {
96            return (n1->get_time() > n2->get_time());
97        }
98    }
99
100    bool functionalWrite(Packet *pkt);
101
102  protected:
103    int m_id;
104    int m_vnet;
105    int m_vc;
106    RouteInfo m_route;
107    int m_size;
108    Cycles m_enqueue_time, m_dequeue_time, m_time;
109    flit_type m_type;
110    MsgPtr m_msg_ptr;
111    int m_outport;
112    Cycles src_delay;
113    std::pair<flit_stage, Cycles> m_stage;
114};
115
116inline std::ostream&
117operator<<(std::ostream& out, const flit& obj)
118{
119    obj.print(out);
120    out << std::flush;
121    return out;
122}
123
124#endif // __MEM_RUBY_NETWORK_GARNET2_0_FLIT_HH__
125