OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Aug 21, 2018 12:32 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: OS Multitasking time distribution
PostPosted: Mon Jul 30, 2018 1:13 pm 
Offline
Member
Member

Joined: Sat Sep 24, 2016 12:06 am
Posts: 48
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


Top
 Profile  
 
 Post subject: Re: OS Multitasking time distribution
PostPosted: Mon Jul 30, 2018 1:27 pm 
Offline
Member
Member

Joined: Wed Jul 25, 2018 2:47 pm
Posts: 33
Location: Pizzaland, Southern Europe
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


Top
 Profile  
 
 Post subject: Re: OS Multitasking time distribution
PostPosted: Mon Jul 30, 2018 2:12 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8450
Location: At his keyboard!
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

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group