CPU time

CPU time
CPU Time on Single CPU Multi Tasking System

CPU time (or CPU usage, process time) is the amount of time for which a central processing unit (CPU) was used for processing instructions of a computer program, as opposed to, for example, waiting for input/output (I/O) operations. The CPU time is often measured in clock ticks or as a percentage of the CPU's capacity. It is used as a point of comparison for CPU workload of a program.

In contrast, elapsed real time (or simply real time, or wall clock time) is the time taken from the start of a computer program until the end as measured by an ordinary clock. Elapsed real time includes I/O time and all other types of waits incurred by the program.

Contents

Unix commands for CPU time

top's display of the CPU time of various processes on a Unix-like (GNU/Linux) system

Unix command top

The Unix command top provides CPU time, priority, elapsed real time, and other information for all processes and updates it in real time.

Unix command time

The Unix command time prints CPU time and elapsed real time for a Unix process.

% time nextPrimeNumber 30000007
Prime number greater than 30000007 is 30000023
0.327u 0.010s 0:01.15 28.6%     0+0k 0+0io 0pf+0w

This process took a total of 0.337 seconds of CPU time, out of which 0.327 seconds was spent in user space, and the final 0.010 seconds in kernel mode on behalf of the process. Elapsed real time was 1.15 seconds.

The following is the source code of the application nextPrimeNumber which was used in the above example.

#include <stdio.h>
#include <stdlib.h>
 
int isPrimeNumber(unsigned long int n){
  int i;
  for(i=2; i<=(n>>1); i++)
    if(n%i==0) return 0;
  return 1;
}
 
int main(int argc, char *argv[]){
  unsigned long int argument = strtoul(argv[1], NULL, 10), n = argument;
  while(!isPrimeNumber(++n));
 
  printf("Prime number greater than %d is %d\n", argument, n);
  return 0;
}

POSIX functions clock() and getrusage()

POSIX functions clock() and getrusage() can be used to get CPU time consumed by any process in a POSIX environment. If the process is multithreaded, the CPU time consumed by all individual threads of the process are added.

Total CPU time

On multi-processor machines, a computer program can use two or more CPUs for processing using parallel processing scheduling. In such situations, the notion of total CPU time is used, which is the sum of CPU time consumed by all of the CPUs utilized by the computer program.

CPU time and elapsed real time

Elapsed real time is always the same or more than CPU time for computer program which use only one CPU for processing. If no wait is involved for I/O or other resources, elapsed real time and CPU time are very similar.

CPU time and elapsed real time for parallel processing technology

If a program uses parallel processing, total CPU time for that program would be more than its elapsed real time. (Total CPU time)/(Number of CPUs) is used to calculate elapsed real time if work load is evenly distributed on each CPU and no wait is involved for I/O or other such external resources.

Example: A software application executed on a Hexa-core processor creates three Unix processes for fulfilling the user requirement. Each of these three processes creates two threads, enumerating a total of 6 working threads. Computation is distributed evenly on the 6 independent threads. If no wait for resources is involved, total CPU time is expected to be six times the elapsed real time.

See also

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • CPU Time —   [engl.], CPU Zeit …   Universal-Lexikon

  • CPU time — noun The length of time that a central processing unit was busy processing instructions for a particular program, function or task …   Wiktionary

  • cpu time — computer time …   English contemporary dictionary

  • Time (Unix) — time is a command in the Unix operating systems. It is used to determine the duration of execution of a particular command.UsageTo use the command, simply precede any command by the word time, such as:time lsWhen the command completes, time will… …   Wikipedia

  • Time-sharing — refers to sharing a computing resource among many users by multitasking. Because early mainframes and minicomputers were extremely expensive, it was rarely possible to allow a single user exclusive access to the machine for interactive use. But… …   Wikipedia

  • CPU-Zeit — Die Prozessorzeit (englisch CPU Time ) bezeichnet die gemessene Zeit in Stunden, Minuten und Sekunden, in der ein laufendes Programm seit dem letzten Programmstart tatsächlich Kommandos an den Prozessor gesendet hat. Diese Summe ist praktisch… …   Deutsch Wikipedia

  • CPU design — is the design engineering task of creating a central processing unit (CPU), a component of computer hardware. It is a subfield of electronics engineering and computer engineering. Contents 1 Overview 2 Goals 3 Performance analysis and… …   Wikipedia

  • CPU shielding — is a practice where on a multiprocessor system or on a CPU with multiple cores, real time tasks can run on one CPU or core while non real time tasks run other other.The operating system must be able to set a CPU affinity for both processes and… …   Wikipedia

  • Time (Unix) — time ist ein Kommando auf Unix Betriebssystemen. Es wird dazu verwendet, um die Ausführungsdauer eines bestimmten anderen Kommandos zu messen. Um es zu benutzen wird das Wort time einfach vor das zu messende Kommando gestellt. Ein Beispiel ist:… …   Deutsch Wikipedia

  • Time (Unix) — Эта статья об утилите; о формате кодирования времени см.: UNIX время. У этого термина существуют и другие значения, см. Time. time unix утилита, возвращающая время выполнения простой команды или получение подсказки по ресурсу. Когда команда… …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”