Hello, I am currently trying to implement preemptive multithreading for Mini-OS and have the following problem: If a context switch needs to occur outside of a timer interrupt, I fail to see how to implement it without race condition, because of the complex way to enable interrupts (clear memory word and perform a hypercall if upcalls are pending). The problem boils down to writing a function that takes the new register content as parameter, sets it and reenables interrupts. xen.h refers to a HYPERVISOR_stack_switch hypercall, which does not seem to be implemented or documented anywhere, though. In contrast, context switching from an interrupt handler is easy, as it just involves changing the struct pt_regs. Any help is greatly appreciated, as I am kind of clueless right now. Regards, Julian _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
How is it more difficult than context-switching inside the timer interrupt? In both cases you switch pt_regs and re-enable interrupts. Certainly I don''t think the more complicated way of enabling interrupts makes context-switching in minios that much more complicated overall. -- Keir On 7/10/07 00:37, "Julian Stecklina" <der_julian@web.de> wrote:> Hello, > > I am currently trying to implement preemptive multithreading for Mini-OS > and have the following problem: > > If a context switch needs to occur outside of a timer interrupt, I fail > to see how to implement it without race condition, because of the > complex way to enable interrupts (clear memory word and perform a > hypercall if upcalls are pending). The problem boils down to writing a > function that takes the new register content as parameter, sets it and > reenables interrupts. xen.h refers to a HYPERVISOR_stack_switch > hypercall, which does not seem to be implemented or documented anywhere, > though. > > In contrast, context switching from an interrupt handler is easy, as it > just involves changing the struct pt_regs. > > Any help is greatly appreciated, as I am kind of clueless right now. > > Regards, > Julian > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On 7/10/07 19:52, "Julian Stecklina" <julian@party-force.de> wrote:> Keir Fraser wrote: >> How is it more difficult than context-switching inside the timer interrupt? >> In both cases you switch pt_regs and re-enable interrupts. Certainly I don''t >> think the more complicated way of enabling interrupts makes >> context-switching in minios that much more complicated overall. > > Ok, I see that the problem regarding the race condition between > re-enabling interrupts and restoring registers is already solved in > x86_32.S. The remaining problem is that as far as I read the instruction > set manual correctly IRET will not perform a stack switch, if it returns > to the same privilege level. But this is exactly what I am trying to > accomplish. Any clues, how to do this?You want to switch to a different kernel stack (i.e., you have a kernel stack per thread)? Or are you running the threads in ring 1 and not using ring 3 at all? Well, either way, you just want to load your new stack pointer with a MOV instruction to ESP. If you are wanting to load a new user stack pointer for running in ring 3, then you rely on IRET (which you can do because there will be a privilege transition). -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel