[pypy-commit] pypy release-5.x: (s390x) setting cflags according to the cpu id (machine = ...), docu updates

plan_rich pypy.commits at gmail.com
Fri May 13 06:24:48 EDT 2016


Author: Richard Plangger <planrichi at gmail.com>
Branch: release-5.x
Changeset: r84420:d8759753a9cd
Date: 2016-05-13 12:15 +0200
http://bitbucket.org/pypy/pypy/changeset/d8759753a9cd/

Log:	(s390x) setting cflags according to the cpu id (machine = ...), docu
	updates

diff --git a/rpython/doc/arch/s390x.rst b/rpython/doc/arch/s390x.rst
--- a/rpython/doc/arch/s390x.rst
+++ b/rpython/doc/arch/s390x.rst
@@ -8,6 +8,7 @@
 
 Currently supported ISAs:
 
+* z13 (released January 2015)
 * zEC12 (released September 2012)
 * z196 (released August 2010)
 * z10 (released February 2008)
diff --git a/rpython/translator/platform/arch/__init__.py b/rpython/translator/platform/arch/__init__.py
new file mode 100644
diff --git a/rpython/translator/platform/arch/s390x.py b/rpython/translator/platform/arch/s390x.py
new file mode 100644
--- /dev/null
+++ b/rpython/translator/platform/arch/s390x.py
@@ -0,0 +1,82 @@
+import re
+
+def extract_s390x_cpu_ids(lines):
+    """ NOT_RPYTHON """
+    ids = []
+
+    re_number = re.compile("processor (\d+):")
+    re_version = re.compile("version = ([0-9A-Fa-f]+)")
+    re_id = re.compile("identification = ([0-9A-Fa-f]+)")
+    re_machine = re.compile("machine = (\d+)")
+    for line in lines:
+        number = -1
+        version = None
+        ident = None
+        machine = 0
+
+        match = re_number.match(line)
+        if not match:
+            continue
+        number = int(match.group(1))
+
+        match = re_version.search(line)
+        if match:
+            version = match.group(1)
+
+        match = re_version.search(line)
+        if match:
+            version = match.group(1)
+
+        match = re_id.search(line)
+        if match:
+            ident = match.group(1)
+
+        match = re_machine.search(line)
+        if match:
+            machine = int(match.group(1))
+
+        ids.append((number, version, ident, machine))
+
+    return ids
+
+
+def s390x_cpu_revision():
+    """ NOT_RPYTHON """
+    # linux kernel does the same classification
+    # http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20131028/193311.html
+
+    with open("/proc/cpuinfo", "rb") as fd:
+        lines = fd.read().splitlines()
+        cpu_ids = extract_s390x_cpu_ids(lines)
+    machine = -1
+    for number, version, id, m in cpu_ids:
+        if machine != -1:
+            assert machine == m
+        machine = m
+
+    if machine == 2097 or machine == 2098:
+        return "z10"
+    if machine == 2817 or machine == 2818:
+        return "z196"
+    if machine == 2827 or machine == 2828:
+        return "zEC12"
+    if machine == 2964:
+        return "z13"
+
+    # well all others are unsupported!
+    return "unknown"
+
+def update_cflags(cflags):
+    """ NOT_RPYTHON """
+    # force the right target arch for s390x
+    for cflag in cflags:
+        if cflag.startswith('-march='):
+            break
+    else:
+        # the default cpu architecture that is supported
+        # older versions are not supported
+        revision = s390x_cpu_revision()
+        assert revision != 'unknown'
+        cflags += ('-march='+revision,)
+    cflags += ('-m64','-mzarch')
+    return cflags
diff --git a/rpython/translator/platform/arch/test/test_s390x.py b/rpython/translator/platform/arch/test/test_s390x.py
new file mode 100644
--- /dev/null
+++ b/rpython/translator/platform/arch/test/test_s390x.py
@@ -0,0 +1,22 @@
+import py
+import platform
+from rpython.translator.platform.arch.s390x import (s390x_cpu_revision,
+        extract_s390x_cpu_ids)
+
+if platform.machine() != 's390x':
+    py.test.skip("s390x tests only")
+
+def test_cpuid_s390x():
+    revision = s390x_cpu_revision()
+    assert revision != 'unknown', 'the model you are running on might be too old'
+
+def test_read_processor_info():
+    ids = extract_s390x_cpu_ids("""
+processor 0: machine = 12345
+processor 1: version = FF, identification = AF
+    """.splitlines())
+    assert ids == [(0, None, None, 12345),
+                   (1, 'FF', 'AF', 0),
+                  ]
+
+
diff --git a/rpython/translator/platform/linux.py b/rpython/translator/platform/linux.py
--- a/rpython/translator/platform/linux.py
+++ b/rpython/translator/platform/linux.py
@@ -22,16 +22,8 @@
     so_prefixes = ('lib', '')
 
     if platform.machine() == 's390x':
-        # force the right target arch for s390x
-        for cflag in cflags:
-            if cflag.startswith('-march='):
-                break
-        else:
-            # the default cpu architecture that is supported
-            # older versions are not supported
-            cflags += ('-march=z10',)
-        cflags += ('-m64','-mzarch')
-
+        from rpython.translator.platform.arch import s390x
+        cflags = s390x.update_cflags(cflags)
 
     def _args_for_shared(self, args):
         return ['-shared'] + args


More information about the pypy-commit mailing list