Can you explain how OS X time sharing works?

in macOS edited January 2014
I've noticed that when I'm running something processor intensive (iTunes while it is converting an AIFF to AAC file for example) that Activity monitor still shows appreciable idle time. I am just curious why this should be. I can understand why a busy program would share time with other active programs but why would a program that is doing something intensive not be given a large chunk of the idle time? Philosophically, why preserve idle time? If most of the idle time is given to one program and a second program became busy then OS X could reassign priorities.

I'm not too concerned with the nuts and bolts, just wondering philosophically why things are setup this way.

As a side issue, is it worth playing with renice (or one of the graphical interfaces for it)?


  • Reply 1 of 3
    The scheduler never saves idle time for the sake of it. The purpose of the scheduler is to give runable programs CPU time and make sure that every process gets it?s fair share based on priority and rules.

    The reason that you are seeing idle time could be many.

    Is your system a dual processor? If so the task at hand might only use a single thread. My system is dual 500Mhz G4 and the same process takes 106% - 118% of the CPU time. Which means it might be using two threads one to perform I/O operations to place the data into a buffer for the converter thread to convert, hence the use of more than 100 percent CPU time. For the most part the second CPU stays idle.

    Other reasons for idle time would be that the CPU is waiting on another part of the system. If the system doesn?t have enough memory and is paging (swapping) during the task you?ll also most likely see idle time as the CPU is waiting for data to be paged in and out. Same goes if your disk sub system is slow, again the CPU is waiting for data.

    There are three main components in a system: CPU, memory and I/O subsystems. It doesn?t sound like your bottleneck is in the CPU so look to the other two and you?ll find your answer.

    One other area of contention that can yield idle time would be in the use of mutexs and semaphores, a coding locking mechanism to make sure that threads don?t clobber each other over resources. When a thread attempts to gain access to a mutex that is already in use it goes to sleep until that mutex is released. I.e. the converter thread waits to read the buffer while the I/O thread adds new data to the buffer.
  • Reply 2 of 3
    xoolxool Posts: 2,460member
    Some tasks could be bound by things other than the CPU. Drive speed or available RAM could limit performance. For example, when ripping CDs on my G5, it is more limited by the CD read speed than my CPU. Not that I'm complaining, as even when limited I get about 22x rip speed.
  • Reply 3 of 3
    neutrino23neutrino23 Posts: 1,558member
    Thanks. I'll pay more attention and get better statistics next time I try one of these intensive processes. I noticed it both with iTunes and a script I run that does a lot of searching and sorting. I'm running a 1.25GHz Al PB with 1GB RAM. The iTunes encoding I do is from AIFF files on the hard drive so they are not limited by the CD.
Sign In or Register to comment.