Re: building tog-pegasus for ARM on Fedora 19

Ashok K Pathak <[email protected]> Sun, 28 Apr 2013 23:20:44 +0530
Newsgroups gmane.network.open-pegasus.general
Message-ID <OF7E7E2B07.77C313B6-ON65257B5B.0058209A-65257B5B.00621AD4@in.ibm.com>
Thanks for patch and write to OpenPegasus Community.

In think to make it easy to write proratable code that will work for
different version of  GCC , we generally use  GCC_VERSION macro that  was
defined  in Pegasus/Common/Config.h

as

#if defined(__GNUC__)
#define GCC_VERSION (__GNUC__ * 10000 \
                               + __GNUC_MINOR__ * 100 \
                               + __GNUC_PATCHLEVEL__)


& use below idiom to take advantage of the GCC version that will provide
better API  to write better code

//test for version for GCC > 4.4.0

#if defined(__GNUC__) && GCC_VERSION >= 40400

Looking the below links I have different perception regarding   GCC
vesrsion in which  atomic_*  are available.

__atomic_*  (http://gcc.gnu.org/wiki/Atomic/GCCMM)

http://gcc.gnu.org/gcc-4.7/changes.html
>>>
Support for atomic operations specifying the C++11/C11 memory model has
been added. These new __atomic routines replace the existing __sync
built-in routines.
<<<

 .
I have taken the latest Pegasus code and applied the patch . I tried to
build  the code and get the following  build error
(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)

>>>
g++ -c -o /home/ashokpathak/latest/pegasus/obj/Pegasus/Common/SCMO.o -W
-Wall -Wno-unused -Wunused-variable -Werror=unused-variable -D_GNU_SOURCE
-DTHREAD_SAFE -D_REENTRANT -g -m64 -fvisibility=hidden -fPIC
-DPEGASUS_COMMON_INTERNAL -DPEGASUS_INTERNALONLY
-DPEGASUS_PLATFORM_LINUX_GENERIC_GNU -DPEGASUS_PLATFORM_LINUX_X86_64_GNU
-DPEGASUS_USE_SYSLOGS -DPEGASUS_ARCH_LIB=\"lib\" -DPEGASUS_ENABLE_CQL
-DPEGASUS_DEFAULT_ENABLE_OOP -DPEGASUS_DISABLE_EXECQUERY -DPEGASUS_HAS_SSL
-DPEGASUS_SSL_RANDOMFILE -DPEGASUS_ENABLE_SSL_CRL_VERIFICATION
-DPEGASUS_ENABLE_AUDIT_LOGGER -DPEGASUS_ENABLE_IPV6
-DPEGASUS_ENABLE_INDICATION_COUNT
-DPEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT
-DPEGASUS_ENABLE_INDICATION_ORDERING -DPEGASUS_ENABLE_INTEROP_PROVIDER
-DPEGASUS_DEBUG -DPEGASUS_USE_EXPERIMENTAL_INTERFACES
-DPEGASUS_USE_DEPRECATED_INTERFACES -DPEGASUS_ENABLE_CMPI_PROVIDER_MANAGER
-DPEGASUS_DEST_LIB_DIR=\"lib\" -DPEGASUS_ENABLE_PROTOCOL_WSMAN
-DPEGASUS_EXTRA_PROVIDER_LIB_DIR=\"\" -DPLATFORM_COMPONENT_NAME=\"pegcommon
\"  -I/home/ashokpathak/latest/pegasus/src  SCMO.cpp

’:
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h:126: error:
‘__ATOMIC_SEQ_CST’ was not declared in this scope
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h:126: error:
‘__atomic_store_n’ was not declared in this scope
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h: In member
function ‘Pegasus::Uint32 Pegasus::AtomicIntTemplate<ATOMIC_TYPE>::get()
const [with ATOMIC_TYPE = Pegasus::AtomicType]’:
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h:137: error:
‘__ATOMIC_SEQ_CST’ was not declared in this scope
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h:137: error:
‘__atomic_load_n’ was not declared in this scope
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h: In member
function ‘void Pegasus::AtomicIntTemplate<ATOMIC_TYPE>::set
(Pegasus::Uint32) [with ATOMIC_TYPE = Pegasus::AtomicType]’:
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h:143: error:
‘__ATOMIC_SEQ_CST’ was not declared in this scope
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h:143: error:
‘__atomic_store_n’ was not declared in this scope
/home/ashokpathak/latest/pegasus/src/Pegasus/Common/AtomicInt.h: In member
function ‘void Pegasus::AtomicIntTemplate<ATOMIC_TYPE>::inc() [with
ATOMIC_TYPE = Pegasus::AtomicType]’:
.....
...

make[3]: Leaving directory
`/home/ashokpathak/latest/pegasus/src/Pegasus/Common'

<<<<

Using gcc version 4.4.6

 &

Red Hat Enterprise Linux Workstation release 6.3 (Santiago)
Kernel \r on an \m

Let me know if I misunderstood it.

Regards
Ashok










                                                                           
             "David A. Marlin"                                             
             <[email protected]                                             
             om>                                                        To 
                                       [email protected],          
             04/26/2013 10:22                                           cc 
             PM                                                            
                                                                   Subject 
                                       building tog-pegasus for ARM on     
                                       Fedora 19                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           





tog-pegasus-2.2.3-4 fails to build successfully for ARM on Fedora 19.  It
is based on pegasus-2.12.1.  The failure is due to failing test cases which
uses atomic operations for synchronization (Tracer).  The atomic operation
code indicates it is for XScale, which is an older ARM platform.

To address this, I replaced the platform-specific code with GCC built-in
atomic operations (libatomic).

   http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

This worked for ARM, so since this was architecture-neutral code I combined
x86 and ARM to use the same (new) code.  This also passed on ARM and
x86_64.  In theory it should work for other architectures as well, but I
don't have access to test.  The only restriction is that it requires a
recent version of GCC (4.1 or newer).

Attached is the patch I used to make these changes.  Please let me know if
this is an acceptable approach.


Thank you,

d.marlin
(See attached file: tog-pegasus-arm.patch)
tog-pegasus-arm.patch (application/octet-stream, 4.7 KB)
--- pegasus/src/Pegasus/Common/AtomicInt.h.arm	2012-07-30 04:23:47.000000000 -0500
+++ pegasus/src/Pegasus/Common/AtomicInt.h	2013-04-22 13:18:00.199877108 -0500
@@ -100,12 +100,14 @@
 // PEGASUS_PLATFORM_LINUX_IX86_GNU
 // PEGASUS_PLATFORM_DARWIN_IX86_GNU
 // PEGASUS_PLATFORM_LINUX_X86_64_GNU
+// PEGASUS_PLATFORM_LINUX_XSCALE_GNU
 //
 //==============================================================================
 
 #if defined(PEGASUS_PLATFORM_LINUX_IX86_GNU) || \
     defined(PEGASUS_PLATFORM_DARWIN_IX86_GNU) || \
-    defined(PEGASUS_PLATFORM_LINUX_X86_64_GNU)
+    defined(PEGASUS_PLATFORM_LINUX_X86_64_GNU) || \
+    defined(PEGASUS_PLATFORM_LINUX_XSCALE_GNU)
 # define PEGASUS_ATOMIC_INT_DEFINED
 
 // Note: this lock can be eliminated for single processor systems.
@@ -121,7 +123,7 @@
 PEGASUS_TEMPLATE_SPECIALIZATION
 inline AtomicIntTemplate<AtomicType>::AtomicIntTemplate(Uint32 n)
 {
-    _rep.n = n;
+    __atomic_store_n (&_rep.n, n, __ATOMIC_SEQ_CST);
 }
 
 PEGASUS_TEMPLATE_SPECIALIZATION
@@ -132,44 +134,31 @@
 PEGASUS_TEMPLATE_SPECIALIZATION
 inline Uint32 AtomicIntTemplate<AtomicType>::get() const
 {
-    return _rep.n;
+    return __atomic_load_n (&_rep.n, __ATOMIC_SEQ_CST);
 }
 
 PEGASUS_TEMPLATE_SPECIALIZATION
 inline void AtomicIntTemplate<AtomicType>::set(Uint32 n)
 {
-    _rep.n = n;
+    __atomic_store_n (&_rep.n, n, __ATOMIC_SEQ_CST);
 }
 
 PEGASUS_TEMPLATE_SPECIALIZATION
 inline void AtomicIntTemplate<AtomicType>::inc()
 {
-    asm volatile(
-        PEGASUS_ATOMIC_LOCK "incl %0"
-        :"=m" (_rep.n)
-        :"m" (_rep.n));
+    __atomic_fetch_add (&_rep.n, 1, __ATOMIC_SEQ_CST);
 }
 
 PEGASUS_TEMPLATE_SPECIALIZATION
 inline void AtomicIntTemplate<AtomicType>::dec()
 {
-    asm volatile(
-        PEGASUS_ATOMIC_LOCK "decl %0"
-        :"=m" (_rep.n)
-        :"m" (_rep.n));
+    __atomic_fetch_sub (&_rep.n, 1, __ATOMIC_SEQ_CST);
 }
 
 PEGASUS_TEMPLATE_SPECIALIZATION
 inline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero()
 {
-    unsigned char c;
-
-    asm volatile(
-        PEGASUS_ATOMIC_LOCK "decl %0; sete %1"
-        :"=m" (_rep.n), "=qm" (c)
-        :"m" (_rep.n) : "memory");
-
-    return c != 0;
+    return (__atomic_fetch_sub (&_rep.n, 1, __ATOMIC_SEQ_CST) == 1);
 }
 
 typedef AtomicIntTemplate<AtomicType> AtomicInt;
@@ -756,109 +745,6 @@
 
 //==============================================================================
 //
-// PEGASUS_PLATFORM_LINUX_XSCALE_GNU
-//
-//==============================================================================
-
-#if defined (PEGASUS_PLATFORM_LINUX_XSCALE_GNU)
-# define PEGASUS_ATOMIC_INT_DEFINED
-
-PEGASUS_NAMESPACE_BEGIN
-
-inline void AtomicIntDisableIRQs(unsigned long& flags)
-{
-    unsigned long temp;
-    unsigned long x;
-
-    asm volatile(
-        "mrs %0, cpsr\n"
-        "orr %1, %0, #128\n"
-        "msr cpsr_c, %1\n"
-        : "=r" (x), "=r" (temp)
-        :
-        : "memory");
-
-    flags = x;
-}
-
-inline void AtomicIntEnableIRQs(unsigned long x)
-{
-    unsigned long temp;
-
-    asm volatile(
-        "mrs %0, cpsr\n"
-        "orr %1, %0, #128\n"
-        "msr cpsr_c, %1\n"
-        : "=r" (x), "=r" (temp)
-        :
-        : "memory");
-}
-
-struct AtomicType
-{
-    volatile Uint32 n;
-};
-
-PEGASUS_TEMPLATE_SPECIALIZATION
-inline AtomicIntTemplate<AtomicType>::AtomicIntTemplate(Uint32 n)
-{
-    _rep.n = n;
-}
-
-PEGASUS_TEMPLATE_SPECIALIZATION
-inline AtomicIntTemplate<AtomicType>::~AtomicIntTemplate()
-{
-}
-
-PEGASUS_TEMPLATE_SPECIALIZATION
-inline Uint32 AtomicIntTemplate<AtomicType>::get() const
-{
-    return _rep.n;
-}
-
-PEGASUS_TEMPLATE_SPECIALIZATION
-inline void AtomicIntTemplate<AtomicType>::set(Uint32 n)
-{
-    _rep.n = n;
-}
-
-PEGASUS_TEMPLATE_SPECIALIZATION
-inline void AtomicIntTemplate<AtomicType>::inc()
-{
-    unsigned long flags;
-    AtomicIntDisableIRQs(flags);
-    _rep.n++;
-    AtomicIntEnableIRQs(flags);
-}
-
-PEGASUS_TEMPLATE_SPECIALIZATION
-inline void AtomicIntTemplate<AtomicType>::dec()
-{
-    unsigned long flags;
-    AtomicIntDisableIRQs(flags);
-    _rep.n--;
-    AtomicIntEnableIRQs(flags);
-}
-
-PEGASUS_TEMPLATE_SPECIALIZATION
-inline bool AtomicIntTemplate<AtomicType>::decAndTestIfZero()
-{
-    Uint32 tmp;
-    unsigned long flags;
-    AtomicIntDisableIRQs(flags);
-    tmp = --_rep.n;
-    AtomicIntEnableIRQs(flags);
-    return tmp == 0;
-}
-
-typedef AtomicIntTemplate<AtomicType> AtomicInt;
-
-PEGASUS_NAMESPACE_END
-
-#endif /* PEGASUS_PLATFORM_LINUX_XSCALE_GNU */
-
-//==============================================================================
-//
 // PEGASUS_PLATFORM_VMS_ALPHA_DECCXX
 // PEGASUS_PLATFORM_VMS_IA64_DECCXX
 //