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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
# Investigations
Probes behind the numbers in `bench/README.md`, and what they left
open.
Machine for everything here: z/OS 29.00, IBM Open
XL C/C++ 2.1 (clang 18.1.8), reached over SSH. Probes live in
`~/tmp/startup-probe` there while they are in use.
## 1. Is the 64-bit start-up cost the address mode or the C runtime?
The C runtime. A 64-bit address space costs nothing.
A `-m64` program that does nothing pays about 28 ms per start; the same
source at `-m32` pays about 1 ms. The open question was which part of
"64-bit" carries that cost: the address space, the loader, XPLINK, or
Language Environment.
### Method: take the C runtime out
Write the program in HLASM, so there is no LE, no XPLINK and no C
library at all: return code 0 in register 15, then `SVC 3` (EXIT). The
source is `bench/probes/tiny31.s` and its 64-bit twin `tiny64.s`; both
assemble and link with the stock tools, and `file` confirms the result:
```sh
as -o tiny31.o tiny31.s && ld -o tiny31 tiny31.o
as -o tiny64.o tiny64.s && ld -o tiny64 tiny64.o
file tiny31 tiny64 # amode=31 / amode=64
```
The C side is the smallest possible program, `bench/probes/tiny.c`, built
at each width:
```sh
ibm-clang -O2 -m32 -o c32 tiny.c
ibm-clang -O2 -m32n -o c32n tiny.c
ibm-clang -O2 -m64 -o c64 tiny.c
```
Measured with 100 starts each in a `/bin/sh` loop, three rounds, the
whole loop timed. `/bin/sh` is AMODE 31, so its own fork adds a constant
0.1 ms to every row and cancels out:
```sh
for p in tiny31 tiny64 c32 c32n c64; do
time sh -c "i=0; while [ \$i -lt 100 ]; do ./$p; i=\$((i+1)); done"
done
```
### Result
| program | AMODE | run-time | per start |
| --- | --- | --- | --- |
| `tiny31` (HLASM) | 31 | none | 0.8 ms |
| `tiny64` (HLASM) | 64 | none | 0.8 ms |
| `c32` (`-m32`) | 31 | LE, XPLINK | 2.0 ms |
| `c32n` (`-m32n`) | 31 | LE, non-XPLINK | 2.0 ms |
| `c64` (`-m64`) | 64 | LE, XPLINK | 29.4 ms |
Three rounds, same numbers to 0.01 s each time.
### What it shows
- `tiny64` is RMODE 64, loads above the bar and starts in 0.8 ms, so
the 64-bit address space and the loader that maps it are free.
- The 28 ms arrives with LE at 64 bits and only with it; at 31 bits LE
costs about 1 ms over bare metal.
- XPLINK does not enter into it: `-m32` and `-m32n` start at the same
speed.
- So the fix for zash was to stop using the 64-bit C run-time, not to
stop using 64-bit addressing.
Earlier notes drew two conclusions from the 32-bit rows alone: that the
cost was "not C code", and that "only the 64-bit address space is
slow". Neither holds. The address space is free and the C run-time is
the whole cost.
### Where the 64-bit runtime is loaded from
The console displays on z/OS 29.00 say the runtime is not in the
LPA:
```text
D PROG,LPA,MODNAME=CELQMAIN CELQMAIN WAS NOT FOUND IN THE LPA
D PROG,LPA,MODNAME=CELQBST CELQBST WAS NOT FOUND IN THE LPA
D PROG,LPA,MODNAME=CEEBMAIN CEEBMAIN WAS NOT FOUND IN THE LPA
```
So neither the 64-bit nor the 31-bit runtime is LPA-resident on this
system. `CEE.SCEERUN` and `CEE.SCEERUN2` are linklist entries 19 and 20
(APF). `CEE.SCEELPA` exists as
a data set but holds only 31-bit members (`CEEPLPKA`, `EDC*`,
`CEL4CTBL`), and it was evidently not loaded at IPL either: the
`CEEBMAIN` query found nothing. The 64-bit DLL is in the linklist
library: `CEE.SCEERUN2` holds `CELQLIB` (aliases `CELALQVT`,
`CELQPIPI`) along with `CELQDCPP`, `CELQDEST`, `CELQDMNP`, `CELQDSNF`,
`CELQIOTD`, `CELQMCHK` and `CELQV004`.
IBM's advice for exactly this case: a DLL used often across many address
spaces "can be installed in dynamic LPA", which "might give the
performance benefits of a single rather than multiple load of the DLL"
(`le-programming-64-bit-ceeam00_v3r2.txt:1743`), and the reentrant part
of an AMODE 64 module "can be shared across multiple spaces or sessions
only if it is installed with dynamic LPA" (`:2827`, `:2842`). The DLL
search order under POSIX(ON) is the z/OS UNIX file system, then JPA,
TASKLIB, STEPLIB or JOBLIB, LPA, and last the linklist (`:1225`).
How far this goes: module pages are shared once loaded, so it is not a
DASD read per start, and 400 starts in a row all cost the same 5.6 ms.
What it does mean is that every address space loads and relocates the
DLL for itself, which is work that can wait while the system is busy.
The 31-bit runtime is equally linklist-only and still starts in 1 ms,
which made this look like a partial explanation at best; it turned out to
be all of it (see below).
### Settled: it is the load
The test above was run, and the load was the cost. Each module is put in
the dynamic LPA from the linklist library it already lives in, no LPALST
change needed (`CSV551I` reports `SUCCESSFUL: 1` for each):
```text
SETPROG LPA,ADD,MODNAME=CELQLIB,DSNAME=CEE.SCEERUN2
```
and the same for `CELQDCPP`, `CELQDEST`, `CELQDMNP`, `CELQDSNF`,
`CELQIOTD`, `CELQMCHK`, `CELQV004` and `IBMHV011`. `D PROG,LPA,MODNAME=CELQLIB`
now answers `D P CELQLIB 148C9011 148C9000 009CC6D0 023730D8`, about
10 MB resident, and the whole set is about 14 MB.
What that changed, measured in one sitting (`build/zos-tools/spawn`,
40 starts, milliseconds per start; zsh from `bench/startup.sh`):
| | before | after |
| --- | --- | --- |
| `c32` (`-m32`) | 1.61 | 1.61 |
| `c64` (`-m64`) | 5.83 (30.45 busy) | 1.63 |
| `pr64` (`-m64`, `printf`) | 6.06 | 1.79 |
| `zash` (`-m32`) | 1.33 | 1.37 |
| `/bin/zsh` (the 64-bit shell) | 31.42 | 3.60 |
| `fk3 0 100`, `fork()` + `wait()` at `-m64` | 4.20 | 0.10 |
| two 64-bit children forked together | 2 × 28 ms | 1.6 ms each, overlapping |
| 32 starts, 8 in flight | 27.5 | 1.60 |
Every 64-bit number that used to be slow is now the 31-bit number, and
the child's CPU charge drops to zero with it: the 4 ms of `fork()` CPU
was the same load work, not a fork of the enclave. `zsh` is the
independent confirmation — it is a 64-bit program we did not write, and
its start went from 31.4 ms to 3.6 ms. `bash` and `oksh` carry no LE at
all and did not move.
### Side by side: 31 and 64 bits
The rerun at 200 starts a row, three rounds in one sitting
(`build/zos-tools/spawn`, milliseconds per start, wall then the CPU the
child was charged), confirms the drop and puts the widths next to each
other. "Before" is the same machine and compiler with the `CELQ` modules
still on the linklist; the 8 and 64 MB fork figures in that column are
the ones `bench/README.md` recorded under Open XL 2.1, since only the 0 MB
case was remeasured here.
| | 31-bit | 64-bit before | 64-bit now |
| --- | --- | --- | --- |
| empty `main`, `tiny.c` | 1.55-1.56 / 0.25 | 5.83 (30.45 busy) | 1.58 / 0.25 |
| `printf`, `pr.c` | 1.53-1.55 / 0.25 | 6.06 | 1.58 / 0.25 |
| `fork()` + `wait()`, 0 MB held | 0.10 | 4.20 | 0.10 |
| `fork()` + `wait()`, 8 MB held | 3.40 | 7.20 | 2.90 |
| `fork()` + `wait()`, 64 MB held | 28.20 | 28.20 | 24.50 |
A 64-bit start is 1.58 ms where it was 5.83, the 31-bit number to
0.03 ms, and the child is charged 0.25 ms of CPU instead of 1.0-1.25.
Fork at 0 MB is 0.10 ms where it was 4.20. The 8 and 64 MB rows moved
less because the memory copy dominates once there is memory to copy; at
those sizes the 64-bit fork came out slightly cheaper than the 31-bit
one, which is inside what load explains (round three read 1.82 against
1.89), so compare across a row rather than across days.
One row is still missing. The HLASM pair will not assemble from the
tree: `as` reports `ASMA144E` on the comment lines of
`bench/probes/tiny31.s` and `tiny64.s`, and every tag and
`_BPXK_AUTOCVT` combination tried either does that or fails with
`ASMA999U Assembly terminated - SYNAD Exit taken - Permanent I/O error
on SYS00011 ... WRONG LEN RECRD`. The probes need an `as` invocation
that works on this system; the machine and the compiler are not
involved, and that is why the bare-metal rows in §1 have no fresh
numbers.
The gain does not survive an IPL: the dynamic LPA is rebuilt at every
IPL. Making it permanent is an operator step, and on this LPAR there is
already a home for it. The installation PARMLIB member `PROGLE` holds the three
`LPA ADD` statements that put the 31-bit runtime there:
```text
LPA ADD DSNAME(CEE.SCEERUN) MODNAME(CEEMENU0,CEEMENU2,CEEMENU3,CEEMENU4,CEEMENU5)
LPA ADD DSNAME(CEE.SCEERUN) MODNAME(EDCZEMSG,EDCZUMSG,EDCPRLK,EDCNINSP,
EDCHDMNP,DEMANGLE,IEDCMSGT,EDCRNLIB,EDCRNLST)
LPA ADD DSNAME(CEE.SCEERUN2) MODNAME(CELHDCPP,CELHV003,SCEECPP,C128,CRTEC128)
```
so a fourth statement alongside them, activated with `SET PROG=LE` and no
IPL, is the smallest change:
```text
LPA ADD DSNAME(CEE.SCEERUN2) MODNAME(CELQDCPP,CELQDEST,CELQDMNP,CELQDSNF,
CELQIOTD,CELQLIB,CELQMCHK,CELQV004)
```
Where those statements live here: `D IPLINFO` says `USED LOADC3 IN
SYS9.IPLPARM`, and `SYS9.IPLPARM(LOADC3)` names the PARMLIB
concatenation --- the installation PARMLIB first, then `CPAC.PARMLIB`,
then `SYS1.IBM.PARMLIB`. Its `IEASYS01` selects the LPA
lists with `LPA=01` (so `LPALST01`, which names `CEE.SCEELPA`) and
`MLPA=01` (so `IEALPA01`), and picks the PROGxx members with
`PROG=(A0,E0,L0,LE,ZW)`.
For re-applying it to the running system, `notes/celq-lpa.rexx` issues
the one `SETPROG` through SDSF's `ISFSLASH`, and `notes/celq-lpa.jcl`
runs that exec in batch; from a z/OS shell the same command goes through
`opercmd`. A `COMMNDxx` member that issues the same `SETPROG` at IPL
would work too, but the PROGxx statement is processing that the IPL is
already doing, so there is nothing to order correctly.
`zash` itself gains nothing from the LPA change: it was already at 1.3 ms.
It is the reason the build went back to 64-bit, where the fork-heavy rows
lose to the run-time load rather than to anything zash does.
### Decision: build 64-bit
With the widths equal, the build is 64-bit: `-m64` in `ZCFLAGS` and
`ZDBGFLAGS`, and `make` and `make zash` on z/OS land on `zos-ascii`, the
64-bit ASCII build. A rerun of `bench/run.sh` and `bench/startup.sh` at
64-bit after the LPA change has zash ahead of `/bin/sh` in every row it
measured, and starting in 1.35 ms against 2.22 (`-c :`, 200 starts); the
31-bit build had no row it won on start-up either way.
The one cost of the switch: IGGCSI00 and BPXWDY2 are AMODE 31, and
`OS_UPSTACK` does not exist at `-m64`. The 64-bit build declares both
with plain `OS` linkage, which is the glue the compiler reference gives a
64-bit XPLINK caller of an AMODE 31 routine. On this system neither
module is installed, so the call is unverified here; `csi_call()` catches
a program check and retires the catalog rather than taking the shell
down.
### Not settled
- Why 31-bit LE costs 1 ms. Assumed to be the same enclave work at
smaller sizes; not measured separately. It is no longer interesting:
it is 1 ms either way.
- Why a linklist load of the 64-bit DLL costs 4-28 ms when the 31-bit
one costs under 1 ms from the same kind of library. With the LPA
answer in hand this is a question for IBM rather than for zash.
Absolute figures drift between sessions and machines (the 32-bit C rows
read 1.0 to 1.1 ms in an earlier run, 2.0 ms here); only comparisons
made in one run are worth quoting.
## 2. Where the 28 ms goes: inside LE, and it is a wait
The cost is paid inside Language Environment, before the first
instruction of `main`. About 1 ms of it is CPU charged to the child and
the rest is time spent waiting on something shared; what that shared
thing was is answered in [Where the 64-bit runtime is loaded
from](#where-the-64-bit-runtime-is-loaded-from) — it was the load of the
64-bit runtime itself. The measurements below were taken before that,
on a system where it was not LPA-resident.
The probes are in `~/tmp/startup-probe2` on the box. `bench/le-init.sh`
reproduces the table below.
### Method
- Phases: the child writes a timestamp as the first instruction of
`main` and another from `atexit`, so the split needs no clock in the
parent (`tchild.c`, `tparent.c`).
- Overlap: two children forked before the parent waits for either
(`twin2.c`), and two `spawn` runs in parallel against one run of twice
the size.
- Everything else: `_CEE_RUNOPTS` from outside, a battery of libc calls
timed from inside `main` (`op.c`, built `-m32` and `-m64`), empty
environment, `LIBPATH`, five working directories, and the CPU the
child is charged (`times()`, child time).
### The phases, from inside the child
| phase | 64-bit | 31-bit |
| --- | --- | --- |
| fork + exec + LE init, to first instruction of `main` | 28,763 µs | 1,172 µs |
| `main` | 4 µs | 4 µs |
| `main` returns, to exit | 720 µs | 467 µs |
The 64-bit distribution is tight (min 28,429, max 29,220 µs over 20
starts), so the cost is systematic rather than one unlucky slice, and 27
of the 28 ms are before `main` gets control.
### The same binary, two regimes
40 starts one after another, `tests/tools/spawn.c` (child wall, then
child CPU, milliseconds per start):
| program | wall | CPU |
| --- | --- | --- |
| `tiny31` (HLASM, no LE) | 1.43 | 0.00 |
| `tiny64` (HLASM, no LE) | 1.39 | 0.00 |
| `c32` (`-m32`) | 1.76 | 0.00 |
| `c32n` (`-m32n`) | 1.47 | 0.00 |
| `c64` (`-m64`) | 5.83 | 1.00 |
| `pr64` (`-m64`, `printf`) | 6.06 | 1.25 |
| `c64`, earlier in the same session | 30.45 | 1.25 |
So the 64-bit path costs about 4 ms over the 31-bit one on a machine that
is otherwise idle, and 28 ms while something else is going on, with the
CPU charge unchanged at 1.0-1.25 ms in both cases. The other rows do not
move between the two regimes, and a 200-million iteration loop still
costs 391 ms of CPU while they do, so the LPAR did not get slower, only
this path did.
### It is a wait, and while it is slow it does not overlap
Charged CPU is 1.25 ms whichever regime we are in, against 5.8 ms of
wall, so most of the cost is spent off-processor.
- Slow regime (30 ms): two children forked together both reach `main`
after 54 ms, i.e. 2 × 28 ms, and 32 starts with 8 in flight give the
same 5.7 ms per start as one at a time. Serialized.
- Quiet regime (5.8 ms): two `spawn` runs of 20 in parallel take 230 ms
where one run of 40 takes 246 ms. They overlap.
Same code, same machine: the shared resource queues while the box is
busy and does not when it is quiet.
### What it is not
- Not the program. `int main(void) { return 0; }` and a battery of 15
libc calls differ by ~0.2 ms; a single `printf` costs ~0.1 ms. The
battery's most expensive entry is `fork()` at 6.2 ms (see §1);
`pthread_create` 269 µs, `getpwuid` 119 µs, `getpwnam` 62 µs,
`setlocale(LC_ALL, "")` 13 µs, `tzset`, `dlopen(NULL)`, `getrlimit`,
`isatty` all ~0.
- Not the address space or the loader: `tiny64` (HLASM, RMODE 64) is
1.39 ms.
- Not XPLINK: `-m32` and `-m32n` start at the same speed (§1).
- Not the environment, `LIBPATH` or the working directory: empty
environment, empty `LIBPATH`, a long `LIBPATH`, and five working
directories (`/`, `/usr/lib`, `/etc`, `$HOME`, the probe directory) all
give the same number.
- Not a run-time option. Taken one at a time from outside, 30 starts
each:
| `_CEE_RUNOPTS` | start |
| --- | --- |
| (nothing) | 30.45 ms |
| `POSIX(OFF)` | 30.5-31.0 ms |
| `TRAP(OFF)` | 29.33 ms |
| `HEAPPOOLS64(OFF)` | 30.69 ms |
| `STACK64(1M,1M,4M)` | 29.40 ms |
| `RPTOPTS(OFF)` | 30.83 ms |
Nothing to tune, and nothing to build into the program with a
`CELQUOPT` module. (`MSGLEVEL(0)` is not an option on this release:
`CEE3611I`.)
#### The `POSIX(OFF)` result that was wrong
The first version of this measurement said `POSIX(OFF)` removes the cost
entirely (1.53 ms). It does not. What happened, since the mistake is easy
to repeat: `_CEE_RUNOPTS` was exported to the *parent*, which was an LE
program (the first `spawn`). With POSIX(OFF) in force, that program's
`execl` fails and every child exits 127 immediately, at 1.5 ms per failed
start; a fork/exec loop that does not check exit status reports that as a
fast start. `_CEE_RUNOPTS` exported from a non-LE shell does reach the
child, which is why the mistake looks like a working result from a shell
prompt. `tests/tools/spawn.c` now builds the child's environment by hand
and passes it to `execve`, since `putenv` after LE has initialized is not
passed on either.
### Not settled
- Which resource the wait is on, and what makes it 5× worse at times.
Everything is uncharged wall time on a shared queue. A DLL search
through the z/OS UNIX file system was ruled out for the fixed part
(`pr64` pays the same 6 ms with the same search), and the runtime is
not in the LPA (see above); an SRB, a service address space, or the
per-address-space load of the DLL remain candidates.
`ps -A` shows no system address spaces to an ordinary user, z/OS
`/proc/<pid>` has no `map`, `wchan` or `sysent`, and the z/OS UNIX
syscall trace (`SIGTRACE` then `SIGDUMP`,
`le-debugging-ceea100_v3r2.txt:17792`) needs dump authority. So this
needs the operator, or a quieter machine to compare against.
- Whether an APAR or PTF already covers it. Everything here is z/OS
29.00 with LE as shipped; no older release was compared.
- The 4 ms `fork()`. From inside a 64-bit LE program it is 6.2 ms
against 0.7 ms from the same source at `-m32`, with an identical child.
The HLASM `BPX1FRK` probe is still unwritten, and an AMODE 64
`BPX4FRK` attempt abended: it needs a 144-byte F8SA save area and a
correct 64-bit parameter list (no end-of-list bit,
`zos-unix-assembler-services-bpxb100_v3r2.txt:272`), and `RMODE 64` is
not supported for callable services (`:246`).
### If this goes to IBM
The reproducible core, without the probes:
```sh
echo 'int main(void) { return 0; }' > tiny.c
ibm-clang -O2 -m32 -o c32 tiny.c
ibm-clang -O2 -m64 -o c64 tiny.c
# 40 starts each, one child at a time, wall clock and child CPU
build/zos-tools/spawn ./c32 40 # z/OS 29.00: 1.5 ms wall, ~0 CPU
build/zos-tools/spawn ./c64 40 # 5.8 ms wall, 1.25 ms CPU
```
What to ask: before the runtime was made LPA-resident, a 64-bit start
spent 4.5-28 ms before the first instruction of `main`, of which
1.0-1.25 ms was charged to the process; the rest was wall time that did
not overlap between concurrent starts when it was at its worst. With the
`CELQ` members in the dynamic LPA the same start costs 1.6 ms and the
fork CPU drops to nothing, so the question for IBM narrows to: why does
loading `CELQLIB` from the linklist cost 4-28 ms per address space when
the 31-bit runtime costs under 1 ms from the same kind of library, and
why does that load not overlap between address spaces? A 64-bit HLASM
program with no LE costs 1.4 ms throughout, and no `_CEE_RUNOPTS` option
moved it, `POSIX(OFF)` included.
### For zash
Nothing to do. zash is 31-bit on z/OS on purpose (`-m32`,
`Makefile:64`), which pays 1.4-1.8 ms of LE instead of 5.8 or 30 ms, and
no run-time option, environment change or link option found here buys
any of the 64-bit cost back.
|