Quantcast
Channel: System – Benjr.tw
Viewing all 14 articles
Browse latest View live

常用的 Performance / Monitor 測試工具

$
0
0

雖然自己是從事 QA(Quality assurance) 相關測試工作但對於這些工具的使用還是有很多問號,下面列出 Linux 下我常用的效能與監控軟體.

Performance

– 要如何知道 Linux 下面各系統的效能如何可以參考下面幾種方式.

Disk

  • 測試磁碟 I/O 的工具 – iometer – Quick start , iometer
  • 除了 iometer 可以來測試硬碟的速度,你可以透過 hdparm 或是 dd 這是一個比較簡單的方式來看目前硬碟傳送的速度
  • 以前用過 dd , hdparm 或是 Iometer 來測試 Disk I/O 的是速度,但 dd, hdparm 太過簡單,Iometer 太過老舊 ,目前看到一套 Fio – Flexible I/O Tester 測試工具.

CPU

  • CPU Burn-in
    只能針對單核心在做運算,不推薦使用
  • Bonnie++
  • BurnInTest
  • Iozone

Network

  • 網路效能測試工具 – iperf
  • 網路效能測試工具 – qperf 功能比 iperf 要強大的多.
  • Pktgen – Packet-Generation 它是一個 Linux 核心的模組,它可以以非常快的速度產生封包
  • 另外一套專業級的網路效能測試工具 –IxChariot
    IXIA系列的 IxAutomate, IxExplorer, IxLoad
  • smartbits / TestCenter 是一套專門用來檢視網路設備的硬體檢測裝置,是由 SPIRENT 這一家公司所提供主要可以用來檢視網卡或是 switch 等網路裝置 smartbits / TestCenter

    乙太網路的發展已經大大超過當年的儲存貴族 Fiber Channel ,40/100G Network 都已經要問世了 測試治具也有了 Spirent 40/100G Ethernet test solutions

  • nttcp , netperf , vdbench , Finisar Medusa Test Tool

Memory

  • stream memory benchmark
  • java performance testing tools

System

  • SysBench
    Linux 下常見的壓力測試工具不多,而且通常很分散,要不然就是協力廠商所開發的工具需收費而且所費不貲,不過現在 Linux 下有一套比較完整的壓力測試工具 sysbench ,具有 File I/O, CPU , Memory , Threads , Mutx , OLTP 等測試.

Monitor

– Linux 底下提供了監控系統使用資源的程式

文字介面

  • Linux 預設最古老的系統資源監控程式 – top
  • 最簡單的硬碟監測工具 – iostat
  • 透過 mpstat 來看個別的 CPU 使用率與統計 –mpstat
  • sar – CPU , Memory ,I/O (Disk, Network) 的資料都可透過這一支程式來統計
  • dstat – 提供更多元的設定方式來顯示要監控的 CPU , Memory ,I/O (Disk, Network) 資料
  • nmon – 比上面幾種都還要好用的系統資源監控程式

圖形介面

  • KDE 底功能最完整的監控程式 – ksysguard
  • 不是Linux 系統預設的系統資源監控程式,不過使用上相當直覺 – gkrellm
  • nTop 這是一套用來觀測網路狀態的軟體,直接透過 web 的方式來進行 – ntop
  • wireshark

Stress – 要如何在 Linux 下針對不同的 I/O 與系統做壓力測試,可以參考下面幾種方式.

  • 在 Linux 的開機光碟中有提供一支專門用來檢視記憶體模組的工具,他就是 memtest86+ – memtest86+

以前的 QA 測試大概就是實際接設備來測試,然後測很多種,現在透過不同的電子量測設備‎,可以很快看出系統是否有設計瑕疵.
下面廠商是我們有詢問過的
立肯科技
太克科技
Spirent – 台灣代理 廣聯科技
IXIA – 台灣代理 派恩科技

外面廠商也有專門幫你做驗證的如 百佳泰

下面的要找時間試,但一直沒有空試.
intel burning test
Rhel / ubuntu stress – http://linuxdrops.com/how-to-produce-high-cpu-load-memory-io-or-stress-test-a-linux-server/
Intel PTU
CPUBurn


KDE System Guard – ksysguard

$
0
0

首先感謝我同事 Jacky 告知這一監控程式.在 Linux 有很多監控系統的程式,除了最一般的 #top http:/benjr.tw/514 外還有 #iostat http:/benjr.tw/527 或是 #gnome-system-monitor ,gnome-system-monitor 有點像是 Windows 的工作管理員.雖然功能不多但是該有的資訊都還是可以看到.

不過如果是要真的很仔細看到系統所有的狀態.我會推薦使用 ksysguard.他算是 RHEL 裡面最好用的系統監控軟體,裡面可以選擇的細項多到對不熟硬體的人會不知所措.ksysguard 不只可以監看,還可以把系統的狀態記錄下來.ksysguard 可以監看的硬體裝置包括了 1.CPU 2.Disk 3.Memory 4.Network 幾乎是系統有什麼就可以監控的到.

gnome-system-monitor

Screenshot-System Monitor

ksysguard

KDE_System_Guard
預設監控項目
系統預設監控的 worksheet 只有下列這兩種.

  • System Load
    CPU Load, Load Average, Physical Memory, Swap Memory
  • Process Table
    Name, PID, GID, Status ,User%, System%, Nice, VmSize, VmRss, Login, Command

KDE_System_Guard08
Process Table

  • Name – 行程的名稱
  • PID – Process ID
  • GID – The ID of the group the process belongs to??
  • Status – 狀態值下 
    D : Uninterruptible sleep 這個 Process 已經進入 Sleeping 而且在等待 I/O 的結果.
    R : Runnable 目前正在執行的 Process
    S : Sleeping 目前沒在執行的 Process T : Stopped 目前已經停止的 Process
    Z : Zombie 造成 zombie 的大多是父程序並不知道其子程序已經死亡,所以才會有這種狀況出現.
  • User% – User CPU time: 使用者的 Process 所花 CPU 的百分比.
  • System% – System CPU time: Kernel 的 Process 所花 CPU 的百分比.
  • Nice – 程序的執行優先順序 -20 ~ 19 越小的優先權越高.
  • VmSize – 目前這個 Process 使用多少 virtual memory ,記憶體單位為 Kbytes.Process 在執行時並不會全部載入記憶體,部分會暫存在 virtual memory.
  • VmRss – 目前這個 Process 真正使用掉多少 physical Memory ,記憶體單位為 Kbytes.
  • Login -這個行程是由哪一個使用者登入執行的
  • Command – 指令名稱

新增監控項目
KDE_System_Guard03

要新增監控項目時,第一步就是新增加 Worksheet.點選左上方新增 worksheet 的按鍵.名稱 (Title) 和 workshhet 內容個數(Properties:Rows,Columns) 都可以自訂.而 Update interval 可以設定監控項目內容幾秒要更新一次,預設為 2 秒最小單位為 1 秒.
結果顯示方式
KDE_System_Guard04
結果顯示方式有下列幾種.

  • Signal Plotter
    以曲線圖來顯示.
  • Multimeter
    以數位數字的顯示方式.
  • BarGraph
    顯示方式不明
  • SensorLogger
    唯一一種可以將監控紀錄下來的方式.只要按下右鍵選擇 "Start Logging" 就可以開始紀錄.

CPU

CPU 可以監控的比 top 少,不過他多出了 CPU Clock 的選項.,在有 EIST(Enhanced Intel SpeedStep Technology) 時 CPU 在負載輕的時候可以讓 CPU 工作在低電壓低時脈的狀態,已達到節省電源的目的. /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies 可以得知 CPU 所有的工作頻率.
KDE_System_Guard07

  • Clock
    CPU 目前的工作頻率
  • Idle
    idle CPU time: 空閑 CPU 的百分比.
  • Nice
    Nice CPU time: CPU 花在使用者的 process 改變優先順序的百分比.
  • System
    System CPU time: Kernel 的 Process 所花 CPU 的百分比.
  • User
    User CPU time: 使用者的 Process 所花 CPU 的百分比.

Disk
不過在選擇硬碟監控時我也真的愣住了,他呈現硬碟的方式很特別是用 "數字" , 我的 sda,sdb …跑去哪裡了!!後來稍微查詢了一下他是以裝置的 [MAJOR MINOR] 的數字來表示. 至於 [MAJOR MINOR] 要怎麼看,要自行參考裝置的參數表 /usr/src/linux-kernel-version/Documentation/devices.txt 嗎??其實也不用查直接看 /proc/diskstats 就可以得知目前硬碟 I/O 狀態以及裝置的 [MAJOR MINOR] .

KDE_System_Guard02
目前sda 的 MAJOR 為 8 sdb 為 9 依序下去, MINOR 就是 partition 的順序了,比如 sda1 其 [MAJOR MINOR] 為 8.1 .Disk 可以監控的包括了 .

  • Read Accesses
    Disk 讀取的 I/O 數
  • Read Data
    Disk 讀取的資料量以 KBytes/sec 為單位
  • Total Acceses
    Disk 讀取+寫入 的 I/O 數
  • Write Accesses
    Disk 寫入的 I/O 數
  • Write Data
    Disk 寫入的資料量以 KBytes/sec 為單位

Memory
記憶體可監控的種類有 5 種,Application Memory, Buffered Memory, Cached Memory, Free Memory , Used Memory

KDE_System_Guard06

  • Application Memory
    所有程式所佔用的記憶體數量,單位為 KBytes.
  • Buffered Memory
    資料還來不及儲存到硬碟中暫儲在記憶體的資料.
  • Cached Memory
    資料已經由硬碟中讀取出來,提供給應用程式接下來使用,用以提高存取效能.
  • Free Memory
    尚未使用到的的記憶體.
  • Used Memory
    Application Memory + Buffered Memory + Cached Memory
    就是目前所有有在使用的記憶體數量.

系統所擁有的總記憶體數就是 Free Memory + Used Memory(Application Memory + Buffered Memory + Cached Memory)

Network

GKrellM – GNU Krell Monitors

$
0
0

在 X-Windows 下我常用的的資源監控程式,很久以前 RedHat 列為標準套件,但是現在在 RHEL 光碟中並沒有收錄,但是他真的很簡單使用又方便所以我還是常常加入這一套件, GKrellM 的原始程式網站 http://members.dslextreme.com/users/billw/gkrellm/gkrellm.html ,程式同套件名稱為 gkrellm-xxxx.rpm.

[root@benjr ~]# rpm -ivh gkrellm.version.rpm
[root@benjr ~]# gkrellm &

gkrellm05

一開啟的 GKrellM 會有一些預設監控裝置

  • 主機的名稱 Hostnamn
  • 目前的日期和時間
  • 個別的 CPU 使用率
  • 目前有多少個行程 Process
  • 總磁碟 Disk 的讀取寫入以 bytes 為單位,讀取 Read 是以藍色為標識, 寫入 Write 為橘色
  • 個別網路 Networking 的傳輸量,傳送 TX 是以藍色為標識, 接收 RX 為橘色
  • Memory 和 Swap 的狀態,點選他們可以以數字來顯示
  • 目前系統未讀的 mail 數量

一開始除了沒有個別的硬碟監控外幾乎都有了.我們可以手動加入,在 GKrellM 和右鍵選擇 "Configuration F1" 或是直接按 F1 進入 GKrellM 並在 Monitors / Builtins / Disk 選擇你要監控的硬碟資源.
gkrellm02
如果你覺得顯示寬度不夠在 monitors / General 將 GKrellM width 加大.
gkrellm04
如果覺得每一個監控單元顯示高度太高想改小一些,只要在該單元按右鍵就會出現 "GKrellM Chart Config" 並將 Chart height 改小即可.
gkrellm03

Linux – ntop

$
0
0

傳統要觀察或是統計網路流量可以透過 mrtg ,不過現在有更簡單的方式去做 ntop (http://www.ntop.org/news.php) 這是一套用來觀測網路狀態的軟體,直接透過 web 的方式來進行,使用上蠻直覺的,
ntop01ntop02
在 RHEL5 / CentOS 下使用 ntop 主要是參考了網站 http://www.wretch.cc/blog/ysy26/8266442 在的方式

安裝所需要的套件有三個,步驟如下:

  1. 下載安裝 rpmforge-release
    [root@benjr ~]# wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
    [root@benjr ~]# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
    
  2. rrdtool , ntop PRM
    ntop 需要 rrdtool 套件
    [root@benjr ~]# yum install rrdtool
    [root@benjr ~]# yum install ntop
    

    基本上 ntop 就安裝成了!!!

  3. 設定 ntop 的 admin 密碼
    這密碼主要是讓 ntop 的 admin 透過 web 的方式去修改設定時所需要的密碼.
    [root@benjr ~]# ntop -A
    Thu Nov 25 10:20:15 2010 NOTE: Interface merge enabled by default
    Thu Nov 25 10:20:15 2010 Initializing gdbm databases
    ntop startup – waiting for user response!
    
    Please enter the password for the admin user:
    Please enter the password again:
    Thu Nov 25 10:20:20 2010 Admin user password has been set
    
  4. 啟動 ntop 服務
    很可惜的是我在啟動 ntop 時 ntop 卻顯示錯誤
    
    [root@benjr ~]# service ntop start
    Starting ntop: Processing file /etc/ntop.conf for parameters…
    Mon Feb 22 10:12:04 2010 NOTE: Interface merge enabled by default
    Mon Feb 22 10:12:04 2010 Initializing gdbm databases
    FATAL ERROR: Unrecognized/unprocessed ntop options…
    , –user ntop, , –db-file-path /var/ntop, , , , –use-syslog, , , , , , ,
    run ntop –help for usage information
    
    Common problems:
    -B "filter expressions" (quotes are required)
    –use-syslog=facilty (the = is required)
    
    [FAILED]
    

    不過還是有解決方式在 http://forum.icst.org.tw/phpbb/ 網友建議把 /etc/rc.d/init.d/ntop 中的語法 由 daemon $prog -d -L @/etc/ntop.conf 修改成 daemon $prog @/etc/ntop.conf 即可

    [root@benjr ~]# vi /etc/rc.d/init.d/ntop
    daemon $prog @/etc/ntop.conf
    

現在透過 web 就可以透過 ntop 的監控來查詢網路的流量狀態.預設使用 port 3000 (ex:http:/172.16.0.38:3000),不過在使用 ntop 時有一件事很令我困惑,所有連上 http://IP:3000 的使用者皆可以看到所有網路流量的資料,不需登入帳號以及密碼.在 ntop 的 Admin / Configure / Protect URL 多加一個空白的 URL (NOTE: if you leave the URL field empty then the access is restricted to all ntop pages, otherwise,this entry matches all the pages begining with the specified string.)就可以改善這困惑的問題.之後所有登入  http://IP:3000 皆須要登入帳號以及密碼.
ntop03ntop04

Linux – SysBench

$
0
0

Linux 下常見的壓力測試工具不多,而且通常很分散,要不然就是協力廠商所開發的工具需收費而且所費不貲,不過現在 Linux 下有一套比較完整的壓力測試工具 sysbench http://sysbench.sourceforge.net/
使用上很簡單,用 apt-get install 就可以安裝 sysbench ,安裝完成之後就可以直接使用了.

ben@ben-SDV:~$ apt-get install sysbench

sysbench 提供 File I/O, CPU , Memory , Threads , Mutx , OLTP 的測試,下面我們一一來詳細了解.

ben@ben-SDV:~$ sysbench
Compiled-in tests:
fileio – File I/O test
cpu – CPU performance test
memory – Memory functions speed test
threads – Threads subsystem performance test
mutex – Mutex performance test
oltp – OLTP test

cpu – CPU performance test
一般我們透過 SPEC CPU 測試 CPU 的效能與評分,sysbench 有提供測試 CPU 的效能與評分,其實他使用的方式也很簡單,只有參數 –cpu-max-prime=100000 就是讓 CPU 去計算出100000的最大值數是多少,需要花多少時間來計算.

ben@ben-SDV:~$ sysbench --test=cpu --cpu-max-prime=100000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1

Doing CPU performance benchmark

Threads started!
Done.

Maximum prime number checked in CPU test: 100000

Test execution summary:
total time: 284.5265s
total number of events: 10000
total time taken by event execution: 284.5207
per-request statistics:
min: 28.37ms
avg: 28.45ms
max: 32.47ms
approx. 95 percentile: 28.55ms

Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 284.5207/0.00

不過這程式很難當作評斷 CPU 好壞的工具,在執行程式後仔細觀察 CPU 的使用狀況,你會發現他只用到單一顆核心去執行該程式.
sysbench02

mutex – Mutex performance test
因為剛剛 CPU 無法發揮所有的效能所以查了他另外一個參數 Mutex – http://sysbench.sourceforge.net/docs/#threads_mode
This test mode was written to emulate a situation when all threads run concurrently most of the time, acquiring the mutex lock only for a short period of time (incrementing a global variable). So the purpose of this benchmarks is to examine the performance of mutex implementation.

官網的說明就是採用多執行緒同時跑,看系統需要多少時間才能執行完畢.

ben@ben-SDV:~$ sysbench --test=mutex --num-threads=10000 --mutex-locks=100000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 10000

Doing mutex performance test
Threads started!
Done.

Test execution summary:
total time: 174.8060s
total number of events: 10000
total time taken by event execution: 1643228.7121
per-request statistics:
min: 94317.58ms
avg: 164322.87ms
max: 174452.17ms
approx. 95 percentile: 173901.13ms

Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 164.3229/9.72

主要我用了 2 個參數.

  • mutex-num
    Number of mutexes. The actual mutex to lock is chosen randomly before each lock 預設值為4096
  • mutex-locks
    Number of mutex locks to acquire per each request 預設值為 50000

雖然 CPU 的負載是平均分配但沒有辦法達到全速 100% 的運作.可能需要再搭配 sysbench 其他的壓力測試工具才會讓系統效能開到 100% 吧.

下面幾項我就沒有特別再試,透過 man sysbench 就可以查到一些相關的測試方式.
memory – Memory functions speed test

$ sysbench --test=memory --memory-block-size=8K --memory-total-size=1G --memory-oper=read run
$ sysbench --test=memory --memory-block-size=8K --memory-total-size=1G --memory-oper=write run

threads – Threads subsystem performance test

oltp – OLTP test

$ sysbench --test=oltp --mysql-table-type=myisam --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock prepare
$ sysbench --num-threads=16 --max-requests=100000 --test=oltp --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --oltp-read-only run

fileio – File I/O test

$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw prepare
$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw run
$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw cleanup

Non Transparent Bridge (NTB)

$
0
0

PCIe Non Transparent Bridge (NTB):NTB可支援容錯移轉

看了半天還是搞不懂 透明橋(TB),非透明橋(NTB) 這兩種方式的意思.

downstream upstream

PCI-E 太好用,所以很多介面就直接從 PCI-E 接下來,如 SATA 3.2 (mSATA & M2) ,傳統兩台具有備援機制 (redundant) 的裝置(通常是儲存裝置 Storage) 會透過 ethernet 或是 infiniband 的介面來溝通.

透明橋(TB)
How the Transparent Bridge Works

The transparent bridge provides electrical isolation between PCI busses. The host enumerates the system through discovery of bridges and end devices. For transparent bridges (TB), the Configuration Status Register (CSR) with a “Type 1” header informs the processor to keep enumerating beyond this bridge as additional devices lie downstream (as illustrated in Bridge A, B and C in Figure 1).

These Bridges with Type 1 headers include CSR registers for primary, secondary and subordinate bus numbers, which, when programmed by the host, define the CSR addresses of all downstream devices.

Endpoint devices have a “Type 0” header in their CSRs to inform the enumerator (BIOS or processor) that no additional devices lie downstream. These CSRs include base address registers (BARs) used to request memory and I/O apertures from the host.

圖片出自於 NTB_Brief_April-05.pdf
TB

透明網橋提供了PCI總線之間的電氣隔離。主機通過發現橋樑和終端設備枚舉系統。對於透明網橋(TB),配置狀態寄存器(CSR)與“1型”頭通知處理器保持列舉超出此橋為其他設備說謊下游(如圖1所示橋A,B和C)。

這些橋樑與1型頭包括CSR寄存器為初級,中級和下級總線號,當主機編程,定義所有下游設備的企業社會責任的地址。

端點設備在他們的CSR“類型0”頭通知枚舉(BIOS或處理器),沒有額外的設備所在的下游。這些客戶服務代表包括基地址寄存器(BAR)用來從主機請求內存和I / O光圈。

非透明橋(NTB)
How the NTB Works
In addition to the electrical isolation the NTB adds logical isolation by providing processor domain partitioning and address translation between the memory-mapped spaces of these domains.

With the NTB, devices on either side of the bridge are not visible from the other side, but a path is provided for data transfer and status exchange between the processor domains.

In this example a system host will enumerate through Bridges A and B (both transparent) on the left branch of the figure 2 until it reaches the endpoint X.

On the right side branch, the host will stop enumeration at Bridge D (NTBD).

Similarly, the local CPU will enumerate through Bridge E and F (both virtual bridges within the switch) and discover the endpoint Y, but will not attempt to discover elements beyond Bridge D. This will result in two memory domains.

圖片出自於 NTB_Brief_April-05.pdf
NTB

除了電隔離NTB通過提供處理器域劃分和地址轉換這些域的存儲器映射空間之間增加了邏輯隔離。

與NTB,在橋的兩邊裝置不從對方可見,但路徑被提供用於在處理器域之間傳送數據和狀態交換。

在本實施例的系統的主機將通過橋接A和B(兩者透明),直到它到達終點十列舉在圖2的左分支

在右側的分支,主機將停止枚舉在橋D(NTBD)。

同樣,本地CPU將通過大橋E和F枚舉(開關內兩個虛擬橋接),並發現端點Y,但不會嘗試發現超出大橋D.元素這將導致兩個內存域。

That white paper described the different address
domains existing in the Root Processor and the Endpoint Processor, memory map management, enumeration
and initialization, peer-to-peer communication mechanisms, interrupt and error reporting, and possible
redundant topologies. Since the release of the white paper, IDT has designed and implemented a multipeer
system using the x86 based system as the Root Processor (RP) and Endpoint Processor (EP)
connecting through IDT’s PES24NT3 NTB port and IDT’s PES64H16 device as the multi-port PCIe® switch
for the System Interconnect.

Endpoint Processor
The x86-based EP Processor is an AMD Athlon64 CPU with the nVidia nForce4 SLI chipset to support
the PCIe interface. Each x86-based PC connects to one down-stream port of the Multi-port PCIe switch via
the Non-transparent Bridge (NTB) port of the IDT PES24NT3 PCIe inter-domain switch.

The software is divided into three layers. The Function
Service layer is the top layer. It provides the device driver interface to the Linux kernel. The Message layer
is the middle layer. It encapsulates and decapsulates transport messages in a common format. The lowest
layer is the Transport layer. The Transport layer provides the service to send and receive data across the
PCIe interface and is hardware-dependent.

http://www.tairoa.org.tw/uploadfiles/file/journal/201212.pdf

http://www.rapidio.org/technology-comparisons/

http://www.plxtech.com/files/pdf/technical/expresslane/NTB_Brief_April-05.pdf

What is NTB (Non-Transparent Bridging)?
http://tofutu.blogspot.tw/2011/10/non-transparent-bridging-ntb.html

file://IDT_AN-571_APN_20080925.pdf

PXImc 介紹
http://www.ni.com/white-paper/12523/zht/

PEX8725, PCI Express Gen 3 Switch, 24 Lanes, 10 Ports
file:///Users/ben/Downloads/PEX8725_Product_Brief_v1.0_22Aug11.pdf

Virtual Ethernet over NTB
https://github.com/jonmason/ntb/wiki

Top

$
0
0

“Top" 是 Linux 提供的系統監控程式, 我們可以藉這支工具得知目前系統資源的使用狀態,使用方法很簡單直接在 command line 打入 top 即可,不過要怎麼看得懂他提供的資訊才是最重要的關鍵.

[root@benjr ~]# top
    • top – 14:47:30 up 10 days,  23:24,    2  user,    load average: 0.00, 0.00, 0.00
      先看一下第一行這些是代表什麼意思
      目前的電腦時間 : 14:47:30 up
      電腦已經開機經過了多少時間 : 10 days, 23:24
      目前登入系統的使用者有幾位 : 2 user
      系統平均負載 : load average: 0.00, 0.00, 0.00 這裡有三個數字,各代表了前 1,5,10 分鐘的平均負載.
      top01
    • Tasks:  107 total,    1 running,    106 sleeping,   0 stopped,   0 zombie
      看看第二行各代表什麼意思.
      目前所有的 Processes : Tasks: 107 total,
      目前正在執行的 Processes : 1 running,
      目前沒在執行的 Processes : 106 sleeping, 會睡著的原因大多是這個 process 需要等待某些 event 產生中斷,才會再度把他叫醒.
      目前已經停止的 Processes : 0 stopped,
      目前已經死掉的 Processes : 0 zombie 造成 zombie 的大多是父程序並不知道其子程序已經死亡,所以才會有這種狀況出現.
      top02

 

    • Cpu(s): 0.0% us,   50.0% sy,   0.0% ni,   50.0% id,   0.0% wa,   0.0% hi,   0.0% si
      0.0% us : User CPU time: 使用者的 Process 所花 CPU 的百分比.
      50.0% sy : System CPU time: Kernel 的 Process 所花 CPU 的百分比.
      0.0% ni : Nice CPU time: CPU 花在使用者的 process 改變優先順序的百分比.
      50.0% id : idle CPU time: 空閑 CPU 的百分比.
      0.0% wa : iowait CPU 花在等待 I/O 的百分比.
      0.0% hi : Hardware IRQ CPU 處理 hardware interrupts 的百分比.
      0.0% si : Software Interrupts CPU 處理 software interrupts 的百分比.

      note:系統預設所看到的 CPU 是所有 CPU core 核心效能的平均值,如果要看個別的效能可以在 top 下面按數字 “1″,即可看到目前所有 CPU 的使用率.

      top03

 

    • Mem:    1033660k total,   287052k used,   746608k free,  28676k buffers
      1033660k total : 系統上所有的記憶體大小.
      287052k used : 目前已經使用的記憶體.可以細分為 1.Application Memory  2.Buffered Memory  3.Cached Memory 不過在這一行下只會看到 buffer 一種, Cached 則是列在 Swap 裡面.雖然列在 Swap 裡但他是實實在在的記憶體所佔的空間.
      746608k free : 目前沒有再用的記憶體.
      28676k buffers : 當成是 buffer 的記憶體大小,主要是當資料還來不及儲存到硬碟中暫儲在記憶體的資料..
      160084k cached : 雖然列在 swap 後面其實它是 記憶體使用的一部分,主要是當資料已經由硬碟中讀取出來,暫存在記憶體提供給應用程式接下來使用,用以提高存取效能.
      top04

 

    • Swap:   2031608k total,   160k used,   2031448k free,   160084k cached
      2031608k total : swap 的大小.
      160k used : 目前 swap 使用區塊大小.
      2031448k free : 目前沒有在使用的區塊大小.
      160084k cached : 雖然列在 swap 後面其實它是 記憶體使用的一部分,主要是當資料已經由硬碟中讀取出來,暫存在記憶體提供給應用程式接下來使用,用以提高存取效能.
      top05

 

  • PID   USER   PR   NI   VIRT   RES   SHR S   %CPU   %MEM   TIME+   COMMAND
    PID : Process ID
    USER : Processes 所屬的使用者
    PR : Prioary,Processes 優先順序
    NI : Nice 值,越低(-20)代表優先順序越高,越高(+20)代表優先順序越低.
    VIRT :VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card’s RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.
    RES :RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.
    SHR :SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.
    這三個值寫的很玄,請參考原始網頁.
    FAQ_Linux_Memory_Management
    S : status 狀態值下
    D : Uninterruptible sleep 這個 Process 已經進入 Sleeping 而且在等待 I/O 的結果.
    R : Runnable 目前正在執行的 Process
    S : Sleeping 目前沒在執行的 Process
    T : Stopped 目前已經停止的 Process
    Z : Zombie 造成 zombie 的大多是父程序並不知道其子程序已經死亡,所以才會有這種狀況出現.
    %CPU : 目前這個 Process 的 CPU 使用率.
    %MEM : 目前這個 Process 的 Memory 使用率.
    TIME+ : 目前這個 Process 執行所花的時間.
    COMMAND : Process 的名稱
    top06

top 是個相當老的程式,現在有比較好用的 htop 可以選用,在 Ubuntu 可以透過 #apt-get install htop 即可下載.
htop01

Linux – lspci (PCI Express Gen 1 , 2 , 3)

$
0
0

在 Linux 下要如何得知 PCI-E Bus 使用的是 Gen(Generation) 1 還是 Gen2 還是新一代的 Gen 3 雖然使用 #lspci 只要可以看到目前系統所有的裝置.但是好像看不到 PCI-E Bus 所採用的是哪一代的 PCI-E.

[root@benjr ~]# lspci
00:00.0 Host bridge: Intel Corporation 3200/3210 Chipset DRAM Controller (rev 01)
00:01.0 PCI bridge: Intel Corporation 3200/3210 Chipset Host-Primary PCI Express Bridge (rev 01)
00:1a.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 02)
00:1a.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 02)
00:1a.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #6 (rev 02)
00:1a.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 02)
00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 02)
00:1c.1 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 6 (rev 02)
00:1c.2 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 02)
00:1d.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 02)
00:1d.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 02)
00:1d.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 02)
00:1d.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 02)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 92)
00:1f.0 ISA bridge: Intel Corporation 82801IR (ICH9R) LPC Interface Controller (rev 02)
00:1f.2 SATA controller: Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port SATA AHCI Controller (rev 02)
00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 02)
03:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express
04:03.0 VGA compatible controller: ATI Technologies Inc ES1000 (rev 02)
09:00.0 Fibre Channel: QLogic Corp. ISP2432-based 4Gb Fibre Channel to PCI Express HBA (rev 03)
09:00.1 Fibre Channel: QLogic Corp. ISP2432-based 4Gb Fibre Channel to PCI Express HBA (rev 03)
0c:00.0 SCSI storage controller: LSI Logic / Symbios Logic SAS1064ET PCI-Express Fusion-MPT SAS (rev 02)

如果有裝置是 unknown 的,需要更新 /usr/share/hwdata/pci.ids 請參考更新方式 http://benjr.tw/265

首先我們先來複習一下 PCI-E bus 的速度上限.

  • PCI Express 1.1
    使用兩對低電壓的差位訊號排線(low-voltage differential signaling pairs),分別各跑 2.5GBit/s 速度,x1 有兩對(傳送與接收) 2.5 G x 2 = 5Gbps 的頻寬.不過在討論頻寬時還是以單方向來計算.下面的速度是以單對的速度而言.
    x1  2.5Gbps (20% overhead – PCI-e 在每八個位元的資料串上用十位元來加以編碼)   2Gbps (250 MB/sec)
    x4  10Gbps  8Gbps (1 GB/sec)
    x8  20Gbps  16Gbps (2GB/sec)
    x16 40Gbps 32Gbps (4GB/sec)
  • PCI Express 2.0
    PCI-SIG 的 PCI Express 2.0 規格,新版每條 Lane 的單向頻寬從 2.5Gbps 倍增到 5Gbps.
    x1  5Gbps (20% overhead-PCIe並且在每八個位元的資料串上用十位元來加以編碼)   4Gbps (500 MB/sec)
    (5G*0.8)Mb/8=500MB
    x4  20Gbps  16Gbps (2 GB/sec)
    x8  40Gbps  32Gbps (4 GB/sec)
    x16 80Gbps 64Gbps (8 GB/sec)
  • PCI Express 3.0
    PCI-SIG 的 PCI Express 3.0 規格,新版每條 Lane 的單向頻寬增到 8Gbps.
    但因為編碼方式改變了,相較於 2.0 之前採用 8b/10b (每10個bit只有8個是有效資料)而 3.0 編碼方式為 128/130,所以資料傳輸頻寬以及原始傳輸率基本當都可以算成 8Gbps
    x1  8Gbps     (1GB/sec)
    x4  32Gbps   (4 GB/sec)
    x8  64Gbps   (8 GB/sec)
    x16 128Gbps (16 GB/sec)

我的系統上有一張 Qlogic Chipset 為 2432 的 4G Fiber Channel HBA,要如何得知目前系統的 PCI-E Bus 的速度呢!!首先要查出這張 HBA 的裝置名稱.

[root@benjr ~]# lspci -n
…..
09:00.0 0c04: 1077:2432 (rev 03)
09:00.1 0c04: 1077:2432 (rev 03)
….

參數 -n 使用 PCI vendor 以及 device codes 使用數字來顯示,後面我們會用到這些數字.
可以看到目前 Qlogic 2432 的 PCI 名稱以及裝置名稱為 09:00.0 0c04: 1077:2432 (rev 03) 先來看看這些數字所代表的意義.
前面的 3 個數字 "09:00.0" 是各代表什麼意思.

在 PCI 的裝置使用三個編號用來當作識別值,個別為 1. "匯流排(bus number)", 2. "裝置(device number) 以及 3. "功能(function number)".

所以剛剛的 09:00.0 就是 bus number = 09 ,device number = 00 function = 0 .

這3個編號會組合成一個 16-bits 的識別碼,

  1. 匯流排(bus number) 8bits 2^8 至多可連接 256 個匯流排(0 to ff),  
  2. 裝置(device number) 5bits 2^5 至多可接 32 種裝置(0 to 1f) 以及  
  3. 功能(function number) 3bits 2^3 至多每種裝置可有 8 項功能(0 to 7).

關於更多 #lspci 的資訊請參考 http://benjr.tw/10851
不過在 Linux 使用 Class ID + Vendor ID + Device ID  來代表裝置,如剛剛的  0c04: 1077:2432 所代表裝置名稱為 (Class ID = 0c04 ,Vendor ID = 1077,Device ID =2432) .

  • 0c04 : class 0c04 表示是 "Fiber Channel controller"
  • 1077 : vendor ID 1077 製造廠商 "Qlogic Corp"
  • 2432 : device ID 2432 產品名稱 "ISP2432-based 4Gb Fiber Channel to PCI Express HBA"

你問我怎麼知道 ID 與名稱是怎麼對應的很簡單直接參考 /usr/share/hwdata/pci.ids 檔案即可.

針對單一裝置來檢視可以使用 -d [vendor]:[device] 剛剛使用 -n 時所查到的 PCI vendor 以及 device codes 這邊就派得上用場了.

接下來透過指令 #lspci -n -d 1077:2432 -vvv |grep -i width 就可以得知 PCI-Express 的速度了.

[root@benjr ~]# lspci -n -d 1077:2432 -vvv |grep -i width
LnkCap: Port #0, Speed 2.5GT/s, Width x4, ASPM L0s, Latency L0 <4us, L1 unlimited
LnkSta: Speed 2.5GT/s, Width x1, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
LnkCap: Port #0, Speed 2.5GT/s, Width x4, ASPM L0s, Latency L0 <4us, L1 unlimited
LnkSta: Speed 2.5GT/s, Width x1, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
  • LnkCap :
    系統能提供的最高頻寬 PCI-Express 1.0 ( 2.5G ) Width x4=10G .如果系統是提供 PCI-Express 2.0 那 x1 速度是 5G.
  • LnkSta :
    目前該PCI-E 裝置跑的速度 PCI-Express 1.0 ( 2.5G ) Width x1=2.5G,

LnkSta 和 LnkCap 這兩個速度有可能不一樣 ,系統所提供的是 PCI Express 是 2.0 但裝置還是使用 1.0 的.

參考文件 http://kb.qlogic.com/KanisaPlatform/Publishing/556/1382_f.SAL_Public.html


Linux – lspci

$
0
0

在 Linux 使用 lspci 只要可以看到目前系統所有的裝置.

[root@benjr ~]# lspci
00:00.0 Host bridge: Intel Corporation 3200/3210 Chipset DRAM Controller (rev 01)
00:01.0 PCI bridge: Intel Corporation 3200/3210 Chipset Host-Primary PCI Express Bridge (rev 01)
00:1a.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 02)
00:1a.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 02)
00:1a.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #6 (rev 02)
00:1a.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 02)
00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 02)
00:1c.1 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 6 (rev 02)
00:1c.2 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 02)
00:1d.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 02)
00:1d.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 02)
00:1d.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 02)
00:1d.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 02)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 92)
00:1f.0 ISA bridge: Intel Corporation 82801IR (ICH9R) LPC Interface Controller (rev 02)
00:1f.2 IDE interface: Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 4 port SATA IDE Controller (rev 02)
00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 02)
00:1f.5 IDE interface: Intel Corporation 82801I (ICH9 Family) 2 port SATA IDE Controller (rev 02)
03:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express
04:03.0 VGA compatible controller: ATI Technologies Inc ES1000 (rev 02)
0c:00.0 SCSI storage controller: LSI Logic / Symbios Logic SAS1064ET PCI-Express Fusion-MPT SAS (rev 02)

後面可以很清楚知道是裝置名稱,如果有裝置是 unknown 的,需要更新 /usr/share/hwdata/pci.ids 請參考更新方式 http://benjr.tw/265
不過這一次我要說明的是前面的 3 個數字是各代表什麼意思.如我系統上的 Network 裝置 03:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express
在 PCI 的裝置使用三個編號用來當作識別值,個別為 1. "匯流排(bus number)", 2. "裝置(device number) 以及 3. "功能(function number)".

所以剛剛的 03:00.0 就是 bus number = 03 ,device number = 00 function = 0 .

這3個編號會組合成一個 16-bits 的識別碼,

  1. 匯流排(bus number) 8bits 2^8 至多可連接 256 個匯流排(0 to ff),  
  2. 裝置(device number) 5bits 2^5 至多可接 32 種裝置(0 to 1f) 以及  
  3. 功能(function number) 3bits 2^3 至多每種裝置可有 8 項功能(0 to 7).

使用 lspci -vt 則可以看到這些 PCI 裝置的樹狀圖以及所使用的資源

[root@benjr ~]# lspci -vt
-[0000:00]-+-00.0  Intel Corporation 3200/3210 Chipset DRAM Controller
           +-01.0-[0000:06]–
           +-1a.0  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4
           +-1a.1  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5
           +-1a.2  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #6
           +-1a.7  Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2
           +-1c.0-[0000:09]–
           +-1c.1-[0000:03]—-00.0  Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express
           +-1c.2-[0000:0c]—-00.0  LSI Logic / Symbios Logic SAS1064ET PCI-Express Fusion-MPT SAS
           +-1d.0  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1
           +-1d.1  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2
           +-1d.2  Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3
           +-1d.7  Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1
           +-1e.0-[0000:04]—-03.0  ATI Technologies Inc ES1000
           +-1f.0  Intel Corporation 82801IR (ICH9R) LPC Interface Controller
           +-1f.2  Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 4 port SATA IDE Controller
           +-1f.3  Intel Corporation 82801I (ICH9 Family) SMBus Controller
           \-1f.5  Intel Corporation 82801I (ICH9 Family) 2 port SATA IDE Controller

不過在 Linux 使用 Class ID + Vendor ID + Device ID  來代表裝置,如剛剛的 03:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express 所代表裝置名稱為 (Class ID = 0200 ,Vendor ID = 14e4 ,Device ID =165a) .後面我們會透過 #lspci -n 就可以看到這三個名稱

  • 0200 : class 0200 表示是 "Network controller"
  • 14e4 : vendor ID 14e4 製造廠商 "Broadcom Corporation"
  • 165a : device ID 1659 產品名稱 "NetXtreme BCM5721 Gigabit Ethernet PCI Express"

透過 lspci 可以查到 PCI 的裝置識別值,1. "匯流排(bus number)", 2. "裝置(device number) 以及 3. "功能(function number)". 之後,我們可以透過 lspci -n 不同的參數來查到 Linux 所使用 Class ID + Vendor ID + Device ID   的裝置值.

[root@benjr ~]# lspci -n
00:00.0 0600: 8086:29f0 (rev 01)
00:01.0 0604: 8086:29f1 (rev 01)
00:1a.0 0c03: 8086:2937 (rev 02)
00:1a.1 0c03: 8086:2938 (rev 02)
00:1a.2 0c03: 8086:2939 (rev 02)
00:1a.7 0c03: 8086:293c (rev 02)
00:1c.0 0604: 8086:2948 (rev 02)
00:1c.1 0604: 8086:294a (rev 02)
00:1c.2 0604: 8086:2940 (rev 02)
00:1d.0 0c03: 8086:2934 (rev 02)
00:1d.1 0c03: 8086:2935 (rev 02)
00:1d.2 0c03: 8086:2936 (rev 02)
00:1d.7 0c03: 8086:293a (rev 02)
00:1e.0 0604: 8086:244e (rev 92)
00:1f.0 0601: 8086:2916 (rev 02)
00:1f.2 0106: 8086:2922 (rev 02)
00:1f.3 0c05: 8086:2930 (rev 02)
03:00.0 0200: 14e4:165a

04:03.0 0300: 1002:515e (rev 02)
09:00.0 0c04: 1077:2432 (rev 03)
09:00.1 0c04: 1077:2432 (rev 03)
0c:00.0 0100: 1000:0056 (rev 02)

參考文件 http://www.oreilly.com.tw/product_linux.php?id=a049_sample

lspci 詳細資訊

$
0
0

指令 lspci 可以看到很多關於 PCI-E 裝置的訊息,但這些訊息個代表什麼意思!!

測試環境為 CentOS7 x86_64

下面這一張是 Intel Corporation 82575EB Gigabit 網卡.

[root@localhost ~]$ lspci -s 02:03.0 -vvv
  • 卡的基本訊息
    其中的 + – 代表有沒有被啟動或是發生.
    01:00.0 Ethernet controller: Intel Corporation 82575EB Gigabit Network Connection (rev 02)	
    
    Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
    Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
    Latency: 0, Cache Line Size: 64 bytes
    Interrupt: pin A routed to IRQ 16
    Region 0: Memory at fbba0000 (32-bit, non-prefetchable) [size=128K]
    Region 1: Memory at fbb80000 (32-bit, non-prefetchable) [size=128K]
    Region 2: I/O ports at e020 [size=32]
    Region 3: Memory at fbbc4000 (32-bit, non-prefetchable) [size=16K]
    Expansion ROM at fbb60000 [disabled] [size=128K]
    
  • Power Management
    與 PCI-E 裝置相關的電源管理.
    Capabilities: [40] Power Management version 2
            Flags: PMEClk- DSI+ D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
            Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=1 PME-
    

    主要可以看一下 PME(D0+,D1-,D2-,D3hot+,D3cold+) power management event 的狀態,+ 代表有被啟動, – 代表沒有被啟動.
    D0 有 Uninitialized 與 Active 兩種狀態.
    D1 為 Light Sleep 狀態.
    D2 為 Deep Sleep 狀態.
    D3 為 Full Off 狀態, 還可以分成為 D3cold 與 D3hot 兩種狀態.

  • Message Signaled Interrupts
    有分兩種 MSI 與 MSI-X .
    Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
            Address: 0000000000000000  Data: 0000
    Capabilities: [60] MSI-X: Enable+ Count=10 Masked-
            Vector table: BAR=3 offset=00000000
            PBA: BAR=3 offset=00002000
    

    MSI 是 PCI Express 中斷產生的方式,採用 in-band (控制訊號與資料同線路) 的方式,取代舊有的 out-of-band 的方式.
    MSI (PCI 2.2 開始採用) 支援 1, 2, 4, 8, 16 或 32 中斷上限.
    MSI-X (PCI 3.0 開始採用) 支援 2048 中斷上限.

  • Express Endpoint
    Capabilities: [a0] Express (v2) Endpoint, MSI 00
            DevCap: MaxPayload 256 bytes, PhantFunc 0, Latency L0s <512ns, L1 <64us
                    ExtTag- AttnBtn- AttnInd- PwrInd- RBE+ FLReset- SlotPowerLimit 0.000W
            DevCtl: Report errors: Correctable+ Non-Fatal+ Fatal+ Unsupported+
                    RlxdOrd- ExtTag- PhantFunc- AuxPwr- NoSnoop-
                    MaxPayload 256 bytes, MaxReadReq 128 bytes
            DevSta: CorrErr+ UncorrErr- FatalErr- UnsuppReq+ AuxPwr+ TransPend-
            LnkCap: Port #0, Speed 2.5GT/s, Width x4, ASPM L0s L1, Exit Latency L0s <4us, L1 <64us
                    ClockPM- Surprise- LLActRep- BwNot- ASPMOptComp-
            LnkCtl: ASPM Disabled; RCB 64 bytes Disabled- CommClk+
                    ExtSynch- ClockPM- AutWidDis- BWInt- AutBWInt-
            LnkSta: Speed 2.5GT/s, Width x4, TrErr- Train- SlotClk+ DLActive- BWMgmt- ABWMgmt-
            DevCap2: Completion Timeout: Range ABCD, TimeoutDis+, LTR-, OBFF Not Supported
            DevCtl2: Completion Timeout: 16ms to 55ms, TimeoutDis-, LTR-, OBFF Disabled
            LnkCtl2: Target Link Speed: 2.5GT/s, EnterCompliance- SpeedDis-
                     Transmit Margin: Normal Operating Range, EnterModifiedCompliance- ComplianceSOS-
                     Compliance De-emphasis: -6dB
            LnkSta2: Current De-emphasis Level: -6dB, EqualizationComplete-, EqualizationPhase1-
                     EqualizationPhase2-, EqualizationPhase3-, LinkEqualizationRequest-
    

    DevCap: Device Capabilities
    其中的 MaxPayload 代表 PCIe 封包最大有效負載量,類似網路設定的 MTU.
    DevCtl: Device Control
    Report errors 表示哪一些錯誤需要被報告 + 代表有需要, – 代表沒有需要.詳細還需要看下面的 Advanced Error Reporting.
    其中的 MaxReadReq (PCIe Max Read Request) 代表 PCIe 讀取請求允許的上限值.
    DevSta: Device State
    目前裝置狀態,有沒有錯誤發生.

    LnkCap: Link capability
    系統能提供的最高頻寬 PCI-Express 1.0 ( 2.5G ) Width x4=10G .
    LnkCtl: Link Control
    裡面的 ASPM 為 PCI Express Active State Power Management ,disabled 代表沒有使用 power savings.
    LnkSta: Link State
    目前該PCI-E 裝置跑的速度 PCI-Express 1.0 ( 2.5G ) Width x1=2.5G,

    DevCap2: 其他與 Device Capabilities 相關的訊息.
    DevCtl2: 其他與 Device Control 相關的訊息.
    LnkCtl2: 其他與 Link Control 相關的訊息.
    LnkSta2: 其他與 Link State 相關的訊息.

  • Advanced Error Reporting
    PCI Express 錯誤信號可能發生在 PCI Express 鏈路本身或在鏈路上啟動時.
    PCI Express 定義兩個錯誤報告: 1. 基本(baseline) 和高級(Advanced) 錯誤報告 (Error Reporting) 功能.
    Capabilities: [100 v1] Advanced Error Reporting
            UESta: DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
            UEMsk: DLP- SDES- TLP- FCP- CmpltTO- CmpltAbrt- UnxCmplt- RxOF- MalfTLP- ECRC- UnsupReq- ACSViol-
            UESvrt: DLP+ SDES- TLP- FCP+ CmpltTO- CmpltAbrt- UnxCmplt- RxOF+ MalfTLP+ ECRC- UnsupReq- ACSViol-
            CESta: RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+
            CEMsk: RxErr- BadTLP- BadDLLP- Rollover- Timeout- NonFatalErr+
            AERCap: First Error Pointer: 00, GenCap- CGenEn- ChkCap- ChkEn-
    

    UESta: UN-correctable Error State
    UEMsk: UN-correctable Error Mask
    UESvrt: UN-correctable Error ?
    CESta: Correctable Error State
    CEMsk: Correctable Error Mask
    AERCap: AER Capabilities

  • 其他訊息
    Capabilities: [140 v1] Device Serial Number 90-fb-a6-ff-ff-76-38-00
    Kernel driver in use: igb
    Kernel modules: igb
    

Linux command – hwloc

$
0
0

Linux 系統下要看 PCI-E 裝置,可以透過 #lspci (list all PCI devices) 來查看 PCI-(E) Bus 的系統硬體相關訊息的指令,請參考 http://benjr.tw/10851

如果是 CPU 可以透過指令 #lscpu (display information about the CPU architecture) 來檢視與 CPU 相關訊息,請參考 http://benjr.tw/98347 .

如果只是要簡單查看一下系統的架構圖,可以利用 hwloc(Portable Hardware Locality) 套件(非預設安裝)所提供的這幾個指令 lstopo(圖形介面), lstopo-no-graphics(文字介面), hwloc-ls(文字介面) .

測試環境為 Ubuntu 16.04 x86_64 (VMware 虛擬機) .

root@ubuntu:~# apt install hwloc
root@ubuntu:~# lstopo

測試環境為 CentOS 6

[root@localhost ~]# yum -y instal hwloc

測試環境為 CentOS 7 to install

[root@localhost ~]# yum -y install hwlock hwlock-gui

在 CentOS 7 下,lstopo 指令包在另外一個套件 hwlock-gui 裡面.

[root@localhost ~]# lstopo

hwloc 不只提供 lstopo(圖形介面), lstopo-no-graphics(文字介面), hwloc-ls(文字介面) ,還有下面幾個指令可以使用.

  • hwloc-annotate – Add info attributes to a XML topology
  • hwloc-compress-dir – Compress a directory of XML topologies
  • hwloc-gather-topology – Saves the relevant Linux topology files and the lstopo output for later (possibly offline) usage
  • hwloc-assembler – Assemble multiple XML topologies
  • hwloc-diff – Compute differences between two XML topologies
  • hwloc-info – Show some information about some objects or about a topol‐
    ogy
  • hwloc-assembler-remote – Assemble multiple remote host topologies
  • hwloc-distances – Displays distance matrices
  • hwloc-ls – Show the topology of the system
  • hwloc-bind – Launch a command that is bound to specific processors and/or memory, or consult the binding of an existing program
  • hwloc-distrib – Build a number of cpu masks distributed on the system
  • hwloc-patch – Apply a topology difference to an existing XML topology
  • hwloc-calc – Operate on cpu mask strings and objects
  • hwloc-dump-hwdata – Dump topology and locality information from hardware tables
  • hwloc-ps – List currently-running processes or threads that are bound

Linux command – Top

$
0
0

“Top” 是 Linux 提供的系統監控程式, 我們可以藉這支工具得知目前系統資源的使用狀態,使用方法很簡單直接在 command line 打入 top 即可,不過要怎麼看得懂他提供的資訊才是最重要的關鍵.

[root@benjr ~]# top
    • top – 14:47:30 up 10 days,  23:24,    2  user,    load average: 0.00, 0.00, 0.00
      先看一下第一行這些是代表什麼意思
      目前的電腦時間 : 14:47:30 up
      電腦已經開機經過了多少時間 : 10 days, 23:24
      目前登入系統的使用者有幾位 : 2 user
      系統平均負載 : load average: 0.00, 0.00, 0.00 這裡有三個數字,各代表了前 1,5,10 分鐘的平均負載.
      top01
    • Tasks:  107 total,    1 running,    106 sleeping,   0 stopped,   0 zombie
      看看第二行各代表什麼意思.
      目前所有的 Processes : Tasks: 107 total,
      目前正在執行的 Processes : 1 running,
      目前沒在執行的 Processes : 106 sleeping, 會睡著的原因大多是這個 process 需要等待某些 event 產生中斷,才會再度把他叫醒.
      目前已經停止的 Processes : 0 stopped,
      目前已經死掉的 Processes : 0 zombie 造成 zombie 的大多是父程序並不知道其子程序已經死亡,所以才會有這種狀況出現.
      top02

 

    • Cpu(s): 0.0% us,   50.0% sy,   0.0% ni,   50.0% id,   0.0% wa,   0.0% hi,   0.0% si
      0.0% us : User CPU time: 使用者的 Process 所花 CPU 的百分比.
      50.0% sy : System CPU time: Kernel 的 Process 所花 CPU 的百分比.
      0.0% ni : Nice CPU time: CPU 花在使用者的 process 改變優先順序的百分比.
      50.0% id : idle CPU time: 空閑 CPU 的百分比.
      0.0% wa : iowait CPU 花在等待 I/O 的百分比.
      0.0% hi : Hardware IRQ CPU 處理 hardware interrupts 的百分比.
      0.0% si : Software Interrupts CPU 處理 software interrupts 的百分比.

      note:系統預設所看到的 CPU 是所有 CPU core 核心效能的平均值,如果要看個別的效能可以在 top 下面按數字 “1”,即可看到目前所有 CPU 的使用率.

      top03

 

    • Mem:    1033660k total,   287052k used,   746608k free,  28676k buffers
      1033660k total : 系統上所有的記憶體大小.
      287052k used : 目前已經使用的記憶體.可以細分為 1.Application Memory  2.Buffered Memory  3.Cached Memory 不過在這一行下只會看到 buffer 一種, Cached 則是列在 Swap 裡面.雖然列在 Swap 裡但他是實實在在的記憶體所佔的空間.
      746608k free : 目前沒有再用的記憶體.
      28676k buffers : 當成是 buffer 的記憶體大小,主要是當資料還來不及儲存到硬碟中暫儲在記憶體的資料..
      160084k cached : 雖然列在 swap 後面其實它是 記憶體使用的一部分,主要是當資料已經由硬碟中讀取出來,暫存在記憶體提供給應用程式接下來使用,用以提高存取效能.
      top04

 

    • Swap:   2031608k total,   160k used,   2031448k free,   160084k cached
      2031608k total : swap 的大小.
      160k used : 目前 swap 使用區塊大小.
      2031448k free : 目前沒有在使用的區塊大小.
      160084k cached : 雖然列在 swap 後面其實它是 記憶體使用的一部分,主要是當資料已經由硬碟中讀取出來,暫存在記憶體提供給應用程式接下來使用,用以提高存取效能.
      top05

 

  • PID   USER   PR   NI   VIRT   RES   SHR S   %CPU   %MEM   TIME+   COMMAND
    PID : Process ID
    USER : Processes 所屬的使用者
    PR : Prioary,Processes 優先順序
    NI : Nice 值,越低(-20)代表優先順序越高,越高(+20)代表優先順序越低.
    VIRT :VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card’s RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.
    RES :RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.
    SHR :SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.
    這三個值寫的很玄,請參考原始網頁.
    FAQ_Linux_Memory_Management
    S : status 狀態值下
    D : Uninterruptible sleep 這個 Process 已經進入 Sleeping 而且在等待 I/O 的結果.
    R : Runnable 目前正在執行的 Process
    S : Sleeping 目前沒在執行的 Process
    T : Stopped 目前已經停止的 Process
    Z : Zombie 造成 zombie 的大多是父程序並不知道其子程序已經死亡,所以才會有這種狀況出現.
    %CPU : 目前這個 Process 的 CPU 使用率.
    %MEM : 目前這個 Process 的 Memory 使用率.
    TIME+ : 目前這個 Process 執行所花的時間.
    COMMAND : Process 的名稱
    top06

top 是個相當老的程式,現在有比較好用的 htop 可以選用,在 Ubuntu 可以透過 #apt-get install htop 即可下載.
htop01

Linux command – nvme format

$
0
0

SSD

傳統的 SSD 硬碟在做硬碟資料抹除 (security erase 可以讓硬碟回覆到原本的效能水準) 是透過 #hdparm .

首先要檢查硬碟是否有支援 security set 指令.

[root@benjr ~]# hdparm -I /dev/sdb 

要先設定 security password 才能執行 security erase.

[root@benjr ~]# hdparm --security-set-pass 1234 /dev/sdb
[root@benjr ~]# hdparm --security-erase 1234 /dev/sdb

NVME

但是 nvme 在做資料抹除時,需要使用 # nvme format 指令.

[root@benjr ~]# nvme format /dev/nvme0 --namespace-id=1 --ses=1

參數
-n nsid, –namespace-id=nsid
Send the format command for the specified nsid. This can be used to override the default value for either character device (0xffffffff) or the block device (result from NVME_IOCTL_ID).

-s ses, –ses=ses
Secure Erase Settings: This field specifies whether a secure erase should be performed as part of the format and the type of the secure erase operation. The erase applies to all user data, regardless of location (e.g., within an exposed LBA, within a cache, within deallocated LBAs, etc). Defaults to 0.

  • 0
    No secure erase operation requested
  • 1
    User Data Erase: All user data shall be erased,contents of the user data after the erase is indeterminate (e.g., the user data may be zero filled, one filled, etc). The controller may perform a cryptographic erase when a User Data Erase is requested if all user data is encrypted.
  • 2
    Cryptographic Erase: All user data shall be erased cryptographically. This is accomplished by deleting the encryption key.
  • 3–7
    Reserved.

Linux – EDAC & rasdaemon

$
0
0

測試環境為 CentOS 8 x86_64

  • 關於 rasdaemon 的說明 – https://github.com/mchehab/rasdaemon
  • 與 EDAC – https://www.kernel.org/doc/html/latest/driver-api/edac.html

Rasdaemon is a RAS (Reliability, Availability and Serviceability) logging tool. It records memory errors, using the EDAC tracing events. EDAC is a Linux kernel subsystem with handles detection of ECC errors from memory controllers for most chipsets on i386 and x86_64 architectures. EDAC drivers for other architectures like arm also exists.

簡單的來說 rasdaemon 全名為 RAS : (R)eliability , (A)vailability , (S)erviceability Daemon , 主要是透過 Linux 核心 Kernel EDAC (Error Detection and Correction) 功能來偵測並收集統計硬體的錯誤訊息.包含了 mc_event (MC : memory controller), aer_event (PCI-E AER : Advanced Error Reporting), mce_record , extlog_mem_event 這幾種.

所需套件.

[root@localhost ~]# dnf install rasdaemon

在 CentOS 7 還提供另外指令 edac-util – EDAC error reporting utility 與 edac-ctl – EDAC admin utility 來使用 (CentOS 8 則是使用 ras-mc-ctl – RAS memory controller admin utility ).

[root@localhost ~]# yum install rasdaemon
[root@localhost ~]# yum install edac-utils

安裝完 rasdaemon 就可以啟動服務了.

[root@localhost ~]# rasdaemon --enable
rasdaemon: ras:mc_event event enabled
rasdaemon: ras:aer_event event enabled
rasdaemon: mce:mce_record event enabled
rasdaemon: ras:extlog_mem_event event enabled
[root@localhost ~]# systemctl enable rasdaemon
Created symlink /etc/systemd/system/multi-user.target.wants/rasdaemon.service → /usr/lib/systemd/system/rasdaemon.service.
[root@localhost ~]# systemctl start rasdaemon
[root@localhost ~]# systemctl status rasdaemon
● rasdaemon.service - RAS daemon to log the RAS events
   Loaded: loaded (/usr/lib/systemd/system/rasdaemon.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-03-05 23:36:29 CST; 5s ago
  Process: 2514 ExecStartPost=/usr/sbin/rasdaemon --enable (code=exited, status=0/SUCCESS)
 Main PID: 2513 (rasdaemon)
    Tasks: 1 (limit: 23493)
   Memory: 612.0K
   CGroup: /system.slice/rasdaemon.service
           └─2513 /usr/sbin/rasdaemon -f -r

Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: Enabled event ras:aer_event
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: Family 6 Model 8e CPU: only decoding architectural errors
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: mce:mce_record event enabled
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: Enabled event mce:mce_record
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: ras:extlog_mem_event event enabled
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: Enabled event ras:extlog_mem_event
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: rasdaemon: Recording mc_event events
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: rasdaemon: Recording aer_event events
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: rasdaemon: Recording extlog_event events
Mar 05 23:36:29 localhost.localdomain rasdaemon[2513]: rasdaemon: Recording mce_record events

透過指令 ras-mc-ctl –summary 來檢視系統硬體是否有問題 ,以下錯誤參考 https://www.setphaserstostun.org/posts/monitoring-ecc-memory-on-linux-with-rasdaemon/ .

[root@localhost ~]# ras-mc-ctl --summary
Memory controller events summary:
  Corrected on DIMM Label(s): 'DIMM_B1' location: 0:2:0:-1 errors: 5

PCIe AER events summary:
  1 Uncorrected (Non-Fatal) errors: BIT21

No Extlog errors.

No devlink errors.
Disk errors summary:
  0:0 has 6646 errors
No MCE errors.

或是

[root@localhost ~]# ras-mc-ctl --errors
No Memory errors.

No PCIe AER errors.

No Extlog errors.

No MCE errors.

這兩種的差別如下:

  1. –summary : Presents a summary of the logged errors.
  2. –errors : Shows the errors stored at the error database.

其他 ras-mc-ctl 可使用參數如下:

[root@localhost ~]# ras-mc-ctl         
Usage: ras-mc-ctl [OPTIONS...]
 --quiet            Quiet operation.
 --mainboard        Print mainboard vendor and model for this hardware.
 --status           Print status of EDAC drivers.
 --print-labels     Print Motherboard DIMM labels to stdout.
 --guess-labels     Print DMI labels, when bank locator is available.
 --register-labels  Load Motherboard DIMM labels into EDAC driver.
 --delay=N          Delay N seconds before writing DIMM labels.
 --labeldb=DB       Load label database from file DB.
 --layout           Display the memory layout.
 --summary          Presents a summary of the logged errors.
 --errors           Shows the errors stored at the error database.
 --error-count      Shows the corrected and uncorrected error counts using sysfs.
 --help             This help message.

大部分的參數是針對 DIMM 的部分,來看一下參數 –error-count

[root@localhost ~]# # ras-mc-ctl --error-count
Label                 CE  UE
mc#0csrow#2channel#0  0   0
mc#0csrow#2channel#1  0   0
mc#0csrow#3channel#1  0   0
mc#0csrow#3channel#0  0   0

CE 與 UE 需要有 Error-Correcting Code ( ECC ) 的 DIMM 才能使用,這一類的記憶體常用於伺服器( Server )上.

  • CE : 代表發生 Correctable Error 的次數.
  • UE: 代表發生 UNCorrectable Error 的次數.

Label 所代表的意思.

  • mc : Memory Controller
  • csrow : Chip-Select Row
  • channel : Memory Channel

我們通常會透過 指令 #journalctl 來查看系統發生什麼錯誤訊息,現在可以直接使用指令 ras-mc-ctl 來查看與硬體相關發生的錯誤次數與其統計.

Viewing all 14 articles
Browse latest View live