feat: router utils to reunite common functions
This commit is contained in:
parent
3c6519fbe5
commit
304e5be196
6 changed files with 238 additions and 161 deletions
|
@ -63,27 +63,6 @@ void TlmRouter::initialize(){
|
|||
}
|
||||
|
||||
/******************* COMMON FUNCTIONS ********************/
|
||||
tlm_gp* TlmRouter::build_transaction(tlm_gp& trans, int dest_link){
|
||||
tlm::tlm_generic_payload* new_trans = m_mm.allocate();
|
||||
new_trans->acquire();
|
||||
new_trans->set_command(tlm::TLM_WRITE_COMMAND);
|
||||
new_trans->set_address(trans.get_address());
|
||||
new_trans->set_data_ptr(trans.get_data_ptr());
|
||||
new_trans->set_data_length(trans.get_data_length());
|
||||
new_trans->set_streaming_width(trans.get_streaming_width());
|
||||
new_trans->set_byte_enable_ptr(trans.get_byte_enable_ptr());
|
||||
new_trans->set_dmi_allowed(false);
|
||||
new_trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
|
||||
|
||||
// add id to new_transaction
|
||||
link_extension* ext = new link_extension();
|
||||
ext->link = dest_link; // set direction of connected router
|
||||
ext->data_type = get_type_from_extension(trans);
|
||||
new_trans->set_extension(ext);
|
||||
|
||||
return new_trans;
|
||||
}
|
||||
|
||||
void TlmRouter::send_begin_req(int link, tlm_gp& trans, int dest_link){
|
||||
tlm_gp* new_trans = build_transaction(trans, dest_link);
|
||||
|
||||
|
@ -129,45 +108,8 @@ bool TlmRouter::send_data(int link, int dest_link, tlm_gp& trans){
|
|||
}
|
||||
}
|
||||
|
||||
void TlmRouter::check_transaction(int link, tlm_gp& trans) {
|
||||
if(trans.is_response_error()) {
|
||||
char txt[100];
|
||||
sprintf(txt, "Transaction returned with error, response status = %s",
|
||||
trans.get_response_string().c_str());
|
||||
log_error(link, txt);
|
||||
}
|
||||
|
||||
// Log completed routing
|
||||
tlm_command cmd = trans.get_command();
|
||||
sc_dt::uint64 adr = trans.get_address();
|
||||
int* ptr = reinterpret_cast<int*>(trans.get_data_ptr());
|
||||
std::stringstream stream;
|
||||
stream << hex << adr << " check, cmd=" << (cmd ? 'W' : 'R')
|
||||
<< ", data=" << hex << *ptr;
|
||||
log_info(link, stream.str());
|
||||
// Allow the memory manager to free the transaction object
|
||||
trans.release();
|
||||
}
|
||||
|
||||
int TlmRouter::get_link_from_extension(tlm_gp& trans){
|
||||
link_extension* extension;
|
||||
trans.get_extension<link_extension>(extension);
|
||||
return extension->link;
|
||||
}
|
||||
|
||||
int TlmRouter::get_type_from_extension(tlm_gp& trans){
|
||||
link_extension* extension;
|
||||
trans.get_extension<link_extension>(extension);
|
||||
return extension->data_type;
|
||||
}
|
||||
|
||||
/******************* CS CONFIG FUNCTIONS **********************/
|
||||
bool TlmRouter::check_cs_needed(int link, int destination, tlm_gp& trans){
|
||||
int type = get_type_from_extension(trans);
|
||||
return (link != Dir::local || destination != Dir::local) &&
|
||||
(type == TYPE_INIT_STREAM || type == TYPE_END_STREAM);
|
||||
};
|
||||
|
||||
void TlmRouter::send_cs_rout_conf_msg(int link, int destination, tlm_gp& trans){
|
||||
int dest_link = Dir::local;
|
||||
unsigned char* data = new unsigned char(link | destination<<2);
|
||||
|
@ -431,25 +373,3 @@ Dir TlmRouter::routing(int link, tlm_gp& trans){
|
|||
uint8_t dest[3] = {dest_x, dest_y, dest_z};
|
||||
return xyz_routing(link, dest);
|
||||
}
|
||||
|
||||
|
||||
/******************* LOG FUNCTIONS ********************/
|
||||
void TlmRouter::log_info(uint8_t link, string msg){
|
||||
string str_link = DIR::toString(link);
|
||||
SC_REPORT_INFO(R_LOG, (router_name+":"+str_link+":"+msg).c_str());
|
||||
}
|
||||
|
||||
void TlmRouter::log_warn(uint8_t link, string msg){
|
||||
string str_link = DIR::toString(link);
|
||||
SC_REPORT_WARNING(R_LOG, (router_name+":"+str_link+":"+msg).c_str());
|
||||
}
|
||||
|
||||
void TlmRouter::log_error(uint8_t link, string msg){
|
||||
string str_link = DIR::toString(link);
|
||||
SC_REPORT_ERROR(R_LOG, (router_name+":"+str_link+":"+msg).c_str());
|
||||
}
|
||||
|
||||
void TlmRouter::log_fatal(uint8_t link, string msg){
|
||||
string str_link = DIR::toString(link);
|
||||
SC_REPORT_FATAL(R_LOG, (router_name+":"+str_link+":"+msg).c_str());
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "tlm_utils/simple_target_socket.h"
|
||||
#include "tlm_utils/peq_with_cb_and_phase.h"
|
||||
|
||||
#include "router/router_utils.h"
|
||||
#include "utils/memory_manager.h"
|
||||
#include "utils/configuration.h"
|
||||
#include "utils/utils.h"
|
||||
|
@ -45,8 +46,6 @@ using namespace tlm_utils;
|
|||
|
||||
#define NUM_LINKS Direction::num_dirs
|
||||
|
||||
DECLARE_EXTENDED_PHASE(INTERNAL_PROC_PHASE);
|
||||
|
||||
// Define an extension for the transactions
|
||||
// link always point to initiator link of transaction
|
||||
struct link_extension : tlm_extension<link_extension> {
|
||||
|
@ -96,16 +95,6 @@ class TlmRouter : public sc_module{
|
|||
*/
|
||||
void initialize();
|
||||
|
||||
/**
|
||||
* Build the transaction tp send. Called by send flit
|
||||
*
|
||||
* @param trans TLM generic payload object
|
||||
* @param dest_link destination link to send the data to
|
||||
*
|
||||
* @return created transaction
|
||||
*/
|
||||
tlm_gp* build_transaction(tlm_gp& trans, int dest_link);
|
||||
|
||||
/**
|
||||
* Send data
|
||||
*
|
||||
|
@ -115,26 +104,6 @@ class TlmRouter : public sc_module{
|
|||
*/
|
||||
bool send_data(int link, int dest_link, tlm_gp& trans);
|
||||
|
||||
/**
|
||||
* Checks transaction for errors, if no error found, log
|
||||
* transaction and release transaction object. Called when
|
||||
* transaction is completed
|
||||
*
|
||||
* @param link active link
|
||||
* @param trans TLM generic payload object
|
||||
*/
|
||||
void check_transaction(int link, tlm_gp& trans);
|
||||
|
||||
/**
|
||||
* If message is init streaming, a router_cs needs to be
|
||||
* configured
|
||||
*
|
||||
* @param link active link
|
||||
* @param destination destination link to transmit transaction
|
||||
* @param trans TLM generic payload object
|
||||
*/
|
||||
bool check_cs_needed(int link, int destination, tlm_gp& trans);
|
||||
|
||||
/**
|
||||
* Sends router_cs configuration message to local link
|
||||
*
|
||||
|
@ -248,44 +217,4 @@ class TlmRouter : public sc_module{
|
|||
* @param trans TLM generic payload object
|
||||
*/
|
||||
Dir routing(int link, tlm_gp& trans);
|
||||
|
||||
|
||||
/**
|
||||
* Get link from extension
|
||||
*
|
||||
* @param trans TLM generic payload object
|
||||
*/
|
||||
int get_link_from_extension(tlm_gp& trans);
|
||||
|
||||
/**
|
||||
* Get type from extension
|
||||
*
|
||||
* @param trans TLM generic payload object
|
||||
*/
|
||||
int get_type_from_extension(tlm_gp& trans);
|
||||
|
||||
|
||||
/** Log info
|
||||
* @param link active link
|
||||
* @param msg log message
|
||||
*/
|
||||
void log_info(uint8_t link, string msg);
|
||||
|
||||
/** Log warning
|
||||
* @param link active link
|
||||
* @param msg log message
|
||||
*/
|
||||
void log_warn(uint8_t link, string msg);
|
||||
|
||||
/** Log error
|
||||
* @param link active link
|
||||
* @param msg log message
|
||||
*/
|
||||
void log_error(uint8_t link, string msg);
|
||||
|
||||
/** Log fatal
|
||||
* @param link active link
|
||||
* @param msg log message
|
||||
*/
|
||||
void log_fatal(uint8_t link, string msg);
|
||||
};
|
|
@ -22,6 +22,9 @@
|
|||
#include "router_cs.h"
|
||||
#include "ratatoskrUtils/utils/Structures.h"
|
||||
|
||||
typedef simple_initiator_socket_tagged<TlmRouter> rout_init_socket;
|
||||
typedef simple_target_socket_tagged<TlmRouter> rout_targ_socket;
|
||||
|
||||
TlmRouterCS::TlmRouterCS(sc_module_name name, uint8_t rout_pos[3],
|
||||
uint8_t max_pos[3]):
|
||||
TlmRouter(name, rout_pos, max_pos) {
|
||||
|
@ -32,14 +35,14 @@ TlmRouterCS::~TlmRouterCS(){
|
|||
|
||||
void TlmRouterCS::initialize(){
|
||||
for(int link=0; link<NUM_LINKS; link++){
|
||||
init_socket[link] = new rout_init_socket(("csnoc_"+router_name+
|
||||
init_socket_cs[link] = new routcs_init_socket(("csnoc_"+router_name+
|
||||
"_"+to_string(link)+"_init").c_str());
|
||||
(*init_socket[link]).register_nb_transport_bw(this,
|
||||
(*init_socket_cs[link]).register_nb_transport_bw(this,
|
||||
&TlmRouterCS::nb_transport_bw_cb, link);
|
||||
|
||||
target_socket[link] = new rout_targ_socket(("csnoc_"+router_name+
|
||||
|
||||
target_socket_cs[link] = new routcs_targ_socket(("csnoc_"+router_name+
|
||||
"_"+to_string(link)+"_targ").c_str());
|
||||
(*target_socket[link]).register_nb_transport_fw(this,
|
||||
(*target_socket_cs[link]).register_nb_transport_fw(this,
|
||||
&TlmRouterCS::nb_transport_fw_cb, link);
|
||||
|
||||
valid_links[link] = false;
|
||||
|
@ -65,7 +68,6 @@ Dir TlmRouterCS::get_auto_router_map(int link){
|
|||
return auto_rout_map[link];
|
||||
}
|
||||
|
||||
|
||||
void TlmRouterCS::send_begin_req(int link, tlm_gp& trans, int dest_link){
|
||||
tlm_gp* new_trans = build_transaction(trans, dest_link);
|
||||
|
||||
|
@ -74,7 +76,7 @@ void TlmRouterCS::send_begin_req(int link, tlm_gp& trans, int dest_link){
|
|||
sc_time delay = sc_time(REQ_INIT_DELAY, UNITS_DELAY);
|
||||
|
||||
tlm_sync_enum status;
|
||||
status = (*init_socket[dest_link])->nb_transport_fw(
|
||||
status = (*init_socket_cs[dest_link])->nb_transport_fw(
|
||||
*new_trans, phase, delay);
|
||||
curr_req[dest_link] = new_trans;
|
||||
credit_counter[dest_link]--;
|
||||
|
@ -135,7 +137,7 @@ tlm_sync_enum TlmRouterCS::send_end_req(int link, tlm_gp& trans){
|
|||
// Queue the acceptance and the response with the appropriate latency
|
||||
sc_time delay = sc_time(REQ_END_DELAY, UNITS_DELAY);
|
||||
tlm_phase phase = END_REQ;
|
||||
tlm_sync_enum status = (*target_socket[link])->nb_transport_bw(
|
||||
tlm_sync_enum status = (*target_socket_cs[link])->nb_transport_bw(
|
||||
trans, phase, delay);
|
||||
if (status == TLM_COMPLETED) {
|
||||
log_warn(link,"Request completed, no response to be send");
|
||||
|
|
|
@ -43,16 +43,24 @@ DECLARE_EXTENDED_PHASE(CONF_ROUT_PHASE);
|
|||
|
||||
class TlmRouterCS : public TlmRouter{
|
||||
public:
|
||||
typedef simple_initiator_socket_tagged<TlmRouterCS> routcs_init_socket;
|
||||
typedef simple_target_socket_tagged<TlmRouterCS> routcs_targ_socket;
|
||||
|
||||
SC_HAS_PROCESS(TlmRouterCS);
|
||||
TlmRouterCS(sc_module_name name, uint8_t rout_pos[3],
|
||||
uint8_t max_pos[3]);
|
||||
~TlmRouterCS();
|
||||
|
||||
|
||||
routcs_init_socket* init_socket_cs[NUM_LINKS];
|
||||
routcs_targ_socket* target_socket_cs[NUM_LINKS];
|
||||
|
||||
|
||||
/** Setter for auto_rout_map variable
|
||||
* @param link auto_router_map index
|
||||
* @param dir direction to route to
|
||||
*/
|
||||
void set_auto_router_map(int link, Dir dir);
|
||||
|
||||
/** Getter for auto_rout_map variable
|
||||
* @param link auto_router_map index
|
||||
* @return direction to route to
|
||||
|
|
86
src/router/router_utils.cpp
Normal file
86
src/router/router_utils.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "router_utils.h"
|
||||
|
||||
namespace RouterUtils{
|
||||
tlm_gp* build_transaction(tlm_gp& trans, int dest_link){
|
||||
tlm::tlm_generic_payload* new_trans = m_mm.allocate();
|
||||
new_trans->acquire();
|
||||
new_trans->set_command(tlm::TLM_WRITE_COMMAND);
|
||||
new_trans->set_address(trans.get_address());
|
||||
new_trans->set_data_ptr(trans.get_data_ptr());
|
||||
new_trans->set_data_length(trans.get_data_length());
|
||||
new_trans->set_streaming_width(trans.get_streaming_width());
|
||||
new_trans->set_byte_enable_ptr(trans.get_byte_enable_ptr());
|
||||
new_trans->set_dmi_allowed(false);
|
||||
new_trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
|
||||
|
||||
// add id to new_transaction
|
||||
link_extension* ext = new link_extension();
|
||||
ext->link = dest_link; // set direction of connected router
|
||||
ext->data_type = get_type_from_extension(trans);
|
||||
new_trans->set_extension(ext);
|
||||
|
||||
return new_trans;
|
||||
}
|
||||
|
||||
|
||||
void check_transaction(int link, tlm_gp& trans) {
|
||||
if(trans.is_response_error()) {
|
||||
char txt[100];
|
||||
sprintf(txt, "Transaction returned with error, response status = %s",
|
||||
trans.get_response_string().c_str());
|
||||
log_error(link, txt);
|
||||
}
|
||||
|
||||
// Log completed routing
|
||||
tlm_command cmd = trans.get_command();
|
||||
sc_dt::uint64 adr = trans.get_address();
|
||||
int* ptr = reinterpret_cast<int*>(trans.get_data_ptr());
|
||||
std::stringstream stream;
|
||||
stream << hex << adr << " check, cmd=" << (cmd ? 'W' : 'R')
|
||||
<< ", data=" << hex << *ptr;
|
||||
log_info(link, stream.str());
|
||||
// Allow the memory manager to free the transaction object
|
||||
trans.release();
|
||||
}
|
||||
|
||||
|
||||
int get_link_from_extension(tlm_gp& trans){
|
||||
link_extension* extension;
|
||||
trans.get_extension<link_extension>(extension);
|
||||
return extension->link;
|
||||
}
|
||||
|
||||
int get_type_from_extension(tlm_gp& trans){
|
||||
link_extension* extension;
|
||||
trans.get_extension<link_extension>(extension);
|
||||
return extension->data_type;
|
||||
}
|
||||
|
||||
bool check_cs_needed(int link, int destination, tlm_gp& trans){
|
||||
int type = get_type_from_extension(trans);
|
||||
return (link != Dir::local || destination != Dir::local) &&
|
||||
(type == TYPE_INIT_STREAM || type == TYPE_END_STREAM);
|
||||
}
|
||||
|
||||
/******************* LOG FUNCTIONS ********************/
|
||||
void log_info(uint8_t link, string msg){
|
||||
string str_link = DIR::toString(link);
|
||||
SC_REPORT_INFO(R_LOG, (router_name+":"+str_link+":"+msg).c_str());
|
||||
}
|
||||
|
||||
void log_warn(uint8_t link, string msg){
|
||||
string str_link = DIR::toString(link);
|
||||
SC_REPORT_WARNING(R_LOG, (router_name+":"+str_link+":"+msg).c_str());
|
||||
}
|
||||
|
||||
void log_error(uint8_t link, string msg){
|
||||
string str_link = DIR::toString(link);
|
||||
SC_REPORT_ERROR(R_LOG, (router_name+":"+str_link+":"+msg).c_str());
|
||||
}
|
||||
|
||||
void log_fatal(uint8_t link, string msg){
|
||||
string str_link = DIR::toString(link);
|
||||
SC_REPORT_FATAL(R_LOG, (router_name+":"+str_link+":"+msg).c_str());
|
||||
}
|
||||
|
||||
}
|
132
src/router/router_utils.h
Normal file
132
src/router/router_utils.h
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2024 Juan Neyra
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
|
||||
#define SC_INCLUDE_DYNAMIC_PROCESSES
|
||||
#endif
|
||||
|
||||
#include <systemc>
|
||||
#include <string>
|
||||
#include "tlm.h"
|
||||
|
||||
#include "utils/memory_manager.h"
|
||||
#include "utils/configuration.h"
|
||||
#include "utils/utils.h"
|
||||
#include "utils/noc_logger.h"
|
||||
|
||||
using namespace sc_core;
|
||||
using namespace sc_dt;
|
||||
using namespace std;
|
||||
using namespace tlm;
|
||||
using namespace tlm_utils;
|
||||
|
||||
#define NUM_LINKS Direction::num_dirs
|
||||
|
||||
DECLARE_EXTENDED_PHASE(INTERNAL_PROC_PHASE);
|
||||
|
||||
|
||||
// Define an extension for the transactions
|
||||
// link always point to initiator link of transaction
|
||||
struct link_extension : tlm_extension<link_extension> {
|
||||
int link;
|
||||
int data_type;
|
||||
virtual tlm_extension_base* clone() const {
|
||||
return new link_extension(*this);
|
||||
}
|
||||
virtual void copy_from(const tlm_extension_base& ext) {
|
||||
link = static_cast<const link_extension&>(ext).link;
|
||||
data_type = static_cast<const link_extension&>(ext).data_type;
|
||||
}
|
||||
};
|
||||
|
||||
namespace RouterUtils{
|
||||
/**
|
||||
* Build the transaction tp send. Called by send flit
|
||||
*
|
||||
* @param trans TLM generic payload object
|
||||
* @param dest_link destination link to send the data to
|
||||
*
|
||||
* @return created transaction
|
||||
*/
|
||||
tlm_gp* build_transaction(tlm_gp& trans, int dest_link);
|
||||
|
||||
|
||||
/**
|
||||
* Checks transaction for errors, if no error found, log
|
||||
* transaction and release transaction object. Called when
|
||||
* transaction is completed
|
||||
*
|
||||
* @param link active link
|
||||
* @param trans TLM generic payload object
|
||||
*/
|
||||
void check_transaction(int link, tlm_gp& trans);
|
||||
|
||||
|
||||
/**
|
||||
* Get link from extension
|
||||
*
|
||||
* @param trans TLM generic payload object
|
||||
*/
|
||||
int get_link_from_extension(tlm_gp& trans);
|
||||
|
||||
/**
|
||||
* Get type from extension
|
||||
*
|
||||
* @param trans TLM generic payload object
|
||||
*/
|
||||
int get_type_from_extension(tlm_gp& trans);
|
||||
|
||||
/**
|
||||
* If message is init streaming, a router_cs needs to be
|
||||
* configured
|
||||
*
|
||||
* @param link active link
|
||||
* @param destination destination link to transmit transaction
|
||||
* @param trans TLM generic payload object
|
||||
*/
|
||||
bool check_cs_needed(int link, int destination, tlm_gp& trans);
|
||||
|
||||
/** Log info
|
||||
* @param link active link
|
||||
* @param msg log message
|
||||
*/
|
||||
void log_info(uint8_t link, string msg);
|
||||
|
||||
/** Log warning
|
||||
* @param link active link
|
||||
* @param msg log message
|
||||
*/
|
||||
void log_warn(uint8_t link, string msg);
|
||||
|
||||
/** Log error
|
||||
* @param link active link
|
||||
* @param msg log message
|
||||
*/
|
||||
void log_error(uint8_t link, string msg);
|
||||
|
||||
/** Log fatal
|
||||
* @param link active link
|
||||
* @param msg log message
|
||||
*/
|
||||
void log_fatal(uint8_t link, string msg);
|
||||
}
|
Loading…
Reference in a new issue