设备驱动绑定和解绑

One new feature in the 2.6.13-rc3 kernel release, is the ability to bind and unbind drivers from devices manually from user space. Previously, the only way to disconnect a driver from a device was usually to unload the whole driver from memory, using  rmmod .

In the sysfs tree, every driver now has bind and unbind files associated with it:

    $ tree /sys/bus/usb/drivers/ub/
    /sys/bus/usb/drivers/ub/
    |-- 1-1:1.0 -> ../../../../devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0
    |-- bind
    |-- module -> ../../../../module/ub
    `-- unbind

In order to unbind a device from a driver, simply write the bus id of the device to the unbind file:

    echo -n "1-1:1.0" > /sys/bus/usb/drivers/ub/unbind

and the device will no longer be bound to the driver:

    $ tree /sys/bus/usb/drivers/ub/
    /sys/bus/usb/drivers/ub/
    |-- bind
    |-- module -> ../../../../module/ub
    `-- unbind

To bind a device to a driver, the device must first not be controlled by any other driver. To ensure this, look for the "driver" symlink in the device directory:

    $ tree /sys/bus/usb/devices/1-1:1.0
    /sys/bus/usb/devices/1-1:1.0
    |-- bAlternateSetting
    |-- bInterfaceClass
    |-- bInterfaceNumber
    |-- bInterfaceProtocol
    |-- bInterfaceSubClass
    |-- bNumEndpoints
    |-- bus -> ../../../../../../bus/usb
    |-- modalias
    `-- power
        `-- state

Then, simply write the bus id of the device you wish to bind, into the bind file for that driver:

    echo -n "1-1:1.0" > /sys/bus/usb/drivers/usb-storage/bind

And check that the binding was successful:

    $ tree /sys/bus/usb/devices/1-1:1.0
    /sys/bus/usb/devices/1-1:1.0
    |-- bAlternateSetting
    |-- bInterfaceClass
    |-- bInterfaceNumber
    |-- bInterfaceProtocol
    |-- bInterfaceSubClass
    |-- bNumEndpoints
    |-- bus -> ../../../../../../bus/usb
    |-- driver -> ../../../../../../bus/usb/drivers/usb-storage
    |-- host2
    |   `-- power
    |       `-- state
    |-- modalias
    `-- power
        `-- state

As the example above shows, this capability is very useful for switching devices between drivers which handle the same type of device (both the ub and usb-storage drivers handle USB mass storage devices, like flash drives.)

A number of "enterprise" Linux distributions offer multiple drivers of different version levels in their kernel packages. This manual binding feature will allow configuration tools to pick and choose which devices should be bound to which drivers, allowing users to upgrade only specific devices if they wish to.

In order for a device to bind successfully with a driver, that driver must already support that device. This is why you can not just arbitrarily bind any device to any driver. To help with the issue of adding new devices support to drivers after they are built, the PCI system offers a dynamic_id (new_id?)file in sysfs so that user space can write in new device ids that the driver should bind too. In the future, this ability to add new driver IDs to a running kernel will be moved into the driver core to make it available for all buses.

FROM: https://lwn.net/Articles/143397/

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: DPDK是一种开源的数据包处理框架,它能够大大提升数据包处理的速度以及效率。DPDK的性能在很大程度上依赖于它与网络接口卡的配合。为了最大化性能,需要将网络接口卡绑定到DPDK上。 DPDK在绑定网卡时,需要先在Linux系统中安装igb_uio驱动程序。然后,可以使用DPDK自带的绑定脚本进行绑定,如下所示: ./usertools/dpdk-devbind.py --bind=igb_uio eth0 其中,“eth0”为需要绑定的网卡名。绑定完成后,可以使用DPDK提供的性能测试工具来测试性能。 需要注意的是,在绑定之前,应先停止任何已经在使用该网卡的服务或应用程序。在绑定过程中,还要确保正确配置DPDK环境变量,如DPDK_SDK和RTE_SDK等。此外,在绑定完成后还需要检查网卡是否成功被绑定。 如果需要解,可以使用同样的绑定脚本来进行操作,只需要将命令中的“bind”替换为“unbind”,如下所示: ./usertools/dpdk-devbind.py --unbind eth0 绑定和解过程需要小心谨慎,否则可能会导致系统崩溃或者网络故障。因此,在操作前应先确认自己掌握了足够的知识和经验,才能进行相应的操作。 ### 回答2: DPDK是一种高性能数据平面开发工具集,可以用于加速包处理和数据包转发。绑定和解网络接口是DPDK的重要功能,它可以为应用程序提供更高效的包处理和网络传输能力。 网卡绑定是将DPDK与物理网卡连接起来的过程。通常情况下,DPDK使用IGB UIO模块将物理网卡作为DPDK的虚拟设备进行管理。网卡绑定的过程包括以下几个步骤: 1. 加载IGB UIO驱动程序:使用modprobe命令加载驱动程序,驱动程序所在路径在DPDK目录下的x86_64-native-linuxapp-gcc/kmod目录中。 2. 绑定网卡到UIO驱动程序上:使用DPDK提供的dpdk-devbind工具,输入命令进行网卡与驱动程序的绑定,如:./dpdk-devbind --bind=uio_pci_generic eth0。 3. 初始化DPDK虚拟设备:使用DPDK提供的脚本,输入命令进行虚拟设备的初始化,如:./usertools/dpdk-devbind.py -s。 网卡解是将DPDK与物理网卡连接断开的过程。解网卡的过程包括以下几个步骤: 1. 停止DPDK进程:使用DPDK提供的脚本,输入命令停止DPDK进程,如:./usertools/dpdk-devbind.py --status。 2. 解网卡:使用DPDK提供的dpdk-devbind工具,输入命令解网卡,如:./dpdk-devbind --unbind eth0。 3. 卸载IGB UIO驱动程序:使用rmmod命令卸载驱动程序,如:rmmod uio_pci_generic。 绑定和解网卡的操作可以通过脚本进行自动化,以提高效率和可靠性。同时也需要注意,绑定和解不当会导致系统网络异常,因此需要进行充分测试和验证。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值