Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
eyck committed Sep 30, 2022
2 parents e2dea44 + ebc5c4f commit 8785c03
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 67 deletions.
7 changes: 7 additions & 0 deletions cmake/FindVerilator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ set_source_files_properties(
set(SOURCES
${VERILATOR_INCLUDE_DIR}/verilated.cpp
${VERILATOR_INCLUDE_DIR}/verilated_cov.cpp
# ${VERILATOR_INCLUDE_DIR}/verilated_threads.cpp
${VERILATOR_INCLUDE_DIR}/verilated_dpi.cpp
${VERILATOR_INCLUDE_DIR}/verilated_vcd_c.cpp
${VERILATOR_INCLUDE_DIR}/verilated_vcd_sc.cpp
)
if(EXISTS ${VERILATOR_INCLUDE_DIR}/verilated_fst_sc.cpp)
list(APPEND SOURCES
${VERILATOR_INCLUDE_DIR}/verilated_fst_c.cpp
${VERILATOR_INCLUDE_DIR}/verilated_fst_sc.cpp
)
endif()

add_library(verilated STATIC ${SOURCES})

Expand Down
2 changes: 1 addition & 1 deletion src/components/scc/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class sc_register : public sc_core::sc_object, public resource_access_if, public
*
* @param trf the trace file
*/
void trace(sc_core::sc_trace_file* trf) const override { sc_trace(trf, storage, this->name()); }
void trace(sc_core::sc_trace_file* trf) const override { sc_core::sc_trace(trf, storage, this->name()); }
//! \brief the reset value
const DATATYPE res_val;
//! \brief the SW read mask
Expand Down
2 changes: 1 addition & 1 deletion src/sysc/scc/configurer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void configurer::config_check() {

void init_cci(std::string name) {
#ifdef HAS_CCI
thread_local static cci_utils::broker broker(name);
thread_local cci_utils::broker broker(name);
cci::cci_register_broker(&broker);
#endif
}
Expand Down
140 changes: 77 additions & 63 deletions src/sysc/scc/report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ thread_local std::unordered_map<uint64_t, sc_core::sc_verbosity> lut;
thread_local cci::cci_originator originator("reporting");
#endif

bool& inst_based_logging() {
thread_local bool active = getenv("SCC_DISABLE_INSTANCE_BASED_LOGGING")==nullptr;
return active;
}

struct ExtLogConfig : public scc::LogConfig {
shared_ptr<spdlog::logger> file_logger;
shared_ptr<spdlog::logger> console_logger;
Expand Down Expand Up @@ -113,11 +118,11 @@ auto get_tuple(const sc_time& t) -> tuple<sc_time::value_type, sc_time_unit> {
auto time2string(const sc_time& t) -> string {
const array<const char*, 6> time_units{"fs", "ps", "ns", "us", "ms", "s "};
const array<uint64_t, 6> multiplier{1ULL,
1000ULL,
1000ULL * 1000,
1000ULL * 1000 * 1000,
1000ULL * 1000 * 1000 * 1000,
1000ULL * 1000 * 1000 * 1000 * 1000};
1000ULL,
1000ULL * 1000,
1000ULL * 1000 * 1000,
1000ULL * 1000 * 1000 * 1000,
1000ULL * 1000 * 1000 * 1000 * 1000};
ostringstream oss;
if(!t.value()) {
oss << "0 s ";
Expand All @@ -139,17 +144,17 @@ auto time2string(const sc_time& t) -> string {
}
auto compose_message(const sc_report& rep, const scc::LogConfig& cfg) -> const string {
if(rep.get_severity() > SC_INFO || cfg.log_filter_regex.length() == 0 ||
rep.get_verbosity() == sc_core::SC_MEDIUM || log_cfg.match(rep.get_msg_type())) {
rep.get_verbosity() == sc_core::SC_MEDIUM || log_cfg.match(rep.get_msg_type())) {
stringstream os;
if(likely(cfg.print_sim_time)) {
if(unlikely(log_cfg.cycle_base.value())) {
if(unlikely(cfg.print_delta))
os << "[" << std::setw(7) << std::setfill(' ')
<< sc_time_stamp().value() / log_cfg.cycle_base.value() << "(" << setw(5) << sc_delta_count()
<< ")]";
<< sc_time_stamp().value() / log_cfg.cycle_base.value() << "(" << setw(5) << sc_delta_count()
<< ")]";
else
os << "[" << std::setw(7) << std::setfill(' ')
<< sc_time_stamp().value() / log_cfg.cycle_base.value() << "]";
<< sc_time_stamp().value() / log_cfg.cycle_base.value() << "]";
} else {
auto t = time2string(sc_time_stamp());
if(unlikely(cfg.print_delta))
Expand All @@ -160,7 +165,7 @@ auto compose_message(const sc_report& rep, const scc::LogConfig& cfg) -> const s
}
if(unlikely(rep.get_id() >= 0))
os << "("
<< "IWEF"[rep.get_severity()] << rep.get_id() << ") " << rep.get_msg_type() << ": ";
<< "IWEF"[rep.get_severity()] << rep.get_id() << ") " << rep.get_msg_type() << ": ";
else if(cfg.msg_type_field_width) {
if(cfg.msg_type_field_width==std::numeric_limits<unsigned>::max())
os << rep.get_msg_type() << ": ";
Expand All @@ -186,7 +191,7 @@ auto compose_message(const sc_report& rep, const scc::LogConfig& cfg) -> const s

inline auto get_verbosity(const sc_report& rep) -> int {
return rep.get_verbosity() > sc_core::SC_NONE && rep.get_verbosity() < sc_core::SC_LOW ? rep.get_verbosity() * 10
: rep.get_verbosity();
: rep.get_verbosity();
}

inline void log2logger(spdlog::logger& logger, const sc_report& rep, const scc::LogConfig& cfg) {
Expand All @@ -208,17 +213,17 @@ inline void log2logger(spdlog::logger& logger, const sc_report& rep, const scc::
break;
}
break;
case SC_WARNING:
logger.warn(msg);
break;
case SC_ERROR:
logger.error(msg);
break;
case SC_FATAL:
logger.critical(msg);
break;
default:
break;
case SC_WARNING:
logger.warn(msg);
break;
case SC_ERROR:
logger.error(msg);
break;
case SC_FATAL:
logger.critical(msg);
break;
default:
break;
}
}

Expand Down Expand Up @@ -253,7 +258,7 @@ void report_handler(const sc_report& rep, const sc_actions& actions) {
if(actions & SC_DO_NOTHING)
return;
if(rep.get_severity() == sc_core::SC_INFO || !log_cfg.report_only_first_error ||
sc_report_handler::get_count(SC_ERROR) < 2) {
sc_report_handler::get_count(SC_ERROR) < 2) {
if((actions & SC_DISPLAY) && (!log_cfg.file_logger || get_verbosity(rep) < SC_HIGH))
log2logger(*log_cfg.console_logger, rep, log_cfg);
if((actions & SC_LOG) && log_cfg.file_logger) {
Expand Down Expand Up @@ -323,21 +328,21 @@ auto scc::stream_redirection::xsputn(const char_type* s, streamsize n) -> stream
}

static const array<sc_severity, 8> severity = {SC_FATAL, // scc::log::NONE
SC_FATAL, // scc::log::FATAL
SC_ERROR, // scc::log::ERROR
SC_WARNING, // scc::log::WARNING
SC_INFO, // scc::log::INFO
SC_INFO, // scc::log::DEBUG
SC_INFO, // scc::log::TRACE
SC_INFO}; // scc::log::DBGTRACE
SC_FATAL, // scc::log::FATAL
SC_ERROR, // scc::log::ERROR
SC_WARNING, // scc::log::WARNING
SC_INFO, // scc::log::INFO
SC_INFO, // scc::log::DEBUG
SC_INFO, // scc::log::TRACE
SC_INFO}; // scc::log::DBGTRACE
static const array<sc_verbosity, 8> verbosity = {SC_NONE, // scc::log::NONE
SC_LOW, // scc::log::FATAL
SC_LOW, // scc::log::ERROR
SC_LOW, // scc::log::WARNING
SC_MEDIUM, // scc::log::INFO
SC_HIGH, // scc::log::DEBUG
SC_FULL, // scc::log::TRACE
SC_DEBUG}; // scc::log::DBGTRACE
SC_LOW, // scc::log::FATAL
SC_LOW, // scc::log::ERROR
SC_LOW, // scc::log::WARNING
SC_MEDIUM, // scc::log::INFO
SC_HIGH, // scc::log::DEBUG
SC_FULL, // scc::log::TRACE
SC_DEBUG}; // scc::log::DBGTRACE

auto scc::stream_redirection::sync() -> int {
if(level <= log_cfg.level) {
Expand All @@ -346,7 +351,7 @@ auto scc::stream_redirection::sync() -> int {
string line;
while(getline(buf, line)) {
::sc_report_handler::report(severity[static_cast<unsigned>(level)], "SystemC", line.c_str(),
verbosity[static_cast<unsigned>(level)], "", 0);
verbosity[static_cast<unsigned>(level)], "", 0);
}
str(string(""));
}
Expand All @@ -361,16 +366,17 @@ static void configure_logging() {
if(!log_cfg.dont_create_broker)
scc::init_cci("SCCBroker");
#endif

if(!log_cfg.instance_based_log_levels || getenv("SCC_DISABLE_INSTANCE_BASED_LOGGING"))
inst_based_logging()=false;
sc_report_handler::set_actions(SC_ERROR, SC_DEFAULT_ERROR_ACTIONS | SC_DISPLAY);
sc_report_handler::set_actions(SC_FATAL, SC_DEFAULT_FATAL_ACTIONS);
sc_report_handler::set_verbosity_level(verbosity[static_cast<unsigned>(log_cfg.level)]);
sc_report_handler::set_handler(report_handler);
if(!spdlog_initialized) {
spdlog::init_thread_pool(1024U,
log_cfg.log_file_name.size() ? 2U : 1U); // queue with 8k items and 1 backing thread.
log_cfg.log_file_name.size() ? 2U : 1U); // queue with 8k items and 1 backing thread.
log_cfg.console_logger = log_cfg.log_async ? spdlog::stdout_color_mt<spdlog::async_factory>("console_logger")
: spdlog::stdout_color_mt("console_logger");
: spdlog::stdout_color_mt("console_logger");
auto logger_fmt = log_cfg.print_severity ? "[%L] %v" : "%v";
if(log_cfg.colored_output) {
std::ostringstream os;
Expand All @@ -386,8 +392,8 @@ static void configure_logging() {
ofs.open(log_cfg.log_file_name, ios::out | ios::trunc);
}
log_cfg.file_logger =
log_cfg.log_async ? spdlog::basic_logger_mt<spdlog::async_factory>("file_logger", log_cfg.log_file_name)
: spdlog::basic_logger_mt("file_logger", log_cfg.log_file_name);
log_cfg.log_async ? spdlog::basic_logger_mt<spdlog::async_factory>("file_logger", log_cfg.log_file_name)
: spdlog::basic_logger_mt("file_logger", log_cfg.log_file_name);
if(log_cfg.print_severity)
log_cfg.file_logger->set_pattern("[%8l] %v");
else
Expand All @@ -414,6 +420,8 @@ void scc::reinit_logging(scc::log level) {
sc_report_handler::set_handler(report_handler);
log_cfg.level = level;
lut.clear();
if(!log_cfg.instance_based_log_levels || getenv("SCC_DISABLE_INSTANCE_BASED_LOGGING"))
inst_based_logging()=false;
}

void scc::init_logging(scc::log level, unsigned type_field_width, bool print_time) {
Expand All @@ -432,7 +440,7 @@ void scc::set_logging_level(scc::log level) {
log_cfg.level = level;
sc_report_handler::set_verbosity_level(verbosity[static_cast<unsigned>(level)]);
log_cfg.console_logger->set_level(static_cast<spdlog::level::level_enum>(
SPDLOG_LEVEL_OFF - min<int>(SPDLOG_LEVEL_OFF, static_cast<int>(log_cfg.level))));
SPDLOG_LEVEL_OFF - min<int>(SPDLOG_LEVEL_OFF, static_cast<int>(log_cfg.level))));
}

auto scc::get_logging_level() -> scc::log { return log_cfg.level; }
Expand Down Expand Up @@ -508,28 +516,34 @@ auto scc::LogConfig::reportOnlyFirstError(bool v) -> scc::LogConfig& {
this->report_only_first_error = v;
return *this;
}
auto scc::LogConfig::instanceBasedLogLevels(bool v) -> scc::LogConfig& {
this->instance_based_log_levels = v;
return *this;
}

auto scc::get_log_verbosity(char const* str) -> sc_core::sc_verbosity {
#ifdef HAS_CCI
auto k = char_hash(str);
auto it = lut.find(k);
if(it != lut.end())
return it->second;
if(strchr(str, '.') == nullptr || sc_core::sc_get_current_object()) {
auto broker = sc_core::sc_get_current_object()? cci::cci_get_broker(): cci::cci_get_global_broker(originator);
auto param_name = std::string(str) + "." SCC_LOG_LEVEL_PARAM_NAME;
auto h = broker.get_param_handle<unsigned>(param_name);
if(h.is_valid()) {
sc_core::sc_verbosity ret = verbosity.at(std::min<unsigned>(h.get_value(), verbosity.size() - 1));
lut[k] = ret;
return ret;
} else {
auto val = broker.get_preset_cci_value(param_name);
auto global_verb = static_cast<sc_core::sc_verbosity>(::sc_core::sc_report_handler::get_verbosity_level());
sc_core::sc_verbosity ret =
val.is_int() ? verbosity.at(std::min<unsigned>(val.get_int(), verbosity.size() - 1)) : global_verb;
lut[k] = ret;
return ret;
if(inst_based_logging()){
auto k = char_hash(str);
auto it = lut.find(k);
if(it != lut.end())
return it->second;
if(strchr(str, '.') == nullptr || sc_core::sc_get_current_object()) {
auto broker = sc_core::sc_get_current_object()? cci::cci_get_broker(): cci::cci_get_global_broker(originator);
auto param_name = std::string(str) + "." SCC_LOG_LEVEL_PARAM_NAME;
auto h = broker.get_param_handle<unsigned>(param_name);
if(h.is_valid()) {
sc_core::sc_verbosity ret = verbosity.at(std::min<unsigned>(h.get_value(), verbosity.size() - 1));
lut[k] = ret;
return ret;
} else {
auto val = broker.get_preset_cci_value(param_name);
auto global_verb = static_cast<sc_core::sc_verbosity>(::sc_core::sc_report_handler::get_verbosity_level());
sc_core::sc_verbosity ret =
val.is_int() ? verbosity.at(std::min<unsigned>(val.get_int(), verbosity.size() - 1)) : global_verb;
lut[k] = ret;
return ret;
}
}
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/sysc/scc/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct LogConfig {
bool log_async{true};
bool dont_create_broker{false};
bool report_only_first_error{false};
bool instance_based_log_levels{true};

//! set the logging level
LogConfig& logLevel(log);
Expand Down Expand Up @@ -193,6 +194,8 @@ struct LogConfig {
LogConfig& dontCreateBroker(bool = true);
//! disable/enable the supression of all error messages after the first error
LogConfig& reportOnlyFirstError(bool = true);
//! disable/enable the supression of all error messages after the first error
LogConfig& instanceBasedLogLevels(bool = true);
};
/**
* @fn void init_logging(const LogConfig&)
Expand Down
6 changes: 5 additions & 1 deletion src/sysc/scc/sc_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

#include <array>
#include <functional>
#include <scc/observer.h>
#include "observer.h"
#include "report.h"
#include <sstream>
#include <sysc/kernel/sc_event.h>
#include <sysc/kernel/sc_simcontext.h>
Expand Down Expand Up @@ -382,6 +383,9 @@ template <typename T> struct sc_variable_vector {
sc_variable<T>& operator[](size_t idx) {
auto ret = values.at(idx);
if(!ret) {
if(sc_core::sc_get_curr_simcontext()->elaboration_done())
SCCFATAL(sc_core::sc_get_current_object()->name())<<"Trying to create a sc_variable vector entry in "<<name <<
" with index "<<idx<<" while elaboration finished is not allowed";
assert(!sc_core::sc_get_curr_simcontext()->elaboration_done());
assert(creator);
std::stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion third_party/axi_chi

0 comments on commit 8785c03

Please sign in to comment.