Jump to content

Mutex unlock delay in SystemC 2.2.0


apoorv_kumar247
 Share

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.

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...