Linux热插拔CPU核心

2022年10月30日 814点热度 0人点赞 0条评论
文章目录

显示系统中共有多少个CPU核心:

输入以下命令:

# cd /sys/devices/system/cpu
# ls -l

示例:

total 0
drwxr-xr-x 4 root root    0 Apr  2 12:03 cpu0
drwxr-xr-x 4 root root    0 Feb 15 07:06 cpu1
drwxr-xr-x 4 root root    0 Feb 15 07:06 cpu2
drwxr-xr-x 4 root root    0 Feb 15 07:06 cpu3
drwxr-xr-x 4 root root    0 Feb 15 07:06 cpu4
drwxr-xr-x 4 root root    0 Feb 15 07:06 cpu5
drwxr-xr-x 4 root root    0 Feb 15 07:06 cpu6
drwxr-xr-x 4 root root    0 Feb 15 07:06 cpu7
-rw-r--r-- 1 root root 4096 Apr  2 12:03 sched_mc_power_savings

共有8个CPU逻辑内核。转换为人类可读格式:

# lscpu

示例:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                32
On-line CPU(s) list:   0-31
Thread(s) per core:    2
Core(s) per socket:    8
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 45
Stepping:              7
CPU MHz:               2000.209
BogoMIPS:              4001.65
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              20480K
NUMA node0 CPU(s):     0-7,16-23
NUMA node1 CPU(s):     8-15,24-31

Under each directory you would find an “online” file which is the control file to logically online/offline a processor.

(查看哪些核心是在线状态:)

关闭某个核心,输入下列命令:

# echo 0 > /sys/devices/system/cpu/cpu6/online
# grep "processor" /proc/cpuinfo

How do I logically turn on (online) cpu#6 ?

Type the following command:

# echo 1 > /sys/devices/system/cpu/cpu6/online
# grep "processor" /proc/cpuinfo

Once done, you can can actually remove CPU if your BIOS and server vendor supports such operation.

How do I verify cpu is online and offline?

Type the following cat command to see a list of cpus which are online:

# cat /sys/devices/system/cpu/online

To see a list of all offline cpus, run:

# cat /sys/devices/system/cpu/offline

WenYinOS

这个人很懒,什么都没留下

文章评论

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理