Why do my CPU workloads mirror each other?

This is a discussion on Why do my CPU workloads mirror each other? within the Tech Board forums, part of the Community Boards category; One thing I've been wondering for a while now is why my CPU workloads seem to mirror each other? I'm ...

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    Why do my CPU workloads mirror each other?

    One thing I've been wondering for a while now is why my CPU workloads seem to mirror each other?

    I'm running Ubuntu Linux with a dual-core and in the System Monitor the CPU graph shows the CPU's in almost mirror images of each other (when one gets busier, the other gets less busy) and they keep swapping which CPU is on top and which is on bottom...

    Is there a particular reason why they do that?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, work-saving thread-swapping when a single-threaded CPU-intensive app is running will swap from one CPU to another. Windows used to be bad at this, but is a bit better now - but all OS's will do this to some extent - if you have one process that really runs 100%, it will swap whenever there are two other processes that must run - which happens every so often (how often depends on what else is going on in the system, such as if there is file or network activity that needs to be dealt with, if there are server/service processes running in the background, etc, etc).

    Since the OS often doesn't know how long a newly awakened process will run, it's best to schedule any process that needs to run on the first available processor. If there are processes that are runnable that haven't run for a while, and there are processes that have been running for a long time, the OS will prioritize those tasks that haven't run for a bit, so that they do not get starved of CPU. And sometimes this means that the next process(es) to run is not the 100% CPU eating process, but some other process.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I can see why a process that gets task swapped out of the CPU might not get the same CPU when it's turn comes again, but what I can't figure out is why the CPU's seem to be exact opposites of each other? If CPU1 goes up 3%, CPU2 goes down 3%, if CPU1 goes down 5%, CPU2 goes up 5%...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    Quote Originally Posted by cpjust View Post
    I can see why a process that gets task swapped out of the CPU might not get the same CPU when it's turn comes again, but what I can't figure out is why the CPU's seem to be exact opposites of each other? If CPU1 goes up 3%, CPU2 goes down 3%, if CPU1 goes down 5%, CPU2 goes up 5%...
    That would make sense, if the system as a whole has a fairly constant amount of load. It's just shifting load from one CPU to another.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Try a
    Code:
    int main() { for(;;); }
    Then the loads on the 2 CPU should add up to 100% all the time (max 200%).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread question
    By quantt in forum Linux Programming
    Replies: 7
    Last Post: 04-07-2009, 01:21 AM
  2. questions on multiple thread programming
    By lehe in forum C Programming
    Replies: 11
    Last Post: 03-27-2009, 07:44 AM
  3. Upgrading my old CPU (for another old one!)
    By foxman in forum Tech Board
    Replies: 16
    Last Post: 01-11-2008, 04:41 PM
  4. Can you still view the bios screen with a bad CPU?
    By HyperCreep in forum Tech Board
    Replies: 4
    Last Post: 12-31-2006, 05:57 PM
  5. CPU temp
    By PING in forum Tech Board
    Replies: 5
    Last Post: 01-28-2006, 05:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21