summaryrefslogtreecommitdiff
path: root/src/intersim/vc.cpp
blob: a1a4ff6b8b27a1498e7028695ccba4dbcec6eb24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "booksim.hpp"
#include "vc.hpp"

void VC::init( const Configuration& config, int outputs ) 
{
   _Init( config, outputs );
}

VC::VC( const Configuration& config, int outputs, 
        Module *parent, const string& name ) :
Module( parent, name )
{
   _Init( config, outputs );
}

VC::~VC( )
{
}

void VC::_Init( const Configuration& config, int outputs )
{
   _state      = idle;
   _state_time = 0;

   _size = int( config.GetInt( "vc_buf_size" ) );

   _route_set = new OutputSet( outputs );

   _occupied_cnt = 0;

   _total_cycles    = 0;
   _vc_alloc_cycles = 0;
   _active_cycles   = 0;
   _idle_cycles     = 0;

   _pri = 0;

   _watched = false;
}

bool VC::AddFlit( Flit *f )
{
   bool success = false;

   if ( (int)_buffer.size( ) != _size ) {
      _buffer.push( f );
      success = true;
   }

   return success;
}

Flit *VC::FrontFlit( )
{
   Flit *f;

   if ( !_buffer.empty( ) ) {
      f = _buffer.front( );
   } else {
      f = 0;
   }

   return f;
}

Flit *VC::RemoveFlit( )
{
   Flit *f;

   if ( !_buffer.empty( ) ) {
      f = _buffer.front( );
      _buffer.pop( );
   } else {
      f = 0;
   }

   return f;
}

bool VC::Empty( ) const
{
   return _buffer.empty( );
}

VC::eVCState VC::GetState( ) const
{
   return _state;
}

int VC::GetStateTime( ) const
{
   return _state_time;
}

void VC::SetState( eVCState s )
{
   _state = s;
   _state_time = 0;

   if ( s == active ) {
      Flit *f;

      f = FrontFlit( );
      if ( f ) {
         _pri = f->pri;
      }

      _occupied_cnt++;
   }
}

const OutputSet *VC::GetRouteSet( ) const
{
   return _route_set;
}

void VC::SetOutput( int port, int vc )
{
   _out_port = port;
   _out_vc   = vc;
}

int VC::GetOutputPort( ) const
{
   return _out_port;
}

int VC::GetOutputVC( ) const
{
   return _out_vc;
}

int VC::GetPriority( ) const
{
   return _pri;
}

void VC::Route( tRoutingFunction rf, const Router* router, const Flit* f, int in_channel )
{  
   rf( router, f, in_channel, _route_set, false );
}

void VC::AdvanceTime( )
{
   _state_time++;

   _total_cycles++;
   switch ( _state ) {
   case idle     : _idle_cycles++; break;
   case active   : _active_cycles++; break;
   case vc_alloc : _vc_alloc_cycles++; break;
   case routing  : break;
   }
}

// ==== Debug functions ====

void VC::SetWatch( bool watch )
{
   _watched = watch;
}

bool VC::IsWatched( ) const
{
   return _watched;
}

void VC::Display( ) const
{
   cout << _fullname << " : "
   << "idle " << 100.0 * (double)_idle_cycles / (double)_total_cycles << "% "
   << "vc_alloc " << 100.0 * (double)_vc_alloc_cycles / (double)_total_cycles << "% "
   << "active " << 100.0 * (double)_active_cycles / (double)_total_cycles << "% "
   << endl;
}