fs-uae icon indicating copy to clipboard operation
fs-uae copied to clipboard

High CPU usage when paused

Open johalun opened this issue 7 years ago • 5 comments

Hi

When I press F12 and select pause I expect the CPU usage to go to almost zero. However, I'm getting constant 30% (compared to 130% when running an A4000 machine).

A good use for the pause function is when running on a laptop and you want to preserve battery. Is it known what is causing such high CPU usage during pause?

johalun avatar Dec 11 '18 17:12 johalun

A 10 second dtrace syscall trace gives me this

root@jm:/usr/home/johannes # dtrace -n syscall:::entry'/pid == 82956/{ @syscalls[probefunc] = count(); }'
dtrace: description 'syscall:::entry' matched 1110 probes
^C

  write                                                           751
  writev                                                         1784
  poll                                                           3682
  ioctl                                                         12609
  select                                                        14984
  nanosleep                                                     17821
  recvmsg                                                       34526

johalun avatar Dec 11 '18 17:12 johalun

So looking at threads we can see that one thread drops down to zero while one stays unchanged at paused state.

Running:

100948 johannes    103    0  2313M   146M CPU2     2   1:46 100.00% fs-uae{fs-uae}
100481 johannes     40    0  2313M   146M CPU6     6  52:40  29.29% fs-uae{fs-uae}

Paused:

100948 johannes     20    0  2313M   146M nanslp   4   1:59   0.19% fs-uae{fs-uae}
100481 johannes     45    0  2313M   146M select   2  52:52  35.26% fs-uae{fs-uae}

johalun avatar Dec 11 '18 18:12 johalun

looks as if select() is called with a tiny timeout repeatedly, rather than blocking indefinitely until a fd is ready to read/write, or one of the polled fds is constantly producing events.

rofl0r avatar Dec 12 '18 01:12 rofl0r

Hi, the pause function is indeed not optimally implemented. If I recall correctly, the emulation itself is paused, but the renderer is still running, so frames (the same ones) are repeated uploaded to the GPU, and buffers are swapped each frame. So there is definitively some improvements possible here with regards to power saving.

FrodeSolheim avatar May 28 '19 22:05 FrodeSolheim

I want to look at improving this for FS-UAE 4.0. Ideally, FS-UAE should use little to no CPU/GPU when paused and the user is not interacting with the emulator (at least if the emulator is not in the foreground).

FrodeSolheim avatar Apr 19 '20 12:04 FrodeSolheim