apoorv_kumar247 Posted March 2, 2013 Report Share Posted March 2, 2013 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. Quote Link to comment Share on other sites More sharing options...
David Black Posted March 3, 2013 Report Share Posted March 3, 2013 A basic question: Which type of mutex are you using? sc_mutex or something else? Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted March 3, 2013 Report Share Posted March 3, 2013 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 maehne 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.