A deep dive into how RenderFocus interfaces with the Darwin kernel to control Apple Silicon core allocation at the hardware level.
01
Privilege-Separated Architecture
RenderFocus uses a two-process architecture that cleanly separates the user interface from privileged kernel operations. The GUI application runs with normal user privileges while all kernel-level thread manipulation is isolated in a separate XPC daemon.
RenderFocus.app
SwiftUI menu bar interface. Runs in user-space. Discovers processes via NSWorkspace.
XPC Daemon (Root)
Privileged helper via SMAppService. Executes taskpolicy(2) for thread scheduling.
Darwin Kernel
XNU scheduler receives QoS changes. Directs threads to P-Core or E-Core clusters.
Key Design Decisions
The GUI application never acquires root privileges. All privileged operations are isolated in the XPC daemon.
LSUIElement = true makes the app invisible in the Dock — it lives only in the menu bar as an agent application.
Communication happens via Mach IPC (XPC), the fastest inter-process communication mechanism on macOS.
02
XPC Communication Protocol
All communication between the main application and the daemon is defined through a shared @objc protocol. This file is compiled into both targets.
throttleMultipleN × taskpolicy -bBulk throttle via DispatchGroup, single reply on completion
unthrottleAllN × taskpolicy -BRestores all PIDs in the daemon's throttledPIDs set
ping—Health check with 1.5s timeout for status indicator
03
taskpolicy & the Darwin Kernel
At its core, RenderFocus uses the taskpolicy(2) system utility to manipulate the XNU scheduler's Quality of Service classes. Here's what happens at the kernel level when a process is throttled.
The privileged helper daemon is registered with the system via Apple's SMAppService API (macOS 13+), the modern replacement for the legacy SMJobBless. Registration requires one-time administrator approval via Touch ID or password.
// Registration flow let service = SMAppService.daemon(plistName: "com.renderfocus.helper.plist") try service.register()
// What register() does internally: // 1. Locates plist in Contents/Library/LaunchDaemons/ // 2. Reads BundleProgram path from plist // 3. Validates code signing (same Team ID) // 4. Requests admin approval (Touch ID / password) // 5. Registers in BTM (Background Task Management) // 6. Loads daemon into launchd system domain // 7. Registers Mach port for XPC access
Daemon State Machine
notRegistered
Initial state
requiresApproval
Awaiting Touch ID
enabled
Active, XPC ready
05
Focus Mode Activation Flow
When the user presses the Focus button, a precise chain of events unfolds — from process discovery to kernel-level thread manipulation.
1
User selects target app and presses Focus
AppManager.activateFocusMode() is called with the selected application.
2
PID collection and filtering
All running .regular applications are collected. The focus app's PID is excluded. Remaining PIDs are sent to the daemon.
3
XPC call to daemon
throttleMultipleProcesses(pids:) sends PIDs via Mach IPC. The daemon executes taskpolicy -b -p for each PID in parallel using DispatchGroup.
4
Kernel applies QoS changes
The XNU scheduler sets TASK_POLICY_DARWIN_BG on each process. Thread priorities drop to 4, and the scheduler directs them to E-Cores.
5
UI updates and monitoring begins
The focus app moves to the P-Core visualization zone. All other apps move to E-Core zone. New app launches are automatically throttled via NSWorkspace.didLaunchApplicationNotification.
06
Auto-Focus Mode
Auto-Focus watches which app is in the foreground and automatically activates/deactivates Focus Mode. Defined in AutoFocusManager.swift (242 lines). Uses NSWorkspace.didActivateApplicationNotification.
Activation Flow
1
User adds target apps to Auto-Focus list (persisted in UserDefaults as JSON)
Beast Mode takes priority. Optional UNUserNotificationCenter alerts on activation.
07
Beast Mode (Auto-Trigger)
System-level P-Core monopolization via daemon-side setBeastMode(). Sweeps all GUI processes with ps -eo pid,args inside the root daemon. 5-second cooldown timer prevents flicker on deactivation.
Permanently restricts selected applications to E-Cores. The daemon monitors jailed bundle IDs every 5 seconds via checkJailedProcesses() using ps -eo pid,args and re-throttles any that relaunch. Works independently of Focus Mode.
Direct SMC access via IOKit. Temperature reading from user-space (read-only), fan speed writes via XPC to root daemon. Supports AppleSMCKeysEndpoint (M3+) and AppleSMC (M1/M2). SMC keys: F0Md (mode), F0Tg (target RPM). Safety: CPU >85°C → auto 2500 RPM floor.
Real-time CPU temperature monitoring with automatic fan boost. ThermalManager reads temperature from FanManager's IOKit SMC bridge every 3 seconds and reacts to prevent thermal throttling during sustained renders.
3-Tier Alert System
Normal
< 85°C — System within safe parameters. No action taken.
Warning
85°C+ — Elevated temperature detected. Monitoring closely.
Critical
95°C+ — Auto Fan Boost activates. Fans set to 100%.
Behavior
• Auto Fan Boost: Sets fans to 100% when CPU reaches 95°C via fanManager.setFanSpeed(percentage: 100)
• Smart Recovery: Resets to automatic fan control when temperature drops below 90°C
• Notification Cooldown: 60-second minimum between alerts to prevent spam
• Recovery Alert: Sends a separate notification when safe temperature is restored
Implementation
Class: ThermalManager — Reads from FanManager.cpuTemperature (IOKit SMC bridge). Depends on XPCManager for daemon fan commands and NotificationManager for alerts. Monitoring interval: 3 seconds.
11
Session Statistics
Live dashboard that quantifies every optimization action during your session. SessionStatsManager tracks Focus Mode duration, memory purged, apps throttled, and Deep Freeze activations—all local, no telemetry.
Tracked Metrics
Focus Duration
Live timer while Focus Mode is active. Accumulates across multiple activations.
RAM Purged
Cumulative bytes freed by Memory Purge. Displayed in MB/GB format.
Apps Throttled
Running count of processes moved to Efficiency Cores.
Deep Freezes
Number of SIGSTOP activation cycles during the session.
Privacy & Design
• Zero telemetry — all counters are local, nothing leaves your Mac
• Session-scoped — data resets on app restart, no persistent tracking
• Human-readable — duration formatted as “2sa 45dk”, memory as “3.2 GB”
Intelligent algorithm that monitors P-Core CPU usage patterns and notifies you when your render finishes. Walk away from long renders and get alerted the moment CPU usage drops.
Detection Algorithm
1. Monitor
Sample averagePCoreUsage every 2 seconds into a rolling 20-sample window.
Trigger when current usage drops below 30% after sustained high period.
4. Notify
Send render completion notification with from/to percentages. 60s cooldown.
Parameters
High Threshold:85%
Low Threshold:30%
Sample Interval:2 seconds
Window Size:20 samples
Sustained Count:15 samples
Cooldown:60 seconds
Activation
Render Detection only operates when Focus Mode or Beast Mode is active. History resets after successful detection to allow re-detection of subsequent renders. Toggle is persisted in UserDefaults.
13
Live Core Monitor
Real-time per-core CPU usage via Mach host_processor_info(PROCESSOR_CPU_LOAD_INFO). Delta-based tick calculation with wrapping subtraction. Topology from sysctl hw.perflevel0/1.physicalcpu.
CPU impact: <0.1%. Direct Mach API — no shelling out. Proper vm_deallocate of Mach buffers.
14
Apple Silicon Core Reference
RenderFocus leverages the asymmetric core architecture unique to Apple Silicon. Here's a reference of the P-Core and E-Core distribution across the M-series chip family.
P-Core (Performance)
Clock3.2 – 4.6 GHz
Decode8-wide
ROB~630 entries
L1 Cache192KB I + 128KB D
Power~15W / core
E-Core (Efficiency)
Clock2.0 – 2.8 GHz
Decode4-wide
ROB~96 entries
L1 Cache128KB I + 64KB D
Power~1-3W / core
ChipP-CoresE-CoresTotal
M1448
M1 Pro6–828–10
M2 Max8412
M3 Max10–12414–16
M4 Pro10414
M4 Max12–14416–18
15
Security Model
RenderFocus is built with a defense-in-depth approach. Every layer is designed to minimize attack surface while maintaining the kernel-level access required for thread manipulation.
ThreatProtectionDetail
Unauthorized XPCCode signingOnly same Team ID apps can connect
Malicious PIDProcess validationtaskpolicy returns error for invalid PIDs
Daemon persistenceSMAppServiceRemovable from System Settings → Login Items
Privilege escalationIsolated architectureGUI never acquires root privileges
// Code signing chain
Apple Root CA
└── Apple Worldwide Developer Relations CA
└── Apple Development: [Developer]
├── com.renderfocus.app// Main Application
└── com.renderfocus.helper// XPC Daemon
16
Project Structure
The project is organized into two build targets and a shared protocol definition. 17 Swift files totaling 5,697 lines of code.