task switching using TGT

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
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

task switching using TGT

Post by yemista »

Ive been reading intels docs, and if I understand this correctly, can you have multi-tasking by letting the hardware do all the work? All you would have to do is setup all the descriptor tables, setup TSS entries for whatever processes you want to run and enter them in the TGT, and then have your scheduler just execute a call instruction on an entry in the TGT pointing to the process you want to switch to? Is it really that simple(conceptually)?
User avatar
Combuster
Member
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:

Re: task switching using TGT

Post by Combuster »

You mean the GDT, and yes it pretty much works that way, only in reverse - the scheduler *returns* to a task, and the task interrupts/calls into the scheduler
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: task switching using TGT

Post by Brendan »

Hi,
yemista wrote:Ive been reading intels docs, and if I understand this correctly, can you have multi-tasking by letting the hardware do all the work? All you would have to do is setup all the descriptor tables, setup TSS entries for whatever processes you want to run and enter them in the TGT, and then have your scheduler just execute a call instruction on an entry in the TGT pointing to the process you want to switch to?
AFAIK most people who used hardware task switching end up using a JMP to the new task, so that they don't need to mess with backlinks...
yemista wrote:Is it really that simple(conceptually)?
In thoery, in can be that simple, and AFAIK it was designed so that (potentially) any task could switch to any other task without scheduler involvement.

In practice, it's slow (e.g. a lot of data can be saved/restored for no reason) and the scheduler needs to do extra work that isn't included - making sure 2 different CPUs don't accidentally try to run the same task, keeping track of time used by each task, changing other CPU state (e.g. debugging registers), changing any OS state, fudging GDT entries so that it can handle more than 8190 tasks, etc.

Basically, using hardware task switching doesn't really make implementing multi-tasking any easier, it's worse for performance, and it's less flexible.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply