深入浅出:Linux下PCIe热插拔的实现与应用 (linux pcie hotplug)

PCIe(Peripheral Component Interconnect Express)是一种高速的串行I/O(interconnect)总线,用于连接服务器/台式机上的硬件组件,例如图形卡、网卡和RD卡等。

对于服务器和工作站,PCIe插槽通常是通过热插拔(hot-plug)技术实现的,以允许无需关闭或重启系统即可从系统中添加或删除PCIe设备。本文将介绍Linux下PCIe热插拔的实现方式和操作。

PCIe热插拔的原理

PCIe热插拔的特性可以归结为两个方面:硬件方面和软件方面。

硬件方面:在支持PCIe热插拔的系统中,每个设备插座都有多个物理引脚用于检测设备插入,通常称为插入检测器。插入检测器与插座地面之间的电阻变化将被检测到,并且在操作系统中触发中断(interrupt)信号,通知驱动程序有设备插入,然后启动相应的设备初始化程序。

在PCIe热插拔过程中,设备被拔出时系统必须能够正确地释放设备所占用的资源,例如DMA通道,I/O内存空间等。类似地,当设备插入时系统必须能够正确地探测并分配资源给设备,以确保它们能够正常工作。

软件方面:Linux内核已经支持PCIe hhot-plug,驱动程序可以通过调用PCIe总线驱动程序(如pciehp驱动)API接口进行注册和注销。一旦一个设备被检测到已经插入,内核会通知bus驱动程序并启动特定的设备驱动程序来配置设备。

PCIe设备驱动程序启动后,执行以下操作:

1.检查设备状态,例如确定设备是否支持热插拔并处理系统中断。

2.分配内存,例如分配EECP(config space)空间和适当的I/O端口。

3.设置总线标识信息,例如VID(vendor ID)和DID(device ID)。

4.初始化设备寄存器,例如初始化MSI/MSI-X中断消息,启用MSI/MSI-X中断,根据需要重定向中断或禁用中断。

5.检出系统中其他设备的信息,例如通过sysfs文件系统将设备位置通知系统管理程序。

6.通知用户应用程序有新设备已添加到系统中。

实际应用

此处以一部服务器为例,介绍了如何在Linux下添加和删除PCIe设备。

在服务器上确定当前系统是否支持PCIe热插拔。可以通过发出以下命令来检查是否已加载pciehp内核模块:

“`

$ lod | grep pciehp

“`

如果结果中列出了pciehp,说明内核已经加装了支持PCIe热插拔的驱动程序,可以继续。

然后,插入PCIe设备:

1.通过lssapce命令查找所有可用的PCIe插槽,并确定设备的PCIe位置。

“`

$ lspci –tv

“`

2.插入设备。插入设备后,可以通过以下命令检查系统是否检测到了新设备:

“`

$ dmesg | tl

“`

3.加载设备驱动程序:

“`

$ modprobe

“`

确定设备ID是什么以及驱动程序的名称并更改。

4.设置权限:

“`

$ chmod 666 /dev/

“`

确保驱动程序具有适当的访问权限。

删除PCIe设备:

1.卸载设备驱动程序:

“`

$ rmmod

“`

2.检查系统是否检测到设备的删除:

“`

$ dmesg | tl

“`

3.拔出设备。

注意:在删除设备之前,应确保任何正在使用设备的操作均已停止。

结论

相关问题拓展阅读:

vmware7.0下使用Other Linux 2.6.x kernel配置gentoo的问题

虚拟机设置中光驱在电源打开时连接选中试一下。另外内核编译有好多选项。

Linux Kernel Configuration: VMware tools configuration

这些是从gentoo的vmware的wiki页上复制下来的

其中光驱相关的是下面几个项唯握,你make menuconfig然后检查下吧:

Device Drivers —>

ATA/ATAPI/MFM/RLL support —>

Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support

Include IDE/ATAPI CDROM support

PCI IDE chipset support

Intel PIIXn chipsets support

下面是安装vmware tools的说明

First, we mount the iso image of the tools. Within vmware player of workstation, connect the CDROM to the iso file. It is located at

/opt/vmware/workstation/lib/vmware/isoimages/老山乎linux.iso.

Now we have to mount the image file

mount /dev/cdrom /mnt/cdrom

Then untar the image file

cd /mnt/cdrom tar -zxf VMwareTools-*.tar.gz -C /opt

Here you need to create the /etc/rc{0..6}.d directories because the installation script wants to create symlinks to /etc/init.d/vmware-tools.

mkdir /etc/rc{0..6}.d

You also need to create symlinks to some kernel headers

ln -s /usr/src/linux/include/generated/utsrelease.h /usr/src/linux/include/linux/utsrelease.h ln -s /usr/src/linux/include/generated/autoconf.h /usr/src/linux/include/linux/autoconf.h

Now we run the install script

cd /opt/vmware-tools-distrib ./vmware-install.pl

Respond to the configuration questions on the screen. Press Enter to accept the default value. Once you answer the last question, the installation will start. It will take quite some time… have a cup of tea.

Once the installation is finished, we have to add vmware-tools to the default runlevel

rc-update add vmware-tools default

Now you can start vmware-tools manually by the following command or you can reboot

/etc/init.d/vmware-tools start

—下面是vmware下gentoo的内核全部的相关设置侍悉

—-如果你觉得不放心自己的设置,可以再和自己的设置对照下

Loadable module support —>

Enable loadable module support —>

Module unloading

Linux Kernel Configuration: Intel PCI/ISA Bridge

Bus options (PCI etc.) —>

PCI Support

ISA Support

EISA support

Support for PCI Hotplug

Support for PCI Hotplug —>

SHPC PCI Hotplug driver

Linux Kernel Configuration: IEEE 1394

Device Drivers —>

IEEE 1394 (Firewire) support —>

Stable Firewire stack

OHCI-1394 controllers

Storage devices (SBP-2 protocol)

Linux Kernel Configuration: Parallel port

Device Drivers —>

Parallel port support —>

PC-style hardware

Linux Kernel Configuration: Parallel ATA

Device Drivers —>

Serial ATA (prod) and Parallel ATA (experimental) drivers —>

PCMCIA PATA support

Linux Kernel Configuration: I2C

Device Drivers —>

I2C Support —>

I2C Hardware Bus support —>

Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SC)

Linux Kernel Configuration: Backplane

Device Drivers —>

Sonics Silicon Backplane —>

Sonics Silicon Backplane support

Linux Kernel Configuration: LSI Logic SCSI adapter

Device Drivers —>

Fusion MPT device support —>

Fusion MPT ScsiHost drivers for SPI

Fusion MPT ScsiHost drivers for FC

Fusion MPT ScsiHost drivers for SAS

SCSI device support —>

SCSI device support

SCSI disk support

SCSI low-level drivers —>

SYM53C8XX Version 2 SCSI support

Linux Kernel Configuration: BusLogic

Device Drivers —>

SCSI device support —>

SCSI device support

SCSI disk support

SCSI low-level drivers —>

BusLogic SCSI support

Linux Kernel Configuration: HID support

Device Drivers —>

HID Devices —>

USB Human Interface Device (full HID) support

USB support —>

Support for Host-side USB

SL811HS HCD support

Linux Kernel Configuration: CDROM

Device Drivers —>

ATA/ATAPI/MFM/RLL support —>

Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support

Include IDE/ATAPI CDROM support

PCI IDE chipset support

Intel PIIXn chipsets support

File systems —>

CD-ROM/DVD Filesystems —>

ISO 9660 CDROM file system support

Microsoft Joliet CDROM extensions

We have to disable IPV6, VMware does not support it yet.

Linux Kernel Configuration: Network

Networking —>

Networking support

Networking options —>

Packet socket

Unix domain sockets

TCP/IP networking

The IPv6 protocol —>

.1d Ethernet Bridging

You need to build the network drivers as modules to be able to unload them later and load vmware optimized modules.

Device Drivers —>

Network Device support —>

Network device support

Ethernet (10 or 100Mbit) —>

Ethernet (10 or 100Mbit)

EISA, VLB, PCI and on board controllers

AMD PCnet32 PCI support

Ethernet (1000Mbit) —>

Intel(R) PRO/1000 Gigabit Ethernet support

VMware virtual machine emulates a Creative Labs Sound Blaster® AudioPCI device. If you like to have sound in your virtual Gentoo Linux, you will need to add support for it. See the following section.

Linux Kernel Configuration: Audio

Device Drivers —>

Sound —>

Sound card support

Advanced Linux Sound Architecture

Sequencer support

Sequencer dummy client

OSS Mixer API

OSS PCM (digital audio) API

OSS PCM (digital audio) API – Include plugin system

OSS Sequencer API

Dynamic device file minor numbers

Support old ALSA API

Verbose procfs contents

Generic sound devices —>

PCI sound devices —>

(Creative) Ensoniq AudioPCI 1371/1373

USB sound devices —>

PCMCIA sound devices —>

Linux Kernel Configuration: Gameport

Device Drivers —>

Input device support —>

Hardware I/O ports —>

Gameport support

Linux Kernel Configuration: Graphics

Device Drivers —>

Graphics support —>

/dev/agpgart (AGP Support) —>

Intel 440LX/BX/GX, I8xx and E7x05 chipset support

Linux Kernel Configuration: Device mapper support

Device Drivers —>

Multiple devices driver support (RAID and LVM) —>

Device mapper support

Snapshot target

Bad Block Relocation Device Target (EXPERIMENTAL)

These other things might be useful for udev. Note: If your kernel has problems mounting udev, you may need to emerge sys-apps/portage, sys-fs/baselayout, and sys-fs/udev to their most current stable versions.

Linux Kernel Configuration: udev support

File Systems —>

Pseudo filesystems —>

*- /proc file system support

/proc/kcore support

Virtual memory file system support (former shm fs)

你光驱有设开机链接没啊?

或者检查一下相应的模块有加载没。

linux双网卡双IP双网关如何配置

注意: 2 张网卡,只能有1张网卡配置网关,另1张网卡不能配置网关,通过route add 添加路由功能来完成第耐哪2张网卡的网关配置。

如 : eth1 (192.168.2.2)不需要配置网关, 但到 192.168.3.0 的网段,需要从eth1 去实现通信,其余的全部走eth0 网卡,eth0 配置 网关.

eth0 的配置如下,配置网关参数

# cat ifcfg-eth0

# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

HOTPLUG=no

TYPE=Ethernet

IPADDR=192.168.1.2

NETMASK=255.255.255.0

HWADDR=d8:d3:85:fb:d4:60

GATEWAY=192.168.1.1

USERCTL=no

IPV6INIT=no

PEERDNS=yes

eth1 的配置如下,不需要配置租亩消网关

# cat ifcfg-eth1

# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

HOTPLUG=no

TYPE=Ethernet

IPADDR=192.168.2.2

NETMASK=255.255.255.0

USERCTL=no

IPV6INIT=no

PEERDNS=yes

Linux 命令弊知行下添加路由,192.168.3.0 走 eth1 的网关 192.168.2.1

route add -net 192.168.3.0 netmask 255.255.255.0 dev eth1

你这个需求,需要使胡迅用iproute2包中的 ip命令完成。

首先 /etc/iproute2/rt_tables 里面添加2个table, 对应2个不同的网段(吵做坦net3 net5)

配置思路是 用ip route 命令为net3 table增加default gw 118.126.3.1,net5 table 增加default gw 118.126.5.1

然后用 ip rule 命令 使用源地址匹配规则 源地址为118.126.3.16的数据包选择 net3 table, 源地址为118.126.5.251的数据包选择net5 table.

当然你也需要设置本机的默认default gw(直接用route命升桐令),那么由本机生成的数据包,默认会选用与default gw连接的那块网卡的ip地址对外通讯(程序指定的除外)。

以上配置对于正常开发的 tcp通讯软件完全可以正确工作,ping也没有问题。 不过某些开发不正确的udp软件可能运行会不正常(这种udp软件,在有两个以上ip地址的主机上工作都会有问题)

或许在118.126.3.1的路由器瞎芹加一条静态路由,route add 118.126.5.0 netmask 255.255.255.0 118.126.3.16就可以了

5段的其他ip可磨友毕以ping通?

不是仅有linux不能有双网关,所有的pc os应告核该都不可以

5网段没有设置网关啊,可以在eht1的配置旁悔内容老腊中加入:

GATEWAY=192.168.5.X

关于linux pcie hotplug的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。


数据运维技术 » 深入浅出:Linux下PCIe热插拔的实现与应用 (linux pcie hotplug)