Skip to content

Commit

Permalink
Experiment: SPEC CPU++ 22 COUNTERS RAN OUT OF DISK SPACE AOAOAOAOAOAO
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanpencil committed May 2, 2022
1 parent 052c67f commit 120e738
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 45 deletions.
7 changes: 1 addition & 6 deletions integration/rewrite_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ mkdir -p bins_rw
for binary_full in ~/bins/*; do
binary=$(basename $binary_full)
[[ $binary =~ "ldecod" ]] && continue
[[ $binary =~ "imagick_r" ]] && continue
[[ $binary =~ "perlbench_r" ]] && continue
[[ $binary =~ "nab_r" ]] && continue
[[ $binary =~ "xz_r" ]] && continue
[[ $binary =~ "cpugcc_r" ]] && continue
[[ $binary =~ "lbm_r" ]] && continue
[[ $binary =~ "diffwrf" ]] && continue

if [[ $1 == "nothing" ]]; then
echo "Not touching ${binary}..."
Expand Down
5 changes: 3 additions & 2 deletions integration/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def run(command):
if len(binary.split("_")) < 2:
quit(f"{binary} wrong format")

if any(x in binary for x in ["perlbench", "cpugcc_r", "mcf_r", "lbm_r", "imagick_r", "nab_r", "xz_r"]):
continue
# skip those
# if any(x in binary for x in ["perlbench", "cpugcc_r", "mcf_r", "lbm_r", "imagick_r", "nab_r", "xz_r"]):
# continue

binary_original_name = "_".join(binary.split("_")[:2])

Expand Down
2 changes: 1 addition & 1 deletion librw_arm64/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
".data",
".rodata",
".init_array",
".fini_array",
# ".fini_array",
".interp",
".data.rel.ro",
".noptrdata",
Expand Down
1 change: 1 addition & 0 deletions librw_arm64/rw.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class Rewriter():
# DATASECTIONS = [".rodata", ".data", ".bss", ".data.rel.ro", ".init_array"]
# DATASECTIONS = [".got", ".fini_array", ".rodata", ".data", ".bss", ".data.rel.ro", ".init_array"]
# DATASECTIONS = [".got", ".rodata", ".data", ".bss", ".data.rel.ro", ".init_array"]
# DATASECTIONS = [".tm_clone_table", ".got", ".rodata", ".data", ".bss", ".data.rel.ro", ".init_array", ".fini_array", ".got.plt"]
DATASECTIONS = [".tm_clone_table", ".got", ".rodata", ".data", ".bss", ".data.rel.ro", ".init_array", ".fini_array", ".got.plt"]
CODESECTIONS = [".text", ".init", ".fini", ".plt"]

Expand Down
58 changes: 22 additions & 36 deletions rwtools_arm64/counter/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,17 @@ def __init__(self, rewriter):
if reg.general_purpose:
self.regmap[reg.name] = reg.subregisters[0][0]

def count_two(self, instruction, idx, free):
enter_lbl = "COUNTER2_%x" % (instruction.address)

instrumentation = """
stp x7, x8, [sp, -16]! // save x7, x8
// build a pointer in x8 to .counted
adrp x8, .counted2
add x8, x8, :lo12:.counted2

// add 1 to .counted2
ldr x7, [x8]
add x7, x7, 1
str x7, [x8]
ldp x7, x8, [sp], 16 // load back x7 and x8
"""
comment = "{}: ".format(str(instruction))
return InstrumentedInstruction(instrumentation, enter_lbl, comment)



def count_one(self, instruction, idx, free):
def count_x(self, instruction, idx, free, x):
enter_lbl = "COUNTER_%x" % (instruction.address)

instrumentation = """
instrumentation = f"""
stp x7, x8, [sp, -16]! // save x7, x8
// build a pointer in x8 to .counted
adrp x8, .counted
add x8, x8, :lo12:.counted
adrp x8, .counted{x}
add x8, x8, :lo12:.counted{x}
// add 1 to .counted
ldr x7, [x8]
Expand All @@ -61,28 +41,31 @@ def count_one(self, instruction, idx, free):
comment = "{}: ".format(str(instruction))
return InstrumentedInstruction(instrumentation, enter_lbl, comment)



def do_instrument(self):
for faddr, fn in self.rewriter.container.functions.items():
for idx, instruction in enumerate(fn.cache):

# if any("adrp" in str(x) for x in instruction.before):
if "br" in instruction.mnemonic:
iinstr = self.count_one(instruction, idx, None)
if "br" == instruction.mnemonic:
iinstr = self.count_x(instruction, idx, None, 0)
instruction.instrument_before(iinstr)

if "blr" in instruction.mnemonic:
iinstr = self.count_two(instruction, idx, None)
elif "bl" == instruction.mnemonic:
iinstr = self.count_x(instruction, idx, None, 1)
instruction.instrument_before(iinstr)

elif "blr" == instruction.mnemonic:
iinstr = self.count_x(instruction, idx, None, 2)
instruction.instrument_before(iinstr)

ds = Section(".counter", 0x100000, 0, None, flags="aw")
content = """
.file: .string \"/tmp/countfile\"
.perms: .string \"a\"
.format: .string \"br: %lld\\nblr: %lld\\n\"
.format: .string \"br: %lld\\nbl: %lld\\nblr: %lld\\n\"
.align 3
.counted: .quad 0x0
.counted0: .quad 0x0
.counted1: .quad 0x0
.counted2: .quad 0x0
"""
ds.cache.append(DataCell.instrumented(content, 0))
Expand All @@ -105,11 +88,14 @@ def do_instrument(self):
bl fopen
// load .counted in x2
adrp x2, .counted
ldr x2, [x2, :lo12:.counted]
adrp x2, .counted0
ldr x2, [x2, :lo12:.counted0]
// load .counted in x3
adrp x3, .counted2
ldr x3, [x3, :lo12:.counted2]
adrp x3, .counted1
ldr x3, [x3, :lo12:.counted1]
adrp x4, .counted2
ldr x4, [x4, :lo12:.counted2]
// build a pointer to .format
adrp x1, .format
Expand Down

0 comments on commit 120e738

Please sign in to comment.