Linux操作系统 CPU

概述

可以使用top命令查看cpu

Cpu(s): 38.3%us, 10.6%sy,  0.0%ni, 44.6%id,  3.0%wa,  0.4%hi,  3.1%si,  0.0%st

%us:表示用户空间程序的cpu使用率
%sy:表示系统空间的cpu使用率,主要是内核程序。
%ni:表示用户空间且通过nice调度过的程序的cpu使用率。
%id:空闲cpu
%wa:cpu运行时在等待io的时间
%hi:cpu处理硬中断的数量
%si:cpu处理软中断的数量
%st:被虚拟机偷走的cpu
在top界面按1,可以查看多核CPU的使用情况

Cpu0  : 50.0%us, 12.0%sy,  0.0%ni, 36.3%id,  1.3%wa,  0.0%hi,  0.3%si,  0.0%st
Cpu1  : 33.0%us, 15.7%sy,  0.0%ni, 43.3%id,  5.7%wa,  0.7%hi,  1.7%si,  0.0%st
Cpu2  : 61.0%us, 10.7%sy,  0.0%ni, 27.0%id,  0.7%wa,  0.3%hi,  0.3%si,  0.0%st
Cpu3  : 42.5%us, 10.0%sy,  0.0%ni, 42.8%id,  0.3%wa,  0.0%hi,  4.3%si,  0.0%st

一般认为us+sy在85%以下是正常值。

但是上述只能看到瞬时值,近期平均值应该通过load average来查看。
load average一般可以通过top或者uptime观察到,格式如下:
load average: 0.10, 0.05, 0.58
load average后面有由逗号分割的3列数字,分别代表了最近1分钟,5分钟,15分钟CPU的平均负载情况。
我们任取一列,如第一列,即表示在刚刚过去的1分钟内:
如果是单核CPU的话,1.00就表示CPU已经满负荷了,
如果是多核CPU的话,load average达到CPU的核数即说明该CPU已经满负荷了,
如果是多颗物理CPU,则当load average达到所有物理CPU的总核数时,说明系统CPU满负荷了。
简而言之,CPU的核数即为我们根据load average衡量CPU负载的依据。

https://scoutapm.com/blog/understanding-load-averages

An idle computer has a load number of 0 (the idle process isn't counted). Each process using or waiting for CPU (the ready queue or run queue) increments the load number by 1. Each process that terminates decrements it by 1. Most UNIX systems count only processes in the running (on CPU) or runnable (waiting for CPU) states. However, Linux also includes processes in uninterruptible sleep states (usually waiting for disk activity), which can lead to markedly different results if many processes remain blocked in I/O due to a busy or stalled I/O system.[1] This, for example, includes processes blocking due to an NFS server failure or too slow media (e.g., USB 1.x storage devices). Such circumstances can result in an elevated load average which does not reflect an actual increase in CPU use (but still gives an idea of how long users have to wait).

大概就是说unix系统的CPU load相当于平均活跃线程数量(包括正在运行的和在队列里等待调度的)。而linux的 cpu load则是还要计算那些因为处在不可中断的sleep状态的的线程。

https://blog.csdn.net/c_z_w/article/details/100702674

性能

CPU的计算性能一般分为

  • 整数计算性能,
  • 浮点数计算性能。浮点的数计算性能一般用于一些数值场景。比如图像处理,编码解码。不过这些工作有可能是由GPU来完整

另外就是CPU的三级缓存的大小。
服务器CPU一般采用SMP架构。即共享子系统。

一般服务器的CPU

可以查看CPU具体信息
cat /proc/cpuinfo
目前,我们的服务器规格以4C8G最为常见

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 85
model name      : Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
stepping        : 4
microcode       : 0x2000043
cpu MHz         : 2501.000
cache size      : 33792 KB
physical id     : 0
siblings        : 4
core id         : 3
cpu cores       : 4
apicid          : 119
initial apicid  : 119
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch ida arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx avx512f rdseed adx smap clflushopt avx512cd xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc
bogomips        : 5004.40
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

这个CPU 24个核心。48个线程。这是因为该处理器使用了超线程技术。

CPU缓存

在这里插入图片描述

  • Cache Line 是 CPU 和主存之间数据传输的最小单位。当一行 Cache Line 被从内存拷贝到 Cache 里,Cache 里会为这个 Cache Line 创建一个条目。这个 Cache 条目里既包含了拷贝的内存数据,即 Cache Line,又包含了这行数据在内存里的位置等元数据信息。

  • cache miss 如果LLC缓存也没有命中,则会产生cache miss事件

  • store & load
    读内存,也就是加载操作(load), 从内存读到寄存器
    写内存,就就是存储操作(store),从寄存器写入到内存

CPU缓存一致性

CPU的进程调度

在这里插入图片描述

调度算法

https://www.pianshen.com/article/1573347832/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值