Saving ARM NEON registers while context switching in Android

1k views Asked by At

At the time of context switching Android saves all ARM general registers on stack and restore it after.

Does Android OS stores NEON registers on stack?

If not, how to make a safe usage of NEON in multi-threading and multi-tasking environment?

2

There are 2 answers

0
Notlikethat On BEST ANSWER

If the kernel is built with NEON/VFP support then it will indeed preserve the NEON state for a task along with the rest as part of the context switch (provided that the task has actually touched NEON/VFP beforehand, so there is some state to preserve).

If the kernel doesn't have NEON/VFP support, then as you guess there is simply no safe way of using it - any task could freely corrupt any other task as they'd all be sharing the same registers. Fortunately that problem doesn't exist in practice because a kernel which isn't aware of NEON also won't enable access to the hardware in the first place. In that case any NEON instructions would be treated as undefined, and signals sent back to the task as appropriate.

The fact that there are tons of Android applications out there with NEON code in them should be a hint as to which of those configurations is relevant here ;)

0
Arun Valiaparambil On

If you are able to use Neon instructions in Android, that means your kernel has enabled the VFP and will be taking care of the switching part(you would have gotten an instruction abort if the kernel didn't enable Neon/VFP). Moreover ARM VFP and NEON share the same set of registers. So in all probability your context is getting saved restored. Some OS's have smarts to reduce switching time by employing lazy switching techniques, but the registers will remain corruption free