Previous Thread
Next Thread
Print Thread
MAME crippled by Spectre #113259 04/27/18 06:25 PM
Joined: May 2007
Posts: 549
M
mizapf Offline OP
Senior Member
OP Offline
Senior Member
M
Joined: May 2007
Posts: 549
It took me some weeks to finally find the reason for the drastic performance loss that I observed since mid-March.

During my works on the Hexbus system and the HX5102 floppy drive for the TI-99/8 I found that for no obvious reason, the bench performance of MAME dropped significantly.

The 99/8 emulation is pretty CPU-hungry, but since my last HW upgrade to a Skylake system (i7-6700K CPU @ 4.00GHz), these issues seemed gone. The naked 99/8 delivered a bench performance of 350%, which was enough reserve for screen output and the floppy drive.

Just about end of March, close to the completion of the HX5102, I noticed that MAME did not achieve 100% emulation speed anymore, which I noticed from the chopped sound. I did another bench test, and got just about 150%. First I thought I accidentally build a debug version, then, a non-optimized version. This was not the case, the build was good. In fact, I found an old build of MAME from June 2017, a 0.186 release, untouched since then. I continued my tests with the 99/4A driver built into that one.

Here again, I remembered that the reserve was pretty high, between 800% and 900%. Now, only 300% were reached.

I am using openSUSE Linux (Tumbleweed rolling release) and suspected some issue in the kernel, so I started bisecting. The results were not clear; the bisect result on one PC did not match the one on my second PC.

I now found the issue, as I believe. When I add the kernel boot parameter "spectre_v2=off", the higher emulation speed is back. Obviously, MAME is particularly affected by the Spectre issue, because it is a heavy CPU-load application. It is not only MAME, though. I am using a Bluray player on WINE, which turned unusable now. I know that I successfully watched a Bluray some time ago with the same system.

A kernel developer explained to me that when you see this:

Code
$ cat /sys/devices/system/cpu/vulnerabilities/spectre_v2
Mitigation: Indirect Branch Restricted Speculation, IBPB, IBRS_FW


it means that your system is heavily slowed down, since the much better performing retpolines do not work.

For me this means that my two PC systems are hit back to pre-2011 performance. I have a laptop from 2012 (Core i5 3220M), which now runs MAME faster than my Skylake PC (i7-6700K CPU @ 4.00GHz) and my KabyLake PC (i7-7700K CPU @ 4.20GHz).

There are some open points to consider:

* Why is my dually installed Windows 10 still running fast? Maybe Microsoft did not yet deploy the mitigation. When this occurs, I am curious what will happen.

* Is this a failure of the openSUSE people who are tailoring the vanilla kernel to their distribution?

For the time being, I seem to be forced to turn off the Spectre mitigation and make my PC vulnerable.

Here are some numbers, gained from the current MAME build:

With mitigation (current situation)
Code
$./mame64 ti99_8 -bench 20
Average speed: 153.85% (19 seconds)
$ ./mame64 ti99_4a -bench 20
Average speed: 298.34% (19 seconds)


Without mitigation (previous situation, now adding "spectre_v2=off"):
Code
$./mame64 ti99_8 -bench 20
Average speed: 362.01% (19 seconds)
$ ./mame64 ti99_4a -bench 20
Average speed: 895.49% (19 seconds)


Note that you may possible be affected only if your system is a Skylake or newer system.

Re: MAME crippled by Spectre [Re: mizapf] #113260 04/27/18 06:27 PM
Joined: May 2004
Posts: 1,608
H
Haze Offline
Very Senior Member
Offline
Very Senior Member
H
Joined: May 2004
Posts: 1,608
fwiw I noticed absolutely no difference in performance on any of my machines under Windows 10, so maybe this is a Linux thing?

Re: MAME crippled by Spectre [Re: mizapf] #113262 04/27/18 07:19 PM
Joined: Mar 2001
Posts: 16,470
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,470
The mitigation should not touch MAME at all, it impacts only things that make a high number of syscalls (mostly server loads).

Re: MAME crippled by Spectre [Re: mizapf] #113263 04/27/18 08:09 PM
Joined: May 2007
Posts: 549
M
mizapf Offline OP
Senior Member
OP Offline
Senior Member
M
Joined: May 2007
Posts: 549
I do not know technical details about the mitigation; I can just say that the kernel developers confirmed to me that this may be the ultimate cause. I found by kernel bisecting and distribution rollback that the issue appeared just with the appearance of the package ucode-intel and with a certain kernel release. The effect from above is reproducible on three different PCs (the two mentioned ones, and an office PC with KabyLake), so I'm judging from observation.

I'm certainly interested in alternative explanations that allow me to keep the mitigation and the normal MAME speed.

Edit: Maybe you have Meltdown in mind? The mitigation here is Kernel page table isolation.

Last edited by mizapf; 04/27/18 08:43 PM.
Re: MAME crippled by Spectre [Re: mizapf] #113267 04/27/18 09:59 PM
Joined: Sep 2004
Posts: 385
A
AaronGiles Offline
Senior Member
Offline
Senior Member
A
Joined: Sep 2004
Posts: 385
Done right, the mitigation should only affect software that calls into the kernel a lot. With those numbers it makes me wonder if the branch predictor is getting stuck in the "off" position somehow, as MAME is largely CPU-bound and should stay in user mode.

Do you see the same slowdown when running very CPU-heavy games vs. lighter stuff?

Re: MAME crippled by Spectre [Re: mizapf] #113274 04/28/18 12:50 AM
Joined: Mar 2001
Posts: 16,470
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,470
FWIW, my CPU is

Code
model name      : Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
stepping        : 3
microcode       : 0xc2


and my Spectre v2 mitigation is

Code
Mitigation: Full generic retpoline, IBPB, IBRS_FW


Note that I have the performance-neutral retpoline version.

Re: MAME crippled by Spectre [Re: mizapf] #113275 04/28/18 02:10 AM
Joined: Feb 2004
Posts: 2,132
Vas Crabb Online Content
Very Senior Member
Online Content
Very Senior Member
Joined: Feb 2004
Posts: 2,132
Interestingly, RHEL seems to not enable the Spectre V2 mitigation by default due to performance issues.

Re: MAME crippled by Spectre [Re: R. Belmont] #113278 04/28/18 11:31 AM
Joined: May 2007
Posts: 549
M
mizapf Offline OP
Senior Member
OP Offline
Senior Member
M
Joined: May 2007
Posts: 549
Originally Posted by R. Belmont
FWIW, my CPU is

Code
model name      : Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
stepping        : 3
microcode       : 0xc2


and my Spectre v2 mitigation is

Code
Mitigation: Full generic retpoline, IBPB, IBRS_FW


Note that I have the performance-neutral retpoline version.


Which Linux distribution do you use?

I just tried the Leawo Bluray Player (run by WINE), and this is again a pretty obvious effect - with the mitigation, jerky video and sound, sound offset by 5 seconds after the first minute. Without the mitigation, fairly good, sound keeps synchronized.

I would be interesting to see whether there is a flaw in the "Indirect Branch Restricted Speculation" on the vanilla kernel, or whether this occurs in the kernel patched by SUSE.

Re: MAME crippled by Spectre [Re: mizapf] #113279 04/28/18 11:52 AM
Joined: Mar 2001
Posts: 16,470
R
R. Belmont Offline
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 16,470
I'm on Fedora, which likely inherits the same policy Vas mentioned for RHEL.


Who's Online Now
1 registered members (dormml), 153 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
ShoutChat Box
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,762
Posts115,156
Members4,888
Most Online890
Jan 17th, 2020
Powered by UBB.threads™ PHP Forum Software 7.7.3