Thread-wise stack switch

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
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Thread-wise stack switch

Post by JJeronimo »

Hello,

I plan having thread support managed by the kernel. However, a small issue came to my mind.

Assume the kernel we are talking about isn't preemptible (cli while in kernel mode) and is always on uniprocessor. Assume too that we are using software task switching.
Each thread needs it's private stack, so that their executions don't conflict with each other, right? However, the TSS makes the processor always switch to the same stack when a software interrupt causes a switch to Ring 0.

Given that, what's the "usual" procedure to have the thread use it's own stack?
* The solution I plan to implement is, whenever a thread enters kernel somehow that it will for sure need to yield execution (ex. timer interrupt, or disk request), copy the "default" Ring 0 stack contents already created to the thread's private stack.
* Another solution I foresee would be patch the TSS every time one switches threads (and before going to user mode). However, this would require reloading the Task Register, afaik, which takes time.

Any other suggestion?

JJ
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Thread-wise stack switch

Post by bewing »

"Patching" the TSS by fixing the stack pointer contained in the TSS does not require reloading the task register. That is the normal method.
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Re: Thread-wise stack switch

Post by JJeronimo »

bewing wrote:"Patching" the TSS by fixing the stack pointer contained in the TSS does not require reloading the task register. That is the normal method.
Thanks.

JJ
Post Reply