首页 > 其他分享 >使用libvirt配置pci bus的numa亲和性

使用libvirt配置pci bus的numa亲和性

时间:2024-05-08 10:22:25浏览次数:13  
标签:-- bus libvirt pci numa qemu

前面的一篇文章在qemu中绑定pci bus到numa node - 半山随笔 - 博客园 (cnblogs.com)中记录了如何使用qemu命令行来设置pci bus与numa的亲和性。本篇来记录如何使用libvirt来做同样的事。

libvirt相较于qemu是一个更高层的工具,在提供便捷性的同时也损失了一点灵活性。就拿设置pci bus的numa亲和性而言,libvirt就很难去配置。参照libvirt的官方说明:

PCI controllers also have an optional subelement <target> with the attributes and subelements listed below. These are configurable items that 1) are visible to the guest OS so must be preserved for guest ABI compatibility, and 2) are usually left to default values or derived automatically by libvirt. In almost all cases, you should not manually add a <target> subelement to a controller, nor should you modify the values in the those that are automatically generated by libvirt. Since 1.2.19 (QEMU only).

node

Some PCI controllers (pci-expander-bus for the pc machine type, pcie-expander-bus for the q35 machine type and, since 3.6.0, pci-root for the pseries machine type) can have an optional <node> subelement within the <target> subelement, which is used to set the NUMA node reported to the guest OS for that bus - the guest OS will then know that all devices on that bus are a part of the specified NUMA node (it is up to the user of the libvirt API to attach host devices to the correct pci-expander-bus when assigning them to the domain).

也就是说在pci controller下面确实有numa相关的配置,但是在大部分情况下是不允许用户去改动的,这部分内容由libvirt自动生成。这就不好办了,既不能改xml配置,也不能在安装的时候设置。我的理解按照官方的设想这个参数只会在host device passthrough的时候会自动设置而不是让用户自由设置。

但是对于确实有这方面需求的该怎么办呢?

还好virt-install提供了qemu commandline直接注入的方式。

virt-install --help
...
 --qemu-commandline QEMU_COMMANDLINE
                        Pass arguments directly to the qemu emulator. Ex:
                        --qemu-commandline='-display gtk,gl=on'
                        --qemu-commandline env=DISPLAY=:0.1

既然我们可以在qemu中设置pci bus和numa亲和性,那么也可以通过将qemu参数直接注入libvirt来实现同样的功能。

sudo virt-install \
  --connect qemu:///system \
  --name node1 \
  --disk none \
  --memory 8192 \
  --vcpus 4,sockets=1,cores=4,threads=1 \
  --network bridge=virbr0 \
  --os-type linux \
  --virt-type kvm \
  --boot hd \
  --graphics none \
  --cpu cell0.cpus=0-1,cell0.memory=4194304,cell1.cpus=2-3,cell1.memory=4194304 \
  --qemu-commandline='-device pxb,id=pcie.1,bus=pci.0,addr=0x6,numa_node=0,bus_nr=5 -device pcie-pci-bridge,id=pcie-pci-br0,bus=pcie.1 -device virtio-blk-pci,scsi=off,bus=pcie-pci-br0,addr=0x1,drive=hd1,id=virtio-disk0,bootindex=1 -drive if=none,file=/home/jianyong/vm/AnolisOS-8.9-x86_64-RHCK.qcow2,id=hd1' \

上面的命令行就可以将virtio-blk设备挂到由pxb扩展出来的pci桥上,而pxb可以设置numa亲和性,这样也就设置了virtio blk的numa亲和性。进入虚拟机查看一下。

# lstopo-no-graphics
Machine (7685MB total)
  L3 L#0 (16MB)
    Group0 L#0
      NUMANode L#0 (P#0 3710MB)
      Package L#0 + L2 L#0 (512KB) + L1d L#0 (64KB) + L1i L#0 (64KB) + Core L#0 + PU L#0 (P#0)
      Package L#1 + L2 L#1 (512KB) + L1d L#1 (64KB) + L1i L#1 (64KB) + Core L#1 + PU L#1 (P#1)
      HostBridge
        PCIBridge
          PCIBridge
            PCI 07:01.0 (SCSI)
              Block "vda"
    Group0 L#1
      NUMANode L#1 (P#1 3975MB)
      Package L#2 + L2 L#2 (512KB) + L1d L#2 (64KB) + L1i L#2 (64KB) + Core L#2 + PU L#2 (P#2)
      Package L#3 + L2 L#3 (512KB) + L1d L#3 (64KB) + L1i L#3 (64KB) + Core L#3 + PU L#3 (P#3)
  HostBridge
    PCI 00:01.1 (IDE)
    PCI 00:02.0 (Ethernet)
      Net "eth0"
  Misc(MemoryModule)

可以看到vda设备已经挂到numa0之下,而eth0并没有跟任何numa绑定。

当然这种设置只是虚拟的,并没有实质性的绑定,只是给guest os一个假象。如果要提高性能还是要根绝host 相关设备topology来设置。

标签:--,bus,libvirt,pci,numa,qemu
From: https://www.cnblogs.com/banshanjushi/p/18179128

相关文章

  • 03_仿Modbus工具案例
    花了6个小时边学边写的Modbus通信案例,通信方式包括RTU,ASCII,TCP,UTP。案例图:   usingModbus.Data;usingModbus.Device;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.IO.......
  • 使用libvirt绑定numa node
    初学libvirt,感觉还挺方便的。它能够像daemon一样运行一个稳定的VM,相比直接用qemu命令行是方便多了。这里记录一下我如何绑定numanode。不知道能不能直接在创建虚拟机的时候绑定numa,我是在xml中设置的。安装libvirt,略去。在host上创建一个网桥,libvirt以它上网,我这里命名为virbr0......
  • 02_Modbus的功能码与报文详解
     Modbus协议类型  Modbus从站四张表类型 主站常用功能码  ModbusTCP请求报文,功能码03ModbusTCP应答报文,功能码03 0017为23个字节:请求长度加应答长度06+17=23;14为20长度:14+06=20  ModbusUDP请求报文,功能码03ModbusUDP应答报文,功能码03  M......
  • stm32f103c8t6的freemodbus移植
    注意:demo.c不要加入到程序中来。1在main.h文件中加入#include"stm32f1xx_hal.h"文件也可以不加a:每次重新生成程序时在主程序main.c中注释掉//MX_USART2_UART_Init();函数,因为在freemodbus中已经调用了该函......
  • 仓储层当前有接口 IRepository<T> 抽象类 BaseRepository<T> 业务逻辑层有抽象类 Bas
    以下是一个简单的C#示例,展示了如何实现不同表对应不同的业务逻辑层和不同的仓储实例://仓储层publicinterfaceIRepository<T>{voidAdd(Tentity);voidUpdate(Tentity);voidDelete(Tentity);TGetById(intid);//其他仓储操作方法...}publ......
  • 232Modbus转Profinet网关接扫码枪与PLC通讯
    Modbus转Profinet网关(XD-PNR100/300)的主要作用是实现Modbus协议和Profinet协议之间的转换和通信。本案例是用Modbus转Profinet网关接扫码枪与PLC通讯,扫码枪通常通过特定的接口与计算机或其他设备传输数据,而PLC(可编程逻辑控制器)则通常使用Profinet等工业通信协议。要将扫码枪通过......
  • Profinet转Modbus网关接称重设备与1200PLC通讯
     Profinet转Modbus网关(XD-MDPN100)是一种能够实现Modbus协议和Profinet协议之间转换的设备。Profinet转Modbus网关可提供单个或多个RS485接口,使用Profinet转Modbus网关将称重设备与西门子1200PLC进行通讯,可以避免繁琐的编程和配置过程,节省了工程师的时间和精力。其次,它提供了灵......
  • 在qemu中绑定pci bus到numa node
    在多numanode的物理机中,pcibus常常是连接到其中一个numa上。如此,不同的numa节点访问该pcibus下的设备的访问速度是不同的。基于此常常要将访问该设备的负载绑定到对应的numanode上可以提供性能。对于qemu虚拟机也可以模拟pcibus与numa之间的亲和性。在x86机器中,只有pxb和pxb......
  • modbus怎么写多个保持寄存器
    近期,在做项目的时候,用到了modbus协议,有一个校时功能,就是需要定时发送时间到相应的设备,给相应的设备校时,协议里给出了寄存器地址和数据格式,如下 这个在程序里就需要写多个连续的保持寄存器,报文格式如下:串口modbus报文格式1110132700040818041C0F0423F0F04ED8......
  • Modbus转Profinet网关连接打印设备与PLC通讯
      Modbus转Profinet网关(XD-MDPN100)是一种能够实现Modbus协议和Profinet协议之间转换的设备。Modbus转Profinet网关可提供单个或多个RS485接口,使得不同设备之间可以顺利进行通信。当我们需要连接打印设备与PLC进行通讯时,Modbus转Profinet网关可以将打印设备与PLC之间建立起稳定......