EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024 
<== Date ==> <== Thread ==>

Subject: [Bug 1932118] Re: Bug in vxWorks epicsAtomicCmpAndSwapIntT
From: Dirk Zimoch via Core-talk <core-talk at aps.anl.gov>
To: core-talk at aps.anl.gov
Date: Thu, 24 Jun 2021 11:48:39 -0000
Using the gcc __sync_* buildins, in particular
__sync_val_compare_and_swap, seems to work for vxWorks 6.6 or higher
(using gcc 4.1.2 or higher) on the PPC architecture.

I see two possibilities to modify gcc/epicsAtomicCD.h so that the compiler builtins are used on PPC as well (and not only on x86):
a. Remove the architecture filter and assume gcc 4.1+ will always have __sync_*
b. Add __ppc to the filter.

I would prefer solution a, but cannot test it as I have no other architectures.
It would affect all non x86 architectures (not only vxWorks) with gcc >= 4.1 but not yet defining __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* macros.
The vxWorks 6.9 gcc 4.3.3 already defines those macros, (which explains that this bug is not visible in vxWorks 6.9) thus probably only gcc 4.1 and maybe 4.2 are affected.

Opinions?

-- 
You received this bug notification because you are a member of EPICS
Core Developers, which is subscribed to EPICS Base.
Matching subscriptions: epics-core-list-subscription
https://bugs.launchpad.net/bugs/1932118

Title:
  Bug in vxWorks epicsAtomicCmpAndSwapIntT

Status in EPICS Base:
  Fix Committed

Bug description:
  The usage of epicsAtomicCmpAndSwapIntT() in callback.c suggests that
  the function should return the previous value. But the VxWorks
  implementation uses vxCas() which is documented as returning "TRUE if
  the write actually occurs, FALSE otherwise."

  vxAtomicLib.html:
  vxCas( )
  NAME
      vxCas( ) - atomically compare-and-swap the contents of a memory location 

  SYNOPSIS
      BOOL vxCas
          (
          atomic_t *  target,    
          atomicVal_t oldValue,  
          atomicVal_t newValue   
          )

  DESCRIPTION
      This routine performs an atomic compare-and-swap; testing that *target contains oldValue, and if it does, setting the value of *target to newValue.

  RETURNS
      TRUE if the swap is actually executed, FALSE otherwise.

  
  Comparing this with the gcc documentation:
  bool __sync_bool_compare_and_swap (type *ptr, type oldval type newval, ...)
  type __sync_val_compare_and_swap (type *ptr, type oldval type newval, ...)

  These builtins perform an atomic compare and swap.  That is, if the
  current value of *ptr is oldval, then write newval into *ptr.

  The “bool” version returns true if the comparison is successful and newval was written.
  The “val” version returns the contents of *ptr before the operation.

  
  That means epicsAtomicCmpAndSwapIntT() behaves behaves like __sync_bool_compare_and_swap(). Simply casting the return value from BOOL to the type of oldVal does not change that.

  But the usage implies an expected bahavior like
  __sync_val_compare_and_swap (), wich is used in the gcc implementation
  of epicsAtomicCmpAndSwapIntT().

  
  This bugs prevents the callback threads from being started in vxWorks 6.7, maybe more or all vxWorks 6 versions.

To manage notifications about this bug go to:
https://bugs.launchpad.net/epics-base/+bug/1932118/+subscriptions

References:
[Bug 1932118] [NEW] Bug in vxWorks epicsAtomicCmpAndSwapIntT Dirk Zimoch via Core-talk

Navigate by Date:
Prev: Build failed: EPICS Base 7 base-7.0-346 AppVeyor via Core-talk
Next: [Bug 1932118] Re: Bug in vxWorks epicsAtomicCmpAndSwapIntT Dirk Zimoch via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024 
Navigate by Thread:
Prev: [Bug 1932118] Re: Bug in vxWorks epicsAtomicCmpAndSwapIntT Dirk Zimoch via Core-talk
Next: [Bug 1932118] Re: Bug in vxWorks epicsAtomicCmpAndSwapIntT Dirk Zimoch via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  <20212022  2023  2024 
ANJ, 24 Jun 2021 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·