From mboxrd@z Thu Jan 1 00:00:00 1970 Subject: Re: A potential Xenomai Mutex issue References: <43f9470f-ed47-0a2a-71f5-ca9bca08879a@siemens.com> <2f51ad42-4be3-606d-dbdf-ee036bd562de@siemens.com> From: Jan Kiszka Message-ID: Date: Fri, 23 Aug 2019 17:23:20 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "DIAO, Hanson (DI PA CI RC R&D SW2)" Cc: "xenomai@xenomai.org" On 23.08.19 16:29, DIAO, Hanson (DI PA CI RC R&D SW2) wrote: > Hi Jan, > > I attached my code here. This is only Lock function. Unlock function is similar. > > > printf("Before Mutex Lock Mutext addr = %p,count = %d, owner = %x\n", > mpMutex, > mpMutex->lockcnt, > xnarch_atomic_get(mpMutex->fastlock)); > int err = rt_mutex_acquire( mpMutex, (RTIME)TM_INFINITE ); > if ( err && > // During boot-up and shutdown we run single-threaded > // so there is no need to lock an semaphore. > !(rc_system_state() != SYSTEM_RUNNING && err == -EPERM) ) > { > rc_xeno_log( LOG_ERROR , "rt_mutex_acquire" , err); > } > printf("After Mutex Lock Mutext addr = %p,count = %d, owner = %x\n", > mpMutex, > mpMutex->lockcnt, > xnarch_atomic_get(mpMutex->fastlock)); OK, now I understand the relation between "count" and "lockcnt". Thanks. Again, for the deadlock case, can you reproduce it with synthetic patterns and share them? > > > For the issue 2 the test case is very simple. The lock sequence is as below. After ReadReg function I checked the lockcnt. The lockcnt is 1. > Int writeReg() > { > SMILock(); > ReadReg(); So you are reading lockcnt here? Then 1 is obviously the expected value. Is owner (fastlock) 0 here? > ...... > SMIUnlock(); > } > > Int ReadReg() > { > SMILock(); If you read it here, it should be 2 in a recursive case. Jan > ........ > ...... > SMIUnlock(); > } > -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux