Skip to content

perf(webos): prefer AES-GCM on CPUs with AES instructions - #318

Open
zampierilucas wants to merge 2 commits into
punktfunk:mainfrom
zampierilucas:feat/aes-gcm-cipher
Open

zampierilucas wants to merge 2 commits into
punktfunk:mainfrom
zampierilucas:feat/aes-gcm-cipher

Conversation

@zampierilucas

Copy link
Copy Markdown

The client advertised ChaCha20 unconditionally because 32-bit ARM has no fast AES in RustCrypto. The aws-lc backend does use the ARMv8 AES and PMULL instructions from a 32-bit process, and the LG C5 reports them, so AES-GCM is faster there.

This enables the aes-aws-lc-rs feature on punktfunk-core and advertises VIDEO_CAP_CHACHA20 only when AT_HWCAP2 lacks HWCAP2_AES. When the bit is absent the host keeps picking ChaCha20 as before, so older webOS TVs without AES are unchanged. The speed test probe uses the same helper so it negotiates the cipher a real stream does. docs/NOTES.md is updated to match.

On a C5 (4x Cortex-A at 1.4 GHz, 32-bit userland) decrypt dropped from about 12 us to about 4.5 us per packet, roughly 10% of one core at 300 Mbps. The host log showed session cipher aes-128-gcm with client_wants_chacha=false. That measurement came from an earlier fork build carrying the same change, not from this exact branch.

Tested with the armv7 release build and the unit tests on the host (113 pass). This branch was not run on a TV. The in-place decrypt change that also helped is in punktfunk core and is not part of this PR.

Enable the aes-aws-lc-rs backend and advertise VIDEO_CAP_CHACHA20 only when AT_HWCAP2 lacks HWCAP2_AES. TVs with ARMv8 AES get the host's AES-GCM default; older ones keep ChaCha20.

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
@dyptan-io

Copy link
Copy Markdown
Collaborator

It is also possible to get hardware AES on older models, but it requires extra work on the pf-core side, and the returns are not big, so I dropped it in favor of ChaCha. However, this change looks like a low-hanging fruit. I will need to confirm that the switch works on the older webOS.

@zampierilucas

Copy link
Copy Markdown
Author

tbh this is an unconventional setup, external network adapter to get 1GB networking, plus custom pyrowave decoder, and thats why I have to take every performance gain I can get to reach 4k60.
So let me know if this should be hidden under a config or env environment and toggle-able by the user instead, altho I think my implementation here should be quite safe, and should just fallback to ChaCha cleanly.

@dyptan-io

Copy link
Copy Markdown
Collaborator

I don’t think 1Gbps is possible on LG hardware with USB 2.0. It has a limit of around 300 Mbps, which is far too low for the Pyrowave. I’m also not sure whether we can get the Vulkan decoder to work on LG, and that is why we do not aim to support it on WebOS. Otherwise the CPU capacity for ChaCha decoding is more than enough for even the oldes TVs, but you change seems minimal and safe to merge it.

@zampierilucas

Copy link
Copy Markdown
Author

@dyptan-io thats true, the most I was able to get is 300mbp on the usb 2.0, but better then the 100mbps nic build in on my c5.
And yes you can get Vulkan decoding, with a bunch of asterisks, as I did in #317, its real vulkan decoding, but not outputting so far. And "300 Mbps, which is far too low for the Pyrowave" I have might doubts tho, but I'll create a proper comparison if I do get to the point I think 317 is good enough to actually contribute, as of now its way to hacky.
So im just contributing the low hanging-fruits I found along the way, like this change.

@dyptan-io

Copy link
Copy Markdown
Collaborator

Oh, I was not aware of your work on Pyrowave. We may need to raise the bandwidth limit to 300 Mbps for Pyrowave if you manage to do it. My experience with Pyrowave on other devices is that 300 Mbps doesn't meet my 1440@120 quality requirements. With a lower framerate, I'm not sure, does it reduce the perceptible input latency at 60 fps?
Also, we may not benefit from CPU savings at all, since the Vulcan decoder is on the GPU. However, the PR is an improvement, so let's merge it once you fix the linter.

@zampierilucas

zampierilucas commented Nov 11, 2026 •

Copy link
Copy Markdown
Author

On raising the limit, it's not needed so far as upstream has its own control for it, PUNKTFUNK_PYROWAVE_MAX_MBPS, but if this ever gets integrated then yeah, I should make it be controlled by the same limits.
It does feel a lot smoother for me than av1 or h265, but to be completely honest this is subjective, as I don't have decode-to-frame timings for av1 and h265, so maybe I have to build/buy one of those Nvidia LDATs.
On the Vulkan decode, I ended up splitting the decode in two, part on the CPU and part on the GPU, to meet the 16 ms timing at 4K60 (4ffe063). So the CPU savings do end up mattering for Pyrowave on LG.

Again, as I state on the pr header, the pr is only open so we can discuss this things, and not that I think this should be merged as it.

@dyptan-io

Copy link
Copy Markdown
Collaborator

@zampierilucas would you please fix merge conflict before I merge it?

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.

2 participants