Page MenuHomePhabricator

Fast approach to clean a memory?
Open, Needs TriagePublic

Description

Hi All,

I want to find a way to clean a memory region in TF-A firmware.
This region is 4KB-aligned, physically continuous (e.g., 0xa0000000 - 0xa0000fff).
And, to clean this region, I just want to fill in some "useless" data, e.g., 0x0 or 0xcfcfcfcf.

Initially, I use "memset()" in TF-A, but it is a bit slow.
I then try to directly repeat the LDR instruction, but each time I can only operate 64-bit, still slow.

Do we have some useful instructions to achieve this goal?

Event Timeline

odeprez added a subscriber: odeprez.EditedDec 19 2022, 9:42 AM

Hi,

I want to find a way to clean a memory region in TF-A firmware.

Can you elaborate what you mean by "clean" ?
From the description it seems to be a simple memset, in which case data may remain in caches.
Does the requested operation need to complete to memory e.g. involving cache clean?

Initially, I use "memset()" in TF-A, but it is a bit slow.

Can you provide expected time/bandwidth budget for the "clean" operation?
I appreciate on Arm reference platforms, memset is an optimized assembly routine (lib/libc/aarch64/memset.S).
Can you try to enable OVERRIDE_LIBC=1 command line build option for your platform, if not an Arm (e.g. FVP) platform?
The default C version (lib/libc/memset.c) is already fairly manually optimized and should get even further optimized by the compiler.

Other alternative, would PSCI_MEM_PROTECT from the PSCI standard serve the purpose?

I want to find a way to clean a memory region in TF-A firmware.

If you just want to zero the memory, you could use zero_normalmem() assembly function in TF-A. This will use the DC ZVA instruction to clear memory by cache line size (typically 64 bytes).