Project

General

Profile

Actions

Emulator Issues #2926

closed

High CPU Usage due to YieldCpu

Added by sskkiipp almost 14 years ago.

Status:
Fixed
Priority:
Normal
Assignee:
-
% Done:

0%

Operating system:
N/A
Issue type:
Bug
Milestone:
Regression:
No
Relates to usability:
No
Relates to performance:
No
Easy:
No
Relates to maintainability:
No
Regression start:
Fixed in:

Description

What steps will reproduce the problem?

  1. see CPU Load of dolphin while playing any game

What is the expected output? What do you see instead?

  1. compare CPU Load after chaning YieldCPU to Sleep(1)

Dolphin version with the problem? Other Dolphin version without the
problem?

all

Please provide any additional information below.
see :
1)http://code.google.com/p/dolphin-emu/source/detail?r=5869
2)http://code.google.com/p/dolphin-emu/source/detail?r=4687
3)http://code.google.com/p/dolphin-emu/issues/detail?id=1479

is there any true reason why it should not be changed? i used to change it for a long time now and didn't experience any negative aspects.

tested on those systems:
intel q6600
amd x4 955
intel i5 750

Actions #1

Updated by BhaaL almost 14 years ago

YieldCPU does YieldProcessor on Windows, which in turn most likely does nothing: http://msdn.microsoft.com/en-us/library/ms687419(VS.85).aspx
"This macro is only effective on processors that support technology allowing multiple threads running on a single processor, such as Intel's Hyperthreading technology."

YieldProcessor might translate into the intrinsic _mm_pause, which emits the pause instruction. _mm_pause is also used on non-win32 platforms.
http://www.devx.com/assets/intel/9315.pdf
"On processors that predate Hyper-Threading Technology, the pause instruction is
translated into a no-op, that is a no-operation instruction, which simply introduces a one instruction delay."

I've seen various people asking about whether mm_pause/yield/YieldProcessor/whatever or Sleep(0)/Sleep(1) were the better thing to do - none of them got any useful answer (at least I couldn't find anything where the op was satisfied with the answers).

Actions #2

Updated by sskkiipp almost 14 years ago

:) thanks for the answer.

did you once try to build a dolphin version without mm_pause?
the speed is the same but the cpu usage really decreases.

So there's no real answer why mm_pause is used, apart from guessing its better which is stated in the source code?

Actions #3

Updated by BhaaL almost 14 years ago

From my side, yes. But I do not have enough experience with those things to make any assumptions on how it will perform with one or the other, nor do i have the time right now to try it out.

One might want to try to remove YieldProcessor from the windows build, and use _mm_pause right away. I can't say which of the YieldProcessor defines is used on a particular machine, using a particular version of Visual Studio, but pretty much all docs I found had mm_pause as part of the known intrinsics.

Actions #4

Updated by sskkiipp almost 14 years ago

http://www.mofeel.net/37-microsoft-public-win32-programmer-kernel/5540.aspx

^^
"Well, Sleep works on every Win32 platform, and YieldProcessor requires Win
Server 2003. Sleep works on every processor, and YieldProcessor requires
HyperThreading. Sleep gives other threads at the same priority a chance to
run. YieldProcessor might actually do nothing at all. "

hmm, i don't really get why the cpu usage goes down with using sleep(0/1).

http://msdn.microsoft.com/en-us/magazine/cc163726.aspx
^^
so, i'd like to take back my suggestion and ask to get rid of all Sleeps since they take more time than we would like them to.

Actions #5

Updated by amberion2dp almost 14 years ago

Well, speaking purely as a person with only a passing understanding of code, it seems to me that CPU usage goes down with Sleep because it's actually putting the CPU to sleep, thus not consuming any resources, as opposed to YieldProcessor, which, according to the links quoted here, may actually be just burning cycles repeatedly without actually accomplishing anything. The consumed cycles do nothing, and artificially inflate the CPU consumption. My mental image is of a program that's sending hundreds of YieldProcessor requests, which turn into no-ops, which is a total waste.

Actions #6

Updated by dfleite almost 14 years ago

I don't understand why it wasn't changed yet, a lot of commits here are experimental anyway, why not make another one?
If it gives any problem we can always revert.

Actions #7

Updated by arthas.tft almost 14 years ago

I have tested two game, and I noticed that there is a dramatic slow down when i replace yieldcpu with sleep. 60 fps drop to 30-40fps.
radiant dawn and ssbb.

Actions #8

Updated by arthas.tft almost 14 years ago

And I can also confirm that radiant dawn runs more stable when audio throttle is off(use sleep) and framelimit is on(use yieldcpu).

Actions #9

Updated by dfleite almost 14 years ago

In r4687 Common::YieldCPU() was replaced by SLEEP(1), is there any difference between Common::SleepCurrentThread and SLEEP?

Actions #10

Updated by Xtreme2damax almost 14 years ago

Ssskip, a patch would be nice so this can be tested. If I knew how to code I would make the changes myself and see if this makes any difference or if it would break any games.

Actions #11

Updated by skidau about 13 years ago

  • Status changed from New to Fixed

Fixed in r7125.

Actions

Also available in: Atom PDF