Multitasking and cr3 updating.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
eXeCuTeR
Member
Member
Posts: 63
Joined: Tue Dec 09, 2008 12:43 pm

Multitasking and cr3 updating.

Post 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.
giszo
Member
Member
Posts: 124
Joined: Tue Nov 06, 2007 2:37 pm
Location: Hungary

Re: Multitasking and cr3 updating.

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Multitasking and cr3 updating.

Post 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
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Multitasking and cr3 updating.

Post 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.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Multitasking and cr3 updating.

Post 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.
Post Reply