Page 1 of 1

Multitasking and cr3 updating.

Posted: Thu Apr 23, 2009 7:34 am
by eXeCuTeR
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. :P
Thanks.

Re: Multitasking and cr3 updating.

Posted: Thu Apr 23, 2009 7:37 am
by giszo
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. :P
Thanks.
When you switch between two different address spaces, there's no way to avoid the TLB flush.

Re: Multitasking and cr3 updating.

Posted: Thu Apr 23, 2009 8:26 am
by AJ
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

Re: Multitasking and cr3 updating.

Posted: Thu Apr 23, 2009 8:40 am
by Colonel Kernel
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.

Re: Multitasking and cr3 updating.

Posted: Fri Apr 24, 2009 1:16 pm
by bewing
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.