1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
import re
import os
def extract_s390x_cpu_ids(lines):
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 = ([0-9A-Fa-f]+)")
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), 16)
ids.append((number, version, ident, machine))
return ids
def s390x_detect_vx():
chunks = []
try:
fd = os.open("/proc/cpuinfo", os.O_RDONLY, 0644)
try:
while True:
chunk = os.read(fd, 4096)
if not chunk:
break
chunks.append(chunk)
finally:
os.close(fd)
except OSError:
pass
content = ''.join(chunks)
start = content.find("features", 0)
if start >= 0:
after_colon = content.find(":", start)
if after_colon < 0:
return False
newline = content.find("\n", after_colon)
if newline < 0:
return False
split = content[after_colon+1:newline].strip().split(' ')
if 'vx' in split:
return True
return False
def s390x_cpu_revision():
# 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 == 0x2097 or machine == 0x2098:
return "z10"
if machine == 0x2817 or machine == 0x2818:
return "z196"
if machine == 0x2827 or machine == 0x2828:
return "zEC12"
if machine == 0x2964:
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()
if revision == 'z13':
# gcc does not recognize z13 as a compiler flag!
revision = 'zEC12'
assert revision != 'unknown'
cflags += ('-march='+revision,)
cflags += ('-m64','-mzarch')
return cflags
|