Skip to content

Instantly share code, notes, and snippets.

@LeaveNhA
Created August 8, 2026 15:36
Show Gist options
  • Select an option

  • Save LeaveNhA/c49ac16e3bf7cb26a0c2e24948578c70 to your computer and use it in GitHub Desktop.

Select an option

Save LeaveNhA/c49ac16e3bf7cb26a0c2e24948578c70 to your computer and use it in GitHub Desktop.
kdebug Class MACH Definitions

Codes for the macOS scheduler's DBG_MACH_SCHED subclass (kdebug class MACH, subclass 0x40) aren't documented anywhere on the web even an LLM couldn't find it after a try-hard session, despite showing up constantly in Instruments' Thread State Trace and raw kdebug captures. This table is a plain transcription of the definitions in sys/kdebug.h as shipped in the Xcode/macOS SDK, and part of Apple's XNU kernel sources released under the Apple Public Source License 2.0.

Local path in my environment and probably in yours too (as of today, because you know, apple...): /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/kdebug.h Current upstream source: github.com/apple-oss-distributions/xnu

I sincerely wanted to let the web have it publicly and search engines index it because sometimes it is really hard to find what we are looking for in 'the mess we are in'.

Also, still surprised why even with the quoted search, google didn't bring the original file up. Maybe they should focus on the job they already have and good instead of AI.

/* Codes for Scheduler (DBG_MACH_SCHED) */
#define MACH_SCHED              0x0     /* Scheduler */
#define MACH_STACK_ATTACH       0x1     /* stack_attach() */
#define MACH_STACK_HANDOFF      0x2     /* stack_handoff() */
#define MACH_CALL_CONT          0x3     /* call_continuation() */
#define MACH_CALLOUT            0x4     /* callouts */
#define MACH_STACK_DETACH       0x5
#define MACH_MAKE_RUNNABLE      0x6     /* make thread runnable */
/* unused  MACH_PROMOTE            0x7 was: promoted due to resource (replaced by MACH_PROMOTED) */
/* unused  MACH_DEMOTE             0x8 was: promotion undone (replaced by MACH_UNPROMOTED) */
#define MACH_IDLE               0x9     /* processor idling */
#define MACH_STACK_DEPTH        0xa     /* stack depth at switch */
#define MACH_MOVED              0xb     /* did not use original scheduling decision */
#define MACH_PSET_LOAD_AVERAGE  0xc
#define MACH_AMP_DEBUG          0xd
#define MACH_FAILSAFE           0xe     /* tripped fixed-pri/RT failsafe */
#define MACH_BLOCK              0xf     /* thread block */
#define MACH_WAIT               0x10    /* thread wait assertion */
#define MACH_GET_URGENCY        0x14    /* Urgency queried by platform */
#define MACH_URGENCY            0x15    /* Urgency (RT/BG/NORMAL) communicated
	                                 * to platform
	                                 */
#define MACH_REDISPATCH         0x16    /* "next thread" thread redispatched */
#define MACH_REMOTE_AST         0x17    /* AST signal issued to remote processor */
#define MACH_SCHED_CHOOSE_PROCESSOR     0x18    /* Result of choose_processor */
#define MACH_DEEP_IDLE          0x19    /* deep idle on master processor */
/* unused                       0x1a    was MACH_SCHED_DECAY_PRIORITY */
#define MACH_CPU_THROTTLE_DISABLE       0x1b    /* Global CPU Throttle Disable */
#define MACH_RW_PROMOTE            0x1c /* promoted due to RW lock promotion */
#define MACH_RW_DEMOTE             0x1d /* promotion due to RW lock undone */
#define MACH_SCHED_MAINTENANCE     0x1f /* periodic maintenance thread */
#define MACH_DISPATCH              0x20 /* context switch completed */
#define MACH_QUANTUM_HANDOFF       0x21 /* quantum handoff occurred */
/* unused  MACH_MULTIQ_DEQUEUE        0x22 was: Result of multiq dequeue */
#define MACH_SCHED_THREAD_SWITCH   0x23 /* attempt direct context switch to hinted thread */
#define MACH_SCHED_SMT_BALANCE     0x24 /* SMT load balancing ASTs */
#define MACH_REMOTE_DEFERRED_AST   0x25 /* Deferred AST started against remote processor */
#define MACH_REMOTE_CANCEL_AST     0x26 /* Canceled deferred AST for remote processor */
#define MACH_SCHED_CHANGE_PRIORITY 0x27 /* thread sched priority changed */
#define MACH_SCHED_UPDATE_REC_CORES     0x28    /* Change to recommended processor bitmask */
#define MACH_STACK_WAIT            0x29 /* Thread could not be switched-to because of kernel stack shortage */
#define MACH_THREAD_BIND           0x2a /* Thread was bound (or unbound) to a processor */
#define MACH_WAITQ_PROMOTE         0x2b /* Thread promoted by waitq boost */
#define MACH_WAITQ_DEMOTE          0x2c /* Thread demoted from waitq boost */
#define MACH_SCHED_LOAD            0x2d /* load update */
#define MACH_REC_CORES_FAILSAFE    0x2e /* recommended processor failsafe kicked in */
#define MACH_SCHED_QUANTUM_EXPIRED 0x2f /* thread quantum expired */
#define MACH_EXEC_PROMOTE          0x30 /* Thread promoted by exec boost */
#define MACH_EXEC_DEMOTE           0x31 /* Thread demoted from exec boost */
#define MACH_AMP_SIGNAL_SPILL      0x32 /* AMP spill signal sent to cpuid */
#define MACH_AMP_STEAL             0x33 /* AMP thread stolen or spilled */
#define MACH_SCHED_LOAD_EFFECTIVE  0x34 /* Effective scheduler load */
/* unused  MACH_PROMOTED              0x35 was: thread promoted due to mutex priority promotion */
/* unused  MACH_UNPROMOTED            0x36 was: thread unpromoted due to mutex priority promotion */
/* unused  MACH_PROMOTED_UPDATE       0x37 was: thread already promoted, but promotion priority changed */
#define MACH_QUIESCENT_COUNTER     0x38 /* quiescent counter tick */
#define MACH_TURNSTILE_USER_CHANGE 0x39 /* base priority change because of turnstile */
#define MACH_AMP_RECOMMENDATION_CHANGE 0x3a /* Thread group recommendation change */
#define MACH_AMP_PERFCTL_POLICY_CHANGE 0x3b /* AMP policy for perfctl cluster recommendation */
#define MACH_TURNSTILE_KERNEL_CHANGE 0x40 /* sched priority change because of turnstile */
#define MACH_SCHED_WI_AUTO_JOIN      0x41 /* work interval auto join events */
#define MACH_SCHED_WI_DEFERRED_FINISH 0x42 /* work interval pending finish events for auto-join thread groups */
#define MACH_SET_RT_DEADLINE       0x43 /* set thread->realtime.deadline */
#define MACH_CANCEL_RT_DEADLINE    0x44 /* cancel thread->realtime.deadline */
#define MACH_RT_SIGNAL_SPILL       0x45 /* RT spill signal sent to cpuid */
#define MACH_RT_STEAL              0x46 /* RT thread stolen or spilled */
#define MACH_PENDING_AST_URGENT    0x47 /* CPU pending_AST_URGENT set/cleared */
#define MACH_SCHED_THREAD_SELECT   0x48 /* Result of thread_select */
#define MACH_SCHED_NEXT_PROCESSOR  0x49 /* Result of choose_next_rt_processor_for_IPI */
#define MACH_PSET_AVG_EXEC_TIME    0x50
#define MACH_SUSPEND_USERSPACE     0x51    /* userspace threads are suspended */
#define MACH_PREEMPTION_EXPIRED    0x52 /* preemption disable threshold crossed */
#define MACH_FLOOR_PROMOTE         0x53 /* promoted upon request */
#define MACH_FLOOR_DEMOTE          0x54 /* unpromoted upon request */
#define MACH_INT_MASKED_EXPIRED    0x55    /* interrupt masked threshold crossed */
#define MACH_INT_HANDLED_EXPIRED   0x56    /* interrupt handling threshold crossed */
/* unused MACH_RT_RESTRICT_DENIED    0x57 was: Denied a thread becoming realtime (with -time-constraint-policy-restrict boot-arg)*/
#define MACH_UPDATE_POWERED_CORES  0x58 /* CLPC requested cores powerup/powerdown */
#define MACH_MODE_DEMOTE_THROTTLED       0x59 /* Sched mode demotion - throttled */
#define MACH_MODE_DEMOTE_FAILSAFE        0x5a /* Sched mode demotion - failsafe */
#define MACH_MODE_DEMOTE_RT_DISALLOWED   0x5b /* Sched mode demotion - rt not allowed */
#define MACH_MODE_UNDEMOTE_THROTTLED     0x5c /* Sched mode undemotion - throttling */
#define MACH_MODE_UNDEMOTE_FAILSAFE      0x5d /* Sched mode undemotion - failsafe */
#define MACH_MODE_UNDEMOTE_RT_DISALLOWED 0x5e /* Sched mode undemotion - rt not allowed */
#define MACH_INT_MASKED_RESET            0x5f /* interrupt masked threshold reset */
#define MACH_RT_DISALLOWED_WORK_INTERVAL 0x60 /* RT disallowed due to unmet work interval requirements */
#define MACH_SCHED_WI_EXTERNAL_WAKEUP    0x61 /* WI thread woken by a thread outside its same work interval */
#define MACH_SCHED_AST_CHECK             0x62 /* run ast check interrupt handler */
#define MACH_SCHED_PREEMPT_TIMER_ACTIVE  0x63 /* preempt timer is armed */
#define MACH_PROCESSOR_SHUTDOWN          0x64 /* processor was shut down */
#define MACH_SCHED_PSET_BITMASKS         0x65 /* Migration, rotation, and recommendation bitmasks for each pset */
#define MACH_SUSPEND_DRIVERKIT_USERSPACE 0x66 /* one driverkit process is suspended/unsuspended by iokit */
#define MACH_SCHED_PREFERRED_PSET        0x67 /* Recommendation change for a thread group at a specific QoS */
#define MACH_SCHED_ONCORE_PREEMPT        0x68 /* CLPC requested thread preemption */
#define MACH_SCHED_MODE_CHANGE           0x69 /* thread scheduling mode change */

/* Codes for Clutch/Edge Scheduler (DBG_MACH_SCHED_CLUTCH) */
#define MACH_SCHED_CLUTCH_ROOT_BUCKET_STATE     0x0 /* __unused */
#define MACH_SCHED_CLUTCH_TG_BUCKET_STATE       0x1 /* __unused */
#define MACH_SCHED_CLUTCH_THREAD_SELECT         0x2 /* Thread selection events for Clutch scheduler */
#define MACH_SCHED_CLUTCH_THREAD_STATE          0x3 /* __unused */
@LeaveNhA

LeaveNhA commented Aug 8, 2026

Copy link
Copy Markdown
Author

Literally seconds after I post this, I searched two definitions from here and after the second one, every one of them appeared on my search results. THANKS GOOGLE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment