跳到主要内容

安装 S3000 5.1.0

安装驱动依赖包​


安装 dkms 依赖包​

yum install dkms

安装驱动​


安装驱动​

根据系统架构获取相应驱动包,并安装,以 amd 版本为例:

rpm -ivh musa_5.1.0-server_amd64.rpm

驱动安装后,可以重启操作系统使驱动加载,也可以不重启系统使驱动加载。

重启系统加载驱动​

shutdown -r now

不重启系统加载驱动​

不重启系统,则需要将当前的相关业务停止,并停止 Xorg,在驱动安装后,重新加载 kmd。

停止正在运行相关的业务,停止 Xorg

killall Xorg
service lightdm stop

卸载已经加载的 kmd 模块

rmmod mtgpu

查看是否成功卸载 mtgpu

lsmod |grep mtgpu

重新加载 kmd

modprobe mtgpu

查看是否成功加载 mtgpu

lsmod |grep mtgpu

更换驱动​


更换驱动,也支持不重启操作系统使驱动加载。更换驱动前需要停止相关业务,卸载原有驱动,安装新驱动,重新加载驱动。具体操作如下:

停止正在运行相关的业务,停止 Xorg

pkill Xorg
service lightdm stop

卸载已经安装的驱动

rpm -e $(rpm -qa |grep musa)

安装新版本的驱动,以 amd 版本为例。

rpm -ivh musa_5.1.0-server_amd64.rpm

卸载已经加载的 kmd 模块

rmmod mtgpu

查看是否成功卸载 mtgpu

lsmod |grep mtgpu

重新加载 kmd

modprobe mtgpu

查看是否成功加载 mtgpu

lsmod |grep mtgpu

配置 Xorg​

--- 配置 Xorg 需要修改配置文件,然后重启 Xorg 生效。

配置 xorg.conf​

服务器环境一般存在集显,当安装 MT 显卡用作图形渲染时,则需要配置多显卡的 Xorg。通过这样的配置,支持集显用作 BMC 远程桌面显示,同时 MT 显卡可以用作图形渲染。

Xorg 的配置路径为 /etc/X11/xorg.conf,配置主要包括集显的配置,MT 显卡配置和公共部分配置。集显和 MT 显卡的配置主要由 Device,Monitor,Screen 组成,公共部分配置由 OutputClass,ServerLayout,ServerFlags 组成。

集显配置​

如果集显用作 BMC 远程桌面显示,则集显做为主显,Identifier 的编号都为 0,DISPLAY 为:0.0。

Device 配置项说明:

  • Identifier 指定 Device 的编号,如果集显做为主显,编号为 Video Device0。

  • Driver 指定集显的驱动,设置为 “modesetting”。

  • BusID:指定集显的 pcie busid。使用 lspci 获取集显的 pcie 地址,lspci 输出的地址为 16 进制,BusID 需要配置成 10 进制,需要将 16 进制转为 10 进制;另外 lspci 获取的地址分隔符为“.”,BusID 的分隔符为“:”。例如使用 lspci 获取 pcie 的地址为:“05:00.0” ,配置项则为"PCI:5:00:0"

使用 lspci 获取显卡的 PCIE 地址

# lspci | grep -E 'VGA|3D|Display'
02:00.0 VGA compatible controller: Matrox Electronics Systems Ltd. MGA G200e [Pilot] ServerEngines (SEP1) (rev 42)
19:00.0 3D controller: Moore Threads Technology Co.,Ltd MTT S3000
1a:00.0 3D controller: Moore Threads Technology Co.,Ltd MTT S3000
1b:00.0 3D controller: Moore Threads Technology Co.,Ltd MTT S3000
1c:00.0 3D controller: Moore Threads Technology Co.,Ltd MTT S3000
b3:00.0 3D controller: Moore Threads Technology Co.,Ltd MTT S3000
b4:00.0 3D controller: Moore Threads Technology Co.,Ltd MTT S3000
b5:00.0 3D controller: Moore Threads Technology Co.,Ltd MTT S3000
b6:00.0 3D controller: Moore Threads Technology Co.,Ltd MTT S3000

将 16 进制转为 10 进制,以“1a”为例:

# echo $((16#1a))
26

Monitor 配置项说明:

  • Identifier:指定 Monitor 的编号,如果集显做为主显,编号为 Monitor0

Screen 配置项说明:

  • Identifier:指定 Screen 的编号,如果集显做为主显,编号为 Screen0。

  • Monitor:配置 Monitor 部分 Identifier 的值,为 Monitor0。

  • Device:配置 Device 部分 Identifier 的值,为 Video Device0。

集显为主显的配置示例:

Section "Device"
Identifier "Video Device0"
Driver "modesetting"
BusID "PCI:5:00:0"
EndSection

Section "Monitor"
Identifier "Monitor0"
EndSection

Section "Screen"
Identifier "Screen0"
Monitor "Monitor0"
Device "Video Device0"
EndSection

MT 显卡配置​

MT 的每张显卡也是由 Device,Monitor,Screen 三个 section 组成,有几张卡则有几组 Device,Monitor,Screen。在集显做主显的场景下,MT 显卡的 Device,Monitor,Screen 的 Identifier 编号从 1 开始,有几张卡依此类推。第一张 MT 显卡为 DISPLAY 的:0.1,第二张为 :0.2。

Device 配置项说明:

  • Identifier 指定 Device 的编号,例如:Video Device1。

  • Driver 指定 MT 显卡的驱动,设置为“mtgpu”

  • BusID:指定 MT 显卡的 pcie busid,获取 MT 显卡的 pcie 地址。lspci 输出的地址为 16 进制,BusID 需要配置成 10 进制,需要将 16 进制转为 10 进制;另外 lspci 获取的地址分隔符为“.”,BusID 的分隔符为“:”。例如使用 lspci 获取 pcie 的地址为:01:00.0 ,配置项则为"PCI:1:00:0",具体命令可以参考上节。

Monitor 配置项说明:

  • Identifier:指定 Monitor 的编号,例如:Monitor1

  • Modeline:指定显示器的显示模式。例如:1024x768_60.00 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync

  • Option:指定偏好的显示模式,设置为:"PreferredMode" 1024x768_60.00

注:为了更好的支持集显做为 BMC 远程显示,将 MT 显卡和集显的分辨率和刷新率设置为相同。本指导书推荐将 ServerLayout 部分的 sceen 是叠加在一起的,如果分辨率不同,会导致分辨率小的屏幕鼠标点击发生偏移。

Screen 配置项说明:

  • Identifier:指定 Screen 的编号,如果集显做为主显,编号为 Screen1

  • Monitor:配置 Monitor 部分 Identifier 的值,为 Monitor1

  • Device:配置 Device 部分 Identifier 的值,为 Video Device1

示例:

Section "Device"
Identifier "Video Device1"
Driver "mtgpu"
BusID "PCI:1:00:0"
EndSection

Section "Monitor"
Identifier "Monitor1"
Modeline "1024x768_60.00" 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync
Option "PreferredMode" "1024x768_60.00"
EndSection

Section "Screen"
Identifier "Screen1"
Monitor "Monitor1"
Device "Video Device1"
EndSection

公共部分配置​

公共部分配置由 OutputClass,ServerLayout,ServerFlags 组成。其中 OutputClass 和 ServerFlags 的配置无需单独修改;ServerLayout 将根据配置显卡的数量,包含集显和 MT 显卡,将屏幕叠加摆放。

OutputClass 配置

Section "OutputClass"
Identifier "mtgpu display"
MatchDriver "mtgpu"
EndSection

ServerLayout 配置

将所有显卡,包括集显和 mtgpu,屏幕叠加摆放。示例中中是将三张卡,一张集显,两张 MT 显卡叠加摆放。

Section "ServerLayout"
Identifier "Server Layout"
Screen 0 "Screen0" 0 0
Screen 1 "Screen1" 0 0
Screen 2 "Screen2" 0 0
EndSection
ServerFlags 配置
Section "ServerFlags"
Option "DefaultServerLayout" "Server Layout"
Option "PrimaryBusDriver" "mtgpu"
Option "AutoAddGPU" "off"
EndSection

完整 Xorg 配置示例请参考附录。

重启 Xorg 进程​

停止 Xorg 进程​

如果 Xorg 进程启动,则关闭 Xorg 进程

pkill Xorg

如果 Xorg 进程是由 lightdm 服务启动的,则关闭 lightdm 进程。

service lightdm stop

启动 Xorg 进程​

如果仅需要 Xorg,则直接启动 Xorg 进程。

Xorg &

如果需要启动窗口管理系统,则使用如下命令

service lightdm start

显示配置​


S3000 显卡有 DP 显示接口,可以连接显示器。S3000 可以做为主显,也可以做为副显,两种方式的 Xorg 配置不同。

系统配置检查​

S3000 用作显示,需要操作系统配置内核参数 CONFIG_GENERIC_PHY 为 ”y“,如果系统未配置,则需要升级内核版本。

# cat /usr/src/kernels/`uname -r`/.config|grep CONFIG_GENERIC_PHY
CONFIG_GENERIC_PHY=y

驱动配置检查​

S3000 用作显示,需要 MT 显卡驱动加载的 display 参数为 ”mt“,否则无法点亮显示器。以下命令可以检查当前加载驱动的 display 参数:

# cat /sys/module/mtgpu/parameters/display
mt

设置 display 参数可以修改 /etc/modprobe.d/mtgpu.conf 配置文件:

# cat /etc/modprobe.d/mtgpu.conf
options mtgpu display=mt

修改配置后,重启系统生效。

MT 显卡作为主显​

如果 MT 显卡作为主显,需要修改 /etc/X11/xorg.conf 配置,将其中一张 MT 显卡配置为主显,集显配置配置为副显。具体配置可参考附录 MT 显卡作为主显的内容。

修改 Xorg 配置之后需要停止 Xorg 进程,具体请参考重启 Xorg 进程部分内容。

启动 lightdm,则显示器可点亮。

service lightdm start

注:如果 MT 显卡配置为主显,则 BMC 远程桌面显示为黑屏。

MT 显卡作为副显​

安装依赖 gnome-shell​

yum install gnome-shell

配置 Xorg​

如果 MT 显卡作为副显,集显做为主显,配置 /etc/X11/xorg.conf,具体配置可参考附录集显作为主显部分的内容。

修改 Xorg 配置之后需要停止 Xorg 进程,具体请参考重启 Xorg 进程部分内容。

启动 lightdm,则显示器可点亮。

service lightdm start

获取桌面权限​

通过 BMC 远程登录桌面,运行以下命令获取桌面权限,其中 -u 的参数为 BMC 登录桌面使用的用户,例如使用 root 登录桌面,则 -u 的参数为 root。

sudo -u root DISPLAY=:0.0 xhost +

启动桌面​

/etc/X11/xorg.conf 指定和显卡和 Screen 一一对应的关系,如果 MT 显卡对应 Screen1,则对应 display:0.1,如果 MT 显卡对应 Screen2,则对应 display:0.2,依此类推。

以下命令可以在 display :0.1,display :0.2 上启动桌面

export XAUTHORITY=/var/run/lightdm/root/:0
DISPLAY=:0.1 gnome-shell --replace
DISPLAY=:0.2 gnome-shell --replace

注:这种方式启动桌面具备键鼠和窗口功能。 #

DirectStream 配置​


启动 DirectStream 抓屏编码功能需要在 Xorg 的配置中打开对应的选项,并设置环境变量。

修改 Xorg 配置​

修改 /etc/X11/xorg.conf,将每张 mtgpu 的 Device 部分增加 ``Option, MTFBCAP, true`,例如:

Section "Device"
Identifier "Video Device1"
Driver "mtgpu"
BusID "PCI:25:00:0"
Option "MTFBCAP" "true"
EndSection

重启 Xorg 使配置文件生效,参考重启 Xorg 进程部分。

修改分辨率​

如果服务器连接了显示器,则直接修改分辨率。如果服务器未连接显示器,需要修改 kmd 的加载方式为 dummy。 检查 driver 的加载模式是否为 mt

cat /sys/module/mtgpu/parameters/display
mt

修改 kmd 的加载模式,然后重启系统。

sudo sed -i 's/=mt/=dummy/' /etc/modprobe.d/mtgpu.conf

查看修改是否成功

cat /etc/modprobe.d/mtgpu.conf
options mtgpu display=dummy

查看指定 Screen 的分辨率

export DISPLAY=:0.1
xrandr

设置指定 Screen 分辨率,“-s” 指定分辨率,“-r” 指定刷新率,以 4K 为例:

export DISPLAY=:0.1
xrandr -s 3840x2160 -r 60

用户权限设置​

如果使用非 root 用户抓屏编码,需要增加 video 组和 render 组的权限

sudo usermod -a -G video user
sudo usermod -a -G render user

mt capture 1.0 启动抓屏编码​

设置环境变量 arm 版本的环境变量

export LIBVA_DRIVER_NAME=mtgpu
export LIBVA_DRIVERS_PATH=/usr/lib/aarch64-linux-gnu/dri/

x86_64 版本的环境变量

export LIBVA_DRIVER_NAME=mtgpu
export LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri/

启动对应 Screen 的抓屏的 app,以 glxgears 为例:

export DISPLAY=:0.1
glxgears -fullscreen

启动抓屏编码

MtCaptureToEncodeDemo -n 9000 -f 60 -s 1 -c 0 -o test

查看抓屏编码 demo 的用法,更多抓屏编码用法请参考 DirectStream API 文档。

MtCaptureToEncodeDemo -h
MtCaptureToEncodeDemo: option requires an argument -- 'h'
Usage: MtCaptureToEncodeDemo [options]

Options:
-n <n> Number of frames to capture (default: 1000)
-f <n> Target fps (default: 60)
-o <str> Name of the output file
-x <n> Grab frame start x (default: 0)
-y <n> Grab frame start y (default: 0)
-w <n> Grab frame width (default: screen width)
-h <n> Grab frame height (default: screen height)
-p <n> Src pixel format (0-BGRA; 1-NV12)
-W <n> Dst frame width (default equal w)
-H <n> Dst frame height (default equal h)
-s <n> Select capture screen (default primary)
-c <n> Encode Type (0-h264; 1-h265; default h264)
-b <n> Average bit rate (kbps, default 8000 kbps)
-E <n> Export bitstream to file (0-NO; 1-Yes, default Yes)
-i <n> Show information about DS (0-NO; 1-Yes, default NO)
-m <n> Enable hardware mouse (0-NO; 1-Yes, default No)
-d <n> Use damage mode to capture screen (0-NO; 1-Yes, default NO)

mt capture 2.0 启动抓屏编码​

获取并解压 mt capture 2.0 demo

tar -xvf 48267bb3e_directstream.tar.gz
cd directstream/x86_64/bin

启动对应 Screen 的抓屏的 app,以 glxgears 为例:

export DISPLAY=:0.0
glxgears -fullscreen

启动抓屏编码

./AppDesktopEnc -n 600 -f 60 -c 0 -o test

查看抓屏编码 demo 的用法,更多抓屏编码用法请参考 DirectStream API 文档。

./AppDesktopEnc -h
Usage: ./AppDesktopEnc [options]

Options:
-n <n> Number of frames to capture (default: 1000)
-f <n> Target fps (default: 60)
-o <str> Name of the output file
-s <n> Select capture screen (default primary)
-c <n> Encode Type (0-h264; 1-h265; default h264)
-E <n> Export bitstream to file (0-NO; 1-Yes, default Yes)
-r <n> Enable rtsp server, rtsp address rtsp://ip:port/live (0-NO; 1-Yes, default NO)
-p <n> Set tcp port(default 8554)
-t <n> Set timeout when capture one frame in ms (default:16 ms)

ffmpeg 编解码​

安装 ffmpeg 编解码需要依赖

yum install SDL2-devel numactl

安装 video 包,根据系统架构获取相应 video 包,并安装,以 rpm 版本为例:

rpm -ivh release-5.1.0_mtcodec_amd64.rpm

设置环境变量

export LIBVA_DRIVER_NAME=mtgpu
export LIBVA_DRIVERS_PATH="/usr/lib/$(uname -m)-linux-gnu/dri${LIBVA_DRIVERS_PATH:+:$LIBVA_DRIVERS_PATH}"
export PATH="/usr/local/mt_vaapi/bin${PATH:+:$PATH}"
export LD_LIBRARY_PATH="/usr/local/mt_vaapi/lib:/usr/local/mt_vaapi/lib/$(uname -m)-linux-gnu${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

启动 ffmpeg 编解码 编码命令范例:

ffmpeg -stream_loop -1 -threads 3 -filter_threads 30 -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -f rawvideo -pix_fmt nv12 -s:v 1920x1080 -r:v 30 -i 1920x1080_nv12.yuv -vf 'format=nv12,hwupload' -c:v h264_vaapi -profile:v main -rc_mode CBR -g 128 -slices 1 -bf 3 -b:v 4000k -maxrate 8000k -low_power 0 -b_depth 1 -vframes 1000 -y sample.h264

解码命令范例:

ffmpeg -stream_loop -1 -threads 3 -hwaccel vaapi -init_hw_device vaapi=hw:/dev/dri/renderD128 -hwaccel_flags allow_profile_mismatch -filter_hw_device hw -i h264-1080p30fps.mkv -pix_fmt yuv420p -f rawvideo -vsync passthrough -autoscale 0 -vframes 1000 -y single.yuv

转码命令范例:

ffmpeg -stream_loop -1 -threads 3 -filter_threads 15 -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i 1920x1080-30fps.mkv -autoscale 0 -c:v hevc_vaapi -an -vframes 1000 -b:v 32M -f rawvideo -y sample.h265

参数举例说明

-vaapi_device :指定运行的 GPU,默认第一张显卡为/dev/dri/renderD128,第二张显卡为/dev/dri/renderD129,以此类推
-s:v :指定编码输出文件的分辨率
-i :指定输入的文件路径
-c:v :指定编码器,h264 编码器为 h264_vaapi,h265 编码器为 hevc_vaapi,av1 编码器为 av1_vaapi
-r :指定编码输出文件的帧率
-vframes :指定编解码输出的文件总帧数
-y :将输出文件覆盖写入到指定路径

附录​


集显作为主显​

xorg.conf 配置参考,以下示例中包含一张集显和两张 MT 显卡,三个 Screen 叠加摆放。

# X.Org X server configuration file.

Section "Device"
Identifier "Video Device0"
Driver "modesetting"
BusID "PCI:5:00:0"
EndSection

Section "Monitor"
Identifier "Monitor0"
EndSection

Section "Screen"
Identifier "Screen0"
Monitor "Monitor0"
Device "Video Device0"
EndSection

Section "Device"
Identifier "Video Device1"
Driver "mtgpu"
BusID "PCI:1:00:0"
EndSection

Section "Monitor"
Identifier "Monitor1"
Modeline "1024x768_60.00" 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync
Option "PreferredMode" "1024x768_60.00"
EndSection

Section "Screen"
Identifier "Screen1"
Monitor "Monitor1"
Device "Video Device1"
EndSection

Section "Device"
Identifier "Video Device2"
Driver "mtgpu"
BusID "PCI:129:00:0"
EndSection

Section "Monitor"
Identifier "Monitor2"
Modeline "1024x768_60.00" 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync
Option "PreferredMode" "1024x768_60.00"
EndSection

Section "Screen"
Identifier "Screen2"
Monitor "Monitor2"
Device "Video Device2"
EndSection

Section "OutputClass"
Identifier "mtgpu display"
MatchDriver "mtgpu"
EndSection

Section "ServerLayout"
Identifier "Server Layout"
Screen 0 "Screen0" 0 0
Screen 1 "Screen1" 0 0
Screen 2 "Screen2" 0 0
EndSection

Section "ServerFlags"
Option "DefaultServerLayout" "Server Layout"
Option "PrimaryBusDriver" "mtgpu"
Option "AutoAddGPU" "off"
EndSection

MT 显卡作为主显​

xorg.conf 配置参考,以下示例中包含一张集显和两张 MT 显卡,三个 Screen 叠加摆放。

# X.Org X server configuration file.

Section "Device"
Identifier "Video Device0"
Driver "mtgpu"
BusID "PCI:1:00:0"
EndSection

Section "Monitor"
Identifier "Monitor0"
Modeline "1024x768_60.00" 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync
Option "PreferredMode" "1024x768_60.00" EndSection

Section "Screen"
Identifier "Screen0"
Monitor "Monitor0"
Device "Video Device0"
EndSection

Section "Device"
Identifier "Video Device1"
Driver "modesetting"
BusID "PCI:5:00:0"
EndSection

Section "Monitor"
Identifier "Monitor1"
EndSection

Section "Screen"
Identifier "Screen1"
Monitor "Monitor1"
Device "Video Device1"
EndSection

Section "Device"
Identifier "Video Device2"
Driver "mtgpu"
BusID "PCI:129:00:0"
EndSection

Section "Monitor"
Identifier "Monitor2"
Modeline "1024x768_60.00" 63.50 1024 1072 1176 1328 768 771 775 798 -hsync +vsync
Option "PreferredMode" "1024x768_60.00"
EndSection

Section "Screen"
Identifier "Screen2"
Monitor "Monitor2"
Device "Video Device2"
EndSection

Section "OutputClass"
Identifier "mtgpu display"
MatchDriver "mtgpu"
EndSection

Section "ServerLayout"
Identifier "Server Layout"
Screen 0 "Screen0" 0 0
Screen 1 "Screen1" 0 0
Screen 2 "Screen2" 0 0
EndSection

Section "ServerFlags"
Option "DefaultServerLayout" "Server Layout"
Option "PrimaryBusDriver" "mtgpu"
Option "AutoAddGPU" "off"
EndSection

常见问题​

安装失败 - 依赖问题​

问题: dpkg/rpm 安装报错依赖缺失

解决:

# DEB 系统
sudo apt --fix-broken install
sudo dpkg -i musa_5.1.0-server_amd64.deb

# RPM 系统
sudo dnf install -y <缺失的依赖包>
sudo rpm -ivh musa_5.1.0-server_amd64.rpm

模块加载失败​

问题: lsmod 看不到 mtgpu 模块

解决:

  1. 检查内核版本兼容性

  2. 查看内核日志:dmesg | grep mtgpu

  3. 尝试手动加载:sudo modprobe -v mtgpu

  4. 检查 dkms 是否成功编译:dkms status

显卡未识别​

问题: lspci 看不到显卡

解决:

  1. 检查显卡是否正确插入 PCIe 插槽

  2. 检查电源连接是否牢固

  3. 尝试重新插拔显卡

  4. 检查 BIOS 中 PCIe 设置

用户权限不足​

问题: 非 root 用户无法访问 GPU 设备

解决:

# 确保用户已加入正确的组
sudo usermod -aG render ${USER}
sudo usermod -aG video ${USER}

# 重新登录使更改生效