Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/sysc/scc/async_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include <future>
#include <scc/report.h>
#include <sysc/communication/sc_prim_channel.h>
#include <sysc/kernel/sc_object.h>
#include <sysc/kernel/sc_simcontext.h>
#include <systemc>
#include <thread>

namespace scc {
struct async_thread : sc_core::sc_prim_channel {

async_thread() = default;
async_thread()
: sc_core::sc_prim_channel{sc_core::sc_gen_unique_name("async_thread")} {}

explicit async_thread(const char* nm)
: sc_core::sc_prim_channel{nm} {}
Expand All @@ -22,7 +24,7 @@ struct async_thread : sc_core::sc_prim_channel {
}

void start(std::function<sc_core::sc_time()> const& f) {
SCCTRACE(SCMOD) << "Starting new thread";
SCCTRACE(SCOBJ) << "Starting new thread";
t1 = std::move(std::thread([this, f]() {
try {
finish_time.store(f().value());
Expand All @@ -41,7 +43,7 @@ struct async_thread : sc_core::sc_prim_channel {
auto end_time = sc_core::sc_time::from_value(finish_time.load());
finish_event.notify(end_time > sc_core::sc_time_stamp() ? end_time - sc_core::sc_time_stamp() : sc_core::SC_ZERO_TIME);
active = false;
SCCTRACEALL(SCOBJ) << "Finished execution of thread";
SCCTRACE(SCOBJ) << "Finished execution of thread";
}
std::thread t1;
sc_core::sc_event finish_event;
Expand Down
6 changes: 6 additions & 0 deletions src/sysc/scc/peq.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <boost/optional.hpp>
#include <deque>
#include <limits>
#include <map>
#include <systemc>
#include <type_traits>
Expand Down Expand Up @@ -168,6 +169,11 @@ template <class TYPE> struct peq : public sc_core::sc_object {
*/
bool has_next() { return !(m_scheduled_events.empty() || m_scheduled_events.begin()->first > sc_core::sc_time_stamp()); }

sc_core::sc_time get_next_time_stamp() {
return m_scheduled_events.empty() ? sc_core::sc_time::from_value(std::numeric_limits<sc_core::sc_time::value_type>::max())
: m_scheduled_events.begin()->first;
}

void clear() {
while(!m_scheduled_events.empty()) {
auto queue = m_scheduled_events.begin()->second;
Expand Down
18 changes: 9 additions & 9 deletions src/sysc/scc/report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ auto scc::stream_redirection::sync() -> int {

static void configure_logging() {
std::lock_guard<mutex> lock(log_cfg.mtx);
std::lock_guard<mutex> lock2(verbosity_mtx);
static bool spdlog_initialized = false;
if(!log_cfg.dont_create_broker)
scc::init_cci("SCCBroker");
Expand Down Expand Up @@ -514,6 +515,7 @@ void scc::init_logging(const scc::LogConfig& log_config) {
}

void scc::set_logging_level(scc::log level) {
std::lock_guard<mutex> lock(verbosity_mtx);
log_cfg.level = level;
sc_report_handler::set_verbosity_level(verbosity[static_cast<unsigned>(level)]);
log_cfg.console_logger->set_level(
Expand Down Expand Up @@ -604,8 +606,8 @@ auto scc::LogConfig::installHandler(bool v) -> scc::LogConfig& {
}
namespace {
std::mutex mtx;
sc_core::sc_verbosity __get_log_verbosity(string current_name, char const* str, cci::cci_broker_handle const& broker,
sc_core::sc_verbosity verb) {
auto get_log_verbosity_from_broker(string current_name, char const* str, cci::cci_broker_handle const& broker, sc_core::sc_verbosity verb)
-> sc_core::sc_verbosity {
std::lock_guard<std::mutex> lk(mtx);
while(true) {
string param_name = (current_name.empty()) ? SCC_LOG_LEVEL_PARAM_NAME : current_name + "." SCC_LOG_LEVEL_PARAM_NAME;
Expand Down Expand Up @@ -633,15 +635,13 @@ sc_core::sc_verbosity __get_log_verbosity(string current_name, char const* str,
}
}
}
return verb;
}
return verb;
}
} // namespace

auto scc::get_log_verbosity(char const* str) -> sc_core::sc_verbosity {
std::unique_lock<std::mutex> lock(verbosity_mtx);
auto global_verb = static_cast<sc_core::sc_verbosity>(::sc_core::sc_report_handler::get_verbosity_level());
lock.unlock();
auto global_verb = verbosity[static_cast<unsigned>(log_cfg.level)];
if(inst_based_logging()) {
auto res = lut.get(str);
if(std::get<0>(res))
Expand All @@ -650,10 +650,10 @@ auto scc::get_log_verbosity(char const* str) -> sc_core::sc_verbosity {
if(strchr(str, '.') == nullptr || curr_object) {
string current_name = std::string(str);
if(log_cfg.broker)
return __get_log_verbosity(current_name, str, log_cfg.broker.value(), global_verb);
return get_log_verbosity_from_broker(current_name, str, log_cfg.broker.value(), global_verb);
else {
return __get_log_verbosity(current_name, str, curr_object ? cci::cci_get_broker() : cci::cci_get_global_broker(originator),
global_verb);
return get_log_verbosity_from_broker(
current_name, str, curr_object ? cci::cci_get_broker() : cci::cci_get_global_broker(originator), global_verb);
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/sysc/scc/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,16 @@ template <sc_core::sc_severity SEVERITY> struct ScLogger {
*
*/
virtual ~ScLogger() noexcept(false) {
std::lock_guard<std::mutex> lock(verbosity_mtx);
auto verb = ::sc_core::sc_report_handler::set_verbosity_level(1000);
int verb = 100;
{
std::lock_guard<std::mutex> lock(verbosity_mtx);
verb = ::sc_core::sc_report_handler::set_verbosity_level(1000);
}
::sc_core::sc_report_handler::report(SEVERITY, t ? t : "SystemC", os.str().c_str(), level, file, line);
::sc_core::sc_report_handler::set_verbosity_level(verb);
{
std::lock_guard<std::mutex> lock(verbosity_mtx);
::sc_core::sc_report_handler::set_verbosity_level(verb);
}
}
/**
* @fn ScLogger& type()
Expand Down
21 changes: 11 additions & 10 deletions src/sysc/tlm/scc/qk/global_time_keeper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "global_time_keeper.h"
#include <limits>
#include <tlm_utils/tlm_quantumkeeper.h>

namespace tlm {
Expand All @@ -11,7 +12,7 @@ global_time_keeper::global_time_keeper() = default;

global_time_keeper::~global_time_keeper() {
// shutting down time keeper thread
stop_it.store(true, std::memory_order_acq_rel);
stop_it.store(true);
update.notify_all();
}
// this function will be called from the systemc thread
Expand Down Expand Up @@ -39,12 +40,11 @@ void global_time_keeper::sync_local_times() {
#ifdef DEBUG_MT_SCHEDULING
SCCTRACEALL("global_time_keeper::sync_local_times") << "update loop";
#endif
uint64_t min_local_time = std::numeric_limits<uint64_t>::max();
bool tail = false;
while(auto res = sc_coms_channel.client2time_keeper.front()) {
sc_coms_channel.thread_local_time = res->time_tick;
sc_coms_channel.client2time_keeper.pop();
}
uint64_t min_local_time = std::numeric_limits<uint64_t>::max();
for(size_t i = 0; i < client_coms_channels.size(); ++i) {
auto& client_coms_channel = client_coms_channels[i];
bool has_task = false;
Expand Down Expand Up @@ -74,14 +74,15 @@ void global_time_keeper::sync_local_times() {
}
#endif
}
window_min_time = min_local_time;
sc_coms_channel.time_keeper2client.store(min_local_time);
auto window_max_time = min_local_time + std::max(tlm::tlm_global_quantum::instance().get().value(), sc_time_step.value());
for(auto& client_coms_channel : client_coms_channels) {
client_coms_channel.time_keeper2client.store(window_max_time);
}
// if all threads are blocked by SystemC use SystemC time as minimum time
if(min_local_time == std::numeric_limits<uint64_t>::max())
min_local_time = sc_coms_channel.thread_local_time;
client_min_time = min_local_time;
// client_max_time = max_local_time;
client_max_time = min_local_time + std::max(tlm::tlm_global_quantum::instance().get().value(), sc_time_step.value());
sc_kernel_time = sc_coms_channel.thread_local_time;
#ifdef DEBUG_MT_SCHEDULING
SCCTRACEALL("global_time_keeper::sync_local_times") << "window_min_time=" << window_min_time;
SCCTRACEALL("global_time_keeper::sync_local_times") << "window_min_time=" << client_min_time;
#endif
} else if(stop_it.load()) {
break;
Expand Down
15 changes: 7 additions & 8 deletions src/sysc/tlm/scc/qk/global_time_keeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ struct global_time_keeper {
*
* @return uint64_t the absolute number of ticks
*/
inline uint64_t get_min_time_ticks() { return window_min_time; }
inline uint64_t get_client_min_time_ticks() { return client_min_time; }
/**
* @brief Get the maximum time ticks a client thread is allowed to advance
*
* @param idx the id of the client thread, to be obtained using get_channel_index()
* @return uint64_t the absolute number of maximum ticks, if no new information it returns -1
*/
inline uint64_t get_max_time_ticks(size_t idx) { return client_coms_channels[idx].time_keeper2client.load(); }
inline uint64_t get_client_max_time_ticks(size_t idx) { return client_max_time; }
/**
* @brief updates the global time keeper with the local time ticks of a clinet thread
*
* @param idx the id of the client thread, to be obtained using get_channel_index()
* @param tick the absolute number of actual ticks
*/
inline void update_time_ticks(size_t idx, uint64_t tick) {
inline void update_client_time_ticks(size_t idx, uint64_t tick) {
client_coms_channels[idx].client2time_keeper.push(std::move(comms_entry{tick, std::move(callback_task())}));
update_it.store(true);
std::unique_lock<std::mutex> lk(upd_mtx);
Expand All @@ -78,17 +78,14 @@ struct global_time_keeper {
*
* @return uint64_t the absolute number of ticks
*/
inline uint64_t get_max_sc_time_ticks() { return sc_coms_channel.time_keeper2client.load(); }
inline uint64_t get_sc_time_ticks() { return sc_kernel_time.load(); }
/**
* @brief updates the global time keeper with the local time ticks of the SystemC thread
*
* @param tick the absolute number of actual SystemC ticks
*/
inline void update_sc_time_ticks(uint64_t tick) {
sc_coms_channel.client2time_keeper.push(std::move(comms_entry{tick, std::move(callback_task())}));
#ifdef DEBUG_MT_SCHEDULING
SCCTRACEALL("global_time_keeper::update_sc_time_ticks") << "sc_time=" << sc_core::sc_time::from_value(tick);
#endif
update_it.store(true);
std::unique_lock<std::mutex> lk(upd_mtx);
update.notify_all();
Expand All @@ -111,7 +108,9 @@ struct global_time_keeper {

std::atomic<bool> stop_it{false};
std::atomic<bool> update_it{false};
std::atomic_uint64_t window_min_time;
std::atomic_uint64_t client_min_time;
std::atomic_uint64_t client_max_time;
std::atomic_uint64_t sc_kernel_time;
std::mutex upd_mtx;
std::condition_variable update;
thread_comms_channel sc_coms_channel{-1ULL};
Expand Down
Loading