[python] ppc --with-tsc fixes

dmalcolm dmalcolm at fedoraproject.org
Tue Aug 23 20:45:10 UTC 2011


commit 92ed49e1f9a286b6ee791a29f6b25be191d0c4c5
Author: David Malcolm <dmalcolm at redhat.com>
Date:   Tue Aug 23 16:44:23 2011 -0400

    ppc --with-tsc fixes
    
    re-enable and fix the --with-tsc option on ppc64, and rework it on
    32-bit ppc to avoid aliasing violations (patch 129; rhbz#698726)

 python-2.7.2-tsc-on-ppc.patch |   58 +++++++++++++++++++++++++++++++++++++++++
 python.spec                   |   13 ++++++++-
 2 files changed, 69 insertions(+), 2 deletions(-)
---
diff --git a/python-2.7.2-tsc-on-ppc.patch b/python-2.7.2-tsc-on-ppc.patch
new file mode 100644
index 0000000..447c6e3
--- /dev/null
+++ b/python-2.7.2-tsc-on-ppc.patch
@@ -0,0 +1,58 @@
+diff -up Python-2.7.2/Python/ceval.c.tsc-on-ppc Python-2.7.2/Python/ceval.c
+--- Python-2.7.2/Python/ceval.c.tsc-on-ppc	2011-08-23 14:59:48.051300849 -0400
++++ Python-2.7.2/Python/ceval.c	2011-08-23 15:33:25.412162902 -0400
+@@ -37,24 +37,42 @@ typedef unsigned long long uint64;
+ */
+ #if defined(__ppc__) || defined (__powerpc__)
+ 
+-#define READ_TIMESTAMP(var) ppc_getcounter(&var)
++#if defined( __powerpc64__) || defined(__LP64__)
++/* 64-bit PowerPC */
++#define READ_TIMESTAMP(var) ppc64_getcounter(&var)
++static void
++ppc64_getcounter(uint64 *v)
++{
++    /* On 64-bit PowerPC we can read the 64-bit timebase directly into a
++       64-bit register */
++    uint64 timebase;
++#ifdef _ARCH_PWR4
++    asm volatile ("mfspr %0,268" : "=r" (timebase));
++#else
++    asm volatile ("mftb %0" : "=r" (timebase));
++#endif
++    *v = timebase;
++}
++
++#else
++/* 32-bit PowerPC */
++#define READ_TIMESTAMP(var) ppc32_getcounter(&var)
+ 
+ static void
+-ppc_getcounter(uint64 *v)
++ppc32_getcounter(uint64 *v)
+ {
+-    register unsigned long tbu, tb, tbu2;
++    union { long long ll; long ii[2]; } u;
++    long tmp;
+ 
+   loop:
+-    asm volatile ("mftbu %0" : "=r" (tbu) );
+-    asm volatile ("mftb  %0" : "=r" (tb)  );
+-    asm volatile ("mftbu %0" : "=r" (tbu2));
+-    if (__builtin_expect(tbu != tbu2, 0)) goto loop;
+-
+-    /* The slightly peculiar way of writing the next lines is
+-       compiled better by GCC than any other way I tried. */
+-    ((long*)(v))[0] = tbu;
+-    ((long*)(v))[1] = tb;
++    asm volatile ("mftbu %0" : "=r" (u.ii[0]) );
++    asm volatile ("mftb  %0" : "=r" (u.ii[1]) );
++    asm volatile ("mftbu %0" : "=r" (tmp));
++    if (__builtin_expect(u.ii[0] != tmp, 0)) goto loop;
++
++    *v = u.ll;
+ }
++#endif /* powerpc 32/64 bit */
+ 
+ #elif defined(__i386__)
+ 
diff --git a/python.spec b/python.spec
index 93c5c7d..7f2951b 100644
--- a/python.spec
+++ b/python.spec
@@ -102,7 +102,7 @@ Summary: An interpreted, interactive, object-oriented programming language
 Name: %{python}
 # Remember to also rebase python-docs when changing this:
 Version: 2.7.2
-Release: 6%{?dist}
+Release: 7%{?dist}
 License: Python
 Group: Development/Languages
 Requires: %{python}-libs%{?_isa} = %{version}-%{release}
@@ -475,6 +475,10 @@ Patch127: fix-test_structmember-on-64bit-bigendian.patch
 # Not yet sent upstream
 Patch128: python-2.7.1-fix_test_abc_with_COUNT_ALLOCS.patch
 
+# Fix the --with-tsc option on ppc64, and rework it on 32-bit ppc to avoid
+# aliasing violations (rhbz#698726)
+# Not yet sent upstream
+Patch129: python-2.7.2-tsc-on-ppc.patch
 
 # This is the generated patch to "configure"; see the description of
 #   %{regenerate_autotooling_patch}
@@ -716,6 +720,7 @@ rm -r Modules/zlib || exit 1
 %patch126 -p0 -b .fix-dbm_contains-on-64bit-bigendian
 %patch127 -p0 -b .fix-test_structmember-on-64bit-bigendian
 %patch128 -p1
+%patch129 -p1 -b .tsc-on-ppc
 
 # This shouldn't be necesarry, but is right now (2.2a3)
 find -name "*~" |xargs rm -f
@@ -836,7 +841,7 @@ LD_LIBRARY_PATH="$topdir/$ConfDir" PATH=$PATH:$topdir/$ConfDir make -s EXTRA_CFL
 BuildPython debug \
   python-debug \
   python%{pybasever}-debug \
-%ifarch %{ix86} x86_64 ppc
+%ifarch %{ix86} x86_64 ppc ppc64
   "--with-pydebug --with-tsc --with-count-allocs --with-call-profile" \
 %else
   "--with-pydebug --with-count-allocs --with-call-profile" \
@@ -1772,6 +1777,10 @@ rm -fr %{buildroot}
 # ======================================================
 
 %changelog
+* Tue Aug 23 2011 David Malcolm <dmalcolm at redhat.com> - 2.7.2-7
+- re-enable and fix the --with-tsc option on ppc64, and rework it on 32-bit
+ppc to avoid aliasing violations (patch 129; rhbz#698726)
+
 * Tue Aug 23 2011 David Malcolm <dmalcolm at redhat.com> - 2.7.2-6
 - don't use --with-tsc on ppc64 debug builds (rhbz#698726)
 


More information about the scm-commits mailing list