Task Switching Types

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
LindusSystem
Member
Member
Posts: 63
Joined: Sat Apr 28, 2012 9:41 am
Location: Earth -> Asia

Task Switching Types

Post by LindusSystem »

I have heard of 2 types of task switching, those are
  • Software based Task switching
  • Hardware based Task switching
I have googled and searched but I would like to know your opinions:
And my questions are
1]What are the advantages and disadvantages in both of the types?
2]What do you prefer?Why?
3]Is there any other type other than these 2?

Thanks for your consideration
Anyone has a idea of making a ntfs bootsector?if yes PM me , plz.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Task Switching Types

Post by Brendan »

Hi,
LindusSystem wrote:1]What are the advantages and disadvantages in both of the types?
Hardware task switching:
  • Is normally slower, because normally half of the state that the hardware task switch saves/loads doesn't need to be saved/loaded
  • Isn't portable (isn't supported in long mode on 80x86 CPUs, or on ARM, PowerPC, Itanium, etc)
  • Is less flexible (e.g. you have to save/load at the same time)
  • Is less complete - won't save/load "extra" things (debug registers, performance monitoring counters, etc) or keep track of time used by the task for you
  • Can be used to allow arbitrary tasks to switch to other tasks without the kernel/scheduler being involved in some cases
Software task switching:
  • Is normally faster, because normally half of the state that the hardware task switch saves/loads doesn't need to be saved/loaded
  • Is more portable (same basic idea works on any CPU)
  • Is more flexible (for example, you can save a task's state when you enter the kernel and load a new task's state when you leave the kernel, and don't have to save/load at the same time)
  • Is more complete - your code can do everything your OS needs it to do, including tracking how much CPU time each task used, and saving/loading debug registers and performance monitoring registers (to have "per task debugging/performance monitoring" rather than "per CPU")
  • Can't be used to allow arbitrary tasks to switch to other tasks without the kernel/scheduler being involved
LindusSystem wrote:2]What do you prefer?Why?
I prefer software task switching, because software task switching:
  • Is normally faster
  • Is more portable
  • Is more flexible
  • Is more complete
  • Kernel/scheduler has to be involved in task switches anyway
LindusSystem wrote:3]Is there any other type other than these 2?
Not that I know of. In theory it might be possible for a system to support firmware based task switches, but I've never heard of a system that does.


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.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Task Switching Types

Post by iansjack »

Purely of historical interest, the Z80 supported a different sort of hardware task switching (two tasks only) by having a duplicate set of registers. This made it very quick to switch between the two tasks without having to save registers on the stack.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: Task Switching Types

Post by OSwhatever »

The ARM also have hardware task switching apart from the fast interrupt (very few use this and usually only applicable for one interrupt line). The hardware task switching was mostly in question for ARM9 and did not work with multiple address spaces and process was limited to 32MB. Symbian and Windows mobile used this feature what I know about.
rdos
Member
Member
Posts: 3297
Joined: Wed Oct 01, 2008 1:55 pm

Re: Task Switching Types

Post by rdos »

I think one might add to Brendan's list that hardware taskswitching is hard (perhaps impossible?) to do in conjunction with SMP. The main problem with hardware taskswitching for me is that it doesn't separate the save stage from the load stage. I wish there were a hardware version for saving all registers in the TSS and another for loading them. That's how a typical scheduler works, and not by doing both of these in the same operation.
Post Reply