{"id":475,"date":"2022-06-22T03:22:16","date_gmt":"2022-06-22T01:22:16","guid":{"rendered":"https:\/\/threedots.ovh\/blog\/?p=475"},"modified":"2022-06-22T03:29:13","modified_gmt":"2022-06-22T01:29:13","slug":"cpu-pinning-on-macos","status":"publish","type":"post","link":"https:\/\/threedots.ovh\/blog\/2022\/06\/cpu-pinning-on-macos\/","title":{"rendered":"CPU Pinning on macOS"},"content":{"rendered":"\n<p>Apple operating systems explicitly do not support CPU pinning in a shipping configuration. <\/p>\n\n\n\n<p>This is unlike almost every other shipping OS, so do not even try to check if the feature is present there to rely on it for shipping applications. Use QoS features instead on Apple platforms. (or anywhere else for that matter)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it&#8217;s gated<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#if DEVELOPMENT || DEBUG\n\n#include &lt;pexpert\/pexpert.h&gt;\nextern int32_t sysctl_get_bound_cpuid(void);\nextern kern_return_t sysctl_thread_bind_cpuid(int32_t cpuid);\nstatic int\nsysctl_kern_sched_thread_bind_cpu SYSCTL_HANDLER_ARGS\n{\n#pragma unused(oidp, arg1, arg2)\n\n\t\/*\n\t * DO NOT remove this bootarg guard or make this non-development.\n\t * This kind of binding should only be used for tests and\n\t * experiments in a custom configuration, never shipping code.\n\t *\/\n\n\tif (!PE_parse_boot_argn(\"enable_skstb\", NULL, 0)) {\n\t\treturn ENOENT;\n\t}<\/code><\/pre>\n\n\n\n<p>(in <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/apple-oss-distributions\/xnu\/blob\/e7776783b89a353188416a9a346c6cdb4928faad\/bsd\/kern\/sys_generic.c#L2700\" target=\"_blank\">bsd\/kern\/sys_generic.c<\/a>)<\/p>\n\n\n\n<p>Not only the CPU pinning code is gated behind a <code>#ifdef<\/code> to not work on production kernels, it is also gated behind a boot argument (<code>enable_skstb<\/code>).<\/p>\n\n\n\n<p>Note that cluster pinning support is also gated behind the same mechanism, for systems shipping with multiple clusters.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to use CPU pinning for development purposes then?<\/h2>\n\n\n\n<p>To do that, you need to follow the instructions on how to set up a <em>development<\/em> kernel. You can pick one from the <em>Kernel Debug Kit<\/em> available at the Apple developer website, which also contains the instructions necessary to install a custom kernel on Intel-based Macs.<\/p>\n\n\n\n<p>After doing so, set the <code>enable_skstb=1<\/code> boot argument then reboot. The corresponding <code>sysctl()<\/code>s will then become available.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apple operating systems explicitly do not support CPU pinning in a shipping configuration. This is unlike almost every other shipping OS, so do not even try to check if the feature is present there to rely on it for shipping applications. Use QoS features instead on Apple platforms. (or anywhere else for that matter) How&hellip;&nbsp;<a href=\"https:\/\/threedots.ovh\/blog\/2022\/06\/cpu-pinning-on-macos\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">CPU Pinning on macOS<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-475","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/posts\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/comments?post=475"}],"version-history":[{"count":3,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/posts\/475\/revisions"}],"predecessor-version":[{"id":479,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/posts\/475\/revisions\/479"}],"wp:attachment":[{"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/categories?post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/threedots.ovh\/blog\/wp-json\/wp\/v2\/tags?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}