Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize FPU save and restore #1235

Open
wkozaczuk opened this issue Jun 2, 2023 · 0 comments
Open

Optimize FPU save and restore #1235

wkozaczuk opened this issue Jun 2, 2023 · 0 comments

Comments

@wkozaczuk
Copy link
Collaborator

wkozaczuk commented Jun 2, 2023

Currently, we save and restore the FPU state in the following places:

  • linux.cc - syscall
  • core/elf.cc - elf_resolve_pltgot
  • arch/x64/exceptions.cc - interrupt and general protection
  • arch/x64/mmu.cc - page fault
  • arch/x64/signal.cc - when calling signal handler

Typically it is achieved by calling xsave and xrstor which are pretty expensive operations. Its total cost can be measured indirectly by commenting out FPU lock code in linux.cc syscall function and running misc-syscall-perf test. The difference between them is on average 70 ns.

It would be nice to figure out how we can take advantage of xsaveopt and other instructions to speed it up. For details please see this excellent article.

Unfortunately, it is not clear how exactly we would need to change FPU saving/restoring code to take advantage of these instructions. I kind of understand the FPU state needs to be saved in the same memory locations for xsaveopt to work correctly. But how exactly would this work across multiple threads?

Also, I am not sure how much performance gain would we see in practical terms. I did hack the FPU save/restore code in syscall function in linux.cc to use some global FPU state variable and I could see 70ns reduced to ~50ns.

Some other relevant notes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant