『壹』 如何查看linux伺服器的cpu數量,內核數,和cpu線程數
lscpu命令,查看的是cpu的統計信息.x0dx0ablue@blue-pc:~$ lscpux0dx0aArchitecture: i686 #cpu架構x0dx0aCPU op-mode(s): 32-bit, 64-bitx0dx0aByte Order: Little Endian #小尾序x0dx0aCPU(s): 4 #總共有4核x0dx0aOn-line CPU(s) list: 0-3x0dx0aThread(s) per core: 1 #每個cpu核,只能支持一個線程,即不支持超線程x0dx0aCore(s) per socket: 4 #每個cpu,有4個核x0dx0aSocket(s): 1 #總共有1一個cpux0dx0aVendor ID: GenuineIntel #cpu產商 intelx0dx0aCPU family: 6x0dx0aModel: 42x0dx0aStepping: 7x0dx0aCPU MHz: 1600.000x0dx0aBogoMIPS: 5986.12x0dx0aVirtualization: VT-x #支持cpu虛擬化技術x0dx0aL1d cache: 32Kx0dx0aL1i cache: 32Kx0dx0aL2 cache: 256Kx0dx0aL3 cache: 6144Kx0dx0a x0dx0a 查看/proc/cpuinfo,可以知道每個cpu信息,如每個CPU的型號,主頻等。x0dx0a#cat /proc/cpuinfox0dx0aprocessor : 0x0dx0avendor_id : GenuineIntelx0dx0acpu family : 6x0dx0amodel : 42x0dx0amodel name : Intel(R) Core(TM) i5-2320 CPU @ 3.00GHzx0dx0a.....x0dx0a 上面輸出的是第一個cpu部分信息,還有3個cpu信息省略了。x0dx0a x0dx0a 內存x0dx0a 概要查看內存情況x0dx0a free -mx0dx0a total used free shared buffers cachedx0dx0a Mem: 3926 3651 274 0 12 404x0dx0a -/+ buffers/cache: 3235 691x0dx0a Swap: 9536 31 9505x0dx0a 這里的單位是MB,總共的內存是3926MB。x0dx0a x0dx0a 查看內存詳細使用x0dx0a# cat /proc/meminfox0dx0aMemTotal: 4020868 kBx0dx0aMemFree: 230884 kBx0dx0aBuffers: 7600 kBx0dx0aCached: 454772 kBx0dx0aSwapCached: 836 kBx0dx0a.....x0dx0a x0dx0a 查看內存硬體信息x0dx0admidecode -t memoryx0dx0a# dmidecode 2.11x0dx0aSMBIOS 2.7 present.x0dx0aHandle 0x0008, DMI type 16, 23 bytesx0dx0aPhysical Memory Arrayx0dx0a Location: System Board Or Motherboardx0dx0a....x0dx0a Maximum Capacity: 32 GBx0dx0a....x0dx0aHandle 0x000A, DMI type 17, 34 bytesx0dx0a....x0dx0aMemory Devicex0dx0a Array Handle: 0x0008x0dx0a Error Information Handle: Not Providedx0dx0a Total Width: 64 bitsx0dx0a Data Width: 64 bitsx0dx0a Size: 4096 MBx0dx0a.....x0dx0a 我的主板有4個槽位,只用了一個槽位,上面插了一條4096MB的內存。x0dx0a x0dx0a 磁碟x0dx0a 查看硬碟和分區分布x0dx0a# lsblkx0dx0aNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTx0dx0asda 8:0 0 465.8G 0 diskx0dx0a├—sda1 8:1 0 1G 0 part /bootx0dx0a├—sda2 8:2 0 9.3G 0 part [SWAP]x0dx0a├—sda3 8:3 0 74.5G 0 part /x0dx0a├—sda4 8:4 0 1K 0 partx0dx0a├—sda5 8:5 0 111.8G 0 part /homex0dx0a└—sda6 8:6 0 269.2G 0 partx0dx0a 顯示很直觀x0dx0a x0dx0a 如果要看硬碟和分區的詳細信息x0dx0a# fdisk -lx0dx0aDisk /dev/sda: 500.1 GB, 500107862016 bytesx0dx0a255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectorsx0dx0aUnits = sectors of 1 * 512 = 512 bytesx0dx0aSector size (logical/physical): 512 bytes / 4096 bytesx0dx0aI/O size (minimum/optimal): 4096 bytes / 4096 bytesx0dx0aDisk identifier: 0x00023728x0dx0a Device Boot Start End Blocks Id Systemx0dx0a/dev/sda1 * 2048 2148351 1073152 83 Linuxx0dx0a/dev/sda2 2148352 21680127 9765888 82 Linux swap / Solarisx0dx0a/dev/sda3 21680128 177930239 78125056 83 Linuxx0dx0a/dev/sda4 177932286 976771071 399419393 5 Extended/dev/sda5 177932288 412305407 117186560 83 Linuxx0dx0a/dev/sda6 412307456 976771071 282231808 83 Linuxx0dx0a x0dx0a 網卡x0dx0a 查看網卡硬體信息x0dx0a# lspci | grep -i 'eth'x0dx0a02:00.0 Ethernet controller: Realtek Semiconctor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06)x0dx0a x0dx0a 查看系統的所有網路介面x0dx0a# ifconfig -ax0dx0aeth0 Link encap:乙太網 硬體地址 b8:97:5a:17:b3:8f x0dx0a .....x0dx0alo Link encap:本地環回 x0dx0a .....x0dx0a 或者是x0dx0aip link showx0dx0a1: lo:
『貳』 linux查看cpu核心數
兩種方法在linux可查看cpu,第一種為打開終端命令行直接輸入lscpu,在cpu(s)和core(s) per-socket能看到真實的邏輯與物理核心數量:
『叄』 如何使用Linux工作隊列workqueue
創建一個per-CPU
*編譯期間靜態創建一個per-CPU
DEFINE_PER_CPU(type, name)
創建一個名為name,數據類型為type的per-CPU,比如static DEFINE_PER_CPU(struct sk_buff_head, bs_cpu_queues),此時每個CPU都有一個名叫bs_cpu_queues,數據結構為sk_buff_head的變數副本。每個副本都是在自己的CPU上工作。
* 動態創建per-CPU,以下代碼是內核create_workqueue實現的片斷
struct workqueue_struct *__create_workqueue(const char *name,
int singlethread)
{
int cpu, destroy = 0;
struct workqueue_struct *wq;
struct task_struct *p;
wq = kzalloc(sizeof(*wq), GFP_KERNEL);
if (!wq)
return NULL;
wq->cpu_wq = alloc_percpu(struct cpu_workqueue_struct);
if (!wq->cpu_wq) {
kfree(wq);
return NULL;
}
……
}