summaryrefslogtreecommitdiffhomepage
path: root/bench/le-init.sh
blob: cc821e202be9ab720a10543febc3c6a31456db13 (plain)
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
#!/bin/sh
# What a 64-bit start costs before `main`, and which part of it is LE.
#
#   sh bench/le-init.sh
#
# z/OS only: it needs ibm-clang for the C rows and `as`/`ld` for the
# HLASM rows, which have no C runtime at all.  The two HLASM rows and the
# `-m64` row are the finding: a 64-bit address space without LE costs
# what a 31-bit one costs, so the penalty is LE's, not the address mode.
# The `POSIX(OFF)` rows are the control for the runtime option that looks
# like a fix and is not.  See notes/investigation.md.
#
# Builds what it times in a work directory under TMPDIR, so nothing is
# left behind and nothing in the source tree has to be rebuilt.
here=$(cd "$(dirname "$0")" && pwd)
spawn=${SPAWN:-$here/../build/zos-tools/spawn}
n=${BENCH_N:-40}
[ "$(uname -s)" = OS/390 ] || { echo 'le-init: z/OS only'; exit 77; }
[ -x "$spawn" ] || { echo "le-init: $spawn is not built; run make bench" >&2; exit 2; }

work=${TMPDIR:-$HOME/tmp}/zash-le-init.$$
mkdir -p "$work" && cd "$work" || exit 1
trap 'cd /; rm -rf "$work"' EXIT

cat >tiny.c <<'EOF'
#include <stdio.h>
int main(int argc, char **argv) {
    (void)argc; (void)argv;
    return 0;
}
EOF
ibm-clang -O2 -m32  -o c32  tiny.c || exit 1
ibm-clang -O2 -m32n -o c32n tiny.c || exit 1
ibm-clang -O2 -m64  -o c64  tiny.c || exit 1

# printf: shows that the C runtime is still there with POSIX(OFF) (the
# last two rows run it) and that a syscall and a string are not the cost.
cat >pr.c <<'EOF'
#include <stdio.h>
int main(void) {
    return printf("hello %d\n", 42) < 0;
}
EOF
ibm-clang -O2 -m64 -o pr64 pr.c || exit 1

# No LE at all: return code 0 in register 15, then EXIT.
cat >tiny31.s <<'EOF'
         CSECT
         AMODE 31
         RMODE 31
         SR    15,15
         SVC   3
         END
EOF
cat >tiny64.s <<'EOF'
         CSECT
         AMODE 64
         RMODE 64
         SR    15,15
         SVC   3
         END
EOF
as -o tiny31.o tiny31.s && ld -o tiny31 tiny31.o || exit 1
as -o tiny64.o tiny64.s && ld -o tiny64 tiny64.o || exit 1

# The last line only: the `printf` rows print before the timing does.
row() {
    out=$("$@" 2>/dev/null | tail -1) ||
        { printf '%-24s %10s %10s\n' "$label" failed -; return; }
    printf '%-24s %10s %10s\n' "$label" $out
}

printf '%-24s %10s %10s\n' 'program' 'wall/start' 'CPU/start'
label='tiny31 (HLASM, no LE)';  row "$spawn" "$work/tiny31" "$n"
label='tiny64 (HLASM, no LE)';  row "$spawn" "$work/tiny64" "$n"
label='c32 (-m32)';             row "$spawn" "$work/c32" "$n"
label='c32n (-m32n)';           row "$spawn" "$work/c32n" "$n"
label='c64 (-m64)';             row "$spawn" "$work/c64" "$n"
# Passed through `spawn` to the child only.  Exported here it would also
# apply to `spawn`, which is an LE program: with POSIX(OFF) in the parent
# its execl fails and every child exits 127.
label='c64 POSIX(OFF)';         row "$spawn" "$work/c64" "$n" '_CEE_RUNOPTS=POSIX(OFF)'
label='pr64 POSIX(OFF)';        row "$spawn" "$work/pr64" "$n" '_CEE_RUNOPTS=POSIX(OFF)'