Skip to main content

Linus Torvalds: Linux Scheduler Not To Blame For Google Stadia Port Issues

Google Stadia
(Image credit: Google)

A few days ago, we learned that the Linux kernel might be responsible for performance issues in titles being ported to the Google Stadia game streaming platform, as developer Malte Skarupke detailed in a blog post. Phoronix reported on Sunday that Linux creator Linus Torvalds investigated the matter, however, and said with his characteristic bluntness that Skarupke's report was "pure garbage."

The short of it had to do with the way the scheduler deals with spinlocks, and that using them caused long hangups in scheduling, consequently causing delays in getting frames rendered. The longest stalls lasted up to over 100ms on spinlocks, which is far too long a hangup when frames need to be displayed at either 30 or 60 fps. 

Skarupke noted that "most mutex implementations are really good, that most spinlock implementations are pretty bad and that the Linux scheduler is OK but far from ideal", and decided to use mutex locks instead of spinlocks to solve the issue. 

Torvalds' comments appeared in an email thread and read as follows.

"The whole post seems to be just wrong, and is measuring something completely different than what the author thinks and claims it is measuring. First off, spinlocks can only be used if you actually know you're not being scheduled while using them...It basically reads the time before releasing the lock, and then it reads it after acquiring the lock again, and claims that the time difference is the time when no lock was held. Which is just inane and pointless and completely wrong. That's pure garbage.

Torvalds' fix suggests developers "Use a lock where you tell the system that you're waiting for the lock, and where the unlocking thread will let you know when it's done, so that the scheduler can actually work with you, instead of (randomly) working against you...I repeat: do not use spinlocks in user space, unless you actually know what you're doing. And be aware that the likelihood that you know what you are doing is basically nil."

This essentially means that Skarupke's finding that spinlocks aren't ideal for use in this scenario is, for all intents and purposes, correct. The catch is that developers shouldn't have been using spinlocks in the first place--so as far as Linus Torvalds is concerned, it wasn't Linux scheduler that was to blame, but rather developers' approaches to using it.

Of course, we'll have to see if this new information actually helps developers sort out the issues they've been having with their Stadia ports.