So, I read the Intel Manuals and looked at early Linux code, and my question is, how does the kernel know when a program is using the math processor?
There is the function math_state_restore, but when is that called?
-JL
Math CoProcessor
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
Math CoProcessor
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
The processor is built to do lazy task switching for coprocessor state. If you look at all FP and vector instructions, you'll notice they all cause an exception when CR0.TS is set. You can set CR0.TS by doing a hardware task switch or by manually setting it. You can clear it via the CLTS instruction.
The routine is roughly as follows:
1) Process A uses the FPU
2) process A gets scheduled
3) the scheduler sets CR0.TS
4) process B runs
5) process B gets scheduled
6) process C runs
7) process C uses the FPU
The coprocessor exception is thrown (#NP, IIRC)
9) The FPU state for process A is saved
10) The FPU state for process C is loaded
11) CLTS is executed to clear CR0.TS
12) process C runs, and can now use the FPU
Notice that there is virtually no FPU-related overhead for process B. And if process A were the only one using the FPU, there would be no floating point save/restore overhead at all.
The routine is roughly as follows:
1) Process A uses the FPU
2) process A gets scheduled
3) the scheduler sets CR0.TS
4) process B runs
5) process B gets scheduled
6) process C runs
7) process C uses the FPU
The coprocessor exception is thrown (#NP, IIRC)
9) The FPU state for process A is saved
10) The FPU state for process C is loaded
11) CLTS is executed to clear CR0.TS
12) process C runs, and can now use the FPU
Notice that there is virtually no FPU-related overhead for process B. And if process A were the only one using the FPU, there would be no floating point save/restore overhead at all.
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
Thanks.
-JL
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io