[PATCH] atomic operations for ppc
Jason Evans
jasone at canonware.com
Tue Mar 13 15:19:28 PDT 2012
On Mar 13, 2012, at 2:52 PM, Ingvar Hagelund wrote:
> This patch should, if it is correct, add the functions atomic_add_uint32 and atomic_sub_uint32 that are missing on some platforms, at least RHEL5/ppc[64]. With this patch, jemalloc may be updated to 2.2.x also in the EPEL5 repositories.
>
> The code was borrowed from the Boost library, see http://www.boost.org/doc/libs/1_49_0/boost/interprocess/detail/atomic.hpp . The Boost library is under the Boost license, which is quite BSD-like, but the license should probably be checked out for compatibility. See http://www.boost.org/LICENSE_1_0.txt
>
> Since I actually know nothing about ppc assembler myself, and have never used the Boost library, I should thank Federico G. Schwindt for valuable input on the patch.
>
> Jason, could you produce a test case that confirms that the patch works?
I think this should be a sufficient sanity check: after running 'make check', run 'MALLOC_CONF=stats_print:true ./test/allocated' and look at the "Current active ceiling" statistic as it relates to the "active" statistic. Here's the relevant output on my system:
Allocated: 53728, active: 57344, mapped: 12582912
Current active ceiling: 4194304
The active ceiling should be >= active, and certainly less than 10 MiB.
I'm a bit confused about where the code actually originated. A quick web search finds hits both in APR (Apache license) and Boost.
Thanks,
Jason
>
> Best regards,
> Ingvar Hagelund
>
>
>
>
>
> --- ../jemalloc-2.2.5.orig/include/jemalloc/internal/atomic.h 2011-11-15 02:18:06.000000000 +0100
> +++ include/jemalloc/internal/atomic.h 2012-03-09 08:44:45.930652898 +0100
> @@ -160,6 +160,33 @@
>
> return (x);
> }
> +#elif (defined(__ppc__) || defined(__PPC__))
> +// Code shamelessly stolen from the boost library
> +// Please do a license check before distributing
> +JEMALLOC_INLINE uint32_t
> +atomic_add_uint32(uint32_t *p, uint32_t x)
> +{
> + uint32_t prev, temp;
> +
> + asm volatile ("0:\n\t" // retry local label
> + "lwarx %0,0,%2\n\t" // load prev and reserve
> + "add %1,%0,%3\n\t" // temp = prev + x
> + "stwcx. %1,0,%2\n\t" // conditionally store
> + "bne- 0b" // start over if we lost
> + // the reservation
> + //XXX find a cleaner way to define the temp
> + //it's not an output
> + : "=&r" (prev), "=&r" (temp) // output, temp
> + : "b" (p), "r" (x) // inputs
> + : "memory", "cc"); // clobbered
> + return temp;
> +}
> +
> +JEMALLOC_INLINE uint32_t
> +atomic_sub_uint32(uint32_t *p, uint32_t x)
> +{
> + return atomic_add_uint32(p, -x);
> +}
> #else
> # error "Missing implementation for 32-bit atomic operations"
> #endif
> _______________________________________________
> jemalloc-discuss mailing list
> jemalloc-discuss at canonware.com
> http://www.canonware.com/mailman/listinfo/jemalloc-discuss
>
More information about the jemalloc-discuss
mailing list