Project

General

Profile

High CPU usage with Nvidia gpu

Added by Jack Jordan over 3 years ago

Dear,

I have tvheadend version 4.2.8-36 installed on ubuntu 18.04 32 bit, my desktop in relatively old with CPU intel(R) Core(TM)2 CPU .

I recently installed Nvidia GK107GL (Quadro K420), the output of nvidia-smi shows that tvheadend is indeed started using nvidia card for teanscoding with 34MiB GPU Memory usage,also i setup new transcoding profile to use video codec h264_nvenc and ho codec preset, HOWEVER CPU usage is still so high 130%+ while checking top -i command.

Kindly help me to overcome this issue, i am new to this domain so please be kind to direct me with details if you need me to extract further details or logs, thanks in advance


Replies (21)

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

hi Jack,

I am by no means an expert but here is my experience. After Flole published on github the modifications to allow for nvidia transcoding (although I think it is only for decoding, so please correct me if I am wrong) I am using that build. Now transcoding works well, the CPU usage is still high-ish...but not as high as you describe. Steps I did:

1. make sure you have the full drivers installed and especially libnpp (sudo apt install -y libnpp*)
2. i am using a build script for tvheadend with ffmpeg internal as per the directions in the manual build described by saen acro

here is the script for your convenience. Also always remove the tvheadend folder created by the github clone before running the command.

#!/bin/bash

BASE=$(dirname "$0")
(
  if [ -d "$BASE/tvheadend" ]; then
    cd "$BASE/tvheadend" 
    git pull
  else
    cd "$BASE" 
    git clone https://github.com/tvheadend/tvheadend.git tvheadend # --depth=5 (need version tag workaround else 0.0.0 version)
    cd "$BASE/tvheadend" 
  fi
  time AUTOBUILD_CONFIGURE_EXTRA="--disable-bintray_cache --enable-vaapi --enable-nvenc" ./Autobuild.sh -j$(nproc) # edit only betwin "quotation marks" 
) | tee "$BASE/build.log" 

Also make sure to:
1. check this post for any additional packages you might miss: https://tvheadend.org/boards/4/topics/24116
2. apply the nvidia-patch to not be restricted at 2 streams
3. if you use Kodi, in thePVR settings enable http, otherwise you will get a stuck stream in nvidia.

the transcoding streaming profile is set like this:

the codec profile would be like this:

I won't be able to give you more details than this, as mileage varies between systems, but i hope it helps.

RE: High CPU usage with Nvidia gpu - Added by Flole Systems over 3 years ago

Encoding was working before, decoding was added recently-ish.

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

Flole Systems Systems is it still software decoding? or were you also able to enable hardware decoding? Cause for me it still complains about filters.

RE: High CPU usage with Nvidia gpu - Added by Flole Systems over 3 years ago

If you enable the Hardware acceleration option you'll get hardware decoding (that's what it's for).

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

Flole Systems wrote:

If you enable the Hardware acceleration option you'll get hardware decoding (that's what it's for).

well that was dumb of me :). It does work now, but interestingly the CPU usage goes up as opposed to when it's off. in all cases it works and i have enough resources to handle that.

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

Thank you dorin ilut and Flole Systems , obviously you add lot of useful information, i have to compose myself and go through the lines several time

A) libnpp was no installed so i followed provided command sudo apt install -y libnpp

B) you want me to apply nvidia-patch in order not to restrict at 2 streams( can you please guide me how to do so?)

B) i understood that you are using different tvheadend version (with ffmpeg built in) as i can see that you are able to create codec profile (in my version 4.2.8-36 i do not have this option)

I will follow provided guild as described by saen acro to install fresh tvheadend version and update you with the income, thank you very much for your help

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

here is the link to the nvidia patch: https://github.com/keylase/nvidia-patch. it also has instructions.

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

Dear dorin ilut,

Please explain more about your statement (Also always remove the tvheadend folder created by the github clone before running the command.) i am planning to run provided script to install latest unstable version of TVheadend, at what stage i have always to remove tvheadend folder, also if you can please guide me how to install nvidia patch,thanks a lot

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

if you build tvheadend from git, you will get a folder called tvheadend, which contains the installation files. i usually like to remove that folder prior to running the script, which always clones the latest version. this has nothing to do with the tvheadend folder where it is actually installed. I know most will say it's an unecessary step as if you do a git pull after it should update the source files...it's just something i like to do.

for the nvidia patch git clone the repo: git clone https://github.com/keylase/nvidia-patch.git

once fully downloaded enter the folder, sudo su and run the two patch files patch.sh and path-fbc.sh

that would be it.

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

Thanks a lot for all your help, i installed new clean linux version 18.04 AMD64 instead of what originally i had I386, will follow your steps and let you know, thanks for all your help

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

I spent almost the whole day trying to install Nvidia Quadro K420 driver for Linux 18.04 AMD64, the driver from Nvidia webiste is keep giving errors and whenever i try sudo apt install nvidia-340, i start getting below error while running vainfo command, not sure if the driver is correctly installed on my machine

sa@ubuntuiptv:~$ vainfo
libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

any help please

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

Finally and after several attempts i managed to reach somewhere

- Installed Ubuntu20.04 LTS
- Accepted generic Nvidia driver come with Ubuntu 20.04 for my Nvidia Quadro K420
- Installed Nvidia Cuda
- Installed Nvidia patch
- Installed all packages in https://tvheadend.org/boards/4/topics/24116
- Run provided installation script

HTS Tvheadend 4.3-1967~geb59284b8 get installed with Codec profile options, i ignored the below error from vainfo command

sa@ubuntuiptv:~$ vainfo
libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

created new h264_nvenc NVIDA NVENCH H.264 encoder codec profile and new streaming profile to use the new codec (screenshot attached for your reference), i can see the transcode is using my NVIDIA card BUT CPU USAGE IS STILL HIGH :-)

Please check screenshots attached, i am seeking expert advise to tell me if this is the maximum i can get based on my setup or i am still doing something wrong, appreciate your comments,and thanks to all

Codec_Profile.png (77.2 KB) Codec_Profile.png Codec Profile
Stream_Profile.png (110 KB) Stream_Profile.png Streaming Profile
nvidia-smi.png (67.1 KB) nvidia-smi.png Nvidia-smi
top-i.png (131 KB) top-i.png top -i High CPU usage

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

try disabling hardware encoding. for me that brings the CPU down. does your machine also have integrated intel graphics? If you use vaapi then the CPU usage goes down even further, but it relies on the intel graphics card.

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

Thank you dorin ilut for your reply, please guide me how to disable hardware encoding - do you mean hardware accelerator option in codec profile? if yes then i tried it but the CPU usage is still high in my case, also please share with me the instructions/setup how to use VAAPI, yes i have integrated intel graphics

I really appreciate your help, thanks a lot

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

for disabling hardware encoding - yes I meant untick the hardware accelerated in the codec profile.

i had to google to remember what were the steps so i found it on another forum. also you can search here as there are sometimes quirks. also make sure that vaapi is actually enabled. i do remeber that there was an issue with hts user having access to the dri folder. so see how to give access to that if something fails.

1.) Create a new profile under Configuration -> Stream -> Codec Profiles. Select "h264_vaapi" as the codec. Confirm and give it a name of your choice (e.g. vaapi-codec).
2.) Activate Hardware Acceleration on the right side and "Profile Settings".
3,) Select Device Name. I only recognized one "i915 v. 1.6.0 (/dev/dri/renderD128)"
4.) Specify the bit rate in kilobits. 3000 to 4000 already gives good results and should be streamable for most lines.
edit: 4.1) IMPORTANT: Deactivate deinterlacing! Otherwise it doesn't work for me at least.
5.) Apply with "Apply".
6.) Under "Stream Profiles" create a new profile with the type "transcode / av-lib"
7.) Assign a profile name (eg "webtv-vaapi")
8.) Under Transcoding set the video codec profile to "vaapi-codec" put
9.) Also there the audio codec profile on pass
10). Click on Apply.

For em it looks like this

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

for me the device (/dev/dri/renderD128) is not showing in the dropdown menu of codec profile although i have integrated Intel graphic

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

I think it has a relation to the error which i am getting while running vainfo

sa@ubuntuiptv:~$ vainfo
libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

i spent the whole day yesterday trying to resolve it with no success

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

this is already beyond me. what does this command return?

lspci | grep -i --color 'vga\|3d\|2d'

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

the command returns below output

01:00.0 VGA compatible controller:NVIDIA Corporation GK107GL (Quadro K420) (rev a1)

Thank you

RE: High CPU usage with Nvidia gpu - Added by Jack Jordan over 3 years ago

Hi,

Just to let you know that i changed my antenna and guess what! CPU utilization drop down to the minimum of 20 to 60% , so it seems good TV signal plays huge role in transcoding (attached for your reference)

CPU.png (22.3 KB) CPU.png

RE: High CPU usage with Nvidia gpu - Added by dorin ilut over 3 years ago

that is an interesting find indeed.

    (1-21/21)