Skip to content

attester: add RA_PERF performance measurement logging - #4

Open
mmxsrup wants to merge 7 commits into
pr/prot-os-versionfrom
pr/perf-logging
Open

attester: add RA_PERF performance measurement logging#4
mmxsrup wants to merge 7 commits into
pr/prot-os-versionfrom
pr/perf-logging

Conversation

@mmxsrup

@mmxsrup mmxsrup commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds RA_PERF timing logs across the attestation stack for the performance evaluation: total attestation time, per-event durations (hashing, CBOR/COSE, ECDSA/CAAM signing, black-key processing), and the CAAM black-key on/off comparison.

Stacked on #3 (base = pr/prot-os-version).

One machine-parsable line per measurement:

RA_PERF|<layer>|<event>|<duration_us>|key=<embedded|plain|black|->
  • pta (ARM generic timer, µs): hashes, CBOR encode, sign breakdown, OCOTP reads, key generation. Events are buffered and printed in one batch after all timestamps are taken (the synchronous console would otherwise skew them); the flush cost is reported as perf_flush.
  • ta (TEE_GetSystemTime, ~1 ms): pta_invoke, cmd_total.
  • host (CLOCK_MONOTONIC): TEE round trip, HTTP round trips, total. New options: --perf (enable logs), --loop N, --no-server (local nonce; no verifier needed).
  • Black-key on/off is a runtime choice (--key-hex); compare via pta|sign_ecdsa — both paths sign on CAAM, the black-key path adds blob decapsulation + CCM key import.

Enable with CFG_REMOTE_ATTESTATION_PERF=y; default builds are unaffected. The i.MX bbappend also raises CFG_TEE_CORE_LOG_LEVEL to 2 (meta-freescale forces 0, which compiles out all core trace).

Full log-point list and measurement protocol: docs/performance-measurement.md (Japanese).

Update (2026-07-28)

Four commits added after the device measurement campaign:

  • Remove the signature self-verify from the PTA sign path: it was a debug-time diagnostic (result ignored, embedded-key path only) that added ~6 ms to that path and had to be excluded from every comparison. With it gone, the embedded-key and plain-key paths run the same code — confirmed statistically identical on the device.
  • Fix the CAAM include-dir guard in sub.mk (CFG_NXP_CAAM_ECC_DRVCFG_NXP_CAAM): a build with the CAAM enabled but the ECC driver disabled (the software-signing configuration used for the CPU-vs-CAAM comparison) failed to find caam_key.h.
  • Per-build provisioning data for the two comparison images: imx-caam (ECDSA on CAAM) and imx-cpu (software ECDSA); ./run.sh imx-caam / ./run.sh imx-cpu work as-is.
  • Document the new environments: run.sh usage/error text now enumerates the available environments, and both provisioning READMEs list imx-caam / imx-cpu.

Testing

  • QEMU E2E: flag off — no perf code compiled, zero RA_PERF lines, flow unchanged; flag on — with verifier / --no-server --loop 3 / without --perf / --generate-blackkey; ear.status: affirming.
  • Numbers internally consistent (sign_*cose_sign1; event sum ≈ cmd_total).
  • i.MX8MP EVK (HAB-signed, closed configuration): full measurement campaign with both builds — E2E affirming on every run; CAAM vs software signing 31.6× on sign_ecdsa; black-key overhead +61 µs (+1.34%) over plain.

mmxsrup added 2 commits June 11, 2026 15:04
Add timing instrumentation across the attestation stack so that the
total attestation time and the duration of each major event (memory
hashing, CBOR/COSE encoding, ECDSA/CAAM signing, black-key processing)
can be collected for performance evaluation. Every measurement is one
machine-parsable line:

  RA_PERF|<layer>|<event>|<duration_us>|key=<embedded|plain|black|->

PTA (microsecond resolution, ARM generic timer): ocotp_srk,
ocotp_lifecycle, instance_id, hash_ta, hash_tee, cbor_encode,
sign_key_setup, sign_tbs_hash, sign_ecdsa, sign_verify, cose_sign1,
cmd_total, plus keypair_generate / blackkey_encap / convert_total for
the black-key provisioning commands. Events are buffered and flushed in
one batch after all timestamps are taken, because the secure console is
synchronous and printing between measured operations would skew them;
the flush reports its own cost as perf_flush. sign_ecdsa is the bracket
for the CAAM black-key on/off comparison (sign_verify only runs on the
embedded-key path and is reported separately so it cannot bias it).

TA (millisecond resolution, TEE_GetSystemTime): pta_invoke, cmd_total.

Host (clock_gettime CLOCK_MONOTONIC): teec_init, teec_open_session,
veraison_new_session, evidence_get, print_evidence,
veraison_post_evidence, total, blackkey_generate, blackkey_convert.
New client options: --perf (or RA_PERF=1) enables the host log lines,
--loop N repeats the attestation for statistics, --no-server attests a
local random nonce without a relying party (useful on devices without
network access to a verifier).

The firmware side is compiled in only with
CFG_REMOTE_ATTESTATION_PERF=y (QEMU: pass it to make check; Yocto: set
the variable for optee-os and veraison-attestation in local.conf) and
default builds are unaffected. The i.MX bbappend raises
CFG_TEE_CORE_LOG_LEVEL to 2 together with the flag because
meta-freescale's optee-os-common-fslc-imx.inc forces it to 0, which
would compile out all core trace including the RA_PERF lines.
Document the RA_PERF timing logs: log format and clock sources per
layer, the full log-point list, how to enable the instrumentation on
QEMU and on the i.MX Yocto build, a recommended measurement protocol
(repetitions, aggregation script), and how to compare CAAM signing with
and without the black key (compare pta|sign_ecdsa only; on i.MX both
paths sign on CAAM hardware, the black-key path additionally pays blob
decapsulation + CCM key import). Includes the security note that
running without the black key leaves the signing key unprotected by the
CAAM, so those numbers are for performance comparison only.
mmxsrup added 4 commits June 23, 2026 08:47
Turn the measurement-protocol's "governor/CPU clock" mention into a
concrete pin-and-record step (scaling_governor=performance + record
scaling_cur_freq), since sub-ms events swing with DVFS and nothing else
fixed it. Note that the aggregation one-liner counts all iterations
(including the cold first one the protocol says to discard), how to trim
it offline, and that teec_init/teec_open_session are measured once
before the loop and so are already outside the per-iteration aggregates.
Drop the embedded-key-only crypto_acipher_ecc_verify self-check (and the
public-key setup that existed only to feed it) from sign_ecdsa_sha256.
It was a debug-time diagnostic: its result was ignored (res was reset to
success either way), it never ran on the black-key path, and it made the
embedded-key path pay an extra ~6 ms verify that had to be excluded from
every performance comparison. With it gone the embedded-key and
plain-key paths execute the same code, which the July device
measurements confirmed (their sign_ecdsa times are statistically
identical). The sign_verify RA_PERF event and its special-casing in the
measurement guide are removed accordingly.
ocotp.c is compiled whenever CFG_NXP_CAAM=y, but the CAAM include
directory was only added with CFG_NXP_CAAM_ECC_DRV=y, so a build with
the CAAM enabled and the ECC driver disabled (the software-signing
configuration used for the CPU-vs-CAAM comparison) failed to find
caam_key.h. Key the incdirs on CFG_NXP_CAAM to match the sources.
Add per-build CoMID templates for the two i.MX8MP images used in the
signing-performance comparison: imx-caam (CFG_NXP_CAAM_ECC_DRV=y,
ECDSA on the CAAM) and imx-cpu (ECC driver disabled, software ECDSA).
The ARoT reference value is identical for both (same TA binary); the
PRoT value differs per build because the OP-TEE core differs. Each
variant gets its own tag-identity id and a matching comid-psa-ta file
so that "./run.sh imx-caam" / "./run.sh imx-cpu" work as-is.
run.sh already accepts any environment with a matching data-file pair,
but its comment and error message still listed only qemu/imx, and the
READMEs did not mention the two per-build variants added for the
CAAM-vs-CPU signing comparison. List them in both READMEs and make the
error message enumerate the actually-available environments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant