當前位置:
首頁 > 知識 > lscpu詳解(每周一個linux命令系列)

lscpu詳解(每周一個linux命令系列)

引言:今天的命令是用來看cpu信息的lscpu

lscpu

我們先看man lscpu

display information about the CPU architecture

翻譯:顯示cpu架構信息

具體的描述如下:

lscpu gathers CPU architecture information from sysfs, /proc/cpuinfo
and any applicable architecture-specific libraries (e.g. librtas on
Powerpc). The command output can be optimized for parsing or for
easy readability by humans. The information includes, for example,
the number of CPUs, threads, cores, sockets, and Non-Uniform Memory
Access (NUMA) nodes. There is also information about the CPU caches
and cache sharing, family, model, bogoMIPS, byte order, and stepping.
In virtualized environments, the CPU architecture information dis‐
played reflects the configuration of the guest operating system which
is typically different from the physical (host) system. On architec‐
tures that support retrieving physical topology information, lscpu
also displays the number of physical sockets, chips, cores in the
host system.
Options that result in an output table have a list argument. Use
this argument to customize the command output. Specify a comma-sepa‐
rated list of column labels to limit the output table to only the
specified columns, arranged in the specified order. See COLUMNS for
a list of valid column labels. The column labels are not case sensi‐
tive.
Not all columns are supported on all architectures. If an unsup‐
ported column is specified, lscpu prints the column but does not pro‐
vide any data for it.

翻譯如下:

lscpu命令從sysfs、/proc/cpuinfo、或者某些適用於特定架構的庫中收集數據。命令的輸出會以人類易讀的方式展示如下信息:cpu、線程、核心、插槽和Non-Uniform MemoryAccess (NUMA)節點的數量,也有cpu共享緩存,cpu的族號,運行模式,處理指令的速度,大小端,步進等信息

在虛擬環境下,系統架構信息展示映射著客戶操作系統的設置,這和物理主機是有明顯差異的。在架構上支持檢索物理拓撲信息,lscpu命令也顯示主機系統中的物理插槽數量,晶元,內核數。

Options可以提供一些參數,用這些參數可以自定義命令輸出。指定一個列表分隔符,指定一個逗號分隔的列標籤列表,以將輸出表限制為按指定的順序排列的指定的列。按指定順序排列。 有效列標籤請參考COLUMNS的列表。列標籤不區分大小寫。(man的輸出中有各種參數太多這裡就不放出來了。可以自己去查看)

我們再來看一下命令執行結果

Architecture: x86_64 //架構--這裡的64指的位處理器
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian //小端法
CPU(s): 4 //cpu數量
On-line CPU(s) list: 0-3 //在線的cpu數量 有些時候為了省電或者過熱的時候,某些CPU會停止運行
Thread(s) per core: 1 //每個核心的線程數
Core(s) per socket: 4 //每個插槽上有幾個核心
座: 1
NUMA 節點: 1 //NUMA 這個太複雜,所以他的解釋在下面
廠商 ID: GenuineIntel
CPU 系列: 6
型號: 94
型號名稱: Intel(R) Xeon(R) CPU E3-1225 v5 @ 3.30GHz
步進: 3 //這個可以簡單理解為版本號 也有A0這樣的標識方式
CPU MHz: 900.023
CPU max MHz: 3700.0000
CPU min MHz: 800.0000
BogoMIPS: 6624.00 // MIPS是每秒百萬條指令,Bogo是Bogus(偽)的意思,這裡是估算MIPS值
虛擬化: VT-x //虛擬化技術,這個我不太懂,不敢亂說
L1d 緩存: 32K //一級高速緩存 dcache 用來存儲數據
L1i 緩存: 32K //一級高速緩存 icache 用來存儲指令
L2 緩存: 256K
L3 緩存: 8192K //緩存速度上 L1 > L2 > L3 > DDR(內存) 內存的理論速度在幾十g一秒
NUMA 節點0 CPU: 0-3 //四個cpu在一個numa節點上
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 art 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 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb invpcid_single intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp
//Flags是標識了一些cpu的特徵 具體可以查看https://blog.csdn.net/nemo2011/article/details/7531212

man中還有更多的描述,對大家來說意義也不大,接下來我們直接看選項了

選項:
-a, --all 同時列印在線和離線 CPU (-e 選項默認值) 此選項只能與選項-e 或-p 一起指定
-b, --online 只列印在線 CPU (-p 選項默認值) 此選項只能與選項-e 或-p 一起指定
-c, --offline 只列印離線 CPU 此選項只能與選項-e 或-p 一起指定。
-e, --extended[=<列表>] 列印擴展的可讀格式 (類似表格的形式)
如果省略該列表參數, 則在命令輸出中包括所有可用數據的列
指定列表參數時, 選項字元串、等號 (=) 和列表不能包含任何空格或其他空白。
結果如下:
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ
0 0 0 0 0:0:0:0 是 3700.0000 800.0000
1 0 0 1 1:1:1:0 是 3700.0000 800.0000
2 0 0 2 2:2:2:0 是 3700.0000 800.0000
3 0 0 3 3:3:3:0 是 3700.0000 800.0000
帶list示例: lscpu -e=cpu,node
-p, --parse[=<列表>] 列印可解析格式
如果省略該列表參數, 則命令輸出與早期版本的 lscpu 兼容。
在此兼容格式中, 兩個逗號用於分隔 CPU 緩存列。
如果未標識任何 CPU 緩存, 則忽略緩存列。
如果使用列表參數, 則緩存列將用冒號 (:) 分隔
示例: lscpu -p=cpu,node,,L1d:L1i
我在使用上面命令的時候,不帶緩存列正常顯示,帶緩存列不能輸出數據也沒報錯,迷茫
-s, --sysroot <目錄> 以指定目錄作為系統根目錄
收集 lscpu 命令所發出的實例以外的 Linux 實例的 CPU 數據。
指定的目錄是要檢查的 Linux 實例的系統根。
-x, --hex 列印十六進位掩碼而非 CPU 列表
-y, --physical print physical instead of logical IDs
顯示所有列的物理 id。 除了由 lscpu 分配的邏輯 id 之外
物理 id 是由內核提供的特定於平台的值。無法檢索元素的物理 ID 用破折號 (-) 字元顯示
此選項不影響 CPU 邏輯編號。
-h, --help 顯示此幫助並退出
-V, --version 輸出版本信息並退出
可用的列:
CPU 邏輯 CPU 數量
CORE 邏輯核心數量
SOCKET 邏輯(CPU)座數量
NODE 邏輯 NUMA 節點數量
BOOK 邏輯 book 數
DRAWER logical drawer number //邏輯抽屜數(不太明白,好像和book有關係)
CACHE shows how caches are shared between CPUs //cpu之間如何共享緩存
POLARIZATION CPU dispatching mode on virtual hardware //虛擬硬體上的CPU調度模式
ADDRESS physical address of a CPU //cpu物理地址
CONFIGURED shows if the hypervisor has allocated the CPU //管理程序是否分配了cpu
ONLINE shows if Linux currently makes use of the CPU //在使用的cpu
MAXMHZ shows the maximum MHz of the CPU //最大頻率
MINMHZ shows the minimum MHz of the CPU //最小頻率

NUMA(Non-Uniform MemoryAccess)

中文名:分散式體系結構 (非統一內存體系結構)
區別於 UMA,統一內存體系結構

由於展開來講設計到很多問題,也需要單獨寫一篇長文章才能說完,這裡可以精簡的說一下:

UMA中,多個CPU訪問內存是沒有區別的,成本和速度相同。而在NUMA中,可以看成每個CPU有自己的內存,被稱為本地內存,CPU之間通過一種方式聯結,使得CPU可以訪問非管轄範圍內的內存(非本地內存),但是。由於不屬於自己的一畝三分地,需要通過另一個通道獲取,速度回比訪問本地內存要慢。但是好處是這種方式增加了擴展性。缺點是速度會受影響,尤其是對mysql這類的資料庫軟體有較大影響。一般應該是接觸不到,接觸到了再去詳細了解吧

希望大家多評論交流,互相學習

lscpu詳解(每周一個linux命令系列)

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

Android APP 性能優化的一些思考
Vibrator(振動器)

TAG:程序員小新人學習 |