-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbridge_monitor.cpp
More file actions
executable file
·395 lines (344 loc) · 13 KB
/
bridge_monitor.cpp
File metadata and controls
executable file
·395 lines (344 loc) · 13 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/*
*
* Author: Tatiana Djaba Nya (Lead author)
* Author: Stephan C. Stilkerich
*
* Reference Architecture Model (EPiCS FP7 FET program, No. 257906)
* - Peter R. Lewis, University of Birmingham
* - Xin Yao, University of Birmingham
*
* Copyright (c) 2013, EADS Deutschland GmbH, EADS Innovation Works
*
*==============================================================================
*
*This file is part of ProprioSimEnv.
*
* ProprioSimEnv is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProprioSimEnv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProprioSimEnv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <systemc.h>
#include "bridge_monitor.h"
#include "constants.h"
#include "reporting.h"
#include "key_functions.h"
unsigned int m_target_idx = 3 ;
static const char *filename = "bridge_monitor.cpp"; ///< filename for reporting
static const char *filename1 = "bridge_monitor.cpp_E1"; ///< filename for reporting
static const char *filename2 = "bridge_monitor.cpp_E2"; ///< filename for reporting
static const char *suffix = "notifcount_output.m";
//=============================================================================
/// @fn bridge_monitor::bridge_monitor
//
/// @brief bridge_monitor constructor
//
/// @details
/// It declares the thread processes ( monitor_see_thread(), monitor_lm_thread() )
/// of the componenent.<br>
/// It binds the initiator and target sockets to the module.<br>
/// It sets the global quantum and initializes the local quantum of each
/// process for temporal decoupling.
//
//=============================================================================
bridge_monitor::bridge_monitor ///< constructor
( sc_core::sc_module_name module_name ///< SC module name
, const unsigned int ID ///< monitor ID
, sc_dt::uint64 mem_size ///< memory size (bytes)
, unsigned int mem_width ///< memory width (bytes)
, unsigned int lm_report_data_length ///< data length for report data from LM (bytes)
, unsigned int see_report_data_length ///< data length for report data from SEE (bytes)
, const sc_core::sc_time read_latency ///< read response delay
, const sc_core::sc_time write_latency ///< write response delay
, const sc_core::sc_time lm_read_latency_ ///< write response delay
, const sc_core::sc_time see_read_latency_ ///< write response delay
, const sc_core::sc_time glob_quantum ///< global time quantum
, unsigned int nodenbr_ ///< Position index for the vectoors of events
)
:
m_id ( ID )
, m_name ( name() )
, m_isocket ( "isocket" )
, m_tsocket ( "tsocket" )
, m_see_delay ( sc_core::SC_ZERO_TIME )
, m_lm_delay ( sc_core::SC_ZERO_TIME )
, m_see_report_dl ( see_report_data_length)
, m_lm_report_dl ( lm_report_data_length )
, m_mem
(
ID
, read_latency
, write_latency
, mem_size
, mem_width
)
, nodenbr(nodenbr_)
{
SC_THREAD(monitor_see_thread);
SC_THREAD(monitor_lm_thread);
m_qk1.set_global_quantum(glob_quantum);
m_qk2.set_global_quantum(glob_quantum);
m_qk1.reset();
m_qk2.reset();
m_isocket.bind( *this );
m_tsocket.bind( *this );
m_notifcount_file = file_ops::build_filename(m_name, suffix);
}
//=============================================================================
/// @fn bridge_monitor::monitor_see_thread
//
/// @brief Thread process E2 of the process cycle of the Node.
//
/// @details
/// It sets new transactions objects to read the report data from the SEE
/// memory. It suspends after every performed transaction and wait until
/// it receives the SEE notification.
/// <br> The funtion trtr::follow_transactions() is called before and
/// after every process synchronization to report or monitor them.
//
/// @see bridge_monitor::set_trans_Obj()
/// @see bridge_monitor::execute_trans()
/// @see trtr::follow_transactions()
//
/// @retval none
//=============================================================================
void bridge_monitor::monitor_see_thread(void) // zu bearbeiten //E2
{
std::ostringstream msg; // log message
msg.str ("");
sc_core::sc_time wait_time = sc_core::SC_ZERO_TIME;
int from_see_adr = 0;
unsigned char *data = new unsigned char[size_t(m_see_report_dl)]; ///< The size of the array in which the data is copied is set to the value of the constant variable #dl_report_data.
unsigned int burst_length = (unsigned int)ceil((double)m_see_report_dl/buswidth2);
while ( true )
{
m_see_delay = m_qk1.get_local_time();
wait( see_to_monitor_vector.at(nodenbr) );
set_target_id ( see_id_nr );
set_trans_Obj ( m_tObj, from_see_adr, data);
trtr::follow_transactions(filename2, m_name, m_id, m_see_delay, trtr::T_CALL, trtr::T_IGNORE, lmodel_id_nr);
execute_trans ( m_tObj );
m_qk1.set( m_see_delay ); // Update quantum keeper with time consumed by target
wait(wait_time);
if ( m_qk1.need_sync() ) // Check local time against quantum and sync if neccessary
{
trtr::follow_synch(filename, m_name, "E2", m_id, m_see_delay, trtr::S_NEED);
m_qk1.sync();
trtr::follow_synch(filename, m_name, "E2", m_id, m_see_delay, trtr::S_RETURN);
}
memset( data, 0, size_t(m_see_report_dl) );
}
}
//=============================================================================
/// @fn bridge_monitor::monitor_lm_thread
//
/// @brief Thread process E1 of the process cycle of the Node.
///
//
/// @details
/// It sets new transactions objects to read the report data from the LM
/// memory. It suspends after every performed transaction and wait until
/// it receives the LM notification.
/// <br> The funtion trtr::follow_transactions() is called before and
/// after every process synchronization to report or monitor them.
//
/// @see bridge_monitor::set_trans_Obj()
/// @see bridge_monitor::execute_trans()
/// @see trtr::follow_transactions()
//=============================================================================
void bridge_monitor::monitor_lm_thread(void) //E1
{
std::ostringstream msg; // log message
msg.str ("");
unsigned char *data = new unsigned char[size_t(m_lm_report_dl)];
unsigned int burst_length = (unsigned int)ceil((double)m_lm_report_dl/buswidth2);
unsigned int from_lm_adr = 0;
while( true )
{
wait(lmodel_to_monitor_vector.at(nodenbr));
m_lm_delay = m_qk2.get_local_time();
set_target_id ( lmodel_id_nr );
set_trans_Obj ( m_tObj, from_lm_adr, data );
trtr::follow_transactions(filename1, m_name, m_id, m_lm_delay, trtr::T_CALL, trtr::T_IGNORE, lmodel_id_nr);
execute_trans (m_tObj);
monitor_ev_vector.at(nodenbr).notify();
m_qk2.set( m_lm_delay ); // Update quantum keeper with time consumed by target
wait(sc_core::SC_ZERO_TIME);
if ( m_qk2.need_sync() ) // Check local time against quantum and sync if neccessary
{
trtr::follow_synch(filename, m_name, "E1", m_id, m_lm_delay, trtr::S_NEED);
m_qk2.sync();
trtr::follow_synch(filename, m_name, "E1", m_id, m_lm_delay, trtr::S_RETURN);
}
memset( data, 0, size_t(m_lm_report_dl) );
}
}
void bridge_monitor::execute_trans( tlm::tlm_generic_payload& tObj)
{
switch(m_target_idx)
{
case 0:
m_isocket -> b_transport(m_tObj, m_lm_delay);
if ( m_tObj.is_response_ok() ) //in case of a successful transaction
{
trtr::follow_transactions(filename1, m_name, m_id, m_lm_delay, trtr::T_RETURN, trtr::T_SUCCESS, lmodel_id_nr);
}
else //could not read
{
trtr::follow_transactions(filename1, m_name, m_id, m_lm_delay, trtr::T_RETURN, trtr::T_FAILURE, lmodel_id_nr , m_tObj.get_response_string().c_str() );
}
break;
case 1:
m_isocket -> b_transport(m_tObj, m_see_delay);
if ( m_tObj.is_response_ok() ) //in case of a successful transaction
{
trtr::follow_transactions(filename2, m_name, m_id, m_see_delay, trtr::T_RETURN, trtr::T_SUCCESS, see_id_nr);
}
else //could not read
{
trtr::follow_transactions(filename2, m_name, m_id, m_see_delay, trtr::T_RETURN, trtr::T_FAILURE, see_id_nr , m_tObj.get_response_string().c_str() );
}
break;
default:
break;
}
}
//=============================================================================
/// @fn bridge_monitor::b_transport
//
/// @brief Implementation of the blocking transport method for access on the
/// monitor memory.
//
//=============================================================================
void bridge_monitor::b_transport ( tlm::tlm_generic_payload& tObj,
sc_core::sc_time& delay )
{
m_mem.operation(gvoc_id_nr, tObj, delay);
}
//==============================================================================
/// @fn initiator_top::get_direct_mem_ptr
//
/// @brief It gets a direct memory pointer on the target component memory.
//
/// @details
/// not yet implemented.
//
//==============================================================================
bool bridge_monitor::get_direct_mem_ptr ( tlm::tlm_generic_payload& tObj,
tlm::tlm_dmi& dmi_data )
{
return false;
}
tlm::tlm_sync_enum bridge_monitor::nb_transport_fw ( tlm::tlm_generic_payload& tObj,
tlm::tlm_phase& phase,
sc_core::sc_time& delay )
{
return tlm::TLM_ACCEPTED;
}
unsigned int bridge_monitor::transport_dbg ( tlm::tlm_generic_payload& tObj )
{
return 0;
}
//=============================================================================
/// @fn bridge_monitor::invalidate_direct_mem_ptr
//
/// @brief invalidates a DMI pointer on the SEE or LM memory subarea which is
/// designated by the given address parameters
//
/// @details
/// not yet implemented
//
//=============================================================================
void bridge_monitor::invalidate_direct_mem_ptr ( sc_dt::uint64 start_range,
sc_dt::uint64 end_range )
{
return;
}
tlm::tlm_sync_enum bridge_monitor::nb_transport_bw ( tlm::tlm_generic_payload& tObj,
tlm::tlm_phase& phase,
sc_core::sc_time& delay )
{
return tlm::TLM_ACCEPTED;
}
//=============================================================================
/// @fn bridge_monitor::set_trans_Obj
//
/// @brief uses the given parameters to build a new transaction object for
/// each transaction initiated by the monitor component.
//
//=============================================================================
void bridge_monitor::set_trans_Obj ( tlm::tlm_generic_payload& tObj,
const sc_dt::uint64 &adr,
unsigned char* data
)
{
std::ostringstream msg;
unsigned int data_length;
switch(m_target_idx)
{
case 0: //lmodel
data_length = m_lm_report_dl;
break;
case 1: //see
data_length = m_see_report_dl;
break;
default:
msg << "\t MONITOR: " << m_id
<< "\t Invalid Target ID: "<< m_target_idx;
ERROR_LOG(filename, __FUNCTION__ , msg.str());
break;
}
tObj.set_command ( tlm::TLM_READ_COMMAND ) ;
tObj.set_address ( adr ) ;
tObj.set_data_ptr ( data ) ;
tObj.set_data_length ( data_length ) ;
tObj.set_byte_enable_ptr ( 0 ) ;
tObj.set_byte_enable_length ( 0 ) ;
tObj.set_streaming_width ( data_length ) ;
tObj.set_gp_option ( tlm::TLM_MIN_PAYLOAD ) ;
tObj.set_dmi_allowed ( false ) ;
tObj.set_response_status ( tlm::TLM_INCOMPLETE_RESPONSE );
}
//=============================================================================
/// @fn bridge_monitor::set_target_id
//
/// @brief indicates the target of a monitor transaction
//
/// @details
/// sets \a m_target_idx to \a 0 if the target is the LModel component
/// or to \a 1 if the target is the see component.
//
/// @param id predefined ID of a component
//
//=============================================================================
void bridge_monitor::set_target_id ( const unsigned int &id )
{
std::ostringstream msg;
msg.str("");
switch(id)
{
case lmodel_id_nr:
m_target_idx = 0;
break;
case see_id_nr:
m_target_idx = 1;
break;
default:
msg << "\t MONITOR: " << m_id
<< "\t Invalid Target ID: "<< id;
INFO_LOG(filename, __FUNCTION__ , msg.str());
m_target_idx = 3;
break;
}
}