how does OSX

faxe

Registered
handle distribution of CPU power between apps?
I am exporting a mpeg movie in Quick Time to a mov file, playing other (mpeg1, mov, ...) movies in another player (Seagull Video Player), playing mp3«s with with iTunes and browsing the web with OmniWeb (by the way I love osx )> iTunes doesn«t stutter, Seagull almost doesn«t stutter. But if I am taking DVD Player instead of Seagull VP, DVD P. looses a lot of frames. So >>> how does OSX distribute its CPU power?

:) faxe:confused:
 
how is wind started? how is dust created? how does osx distribute the cpu? how does it allocate ram? i want a better answer than "effciently". i have found apps that show overall memory usage or cpu load, but none that breaak it down like the old 'about this mac". i miss this. good question faxe.
 
add that to the list.

Bring back the memory allocation list (as OS9 in About This Mac);)
 
Or for the Terminally nervous, open Process Viewer in the /Applications/Utilities directory. Click on Memory in the display window, and it'll sort all your running processes by amount of memory they are using.
:D
 
i tried both ways. terminal certainly gives more info. both are an improvement over not knowing. terminal is better than the old way.
 
I recently just finished a course for my Computer Science Master's degree on this topic. The full answer could fill a chapter in a book and I'm sure there are details that I would mess up.

The short answer is that it's based on the priority of the process. When the process has had all the CPU time that the scheduler is willing to give it, it will devote time to the next process on the stack. The order of who get's time next is determined by priority and how long it's been since a process has had time.

As a process ages it's priority (in the kernel, not as reported to a user) goes up.

That's scheduling in a nutshell.
 
wow, a whole class on how osx works? or on how cpu's work? either way your answer is an improvement over any i have found so far. but let me make sure i understand. 1st, who sets the priority? the program or the system? in other words will browser get priority when it needs it or because it knows how much it needs to complete operation, or does the system analyse this on a command by command basis? 2nd - "willing to give it" - so the schedular has set limits on any app - if something takes too long it has to get back in line and wait its turn? 3rd - about the aging - i know i don't understand anything about kernels though i keep meaning to spend some time looking it up (i am sure it will become apriority as soon as i have my first kernel panic). But does this mean that an open application in foreground being used intermittently (like my browser) will get priority when given a command over a background app like toast titanium or the nav i have running right now which might get more while i am sitting here staring deciding what to type next? when i post this reply, will the browser get more of the process attention? and how can aging, the passing of time, be different for the kernel than for me? or are you just saying that things are going on behind my view that rotate even whn i m not giving commands and so it is possible i might make a command that doesn't have priority, even though i think it has been along time since i did anything in the program?

ok, i know this sounds pretty muddled, which is probably pretty par for the course when explaining this to someone like me who is technically challenged and has a limited tech vocabulary. but i am trying to figure out why, in osx, the same operation takes almost no time sometimes, and seems to snag or pause when executing at others. I'm still not sure if any of this explains that when there is only one app open. i notice this quite often when launching and quitting an app. sometimes it pops open and other times it takes awhile.

i still think it's great you had a whole class on this. thanks for sharing 11
 
If you are really interested in these topics, a number of PhD's have been granted for answers to some of them. Some major books have been written about it, and the best advice I can give you is to try to get a hold of few.

The better (i.e. more suited to the Mach3/BSD marriage) are documents on Mach scheduling (some of those available at CMU), Design and Implementation of 4.4BSD (going for the third edition), Vahalia book (Unix: new frontiers, or something like that), the classic Maurice Bach book, Andy Tannenbaum works, and a relatively poor Magic Garden Explained.

Or, you can take the plunge, read all of the FreeBSD archives, and compare them to FreeBSD and Darwin source. Scheduler is a relatively small piece of the kernel.
 
Well, the course was called Operating System Principles and CPU scheduling was just one of the things we covered. BSD and Mach were amoung the OSes we covered.

1. I'm not totally sure who sets the priority. The user can change it with the nice command and each user has his own default priority. However, I noticed that some programs (RealPlayer on other systems) seem to start with a higher priority so the program must have something to do with it too.

2. What you said was pretty much on target. The scheduler decides how much time it can have. If it needs more it has to stop and get back in line. It's called preemptive multi-tasking. The alternative to have a scheduler that cam preempt a task is having tasks with the ability to hang your system as they refuse to let go of the CPU. (Is that clear?)

3. I'm not sure how being in the foreground impacts the scheduler is OSX. I know that it NT it can raise the priority (again, not the reported priority with is probably "normal", the kernel tracks the priority internally too).

At this point your questions get pretty badly formatted. It would be so cool if they were one per line instead of a giant paragraph. :(

Anyway, the browser will get more attention as you type. Sort of. A process will not get more CPU time than it needs. If it's finished it's task or if it's waiting on something (fetching data from a hard drive, waiting for a user to type, etc.) it will voluntarily yeild the CPU to something else. When a user types or the data is back (or whatever) an interrupt is thrown and it gets immediate attention.

I'm not sure I understand your question about how the passing of time is different for you than it is for the kernel. One thing is for sure, this all happens so fast that and human can't possibly keep up. If you type three keystrokes per second the CPU probably does about 200 Billion (math may be off for a 600mhz system) things between keystrokes. To keep a system responsive to the user, interrupts get immediate attention. Typing is an interrupt.

I hope this helps,
Vanguard
 
ladavacm - i can barely face doing that much investigation into my own phd research:p

vanguard - i agree, very nicely done. sorry about my babbling style. so to clarrify about the kernal aging thing. originally you stated "As a process ages it's priority (in the kernel, not as reported to a user) goes up. " So i'm wondering how the time can be different. My interpretation is that i may perceive a longer time between my commands and assume they will be getting priority, but that because things are happening I cannot 'see', my command may not be as 'old' as i think it is, in the perception of the machine. hence a small lag i was not expecting.
 
Ed,

I'm not sure I totally understand what you're asking but I'll try to answer anyway.

There are three ways (at least) that an application will get time from the CPU.

1. The CPU is idle (none of the applications are ready for CPU time) so it just gets what it requests.
2. An interrupt occurred. (keystroke, hard drive finished getting the data you needed, mouse movement, etc.)
3. The app that had the CPU has used all of it's alloted time and must get back in line.

I think what I don't understand is what you mean by command? Is that something like a keystroke or an application (like lame or something).

If you mean keystroke, it should get attention right away because interrupts get attention right away.

If you mean an app, it will get all the cpu time it can unless two apps require all the cpu. In that condition, the scheduler will grant time to one, then move on to the next process in line.

Scheduling is complicated. Because switching tasks wastes time (it's called a context switch) the fastest way to finish all the work is to finish your process completly then move on. However, that system would be painful for a user (but effcient if you were sending big jobs in batched) because he would have to wait. Systems with users on them tend to switch between processes a lot and respond to interrupts quickly.

So back to this aging thing. Most of the processes on your system will have the default priority (zero in a range of -20 to 20 on most unix systems). So how does the scheduler know who to devote cpu time to? It usually goes by age. Whoever has waited the longest for CPU get's it.

There are other ways to do it too. Working on the longest processes first will ensure that SMP systems don't have lots of idle time. By keeping the shortest jobs last, one CPU won't be working for a long time while the other is idle. (I wish I could draw a picture here. I've gotten to the point where I can barely talk without a whiteboard around:) ) I could go on, people have been refining schedulers for a long time now.

I hope this helps,
Vanguard
 
BTW, I have a question of my own. I'm fairly new to apple (I come from the linux camp) and I've never seen the "about this mac" application.

What did it do?
 
once more THANKS for a well written and reasonably understandable presentation of this. I'm starting to get it i think.
by command, i would mean a keystroke, a mouse click, a selection from menu, launching, saving, etc. - telling the program to do something -commanding it to do what you want. what do you programmers call this? I, and other average users i have known, have been calling it a command for some time now. I should be the boss of this mac-chine, not the other way around:p
i guess i still don't get your statement about differences in ageing reported to kernel and to user. i'm not sure anymore that it makes a difference for me to know this. i think you have given us a pretty good overview of things.
if you want to see 'about this mac', boot into 9x, launch an app or 2 and go to apple menu. the very first selection is 'about this mac'. it will show your memory usage of each app and the system, both graphically and verbally. It shows how much of the allotted memory each application has that it is actually using, as well. After reading your explanations, i am starting to see why we don't really need it as much anymore. It was a way for the user to keep track of the neccesary memory allowed by each app so that one could in essence prioritize the allotment by raising and lowering it in each app thru get info in the file menu. System 9 typically takes up about 20 -40mb ram depending on loaded extensions. so if my browser has 50mb ram allotted and it is maxing it out and crashing or quitting, we would have raised it to 60mb continuing this process until it was stable within the limitations of our hardware. you might be able to get a second or third app to launch & run safely by lowering their allocation if the tasks you are working for aren't using all that it is capable of. eg, illustrator uses a lot less if you are working on line drawings than when saving colors or other more complex tasks. of course, with the limited amounts of memory we used to find acceptable due to cost, this often meant quitting one app to run another. about this mac was(is) a tool for helping to do this effectively. when programs quit unexpectedly or crash during processing of a commmand, the first place to look was there to see what you might need to reconfigure. am i being clear?
i think what we really miss, after being enlightened some by you, is a way for us to take a little control back when our apps suddenly quit. We used to have some, and now we don't seem to have any in this area. It has become a matter of having to trust the programmer of the app and the system priorities to make sure everything is working right. Obviously not all the programs do at this point. so we're busy blaming the programmers and apple for screwing up something we used to be able to fix on our own. or at least that's the way i see it. I just want to have this control, without having to learn a computer language to do it.
hey, go play with 9x for awhile. I think every linux convert should, especially programmers. In order to replicate the advantages, conviences, and (for some of us) just plain habitual aspects of the mac experience, it might help to know what we've been doing all these years. Thanks for asking.:) and once more thank you for taking this much time and effort to explain to us!!!!
 
i just realized that i didn't break up my paragraphs as you asked. this is a great example of what i was talking about. When i type in more text than will fit in this box, i start getting all sorts of weirdness. the last line disappears below the box where i can't see what i am typing. the upper text starts to bleed over the top of the box. I lose the ability to add vB code. so i type as clse together as possible since i have no other control over this.
with 9, i could go to 'about this mac' and see how much memory the browser was using of its alllocation. if it was maxing or near to max, i'd go to 'get info' and allocate more memory to my browser. one or two attempts would probably cure this. if not, i would figure there was something wrong with my software and report it if i wanted to. now i can do nothing except report if i choose to. i can only guess at the real reason i'm not getting enough processing priority to complete a simple task like this.:(
there are times the old way sucks, but there are times the new way sucks too!!
 
You want to know about memory usage, you want control of your apps, now you have it unix style.

Ok, I'll agree that some user friendly apps that display what the os is doing would be great. However, it's there now.

If you like learning, check out this url:

http://arstechnica.com/reviews/01q4/macosx-10.1/macosx-10.1-6.html

and the next page:

http://arstechnica.com/reviews/01q4/macosx-10.1/macosx-10.1-7.html

You know more about what's going on with system memory than ever before.

As for "a way for us to take a little control back when our apps suddenly quit" you still have it. As a matter of fact, you have more. In the days of a non-preemptive os the entire system could freeze and ignore your requests. Now, even when a single app badly misbehaves you're ok. You can go to the terminal, use ps to find the process number, then use kill to end it.

Yeah, it's not nearly as friendly as you might be used to but it's the type of thing guy who like to stay "closer to the machine" love.

The beauty of osx (according to me) is that it has both. It's ui is awesome and it's internals are still exposed. As time passes holes like the one you mentioned (the lack of nice performance monitoring apps) will be filled.
 
Originally posted by vanguard
The beauty of osx (according to me) is that it has both. It's ui is awesome and it's internals are still exposed. As time passes holes like the one you mentioned (the lack of nice performance monitoring apps) will be filled.

Agree. Even though I would consider killing for a port of systat. I found it more useful than Glance or BMC Patrol. Hint to Apple (jkh, are you listening?)
 
Back
Top