Clement Deschamps
Builds for 1 pipeline failed in 30 minutes 51 seconds

cleanup

/*
* sync.h
* Greenthreads Sync Library
*
* Copyright (C) 2014, GreenSocs Ltd.
* Copyright (C) 2018, GreenSocs.
*
* Developped by Clement Deschamps <clement.deschamps@greensocs.com>
* Authors:
* Mark Burton <mark.burton@greensocs.com>
* Clement Deschamps <clement.deschamps@greensocs.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
... ... @@ -58,7 +60,7 @@
#include "greenthreads/util.h"
#include "greenthreads/async_event.h"
#define COUT if (1) cout << sc_time_stamp() << ":"
#define COUT if (0) cout << sc_time_stamp() << ":"
//<< pthread_self() << ":"
namespace gs {
... ... @@ -92,8 +94,15 @@ private:
bool sc_is_back_window;
int active;
async_event checkWindowEvent;
pthread_t systemc_thread;
public:
/* return true if the current thread is the SystemC thread */
bool on_systemc_thread() {
return pthread_equal(pthread_self(), systemc_thread) != 0;
}
void unlock() {
cnd_mutex.lock();
active++;
... ... @@ -124,18 +133,20 @@ public:
/* Prevent sc_stop posting an invisible event (causing us to hang) */
sc_core::sc_set_stop_mode(SC_STOP_IMMEDIATE);
systemc_thread = pthread_self();
SC_METHOD(checkWindow);
sensitive << checkWindowEvent;
dont_initialize();
}
void start_of_simulation() {
/*
/*
* Need to wait till start of simulation to start the window,
* because otherwise the quantum may not be set.
*/
// checkWindowEvent.notify(tlm_utils::tlm_quantumkeeper::get_global_quantum());
run_source=sources.end();
// checkWindowEvent.notify(tlm_utils::tlm_quantumkeeper::get_global_quantum());
run_source = sources.end();
checkWindowEvent.notify();
COUT << " quantum " << tlm_utils::tlm_quantumkeeper::get_global_quantum() << "\n";
}
... ... @@ -153,7 +164,7 @@ public:
cnd_mutex.lock();
source->end_time = t;
update_window();
source->decoupled=decoupled;
source->decoupled = decoupled;
cnd_mutex.unlock();
}
... ... @@ -164,8 +175,8 @@ public:
update_window();
if (source->decoupled) {
cnd_mutex.unlock();
return; // do not attempt to sync this source.
cnd_mutex.unlock();
return; // do not attempt to sync this source.
}
/* wait if we're ahead the backWindow plus a quantum */
... ... @@ -199,14 +210,14 @@ public:
entry->source = source;
entry->end_time = SC_ZERO_TIME;
entry->quantum = sc_time(quantum, SC_NS);
entry->locked=false;
entry->locked = false;
entry->name = name;
cnd_mutex.unlock();
return entry;
}
/* deterministic round-robbin
*/
*/
void checkRunning(source_entry *source)
{
start_mutex.lock();
... ... @@ -227,7 +238,7 @@ public:
void startRun()
{
start_mutex.lock();
run_source=sources.begin();
run_source = sources.begin();
COUT << "Start "<< (*run_source).name<<" @ "<<(*run_source).end_time<<"\n";
start_mutex.broadcast();
start_mutex.unlock();
... ... @@ -246,14 +257,14 @@ public:
if (sc_is_back_window) {
update_window();
}
sc_core::sc_time sc_front_window=(sc_behind_mode)?backSourceWindow:frontWindow;
sc_core::sc_time sc_front_window = (sc_behind_mode)?backSourceWindow:frontWindow;
// or backWindow+quantum
if (sc_time_stamp() < sc_front_window) {
// Begining of our quantum !
if (deterministic) {
if (run_source==sources.end()) {
if (run_source == sources.end()) {
/* we have the right to run
* otherwise a sync source has it, and we will be called
* again.
... ... @@ -267,9 +278,9 @@ public:
} else {
// End of our quantum !
/* Ensure there are no pending token requests. */
if (active==0) {
if (active == 0) {
if (deterministic) {
if (run_source==sources.end()) {
if (run_source == sources.end()) {
COUT << "Stoppping SystemC\n";
startRun();
}
... ... @@ -328,27 +339,24 @@ protected:
};
class syncSource {
private:
source_entry *handle;
pthread_t sc_thread;
const char* name;
sc_event quantumEvent;
public:
SC_HAS_PROCESS(syncSource);
/*
* This class MUST be instanciated from SystemC (and in the SystemC thread)
*/
syncSource(const char* _name, uint64_t quantum, bool _decoupled = false):name(_name) {
sc_thread = pthread_self();
handle = centralSyncPolicy::share.registerSource(name, this, quantum);
centralSyncPolicy::share.initWindow(SC_ZERO_TIME, handle, _decoupled);
}
void syncAt(sc_core::sc_time t) {
if (pthread_equal(pthread_self(), sc_thread)) {
if (centralSyncPolicy::share.on_systemc_thread()) {
return;
}
// COUT << "Sync "<<name<<" At sc_time:"<<sc_time_stamp()<< " sync time:"<<t<<"\n";
// COUT << "Sync "<<name<<" At sc_time:"<<sc_time_stamp()<< " sync time:"<<t<<"\n";
centralSyncPolicy::share.setWindow(t, handle);
}
};
... ...