OSDev.org
https://forum.osdev.org/

OS Multitasking time distribution
https://forum.osdev.org/viewtopic.php?f=1&t=33093
Page 1 of 1

Author:  MrLolthe1st [ Mon Jul 30, 2018 1:13 pm ]
Post subject:  OS Multitasking time distribution

Hi all!
I'm written multitasking for my own OS, it working ok, but i'm switching tasks when interrupt from PIT has thrown, an interrupt is working with frequency ~1000.15 Hz and that give me about 1000 processes will be working in one second(for every ~1ms, sorry for my english), but when running more than 1000 processes my task-switching mechanism will work more one second. Are there other methods to switch task more than 1000 times per second?
WIth best regards, thanks a lot,
Aleksandr

Author:  frabert [ Mon Jul 30, 2018 1:27 pm ]
Post subject:  Re: OS Multitasking time distribution

If your processes each have a time quantum of 1ms, and you have more than 1000 of them, then there's no way you can execute them all within 1s, unless some of them yield partway through their time slice, so your only option is to increase the timer's frequency. But the bigger question is, why do you want your processes to end before 1s? Seems like a XY problem to me

Author:  Brendan [ Mon Jul 30, 2018 2:12 pm ]
Post subject:  Re: OS Multitasking time distribution

Hi,

MrLolthe1st wrote:
I'm written multitasking for my own OS, it working ok, but i'm switching tasks when interrupt from PIT has thrown


Unfortunately, assuming task switches are caused by the timer IRQ and nothing else is a common mistake. I've even seen kernels where (e.g.) near the start of its time slice a process will call a function like "read()" and have to wait for data to arrive from disk, but the CPU will be left doing nothing for almost the entire time slice until a timer IRQ triggers a task switch; so about 99% of CPU time ends up being wasted.

The reality is that most task switches are caused by the currently running task blocking (e.g. needing to wait for data from another process, or from keyboard or network or disk or...), or are caused by something happening that a task was waiting for (especially when there were no other tasks running at the time or there's some kind of task priorities involved); and doing task switches when the timer IRQ occurs is just a relatively unimportant optional thing in case a task doesn't block sooner.

I guess what I'm saying is that you could set your timer to 1 Hz, and still get 1 million task switches per second between thousands of tasks.


Cheers,

Brendan

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/