‘壹’ 如何查看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;
}
……
}