Skip to content

Commit 8bf8c92

Browse files
committed
experiments/lap.py: New experiment
Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 7b04a62 commit 8bf8c92

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

proxyclient/experiments/lap.py

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: MIT
3+
import sys, pathlib, time, random, array
4+
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
5+
6+
from m1n1.setup import *
7+
from m1n1 import asm
8+
9+
PAGE_SIZE = 16384
10+
11+
REPETITIONS = 1000
12+
13+
TEST_ECORE = 1
14+
TEST_PCORE = 5
15+
16+
S = 8
17+
ITERS = 1024
18+
SIZE_DATA_ARRAY = ITERS * S * 4
19+
20+
WRITE_MAX = SIZE_DATA_ARRAY // 4
21+
22+
seq_data_buf = u.memalign(PAGE_SIZE, SIZE_DATA_ARRAY)
23+
random_data_buf = u.memalign(PAGE_SIZE, SIZE_DATA_ARRAY)
24+
25+
seq_data = [0] * WRITE_MAX
26+
for i in range(0, WRITE_MAX, S):
27+
seq_data[i] = i + S
28+
29+
random_data = [0] * WRITE_MAX
30+
order = list(range(1, ITERS))
31+
random.shuffle(order)
32+
off = 0
33+
for i in range(ITERS - 1):
34+
next_off = order[i]
35+
assert random_data[S * off] == 0
36+
random_data[S * off] = S * next_off
37+
off = next_off
38+
39+
print(f"Seq data buf: {seq_data_buf:#x}")
40+
print(f"Random data buf: {random_data_buf:#x}")
41+
42+
iface.writemem(seq_data_buf, array.array('I', seq_data).tobytes())
43+
iface.writemem(random_data_buf, array.array('I', random_data).tobytes())
44+
45+
freq = u.mrs(CNTFRQ_EL0)
46+
code = u.malloc(0x1000)
47+
48+
util = asm.ARMAsm(f"""
49+
test:
50+
mov x6, x2
51+
mov x5, x0
52+
mov x7, #0
53+
mov x4, #0
54+
mov x2, x1
55+
mov x3, #0
56+
1:
57+
ldr w3, [x5, x3, lsl #2]
58+
subs x2, x2, #1
59+
b.ne 1b
60+
61+
3:
62+
mov x2, x1
63+
mov x3, #0
64+
65+
dsb sy
66+
isb
67+
mrs x9, S3_2_c15_c0_0
68+
isb
69+
70+
2:
71+
ldr w3, [x5, x3, lsl #2]
72+
subs x2, x2, #1
73+
b.ne 2b
74+
75+
dsb sy
76+
isb
77+
mrs x10, S3_2_c15_c0_0
78+
isb
79+
80+
sub x0, x10, x9
81+
add x7, x7, x0
82+
83+
subs x6, x6, #1
84+
b.ne 3b
85+
86+
mov x0, x7
87+
ret
88+
""", code)
89+
iface.writemem(code, util.data)
90+
p.dc_cvau(code, len(util.data))
91+
p.ic_ivau(code, len(util.data))
92+
93+
# Set higher cpufreq pstate on all clusters
94+
p.cpufreq_init()
95+
96+
p.smp_start_secondaries()
97+
p.smp_set_wfe_mode(False)
98+
99+
def cpu_call(cpu, x, *args):
100+
return p.smp_call_sync(cpu, x | REGION_RX_EL1, *args)
101+
102+
def init_core(cpu):
103+
p.mmu_init_secondary(cpu)
104+
105+
def mrs(x):
106+
return u.mrs(x, call=lambda x, *args: cpu_call(cpu, x, *args))
107+
def msr(x, v):
108+
u.msr(x, v, call=lambda x, *args: cpu_call(cpu, x, *args))
109+
110+
msr(SPRR_CONFIG_EL1, 1)
111+
112+
is_ecore = not (mrs(MPIDR_EL1) & (1 << 16))
113+
# Enable DC MVA ops
114+
v = mrs(EHID4_EL1 if is_ecore else HID4_EL1)
115+
v &= ~(1 << 11)
116+
msr(EHID4_EL1 if is_ecore else HID4_EL1, v)
117+
118+
# Enable PMU
119+
v = mrs(PMCR0_EL1)
120+
v |= 1 | (1<<30)
121+
msr(PMCR0_EL1, v)
122+
msr(PMCR1_EL1, 0xffffffffffffffff)
123+
124+
v = mrs(CNTKCTL_EL1)
125+
v |= 3
126+
msr(CNTKCTL_EL1, v)
127+
128+
# Enable user cache ops
129+
v = mrs(SCTLR_EL1)
130+
v |= (1 << 26)
131+
msr(SCTLR_EL1, v)
132+
133+
def cpu_msr(cpu, x, v):
134+
u.msr(x, v, call=lambda x, *args: cpu_call(cpu, x, *args))
135+
136+
init_core(TEST_ECORE)
137+
init_core(TEST_PCORE)
138+
139+
# Enable DC MVA ops
140+
v = u.mrs(EHID4_EL1)
141+
v &= ~(1 << 11)
142+
u.msr(EHID4_EL1, v)
143+
144+
def test_cpu(cpu, buf, iters):
145+
elapsed = p.smp_call_sync(cpu, util.test | REGION_RX_EL1, buf, iters, REPETITIONS)
146+
return elapsed / iters / REPETITIONS
147+
148+
def run_tests():
149+
a = test_cpu(TEST_ECORE, seq_data_buf, ITERS)
150+
b = test_cpu(TEST_ECORE, random_data_buf, ITERS)
151+
c = test_cpu(TEST_PCORE, seq_data_buf, ITERS)
152+
d = test_cpu(TEST_PCORE, random_data_buf, ITERS)
153+
print(f" ECore seq: {a:.02f}, ECore random: {b:.02f}")
154+
print(f" PCore seq: {c:.02f}, PCore random: {d:.02f}")
155+
156+
print("Testing with SSBS=1 (load/store speculation permitted)")
157+
for cpu in (TEST_ECORE, TEST_PCORE):
158+
cpu_msr(cpu, SSBS, 1<<12)
159+
160+
run_tests()
161+
print("Testing with SSBS=0 (load/store speculation disallowed)")
162+
for cpu in (TEST_ECORE, TEST_PCORE):
163+
cpu_msr(cpu, SSBS, 0)
164+
165+
run_tests()

0 commit comments

Comments
 (0)