termux / termux-x11

Termux X11 add-on application.
https://termux.dev
GNU General Public License v3.0
1.96k stars 301 forks source link

Bad video performance and screen tearing #334

Closed zanfix closed 1 year ago

zanfix commented 1 year ago

Hi @twaik

Here is my findings with the last version (I'm using build https://github.com/termux/termux-x11/actions/runs/5108462890)

I have bad video performance and noticeable screen tearing, that I did not have with previous versions.

So I had a look at the cpu usage for termux-x11 from android terminal with htop and I noticed that, on my device at least, the app_process process seems forced to run on the little cores (cpus from 0 to 3). In particular 1 thread, appears to be the one that uses cpu resources when the screen is refreshed.

So i tried to create a stune cgroup and place the app_process process into it and apply a schedtune.boost of 10 to see if video performance would increase.

The result is that the app_process in no longer bound to the small cores but will run on the big cores (cpus from 4 to 7). This improved performance a lot on my device!

But still, something changed from previous releases because I can still clearly see screen tearing! It's quite noticeable with a 24/30fps video on youtube, and nearly not noticeable with a 50/60fps video, so basically what I am seeing is that screen tearing will occur with anything below 60 fps!?

It's actually strange because if I have a look at the youtube "stat for nerds" i actually see very few dropped frames even at 60 fps (I am actually using an old version of firefox-esr to watch youtube videos since with recent versions of firefox or chromium video playback is actually bad... but this another story...)

Maybe issue #322 is related...

My device is a rooted samsung galaxy tab s6 (Snapdragon 855) with samsung firmware, android 10 with dex 2.5

EDIT: actually with chromium 113 from debian repos i do not have screen tearing with 30fps videos, so I may be an issue with the old firefox-esr version I am using (78.15.0esr). 60fps videos with chromium use too much resources but play fine with firefox-esr... oh well...

ask9027 commented 1 year ago

try latest now.

twaik commented 1 year ago

That happened before https://github.com/termux/termux-x11/commit/49274325547cdc8b5cc0cee9520b9792c006c328 so it is not fixed.

ask9027 commented 1 year ago

oh.. i have not noticed

zanfix commented 1 year ago

Update: I tried installing termux. From there I installed x11-repo termux-x11-nightly and firefox.

No tearing at all in firefox! videos play fine!

This also does not appear to be a problem: So I had a look at the cpu usage for termux-x11 from android terminal with htop and I noticed that, on my device at least, the app_process process seems forced to run on the little cores (cpus from 0 to 3). In particular 1 thread, appears to be the one that uses cpu resources when the screen is refreshed Runs just fine on the big cores...

videos i use for testing:

30 fps: https://www.youtube.com/watch?v=MfL_JkcEFbE 60 fps: https://www.youtube.com/watch?v=0RvIbVmCOxg

Well... will have to understand what is going on... Anyone has and idea what it could be?

zanfix commented 1 year ago

I fixed the issue with this workaround:

NOTE: the library will not compile out of the box, i had to tweak it a little for missing headers/definitions

zanfix commented 1 year ago

The workaround for the app_process process running on small cores still remains, this affects performance. The solution i adopted to place the process in an stune and cpuset cgroups may not be possible on some devices. Maybe taskset can also work, did not try.

NOTE: may not affect al devices...

twaik commented 1 year ago

Related to #14

Maybe taskset can also work, did not try.

Other users used this to enforce runnning termux-x11 on big cores. I can make termux-x11 force using big cores sched_setaffinity just like it is done by taskset.

zanfix commented 1 year ago

Related to #14

Maybe taskset can also work, did not try.

Other users used this to enforce runnning termux-x11 on big cores. I can make termux-x11 force using big cores sched_setaffinity just like it is done by taskset.

Fixed with build 396!