Page 1 of 1
Task Switching (software vs. TSS)
Posted: Thu Jan 22, 2004 12:00 am
by BillFarber
Love your board. Long time reader, first time poster.
Anyway, I'm muddling through developing an extremely simple OS simply as a learning exercise. I have gotten to the point where I would like to start doing some task switching. So, I need to decide whether to do that via software or hardware. Do you, the readers and posters on this board, have a preference between software or hardware task switching? If so, why?
The most important thing to me while developing this OS is simplicity. I don't care about speed of execution or the size of the code or data structures.
These are the things I have working thus far:
Running in protected mode
Interrupt Service Routines
GDT
simple video driver
simple keyboard driver
Paging
Call Gates via the GDT
rudimentary debugger
Are there any other basic functions that I need to have working before attacking task switching?
Thanks in advance for your input!
Phil
RE:Task Switching (software vs. TSS)
Posted: Thu Jan 22, 2004 12:00 am
by carbonBased
Personally, I would suggest implementing memory management before task switching.
MM is one of the more difficult aspects of osdev, however, having it in place before tasking code makes the tasking code much simpler. Each task is going to have to have some structure of data associated with it; whether it be a TSS, or a structure you've defined... or both. You'll probably want to be able to allocate this dynamically, rather then set aside memory statically.
However, that aside... my preference, would actually be a hybrid. In my current OS, I've used TSS based multitasking... which I found fairly easy to implement. However, you're limited to 8192 tasks, minus whatever else is in the GDT. Hardly much of a limit... but a limit, all the same.
What I intend to do, when I rewrite my tasking code, is to still utilize TSS based multitasking, but only two TSSs. Essentially you have the TSS of the currently executing task, and in your timer interrupt, you copy the next task's TSS into the other remaining TSS, and jump to it. Essentially, you just switch back and forth between the same two TSSs.
In this since, you only have two TSSs in your GDT... all the other TSSs are stored in memory.
In the long run, this technique will actually be slightly slower then your standard TSS, however, to me it seems a lot more elegant of a solution.
Another approach, that a lot of people like is pure software based which, apparently, can be quite quick. However, my only gripe about that is the lack of hardware IO protection. If you don't care about that, then perhaps software based is a good solution for you. Hopefully someone that's actually implemented both can give a good comparison.
Cheers,
Jeff
RE:Task Switching (software vs. TSS)
Posted: Fri Jan 23, 2004 12:00 am
by hartyl
although i've heard that the hardware-taskswitch is slower than the software one (interesting, eh?) i'm using the hardware-version. it's really easy to implement and i don't think i'll run 8188 tasks anywhen.
actually i don't know excactly how to write that jump in c (in assembler it's easy as well), but i'll see.
RE:Task Switching (software vs. TSS)
Posted: Fri Jan 23, 2004 12:00 am
by Gandalf
hi friend,
Well I personally use two TSS to do the switching. You just have to switch between these two. In my opionion it is pretty simple enough. But I have heard hardware switching is slower but it doesn't show up - also while switching tasks you have approximately 11 internal protection checks that the hardware performs for you (which I think is pretty good and probably accounts for the delay).
So the choice is yours.
rgds
Gandalf
RE:Task Switching (software vs. TSS)
Posted: Mon Jan 26, 2004 12:00 am
by GFL
hi all, I have read this statement many times (hardware task-switching via TSS being slow, even slower than software implementations). I would know how much slower hardware task-switching is since my actual TS implementation relies on this... if you have any link or reference to some measurements backing up this affirmation, could you please post them?
Regards,
Gerard
RE:Task Switching (software vs. TSS)
Posted: Thu Feb 05, 2004 12:00 am
by GFL
I just finished to implement task switching in my microkernel, I am also using the two alternating TSS descriptors to perform hardware task switching. I performed a rapid test and I got about 10600 task switches per second, i.e. less than 0,1 msec per switch on an XP1600+ machine. Anyway I think there's some room for optimization in my code... Anyone has some performance measurements of its own?
RE:Task Switching (software vs. TSS)
Posted: Mon Mar 22, 2004 12:00 am
by Rambo
I'm working on tasking as well, and I have chosen to do things the software method. I have essentially created a structure that stores all the relevant information that TSS does, so there's not much difference. The primary advantage (i feel) is that it allows you to store additional information about each task, such as it's last use, etc. On problem I'm having is accessing eip... hth do you get it's current value?
RE:Task Switching (software vs. TSS)
Posted: Mon Mar 22, 2004 12:00 am
by carbonBased
When your task is interrupted by the timer interrupt, you should be able to grab it's eip from the stack frame.
Cheers,
Jeff
RE:Task Switching (software vs. TSS)
Posted: Tue Mar 23, 2004 12:00 am
by hartyl
i have benchmarked my taskswitching-algo right before.
i've done it in software, without using any TSS. when the timer-interrupt is calle, i get eip, cs and eflags of the running tasks, i backup all the other registers and and get the next task pushing eflags, cs and eip on the stack (so that iret continues the task). both tasks just call the timer interrupt in order to switch to the other task.
the results: about 128000 taskswitches per second on my athlon xp 2600+ (and now it comes) with BOCHS at 1000000 ips. i'll test it on my p3/900 and my amd 1300 at home in the evening.
greets, hartyl
RE:Task Switching (software vs. TSS)
Posted: Tue Mar 23, 2004 12:00 am
by hartyl
so, my lastest benchmarks:
the p3/900-machine got about 229000 tsps (taskswitches per second), which is 4.3µs.
the amd1300-machine got about 240000 tsps, 4.2µs
...software-taskswitching rulez...
greets, hartyl
RE:Task Switching (software vs. TSS)
Posted: Wed Mar 31, 2004 12:00 am
by Rambo
true true true... didn't think of that.