Plex in FreeNAS jail and vaapi Intel hardware acceleration support

FWIW, I got to the point where I could get /dev/dri/renderD128 to be addressable in a jail under 11.2. Everything just works with vainfo and ffmpeg (that I built to support VAAPI). The only way that works for me though is to use the Intel Media Driver, and include the following in .login (and perhaps its equivalent in .profile):

setenv LIBVA_DRIVER_NAME iHD

However, that won’t work with Plex because it is insisting on using its own version of i965 driver included with the installation (found in the /dri directory where the Plex executable lives) and LIBVA_DRIVER_NAME is ignored. Plex is likewise hardcoded to use renderD128, so no way to use card0 if your server is headless (like mine).

All that said, I built my own copy of libva that allows it to properly resolve iHD as the driver*, copied the libraries and iHD driver to their plex locations and tried it.

Well, Plex does what I want, it finds and uses renderD128, the driver loads and it kinda looks like its doing the right thing judging by the logs. But it always crashes Plex in the end.

So, I’m giving up and will look at this again once FreeNAS is on 12.

*per this bug: https://github.com/intel/libva/pull/245 and too, by making libva use whatever driver is specified in /etc/libva.conf since whatever context Plex is running in does not seem to get LIBVA_DRIVER_NAME in its environment.

3 Likes

The above solution of adding the LIBVA_DRIVER_NAME environment variable seems to solve the issue for ffmpeg at least…

@mikec_pt just getting your attention on the above post. Looks like it’s hopefully very close to working.

Hi,

First for all, sorry for my bad English and also FreeBSD knowledge.

After serverals testing using 2 machines with FreeBSD 11.2 and 12.0, I can say HW Acceleration is working on host and jail, at least based on my testing.

  1. Machine 1: NUC6CAHY. FreeBSD 11.2 and 12 install from scratch working fine on host and jail using latest drm-kmod. drm-fbsd11.2-kmod for 11.2 and drm-fbsd12.0-kmod for 12.0
    Also instlled latest intel libva @Cephas guidance.

  2. Machine 2: My NAS. Intel 3210, 16GB, 6x2TB Raidz2.

  • XigmaNAS 12.0.0.4.6412. Using 1 boot drive and 1 boot for storage working fine on host and jail. But it always problem when I put a lot off HDD and indicated same problem with @zperetz.
    After trial and error, got interesting finding when I checked sysctl parameters related to dri.
xigmanas: /tmp# sysctl -a |grep hw.dri
hw.dri.timestamp_precision: 20
hw.dri.vblank_offdelay: 5000
hw.dri.debug: 1
hw.dri.0.modesetting: 1
hw.dri.0.busid: pci:0000:00:02.0
hw.dri.0.vblank:
hw.dri.0.bufs:
hw.dri.0.clients:
hw.dri.0.vm:
hw.dri.0.name: i915 0x182

I don’t know how I called above 0x182 address, port address or something? maybe anyone here can explainded about this name.
If that port address above 0x180, VAAPI not working. I have to make it 0x17f or below for VAAPI working. I think this is assigned port address automatically from OS for devices on startup. When we load i915kms ( earlier or later ) will be affected to this port address.
When using minimal setup only using 2 HDDs and few numbers of partitions, that address will be got low number. But when I put a lot off HDDs and of course also lot of Partition, will got higher than 0x180

I tried to load i915kms earlier on loader.conf. All modules loaded but it’s not working. but when i915kms load on rc.conf or preinit command script, it was too late and got address above 0x180
i915kms loading also need drm.ko, debugfs.ko and linuxkpi_gplv2.ko. The trick is load drm.ko on loader.conf and load i915kms on rc.conf or preinit command script. Address will reserved when drm.ko loaded before i915kms loaded on rc.conf
This trick works for me. I got low address and VAAPI working fine for vainfo excecution and also plex HW transcoding.

xigmanas: /tmp# sysctl -a |grep hw.dri
hw.dri.timestamp_precision: 20
hw.dri.vblank_offdelay: 5000
hw.dri.debug: 0
hw.dri.0.modesetting: 1
hw.dri.0.busid: pci:0000:00:02.0
hw.dri.0.vblank:
hw.dri.0.bufs:
hw.dri.0.clients:
hw.dri.0.vm:
hw.dri.0.name: i915 0x71

PS. Xigmanas 12 will blacklisted module for drm and i915kms. So, I have to manually unset parameter when every boot.

  • Freenas 11.2. Using 6x2TB Raidz2 and 2 additional HDDs it still fine using above trick. But, in Freenas still got high number even below 0x180
root@dodol02:/ # sysctl -a |grep hw.dri
hw.dri.timestamp_precision: 20
hw.dri.vblank_offdelay: 5000
hw.dri.debug: 0
hw.dri.0.modesetting: 1
hw.dri.0.busid: pci:0000:00:02.0
hw.dri.0.vblank:
hw.dri.0.bufs:
hw.dri.0.clients:
hw.dri.0.vm:
hw.dri.0.name: i915 0x172

vainfo test working, ffmpeg test working but plex not working. I got message GPU hang and resetted when debbug on drm. So, final workaound is override file kernel modules related to i915kms on /boot/modules using latest gpu-firmware-kmod.
all of i915*, drm.ko, debugfs.ko and linuxkpi_gplv2.ko.

Finally it working on plex, at least for me.

So, resume for me:

  • Follow @Cephas guidance for using latest package for 11.2 or 12.0 and also devfs guidance for jail
  • Make sure port address on sysctl parameters.

Thanks

1 Like

FYI this is because you need an updated version of the kernel module → pkg install drm-fbsd12.0-kmod Older version don’t have support for that

1 Like

As for the need for LIBVA_DRIVER_NAME iHD I must say when I tested this it was an ivybridge looking at the packges descriptions:

libva-intel-driver-2.3.0_3     VAAPI legacy driver for Intel GMA 4500 (Gen4) or newer
libva-intel-hybrid-driver-1.0.2_1 Hybrid VP8 encoder and VP9 decoder for Intel GPUs
libva-intel-media-driver-18.4.1 VAAPI driver for Intel HD 5000 (Gen8) or newer

looks like for newer we need libva-intel-media-driver and this requires extra setup… I might have access to hardware with a more recent intel cpu, if so I can possibly look into it but not promises on timing

Just remembered I actually have a intel nuc with freebsd installed to test the beta builds, I didn’t have a jail setup there but just did that with iocage devfsrules and all seems to work… I just installed libva-intel-media-driver as this seem to be the one I need for my card.

Made sure plex is in the video group and it seems to be working,:

Thanks for keeping us updated. The new kernel driver did the work. Running vainfo against the renderD128 node works fine AND I can now transcode the video inside the jail.

Glad its all working :slight_smile:

@big-danish Thanks for some tricks! Could you please be a bit more specific about overriding modules in FreeNAS 11.2?

Hi @zperetz,

Sorry for unclear explanations. For Freenas 11.2, my workaround beside load drm.ko on loader.conf:

  • Install latest drm-kmod or drm-fbsd11.2-kmod on plex jail. We will get a lot of kernel modules file on /boot/modules related to kms and gpu firmware.
root@plex:~ # pkg info | grep drm
drm-fbsd11.2-kmod-4.11g20181210 DRM modules for the linuxkpi-based KMS components
drm-kmod-g20181126             Metaport of DRM modules for the linuxkpi-based KMS components
libdrm-2.4.96,1                Userspace interface to kernel Direct Rendering Module services

Files list:

-r-xr-xr-x  1 root  wheel     8216 Feb  8 11:05 debugfs.ko
-r-xr-xr-x  1 root  wheel   867528 Feb  8 11:05 drm.ko
-r-xr-xr-x  1 root  wheel    12472 Feb  7 19:28 i915_bxt_dmc_ver1_07_bin.ko
-r-xr-xr-x  1 root  wheel   145000 Feb  7 19:28 i915_bxt_guc_ver8_7_bin.ko
-r-xr-xr-x  1 root  wheel   158552 Feb  7 19:28 i915_bxt_huc_ver01_07_bin.ko
-r-xr-xr-x  1 root  wheel    15312 Feb  7 19:28 i915_cnl_dmc_ver1_06_bin.ko
-r-xr-xr-x  1 root  wheel    12888 Feb  7 19:28 i915_glk_dmc_ver1_04_bin.ko
-r-xr-xr-x  1 root  wheel    12704 Feb  7 19:28 i915_kbl_dmc_ver1_01_bin.ko
-r-xr-xr-x  1 root  wheel    12928 Feb  7 19:28 i915_kbl_dmc_ver1_04_bin.ko
-r-xr-xr-x  1 root  wheel   146744 Feb  7 19:28 i915_kbl_guc_ver9_14_bin.ko
-r-xr-xr-x  1 root  wheel   222808 Feb  7 19:28 i915_kbl_huc_ver02_00_bin.ko
-r-xr-xr-x  1 root  wheel    13016 Feb  7 19:28 i915_skl_dmc_ver1_26_bin.ko
-r-xr-xr-x  1 root  wheel    13016 Feb  7 19:28 i915_skl_dmc_ver1_27_bin.ko
-r-xr-xr-x  1 root  wheel   133096 Feb  7 19:28 i915_skl_guc_ver6_1_bin.ko
-r-xr-xr-x  1 root  wheel   145112 Feb  7 19:28 i915_skl_huc_ver01_07_bin.ko
-r-xr-xr-x  1 root  wheel  2092384 Feb  8 11:05 i915kms.ko
-r-xr-xr-x  1 root  wheel   139256 Feb  8 11:05 linuxkpi_gplv2.ko
  • Copy above files to /boot/modules on Freenas host. It will overwrite some files. Maybe you can backup first the original freenas files. For older Intel GPU like mine, actually only need file debugfs.ko, drm.ko, i915kms.ko and linuxkpi-gplv2.ko. The rest files with prefix i915_ for new gpu firmware like broxton, skylake, kabylake and cannonlake.

  • on Freenas host, I also run command kldxref /boot/modules to update linker.hints file.

So, basically the point is replace all of kernel modules related with i915kms on Freenas host with new one.

Thanks

An update, worth noting down.
My Haswell-class Xeon CPU stopped HW-transcoding when I updated a) drm-fbsd12.0-kmod and b) gpu-firmware-kmod from g20181215 to g20190305.

According to the devs Haswell CPU should use i915kms.ko provided in BASE, while newer CPU:s, i.e. >=Broadwell should use ports-provided i915kms.ko.

The issue with the BASE-provided one is that it does not present renderD128, while the ports-provided does.

For now, I have rolled back to the working ports-revision of the kmod’s until I invest in a newer CPU. My CPU is anyway too old to support H.265. Hope this helps if someone still is struggling with getting HW-acceleration in FreeBSD.

I have the same issue but mine is:

hw.dri.0.name: i915 0x18b

And I can’t get it lower. I see no changes when add drm_load=“YES” in the /boot/loader.conf. I suspect that the drm module is actually being loaded with the i915kms module.

I think that guide is conservative. It says:

The new i915kms.ko driver available from ports (graphics/drm-next-kmod) since FreeBSD 11.2-RELEASE, supports Intel Core family processors up to Kaby Lake (7th) generation.

I hope the new driver would work for the old CPUs.
The new driver from the ports is mandatory for the 5th generation CPUs and newer.

Do you use Freenas?

I don’t think Freenas blacklisted DRM on loader at least until last version. I also using latest Freenas (11.2-U2.1) right now and I can load DRM on loader.conf

Last time I tested on Nas4Fre 12, kernel blacklisted DRM. I think also on Freebsd 12 latest

Maybe you can try setup with minimal HDD, normally it will get hw.dri addres lower.

Thanks

I don’t know what I’m doing wrong here. I’ve followed all the recomended things, If i test using ffmpeg, or vainfo, it’s ok… I can see the devices inside the jail, the right packages are installed, plex is in the video group…

But.

Apr 01, 2019 13:45:20.858 [0x80bd6da00] DEBUG - Codecs: testing h264_qsv (encoder)
Apr 01, 2019 13:45:20.858 [0x80bd6da00] WARN - Failed to find encoder 'h264_qsv'
Apr 01, 2019 13:45:20.858 [0x80bd6da00] DEBUG - Codecs: testing h264_vaapi (encoder)
Apr 01, 2019 13:45:20.858 [0x80bd6da00] DEBUG - Codecs: hardware transcoding: testing API vaapi
Apr 01, 2019 13:45:20.858 [0x80bd6da00] ERROR - [FFMPEG] - libva: va_getDriverName() failed with operation failed,driver_name=i965
Apr 01, 2019 13:45:20.858 [0x80bd6da00] ERROR - [FFMPEG] - Failed to initialise VAAPI connection: 1 (operation failed).

I’m totally lost

FYI I was testing this again on freebsd after confirming we do ship all that’s needed in plex (provided the kernel supports this).

So in a FreeBSD 12 based system all that should be needed is the new drm kmod nothing else, this packages installs drm and gpu firmware and we just need to make sure we are using the correct version by using kld_list="/boot/modules/i915kms.ko" in /etc/rc.conf and ofc the user that runs plex added to the video group.

That said we got a recent report of an issue with libva and the way freebsd drm implementation exposes the device that could be why it fails for some folks:

See: https://github.com/intel/libva/pull/292

I passed it along internally to see if we can workaroudn this our side too, however the proper fix would be freebsd side and its already reported here: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236933

Been screwing around with Freenas 11.2 U3
I have a E2146G xeon with a supermicro x11 sca board.

Loading the i915kms.ko module on the base OS creates /dev/drm nodes but doesn’t create /dev/dri nodes.

Have updated modules by getting the drm-fbsd11.2-kmod-4.11g20181210 modules as outlined in post from Feb18

Any ideas ?

1 Like

STbh I’ve never tried this with 11 (freebsd) only 12.
However… How are you loading the module?
Note that the full path is needed. Otherwise it might try to use the built-in i915kms.

yep replaced the modules in /boot/modules/ (after backing them up)

Not sure what you mean by that… you should just need to install the port/pkg and make sure to load then by adding kld_list="/boot/modules/i915kms.ko" to rc.conf.