C语言支持超线程么,关于cores,processor,CPU,超线程

本文详细解析了lscpu和/proc/cpuinfo输出信息,阐述了电脑中处理器芯片、核心和线程的概念。内容包括:Socket表示的处理器芯片数量,Core(s)perSocket表示的每个芯片上的物理核心数,Thread(s)perCore表示的超线程情况。通过例子说明了一个拥有2个芯片,每个芯片6个物理核心,支持超线程的系统,总计12个物理核,24个逻辑核(线程)。此外,还介绍了top和ps命令中关于CPU利用率的计算方式,并讨论了在程序设计中如何考虑CPU资源的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近被这些概念搞晕了,梳理一下。

首先看看lscpu的输出:

shuyin.wsy@r10g16352:/workspace/django/logstore/test_files/compressed$ lscpu

Architecture: x86_64

CPU op-mode(s): 32-bit, 64-bit

Byte Order: Little Endian

CPU(s): 24

On-line CPU(s) list: 0-23

Thread(s) per core: 2

Core(s) per socket: 6

Socket(s): 2

NUMA node(s): 2

Vendor ID: GenuineIntel

CPU family: 6

Model: 44

Stepping: 2

CPU MHz: 2401.000

BogoMIPS: 4800.20

Virtualization: VT-x

L1d cache: 32K

L1i cache: 32K

L2 cache: 256K

L3 cache: 12288K

NUMA node0 CPU(s): 6-11,18-23

NUMA node1 CPU(s): 0-5,12-17

再看看cat /proc/cpuinfo的输出:

shuyin.wsy@r10g16352:/workspace/django/logstore/test_files/compressed$ cat /proc/cpuinfo

processor : 0

vendor_id : GenuineIntel

cpu family : 6

model : 44

model name : Intel(R) Xeon(R) CPU E5645 @ 2.40GHz

stepping : 2

microcode : 0x13

cpu MHz : 2401.000

cache size : 12288 KB

physical id : 1

siblings : 12

core id : 0

cpu cores : 6

apicid : 32

initial apicid : 32

fpu : yes

fpu_exception : yes

cpuid level : 11

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 pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 popcnt aes lahf_lm ida arat dtherm tpr_shadow vnmi flexpriority ept vpid

bogomips : 4800.22

clflush size : 64

cache_alignment : 64

address sizes : 40 bits physical, 48 bits virtual

power management:

概念的解释: Socket(s):             2:电脑里面有两个处理器芯片,/proc/cpuinfo里面有几个physical id,就有几个芯片,physical id为芯片的序号

Core(s) per socket:    6:每个芯片里面physical cores个数,/proc/cpuinfo里面的cpu cores

Thread(s) per core:    2:超线程的话,为2,不超线程,为1,一个physical core可以同时运行的线程数。/proc/cpuinfo里面唯一physical id(电脑里芯片的序号)和core id(芯片里面physical cores的序号)对应的processor个数

也就是说有两个芯片,每个芯片里面有6个物理核,电脑共12个物理核。

由于超线程,每个物理核可以同时运行两个线程,对应了两个processors,电脑共24个processors/CPUS。

按照买电脑时的说法,就是12核24线程,一般不使用这种概念了。

通常简称24核,也就是24CPUS,24processors,24 virtual cores。

ps和top中的使用:

top看的load average就是整个系统执行的任务/每个CPU可执行的任务,分别为1分钟,5分钟,15分钟的均值;对于该服务器来说,理论最大值可以是24

http://www.ruanyifeng.com/blog/2011/07/linux_load_average_explained.html

ps看的%CPU,基数是单CPU,100%表示进程把一个CPU被占满了,200%表示进程把两个CPU被占满了;对于该服务器来说,理论最大可以是2400%

http://unix.stackexchange.com/questions/145247/understanding-cpu-while-running-top-command

在程序中的使用:

我们写一个单进程单线程的死循环程序,ps看到的%CPU应该是100%,运行一段时候后,如果没有其他占用CPU比较大的程序,那么load average应该是1.00左右 上学的时候在netbeans里面看c语言的死循环程序,CPU占用了只有50%(2CPUS),可能是做了处理,将ps看到的%CPU除以了CPU的个数,待验证。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值