Multitasking idea i wanted some feedback on
Posted: Sat Jun 07, 2008 4:45 am
Right.. my OS is going no where fast at the moment (stupid exams/revision/social life/ELF DLL's!), but i'm still thinking of ideas to implement when i have time.
So, i was thinking about drivers earlier, and once i get them succesfully relocated i realised that if i run them as normal tasks a large percentage of CPU time is going to be wasted while waiting for while() loops involved in hardware checks etc.
It would be a bit much to expect all the programmers making drivers to use the syscall i will implement to release the tasks time in the while loop (something like sleeptask()), so i was thinking about how i could do this in my scheduler.
If i had my scheduler check the current task was a driver, and then every n PIT IRQ's dissassemble the code being executed (say 5 instructions either way), i could analyse that and see if it was in a while() loop (or equivalent). Then the time would be released, and the when the task next comes into the scheduler (this is dependant on the priority etc) the requirements of the while() are checked before control is passed to the task. for example:
- code is dissassembled every 20 timer ticks
- the driver is discovered to be waiting for a inb() to read a certain value
- the latency for the command is taken into accound and the task is put to sleep for a certain amount of time - say half a second
- when the task is fed back into the scheduler the scheduler performs the inb() command to see if execution is ready to carry on
- if so, control is returned to the task. if not, the time to put the task to sleep is reanalysed.
Does this sound like it would work?
The possible issues i identified where:
when i while() loop is about to finish, but the scheduler cannot work this out and so puts the task to sleep, wasting time.
could put the task to sleep for far longer than was needed
So, i was thinking about drivers earlier, and once i get them succesfully relocated i realised that if i run them as normal tasks a large percentage of CPU time is going to be wasted while waiting for while() loops involved in hardware checks etc.
It would be a bit much to expect all the programmers making drivers to use the syscall i will implement to release the tasks time in the while loop (something like sleeptask()), so i was thinking about how i could do this in my scheduler.
If i had my scheduler check the current task was a driver, and then every n PIT IRQ's dissassemble the code being executed (say 5 instructions either way), i could analyse that and see if it was in a while() loop (or equivalent). Then the time would be released, and the when the task next comes into the scheduler (this is dependant on the priority etc) the requirements of the while() are checked before control is passed to the task. for example:
- code is dissassembled every 20 timer ticks
- the driver is discovered to be waiting for a inb() to read a certain value
- the latency for the command is taken into accound and the task is put to sleep for a certain amount of time - say half a second
- when the task is fed back into the scheduler the scheduler performs the inb() command to see if execution is ready to carry on
- if so, control is returned to the task. if not, the time to put the task to sleep is reanalysed.
Does this sound like it would work?
The possible issues i identified where:
when i while() loop is about to finish, but the scheduler cannot work this out and so puts the task to sleep, wasting time.
could put the task to sleep for far longer than was needed