OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:05 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How and when to use XSAVE feature set?
PostPosted: Fri Oct 29, 2021 12:21 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
I'm thinking of implementing this in my kernel sometime soon, but I'm confused on exactly how to use it. For example, should I use XSAVES/XRSTORS or the normal XSAVE/XSAVEOPT/XSAVEC and XRSTOR? Should I use it in every interrupt handler? And how do I go about allocating the memory area?


Top
 Profile  
 
 Post subject: Re: How and when to use XSAVE feature set?
PostPosted: Fri Oct 29, 2021 8:20 pm 
Offline
Member
Member
User avatar

Joined: Wed Sep 28, 2005 11:00 pm
Posts: 85
XSAVES is similar to XSAVEC except it also saves the supervisor state as specified in the XSS MSR.

Ethin wrote:
Should I use it in every interrupt handler?


You'd typically use it before a task switch or if your kernel modifies the SSE/AVX registers.


Top
 Profile  
 
 Post subject: Re: How and when to use XSAVE feature set?
PostPosted: Fri Oct 29, 2021 8:28 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Ethin wrote:
For example, should I use XSAVES/XRSTORS or the normal XSAVE/XSAVEOPT/XSAVEC and XRSTOR?

All of these instructions are meant for context switches, but XSAVES/XRSTORS works for privileged context. If you want that privileged context to be unique for each thread, using XSAVES/XRSTORS would be the best way to do it.

I've seen some hints that XSAVES might be faster than XSAVEOPT, but I don't know of any benchmarks to compare the two.

...And of course, whichever one you choose limits you to CPUs that support it.

Ethin wrote:
Should I use it in every interrupt handler?

Saving and restoring extended state can be pretty expensive. Usually interrupt handlers are written to avoid touching any extended state so that it doesn't need to be saved and restored. Plus, if your interrupt handler wants to use any extended state, it probably needs the extended state to be initialized to reasonable values, which adds even more time on top of saving and restoring.

Ethin wrote:
And how do I go about allocating the memory area?

Allocate it alongside the rest of the data your kernel needs to track for each thread. The manuals explain how to figure out how much memory to allocate and what you need to put into that memory before you can use it for XSAVE. The specifics depend on which one you're using.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 67 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group