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