Clement Deschamps
Builds for 1 pipeline failed in 5 minutes 1 second

greenthreads: add a param to set the deadlock detection timeout

centralSyncPolicy {
    deadlock_timeout = n;
}

n = 0: Disabled (default)
n > 0: Timeout in seconds
... ... @@ -88,7 +88,7 @@ class global_pause : sc_core::sc_module {
cnd_mutex.lock();
while (pause_requests>0 && active<=0) {
COUT << " SC sleep (pause: "<<pause_requests<<" active: "<<active<<")\n";
int p = cnd_mutex.timedwait();
int p = cnd_mutex.timedwait(get_timeout());
if ( p != 0 ) {
SC_REPORT_ERROR("async threads", "Deadlock timeout reached");
}
... ... @@ -97,6 +97,8 @@ class global_pause : sc_core::sc_module {
cnd_mutex.unlock();
}
int get_timeout();
public:
static global_pause singleton;
... ...
... ... @@ -106,6 +106,7 @@ public:
gs::gs_param<sc_time> quantum;
gs::gs_param<sc_time> printTimeEvery;
gs::gs_param<unsigned int> seed;
gs::gs_param<int> deadlock_timeout;
sc_time startTime;
uint64_t startsecs;
... ... @@ -119,6 +120,7 @@ public:
, quantum("quantum",SC_ZERO_TIME)
, printTimeEvery("print_time",SC_ZERO_TIME)
, seed("seed", 0)
, deadlock_timeout("deadlock_timeout", 0)
, startTime(SC_ZERO_TIME)
{
SC_METHOD(quantumHandler);
... ... @@ -439,7 +441,7 @@ public:
if (t==SC_ZERO_TIME) {
COUT << " Initial wait\n";
int p=sem.timedwait(); // wait for SystemC to say we can do another quantum
int p=sem.timedwait(centralSyncPolicy::share.deadlock_timeout); // wait for SystemC to say we can do another quantum
if ( p != 0 ) {
SC_REPORT_ERROR("greenthreads", "Deadlock timeout reached (initial wait)");
}
... ... @@ -493,7 +495,7 @@ public:
if (centralSyncPolicy::share.deterministic) {
centralDeterministic::share.runDoneEvent.notify();
}
int p=sem.timedwait(); // wait for SystemC to say we can do another quantum
int p=sem.timedwait(centralSyncPolicy::share.deadlock_timeout); // wait for SystemC to say we can do another quantum
if ( p != 0 ) {
SC_REPORT_ERROR("greenthreads", "Deadlock timeout reached");
}
... ...
... ... @@ -90,13 +90,16 @@ public:
{
pthread_mutex_unlock(&mutex);
}
int timedwait()
int timedwait(int timeout)
{
struct timespec ts;
int p;
do {
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 60;
if (timeout <= 0) {
timeout = std::numeric_limits<int>::max();
}
ts.tv_sec += timeout;
p = pthread_cond_timedwait(&cnd, &mutex, &ts);
if (p == ETIMEDOUT) {
return p;
... ... @@ -125,11 +128,11 @@ public:
cnd_mutex.broadcast();
cnd_mutex.unlock();
}
int timedwait()
int timedwait(int timeout)
{
cnd_mutex.lock();
while (i<=0) {
int p = cnd_mutex.timedwait();
int p = cnd_mutex.timedwait(timeout);
if ( p != 0 ) {
cnd_mutex.unlock();
return p;
... ...
... ... @@ -18,6 +18,10 @@ gs::gt::centralDeterministic gs::gt::centralDeterministic::share("CentralDetermi
// ((gs::gt::realTimeBase*)(s.sival_ptr))->run();
//}
int gs::gt::global_pause::get_timeout()
{
return gs::gt::centralSyncPolicy::share.deadlock_timeout;
}
/* WARNING
* this is LINUX SPECIFIC code, this will need porting to other O/Ss
... ...