hrydgard / ppsspp

A PSP emulator for Android, Windows, Mac and Linux, written in C++. Want to contribute? Join us on Discord at https://discord.gg/5NJB6dD or just send pull requests / issues. For discussion use the forums at forums.ppsspp.org.
https://www.ppsspp.org
Other
11.43k stars 2.19k forks source link

CPU utilization is high running on server (software graphics drivers) #16245

Open bengalih opened 2 years ago

bengalih commented 2 years ago

Game or games this happens in

N/A

What area of the game

I have had PPSSPP open on my media server for several days configured in remote streaming mode so that I can play my games on my Pixel 3 XL So far, actual streaming performance over my local WiFi seems perfectly fine and overall I impressed by both the streaming speed and the speed of playing on my phone.

However, I went into my server today to check some stats and PPSSPP was taking up 35% CPU utilization of my AMD Ryzen 3 2200 system (RAM utilization was < 30 MB). After playing around with some things, the lowest I ever saw PPSSPP take up was 8.8%, but it still seemed to waver between that and 25% CPU utilization, usually settling on closer to 15-22% utilization.

It seems that when the PPSSPP screen is actually toggled to the Games or Recent tab it spikes in CPU utilization (to the 30-35% high end) and while it may eventually go back down when switching back to a screen like "settings" it doesn't seem to have a repeatable pattern.

I have tried to disable the falling symbols animation and also shut off the streaming component, but neither one seems to have much immediate bearing on the CPU utilization that is being reported at the time.

This is a media center apportioned PC with many many services running on it. Including Plex, Sonarr, Radarr, Deluge, Hyper-V running a backup Domain Controller, and several other services. PPSSPP is by far the outlier showing the highest consistent CPU utilization of anything else running on the system.

Unfortunately, I don't think I can keep this service running when it wants to monopolize about 20% of my system for doing nothing 99.9999% of the time. Interesting to note that when I do stream a game from the server it doesn't appear to have much of an impact on the cpu/ram that PPSSPP has when sitting idle.

Is there some tuning that can be done to the PPSSPP settings for a "server" environment where the PPSSPP app is not going to be used for playing games, but only for streaming them?

Speed seen in PPSSPP

N/A

GE frame capture and debug statistics

N/A

Platform

Windows

Mobile phone model or graphics card

AMD Ryzen 3 2200

PPSSPP version affected

1.13.2

Last working version

No response

Graphics backend (3D API)

Other

Any other notes or things you've tried

No response

Checklist

hrydgard commented 2 years ago

There's some slowness in text rendering that I've been meaning to take care of, but didn't think it was that bad. 20% sounds really high. Tagging for investigation before 1.14.

bengalih commented 2 years ago

Thanks. In the meantime since I posted this I have been playing around trying to figure out how the games have been streaming and I have arrived on a solution which bypasses my need for PPSSPP altogether on the server end. I'm sure you know the details, but I will recount them here for anyone else that might be interested. Perhaps we can change this into a wiki page somewhere.

Through a packet capture I determined that PPSSPP hosts the files out using standard http web services. It appears to present an index html document which contains a list of games in text/plain format. The format looks like this:

/ /Ape%20Escape%20On%20the%20Loose%20[UCUS-98609]%20(UMD).cso /Assassin's%20Creed%20Bloodlines%20[ULUS-10455]%20(UMD).cso /Black%20Rock%20Shooter%20The%20Game%20[NPUH-10126]%20(PSN).cso /Brandish%20The%20Dark%20Revenant%20[NPUH-10195]%20(PSN).cso /Burnout%20Dominator%20[ULUS-10236]%20(UMD).cso /Burnout%20Legends%20[ULUS-10025]%20(UMD).cso /Castlevania%20The%20Dracula%20X%20Chronicles%20[ULUS-10277]%20(UMD).cso

And the list would go on with an entry for each game that was listed in the PPSSPP server's recent list (which I had pre-populated with all my games).

Note: this is URL encoded format with spaces (and other special characters?) replaced. This file apparently needs to be in UTF-8 format with just an LF (Unix EOL) on each line. The easiest way to generate this file is to use a web browser to browse to the PPSSPP ip:port and you will see what the PPSSPP server is providing. You can then save this as an html document and serve it up in text/plain format on your custom server.

Then copy/paste this output into a text file (be sure to put the top '/' in the file.

So, I just setup a web server that was hosting out all of my .cso/.iso files (be sure to allow those extensions through your web server. I did so by setting MIME type as application/octet-stream for these extensions). And be sure to share the the listing of games in text/plain format as a default document.

If you set your web server up using the same port ppsspp was using (on mine it was 56794) it appears you don't need to do anything special on the PPSSPP client. If you set a different port you will need to go to the settings of the remote streaming client and choose to "Manually configure client" with the IP and port your custom web server is running on.

Then, simply browse from the client as normal to see your games and stream them. I tested this both from HFS (rejetto.com) web server and after that quick test set it up on my IIS server which I already use for other things.

It appears the file list shown above automatically prepends the server:port to each entry, so whatever server you are browsing from is what will get appended. It does however appear you can create your entries in this list to specify an exact URL to each game. You could do this if, for instance, you needed to host the index document on one system, but your games were hosted on another. I can't think of too many reasons why you wouldn't just put the index file where the games were, but you could specify line entries like this:

http://10.10.10.102:56794/Ape%20Escape%20On%20the%20Loose%20[UCUS-98609]%20(UMD).cso

Anyway, I have tested this thoroughly with a half dozen games and they all appear to work fine. Performance doesn't seem to be an issue, though I haven't played through much of the games. I did load them and use FF to accelerate through things like opening cinematic sequences, etc and then play a few seconds of the games and they all appear fine.

I prefer to use IIS because I have it setup for other things, but I expect any performance issues would be tied to the web server, so you could always run Apache, HFS, or probably even a simply no-frills python server. Perhaps you could add some information for the end user (without us having to dig it up through the code base) on what you implement as a web server and if there are any tuning parameters you might recommend. Also, as I noted above it seems the index file gets encoded to remove spaces, but it didn't seem to be a full url encoding (e.g. it didn't encode my bracket '[' ']' characters?). Also the EOL/BOM seems to be important. So some documented info on that might also help those wanting to run their own server.

So in short - my personal issue seems to be gone now because I can simply host the files myself without PPSSPP on the server side and no discernable impact to my PCs performance (minus the bandwidth used when streaming).

If however you require some additional data from me if you are unable to recreate high CPU utilization on your end, I am happy to provide you what I can.

hrydgard commented 2 years ago

Indeed, we use a pretty simple protocol for that :) Glad you figured something out. And we might support other server setups in the future.

I'm not gonna investigate the CPU problem right now, but I'll post again here when I do.

unknownbrackets commented 2 years ago

I can't reproduce this at all - on Windows 10, I get 0.4-0.8% CPU usage using Vulkan, and 1-2% resting CPU usage on GLES/Direct3D 11. This is while using remote streaming from a phone. I'm using an NVIDIA card, and wonder if this performance is really just a menu performance and not related to streaming or the webserver at all.

If it only happens on the recent tab, is it possible you have background audio or something else playing? Does it still happen if you disable remote disc streaming and go to the Recent tab?

It was of course intentional that the streaming uses standard HTTP, any server should work as long as it supports range requests (most do, i.e. Apache, nginx, etc.) Someone also added support to scan an html response for URLs, so if you just enable directory indexes in Apache or similar, it should work fine as well. I think there's also a docker server setup that runs a local webserver to server files too.

-[Unknown]

unknownbrackets commented 2 years ago

See this for the little mini server that generates the index for you: https://github.com/hrydgard/ppsspp/issues/14319#issuecomment-810651895

-[Unknown]

bengalih commented 2 years ago

I can't reproduce this at all - on Windows 10, I get 0.4-0.8% CPU usage using Vulkan, and 1-2% resting CPU usage on GLES/Direct3D 11. This is while using remote streaming from a phone. I'm using an NVIDIA card, and wonder if this performance is really just a menu performance and not related to streaming or the webserver at all.

If it only happens on the recent tab, is it possible you have background audio or something else playing? Does it still happen if you disable remote disc streaming and go to the Recent tab?

It was of course intentional that the streaming uses standard HTTP, any server should work as long as it supports range requests (most do, i.e. Apache, nginx, etc.) Someone also added support to scan an html response for URLs, so if you just enable directory indexes in Apache or similar, it should work fine as well. I think there's also a docker server setup that runs a local webserver to server files too.

-[Unknown]

Thanks for the info on the directory browsing. I did have that enabled but didn't test it without generating the index file myself. I just tested removing the index file and browsing still works. This is really the most efficient way as you don't have anything to update and, unlike using PPSSPP, you don't even need to worry about games being loaded into Recents - you just need the game in the folder to show up. So anyone looking at above can bypass most of the info on creating that file and simply enable directory browsing.

As far as the CPU utilization, this is happening to me on a brand new extract from the .zip package. So I don't even have any games loaded or streaming on, etc. 100% OOB. That being said I went ahead and downloaded the same package on my laptop (i7 3rd gen) and I do not have this problem. I get similar numbers to you.

However I did a fresh extract on my Radeon system of the .zip and the issue remains. I thought perhaps it might have to do with the fact that I access that system over RDP, so I connected it and accessed it directly and still have the issue. Straight from the zip and launch and I am seeing a consistent 16-18% CPU utilization.

Maybe it is a problem with the Radeon? I don't know. I don't ever game on this system it is mostly server functions and to stream media files. I'm happy to try some tweaks to see but I did want to report what I am seeing as perhaps there is a conflict with certain configurations that causes this excessive CPU.

unknownbrackets commented 2 years ago

I suspect it is GPU (really GPU driver) related.

If you go to Settings -> Tools -> Developer tools -> Framedump tests (it's after "Enable driver bug workarounds" which is a lone checkbox) -> crisis_core_flat_repro, does it happen when running that frame dump as well? This is a very simple scene and on my system has minimal CPU usage.

If this is a server, it's possible it's forcing off hardware accelerated graphics. Maybe the menu is being rendered (slowly) by some software emulation. Or maybe AMD's driver just has some performance issue with PPSSPP, some baseline CPU usage based on something we're doing (but that would be surprising especially if it's across multiple graphics backends.)

-[Unknown]

bengalih commented 2 years ago

So you are right about this and I probably should have remembered this before you brought it up. This is Windows Server 2016 which, when I purchased the Ryzen 3 CPU new I was not aware that it did not provide drivers for Server 2016. It was actually at that point that I decided to forgo running my media center PC direct via HDMI and switched to streaming over Plex because I could not get the graphics output I wanted without the purchase of an external graphics card.

As mentioned, I don't do any gaming on this system and it actually uses the driver "Microsoft Basic Display Adapter." Because I don't run anything graphics intensive on it I never see an issue like this.

On the one hand, I wouldn't think an application like PPSSPP should be coded to tax the CPU at all when not playing a game, but I see it was a design decision on how to make the UI and I don't expect any major redesign there. Obviously, this is a pretty niche case and I wouldn't expect most users to not even be running any display driver. Up until now this hasn't shown up with any other apps I've needed to run on the server side.

Additionally, since I only need to run PPSSPP for the web services and we've established I can do that via any old web server this is really not an issue.

I will leave this for you guys to close, as I don't need a resolution for myself. However I guess it is good for you to know that this could potentially be an issue with certain drivers.

BTW the crisis_core_flat_repro didn't seem to change anything.

Thanks.

bengalih commented 2 years ago

scan an html response for URLs

I just wanted to update here since it was discussed (for anyone else finding this issue and wanting to setup their own remote streaming server) that the in-built URL parsing appears to have issues escaping certain characters.

I don't know the full extent, but definitely it has problems with titles containing an ampersand. Because of this it was necessary to generate an index file as I detail above and not simply allow the web server directory listing to serve out the list of files if you have any offending characters in the game title.

I filed a bug against this: https://github.com/hrydgard/ppsspp/issues/16263

Clearly not high priority, but also likely an easy fix.