Project

General

Profile

Actions

Feature #17566

open

Tune thread QoS / efficiency on macOS

Added by mperham (Mike Perham) almost 4 years ago. Updated 23 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:102185]

Description

Hi, new Apple M1 processors have "performance" and "efficiency" cores. Apple provides a QoS API so threads can tune which cores they should execute on. Some threads should be executed as high-priority, some should be treated as low-priority.

This page shows the pthread APIs that Apple provides:

https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/PrioritizeWorkAtTheTaskLevel.html

pthread_set_qos_class_self_np(QOS_CLASS_BACKGROUND, 0)

I noticed Ruby already provides Thread#priority= which says This is just hint for Ruby thread scheduler. It may be ignored on some platform. Does this API work still or was it only active for Ruby 1.8's green threads? Should this API use the QoS APIs on macOS?

Updated by ko1 (Koichi Sasada) almost 4 years ago

Actually, Thread#priority is not tested.
I'm not sure we can use this pthread_set_qos_class_self_np API for priority because it accepts an integer and there is no agreement which number is "high" and "low". Introducing another API makes sense more for me. But I'm also not sure we can introduce a new API only for Mac OS.

Also I'm not sure pthread_set_qos_class_self_np is needed for Ruby users (I think Mac OS will choose good core than a programmer, I guess).

Updated by shan (Shannon Skipper) about 1 month ago

From Apple's perspective, it's our "obligation" as developers to make apps go "absolutely idle" on performance cores when "not responding to user input." From their docs, it seems they hope for us to use fine grained priority when we can. See https://developer.apple.com/news/?id=vk3m204o

Apple silicon is so popular with programmers that I wonder if it's worth supporting QoS for the sake of developer tools written in Ruby?

Updated by shan (Shannon Skipper) 23 days ago

I just ran across this article that touches on the sordid history of Thread priority and on how Apple Silicon is using QoS dispatch, and thought it might be nice to add here for context. https://blog.xoria.org/macos-tips-threading/

The author mentions from experience that "most of the time it isn’t possible to cleanly assign a single priority to a thread" so priority is better handled at the Dispatch library level. This seems to suggest Thread-level priority may not be the best way to have macOS apps use efficiency cores, leaning towards it not being "a priority" for Ruby.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0