4

Assume the computer has a single core - what exactly does it mean for process A to be running at 100% CPU capacity vs (lets say) 10% CPU capacity.

If the CPU was 2.0 GHz, does that mean in a time slice for process A, that the processor was executing 2 billion steps per second (if at 100% cap), but would only be executing 200 million steps (if at 10% cap)?

What would cause the 100% scenario vs the 10% scenario?

  • The different between 10% usage and 100% usage is clear. In one case the task in question is taking 10% of the executing capabilities. In other words everytime the clock is trigged, 10% of the execution time, is assigned to that process. Likewise 100% usage means 100% of the execution time is assigned to that process ( i.e. no other proceses tasks are able execuate ) thus creating a deadlock situation. My example uses a single process to make the process of the CPU running a task easier to understand. – Ramhound Nov 14 '13 at 19:03
  • When you say 'everytime the clock is triggered', is that the same thing as a time slice or is that an actual tick of the CPU? – Dave Stibrany Nov 14 '13 at 19:12
  • @DaveStibrany in this case, it's just a generic time-slice assigned by the OS task scheduler (you should be able to find granularity details for your specific OS/processor architecture if you need actual numbers). Going back to the infinite-loop idea, if I wrote a program that just had a big list of NOP instructions, that would still technically classify as CPU use (during the time slices where the OS says to that program "Ok, it's your turn to run for the next X microseconds", even if my program is doing nothing, it is still running - and that's what CPU Usage Percentage describes.) – Breakthrough Nov 14 '13 at 19:15
  • @DaveStibrany - Lets say you have a 2Ghz Intel CPU. This means that everytime the clock signal is triggered the CPU will process X x86 operation instructions. How many insructions are actually performed depends on several different things. If you have a 2-core x86 CPU it means that you can perform 2 seperate instructions in the same amount of time. This means either 2 different processes have equal priority or a single process can perform an instruction twice as fast ( requires you to write said operation in a certain way in order to do so ). – Ramhound Nov 14 '13 at 19:22
  • A great starting point to understand what actually happens during a clock cycle is to learn the x86 assembly language. Once you do that you understand what an instruction is. – Ramhound Nov 14 '13 at 19:25
7

CPU usage is computed by the operating system's process/task scheduler. Indeed, if a CPU usage is 10%, that indicates that the task is actively running for 10% of the task scheduler's unit periods; other programs may run in the remaining 90% CPU time, or the OS will simply idle. Likewise, if the total CPU usage for all programs is 10%, that indicates that no programs on the system are being executed 90% of the time.

Since no programs run on the "bare metal" in a multitasked operating system (like Windows or Linux), CPU usage is a measure of what percentage your CPU's cycles are dedicated to running that one particular program. This is why if you have an infinite loop in a program, even though no "work" is being done, the CPU usage still approaches 100% (as the program is attempting to use every scheduling period offered to it by the operating system to execute some code).

Although processes are always running, they don't use 100% of the CPU in most cases since a process can wait for a particular event/interrupt to occur, or have indicated to the operating system to suspend/sleep its' operation for a short amount of time.

  • @Breakthrough - What do you consider 'bare metal" because I have always considered that to be a program written in assembly language and you certainly can do that. – Ramhound Nov 14 '13 at 19:26
  • 2
    @Ramhound one that isn't run under a process scheduler, i.e. one that isn't run under a multitasking operating system. This was possible to do in DOS, but Windows itself schedules when that particular code is run, and for how long (it will interrupt the process, and allow more to continue running until it is your processes' "turn" again). – Breakthrough Nov 15 '13 at 1:02
  • I think "real time" is a better word than "bare-metal" – surfasb Nov 17 '13 at 4:12
  • 1
    @surfasb the two are not comparable in this context. A real-time operating system just guarantees that your process can act upon some event/interrupt within X micro/milliseconds, but indeed your program is still run under an operating system. – Breakthrough Nov 17 '13 at 10:55
  • It's amazing how much OS code is involved to do even simple tasks. The printf of your typical "Hello world" program, if run in a character-mode window in Windows, actually takes more OS code (some of it running in another process!) than would putting up a simple message window. There's a lot of code involved in I/O to anything, for that matter. A program confined to calling NO OS functions might "run" but it could not read any data from anywhere nor send any results anywhere. Might as well not run it. – Jamie Hanrahan Nov 12 '14 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.