Jump to content
apoorv_kumar247

Mutex unlock delay in SystemC 2.2.0

Recommended Posts

Hi,

I am creating a RTL simulation model of a chip which involves arbitrating 2 common channels among multiple cores. I have implemented the channels using 1 mutex (sc_mutex) each, one of which any core wishing to transmit needs to lock before accessing the channel. Every core first tries to lock on first mutex, if unsuccessful, it tries the same on the second mutex. If it fails to lock either, it backs out until next cycle.

The issue is that the mutex doesn't become available until many cycles after a resource calls mutex.unlock() . Consider the following trace.

<CYCLE NO.> : <EVENT>

1033: Channel[0] lock attempt by - Router[0]

1033: Channel[0] locked by - Router[0]

1037: Channel[0] UNlocked by - Router[0]

1038: Channel[0] lock attempt by - Router[12]

----> locking unsuccessful.

1038: Channel[1] lock attempt by - Router[12]

1038: Channel[1] locked by - Router[12]

In the above trace it might look like the problem is only for a single cycle, but it actually shows across hundreds of cycles at times.

To further investigate the problem, I added a small snippet just after the mutex.unlock() that looks something like -

mutex[0].unlock();
if ( mutex[0].trylock() != -1 ){
 cout << "SUCCESS!";
}
else{
 cout << "FAILURE!";
}

the code essentially unlocks the mutex and then tries to lock it within the same cycle (however, a later delta cycle in any sequentially consistent simulation kernel). The output invariably comes out as "FAILURE!". I cannot use semaphore because of design issues.

I don't understand why the unlock fails to be detected across many cycles when it should be done within a delta cycle. Any help would be appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites

mutex[0].unlock();
if ( mutex[0].trylock() != -1 ){
 cout << "SUCCESS!";
}
else{
 cout << "FAILURE!";
}

the code essentially unlocks the mutex and then tries to lock it within the same cycle (however, a later delta cycle in any sequentially consistent simulation kernel). The output invariably comes out as "FAILURE!". I cannot use semaphore because of design issues.

I have two comments on the above snippet, assuming you're using sc_mutex.

Firstly, your check should never print FAILURE, unless the unlock itself failed. Therefore, you should check for the return value of the unlock call instead. You need to unlock the mutex from within the same SystemC process you have locked the mutex from, otherwise the unlock will be rejected.

Secondly, there is no delta delay required (or enforced) between the unlock and a subsequent lock. The pending lock calls (or any subsequent trylock during the same evaluation cycle) will succeed to lock the mutex again. The internal event used to notify blocked processes is triggered immediately, not within the next delta cycle.

This may help to track down your problem.

Greetings from Oldenburg,

Philipp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×