简体   繁体   中英

User Level Interrupt Handler for Timer

I have to implement a simple os and a virtual machine, for a project, that supports some basic functions. This os will run on the virtual machine and the virtual machine like a normal program in Linux.

Suppose that now is the quantum that the virtual machine is executed.

  1. How is possible to receive some extra timer signals in order to divide the virtual machine execution time in smaller quanta?
  2. How many timers are available in my cpu? (It's more like a general question)
  3. Can I handle timer signals inside the virtual machine with a user lever interrupt handler?

Any help or guidance would be very appreciated. Thank you

I suggest you use exactly 1 interrupt, and organize your timers in either a queue (for few times, eg <50) or in a heap, which is quite a quick tree which, at any time, gives you access to the smallest element, that is, the element with the next Timer to be handled.

Thus you have one interrupt, one handler, and many Timers with associated functions that will be called by that single handler.

In fact, the normal program is also using interrupt(system-level),for example when they want to use system call. In user level ,you can use swapcontext/makecontext to simulate system level swap context, but when you want to get time(to caculate the time difference) , you have to use syscall.So you'd better use the system timer directly, it's not a bad idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM