In my multitasking code, each task is given the same time of duration (the frequency of the PIT) and I'm simply implementing the Round Robin algorithm.
Well, since I've entered usermode task scheduling will take much more time since I'll have to update the cr3 which is a long process.
How can I get my code work faster and make the long process of updating the CR3 register faster (I'm of course checking if currenttask->page_dir equals to nexttask->page_dir and update it according to the results). I think there's no other solution than just update the cr3 everytime needed, but any suggestions are welcomed.
Thanks.
Multitasking and cr3 updating.
Re: Multitasking and cr3 updating.
When you switch between two different address spaces, there's no way to avoid the TLB flush.eXeCuTeR wrote:In my multitasking code, each task is given the same time of duration (the frequency of the PIT) and I'm simply implementing the Round Robin algorithm.
Well, since I've entered usermode task scheduling will take much more time since I'll have to update the cr3 which is a long process.
How can I get my code work faster and save the long process of updating the CR3 register (I'm of course checking if currenttask->page_dir equals to nexttask->page_dir and update it according to the results). I think there's no other solution than just update the cr3 everytime needed, but any suggestions are welcomed.
Thanks.
Re: Multitasking and cr3 updating.
Hi,
If you're not already doing so, you can make use of the global flag so that you can at least try to avoid TLB misses in selected areas.
Cheers,
Adam
If you're not already doing so, you can make use of the global flag so that you can at least try to avoid TLB misses in selected areas.
Cheers,
Adam
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: Multitasking and cr3 updating.
Just a quick clarification: It isn't loading CR3 or even the TLB flush itself that take a long time. It's the subsequent TLB misses that really slow things down.
Using the G bit is probably the best you can do.
Using the G bit is probably the best you can do.
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re: Multitasking and cr3 updating.
If you are running hyperthreaded, there is also a technique to use the hyperthread to try to prefetch a few non-global TLB entries a few clock cycles earlier than they might otherwise happen.