请输入您要查询的百科知识:

 

词条 CPU time
释义

  1. Subdivision

  2. Unix commands for CPU time

      Unix command top    Unix command time  

  3. POSIX functions clock() and getrusage()

  4. Total CPU time

  5. CPU time and elapsed real time

  6. CPU time and elapsed real time for parallel processing technology

  7. See also

  8. References

  9. External links

{{original research|date=November 2016}}

CPU time (or process time) is the amount of time for which a central processing unit (CPU) was used for processing instructions of a computer program or operating system, as opposed to elapsed time, which includes for example, waiting for input/output (I/O) operations or entering low-power (idle) mode. The CPU time is measured in clock ticks or seconds. Often, it is useful to measure CPU time as a percentage of the CPU's capacity, which is called the CPU usage.

CPU time and CPU usage have two main uses. The first use is to quantify the overall busyness of the system. When the CPU usage is high, the user may experience lag. Such high CPU usage indicates insufficient processing power. Either the CPU needs to be upgraded, or the user experience reduced, for example, by switching to lower resolution graphics or reducing animations.

The second use, with the advent of multi-tasking, is to quantify how the processor is shared between computer programs. High CPU usage by a single program may indicate that it is highly demanding of processing power or that it may malfunction; for example, it has entered an infinite loop. CPU time allows measurement of the processing power a single program requires, eliminating interference, such as time executed waiting for input or being suspended to allow other programs to run.

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, any multitasking delays, and all other types of waits incurred by the program.

Subdivision

CPU time or CPU usage can be reported either for each thread, for each process or for the entire system. Moreover, depending on what exactly the CPU was doing, the reported values can be subdivided in:

  • User time is the amount of time the CPU was busy executing code in user space.
  • System time is the amount of time the CPU was busy executing code in kernel space. If this value is reported for a thread or process, then it represents the amount of time the kernel was doing work on behalf of the executing context, for example, after a thread issued a system call.
  • Idle time (for the whole system only) is the amount of time the CPU was not busy, or, otherwise, the amount of time it executed the System Idle process. Idle time actually measures unused CPU capacity.
  • Steal time (for the whole system only), on virtualized hardware, is the amount of time the operating system wanted to execute, but was not allowed to by the hypervisor.[1] This can happen if the physical hardware runs multiple guest operating system and the hypervisor chose to allocate a CPU time slot to another one.

Unix commands for CPU time

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.

% gcc nextPrimeNumber.c -o nextPrimeNumber

% 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.

// nextPrimeNumber.c

  1. include
  2. include

int isPrimeNumber(unsigned long int n){

  for (int 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 %lu is %lu\", 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 is the sum for all threads.

With Linux starting from kernel 2.6.26 there is a parameter RUSAGE_THREAD which leads to resource usage statistics for the calling thread only.

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 greater than or equal to the CPU time for computer programs 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) would be same as elapsed real time if the work load is evenly distributed on each CPU and no wait is involved for I/O or other 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

  • Elapsed real time
  • CPU
  • Process (computing)
  • System time
  • top
  • mpstat
  • Load (computing)

References

1. ^{{cite web| url=http://www.ibm.com/developerworks/linux/linux390/perf/tuning_cputimes.html| title=CPU time accounting| first=Christian| last=Ehrhardt| date=July 2010| publisher=IBM| accessdate=2014-08-05}}

External links

  • {{cite book

| title=CPU Design: Answers to Frequently Asked Questions
| first=Chandra
| last=Thimmannagari
| date=2005-01-01
| publisher=Springer
| page=68
| isbn=0-387-23799-2}}
  • {{cite web

| url=https://www.gnu.org/software/libc/manual/html_node/Processor-And-CPU-Time.html#Processor-And-CPU-Time
| title=Processor And CPU Time
| work=The GNU C Library
| date=2014-02-09
| accessdate=2014-08-05}}
  • {{cite web

| url=http://www.opengroup.org/onlinepubs/000095399/functions/clock.html
| title=clock - report CPU time used
| work=The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
| accessdate=2014-08-05}}
  • {{cite web

| url=http://www.opengroup.org/onlinepubs/000095399/functions/getrusage.html
| title=getrusage - get information about resource utilization
| work=The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
| accessdate=2014-08-05}}

1 : Computer performance

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/10 15:28:14