多核处理器上的 top 命令

use*_*847 62 linux top parallelism cpu-usage

我正在使用飞思卡尔 IMX6 四核处理器。我想知道该top命令是否列出了所有 4 个内核或单个内核的 CPU 使用率。我看到应用程序的 CPU 使用率与 4 核和单核相同。我猜测应用程序的 CPU 使用率会在单核上增加而在 4 核上减少,但它没有改变。

ter*_*don 88

我不完全确定你在这里问什么。是的,top默认情况下将 CPU 使用率显示为单个 CPU 的百分比。这就是为什么您可以拥有 >100 的百分比。在具有 4 个内核的系统上,您可以看到高达 400% 的 CPU 使用率。

您可以通过在运行时按I(即Shift+i并切换“Irix 模式”)来更改此行为top。这将导致它显示正在使用的可用 CPU 功率的百分比。如中所述man top

    1. %CPU  --  CPU Usage
       The task's share of the elapsed CPU time since the last screen
       update, expressed as a percentage of total  CPU  time.   In  a
       true  SMP environment, if 'Irix mode' is Off, top will operate
       in 'Solaris mode' where a task's cpu usage will be divided  by
       the  total  number  of  CPUs.  You toggle 'Irix/Solaris' modes
       with the 'I' interactive command.
Run Code Online (Sandbox Code Playgroud)

或者,您可以按1这将显示每个 CPU 的 CPU 使用率明细:

top - 13:12:58 up 21:11, 17 users,  load average: 0.69, 0.50, 0.43
Tasks: 248 total,   3 running, 244 sleeping,   0 stopped,   1 zombie
%Cpu0  : 33.3 us, 33.3 sy,  0.0 ni, 33.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  : 16.7 us,  0.0 sy,  0.0 ni, 83.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  : 60.0 us,  0.0 sy,  0.0 ni, 40.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   8186416 total,  6267232 used,  1919184 free,   298832 buffers
KiB Swap:  8191996 total,        0 used,  8191996 free,  2833308 cached
Run Code Online (Sandbox Code Playgroud)

  • 使用超线程,我相信您可以看到高达 800% 的信息,因为 /proc/cpuinfo 会将每个线程显示为 cpu (2认同)
  • @Dani_l是的,“核心”是物理的还是虚拟的都无关紧要,它被“top”视为“CPU”。我显示的输出来自我的笔记本电脑,该笔记本电脑有一个带两个内核的物理 CPU,每个内核都有一个第二个逻辑内核。结果是“top”看到 4 个核心。 (2认同)

Lei*_*och 8

如果您想top立即打开显示单独的 CPU 而无需按1,您可以使用该-1选项。

例如:

top -1

...
%Cpu0  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  : 44.7 us, 55.3 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  : 46.7 us, 53.3 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
...     
Run Code Online (Sandbox Code Playgroud)

注意:这适用于 Debian,但 top installed 的变体可能因发行版而异。

  • 在 Gnu/Linux 3.10.0-1127.13.1.el7.x86_64 上我没有看到这个工作 (2认同)

小智 6

如果您希望top命令在每次运行时显示每个 CPU 使用情况top

  • 运行top命令
  • 1,这将显示每个 CPU 使用情况
  • 键入W并按Enter将配置保存到文件
  • 下次运行时top将显示每个 CPU 使用情况。
  • 这样我们就可以根据我们的自定义要求配置 top

(以上步骤适用于顶级版本procps-ng 3.3.12