AW: [PATCH 05/12] kern_tc.c: Replace atomic functions required by PPS API

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Apr 7 11:41:03 UTC 2022



On 07/04/2022 11:55, Gabriel.Moyano at dlr.de wrote:
>> On 07/04/2022 10:36, Gabriel Moyano wrote:
>>> ---
>>>    cpukit/include/sys/timepps.h | 4 ++++
>>>    cpukit/score/src/kern_tc.c   | 7 +++++++
>>>    2 files changed, 11 insertions(+)
>>>
>>> diff --git a/cpukit/include/sys/timepps.h
>>> b/cpukit/include/sys/timepps.h index 621afb08ec..5703381ffa 100644
>>> --- a/cpukit/include/sys/timepps.h
>>> +++ b/cpukit/include/sys/timepps.h
>>> @@ -32,7 +32,11 @@
>>>
>>>    typedef int pps_handle_t;
>>>
>>> +#ifndef __rtems__
>>>    typedef unsigned pps_seq_t;
>>> +#else /* __rtems__ */
>>> +typedef Atomic_Uint	pps_seq_t;
>>> +#endif /* __rtems__ */
>>>
>>>    typedef struct ntp_fp {
>>>    	unsigned int	integral;
>>> diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
>>> index e57da2c0ca..77f7a9212c 100644
>>> --- a/cpukit/score/src/kern_tc.c
>>> +++ b/cpukit/score/src/kern_tc.c
>>> @@ -1932,10 +1932,17 @@ pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
>>>    			tv.tv_usec = fapi->timeout.tv_nsec / 1000;
>>>    			timo = tvtohz(&tv);
>>>    		}
>>> +#ifndef __rtems__
>>>    		aseq = atomic_load_int(&pps->ppsinfo.assert_sequence);
>>>    		cseq = atomic_load_int(&pps->ppsinfo.clear_sequence);
>>>    		while (aseq == atomic_load_int(&pps->ppsinfo.assert_sequence) &&
>>>    		    cseq == atomic_load_int(&pps->ppsinfo.clear_sequence)) {
>>> +#else /* __rtems__ */
>>> +		aseq = atomic_load_acq_int(&pps->ppsinfo.assert_sequence);
>>> +		cseq = atomic_load_acq_int(&pps->ppsinfo.clear_sequence);
>>> +		while (aseq == atomic_load_acq_int(&pps->ppsinfo.assert_sequence) &&
>>> +		    cseq == atomic_load_acq_int(&pps->ppsinfo.clear_sequence)) {
>>> +#endif /* __rtems__ */
>>>    			if (abi_aware(pps, 1) && pps->driver_mtx != NULL) {
>>>    				if (pps->flags & PPSFLAG_MTX_SPIN) {
>>>    					err = msleep_spin(pps, pps->driver_mtx,
>> Why do you need this change?
>>
> If you mean why atomic_load_int() was replaced by atomic_load_acq_int(), it is because atomic_load_int()  is not defined in rtems but in rtems-libbsd.

In FreeBSD, it seems the sequence is sometimes incremented using a 
normal increment, for example:

	*pcount = pps->capcount;
	(*pseq)++;
	*tsp = ts;

So, just add the atomic_load_int() as an relaxed atomic load to the 
other inline functions at the top of the file.

I guess the synchronization needs a review in FreeBSD.

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber at embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


More information about the devel mailing list