No description
Find a file
2026-06-28 18:28:45 +02:00
.idea/.idea.AutoAffinityApply/.idea First Commit (14/06/2025) 2026-06-11 21:30:17 +02:00
AutoAffinityApply Updated version in credits 2026-06-28 18:28:45 +02:00
.gitignore Added LICENSE, fixed path issue & added README.md 2026-06-11 23:24:24 +02:00
AutoAffinityApply.sln First Commit (14/06/2025) 2026-06-11 21:30:17 +02:00
global.json First Commit (14/06/2025) 2026-06-11 21:30:17 +02:00
LICENSE Added LICENSE, fixed path issue & added README.md 2026-06-11 23:24:24 +02:00
README.md Added LICENSE, fixed path issue & added README.md 2026-06-11 23:24:24 +02:00

AutoAffinityApply (A.A.A.)

Auto Affinity Apply - Manage CPU affinity for processes with ease.

Made by @tismatis

📋 Description

AutoAffinityApply is a Windows-based utility that allows you to control and manage CPU affinity for running processes. You can assign processes to specific CPU cores, export current affinity configurations, and load/apply saved configurations.

This tool is useful for:

  • Optimizing performance by binding processes to specific CPU cores
  • Balancing workload across CPU cores
  • Testing multi-threaded applications with different core configurations
  • Managing resource allocation on multi-core systems

🎯 Features

  • Full CPU Affinity: Assign all processes to use all available CPU cores
  • Half CPU Affinity: Assign processes to use only the first half of available cores
  • Export Configuration: Export current process affinities to a JSON file for backup or sharing
  • Import Configuration: Load and apply a saved affinity configuration from a JSON file
  • Command-line Interface: Run operations directly via command-line arguments without interactive menu
  • Interactive Menu: User-friendly menu-driven interface for manual operations
  • Multi-threaded: Efficient parallel processing of multiple processes using async tasks

🛠️ Requirements

  • Windows operating system
  • .NET 8.0 runtime or SDK
  • Administrator privileges (required to modify process affinities)

📦 Project Structure

AutoAffinityApply/
├── Program.cs              # Entry point with interactive menu
├── ArgumentListener.cs     # Command-line argument parsing and handling
├── PlannerAffinity.cs      # Core logic for CPU affinity management
├── ObjectProcess.cs        # Data model for process information
├── ParentObjectProcess.cs  # Wrapper for process collections
└── AutoAffinityApply.csproj# Project configuration

🚀 Usage

Interactive Mode

AutoAffinityApply.exe

This launches the interactive menu where you can select operations by number.

Command-line Mode

Apply full CPU affinity to all processes:

AutoAffinityApply.exe -r
AutoAffinityApply.exe --reset

Apply half CPU affinity (useful for gaming or resource limiting):

AutoAffinityApply.exe -H
AutoAffinityApply.exe --half

Export current process affinities:

AutoAffinityApply.exe -e
AutoAffinityApply.exe --export
AutoAffinityApply.exe -e -p="C:\custom_path\my_config.json"

Apply saved affinity configuration:

AutoAffinityApply.exe -l
AutoAffinityApply.exe --load
AutoAffinityApply.exe -l -p="C:\custom_path\my_config.json"

Display help:

AutoAffinityApply.exe -h
AutoAffinityApply.exe --help

📄 JSON File Format

Exported JSON files follow this structure:

{
  "processes": [
    {
      "processName": "C:\\Path\\To\\Process.exe",
      "cpuMask": [0, 1, 2, 3, 4, 5, 6, 7]
    },
    {
      "processName": "C:\\Another\\Process.exe",
      "cpuMask": [0, 1, 2, 3]
    }
  ]
}

The cpuMask array contains the indices of CPU cores assigned to each process (0-based indexing).

⚠️ Important Notes

  • Administrator Privileges: You must run this application with administrator privileges to modify process affinities
  • Self-Protection: The application prevents modifying its own affinity to ensure stability
  • Error Handling: Exceptions during process affinity modification are caught and logged; the application continues processing other processes
  • Thread-Safe: Operations use async/await patterns to process multiple processes in parallel efficiently
  • Default File Names:
    • Export: process_YYYY-MM-DD_HH-MM-SS.json (timestamped)
    • Import: process.json (in current directory)

🔧 Build & Development

Prerequisites

  • Visual Studio 2022 or JetBrains Rider
  • .NET 8.0 SDK

Building

dotnet build

Running

dotnet run

Release Build

dotnet publish -c Release -o ./bin/Release

📝 Examples

Scenario 1: Optimize AMD Ryzen (2 CCD) - Game Performance

For AMD CPUs with dual CCDs, you can bind games to a specific CCD for better latency:

# Export current configuration
AutoAffinityApply.exe -e -p="ryzen_ccd0.json"

# Modify to assign your game to CCD0 cores (e.g., 0-7 on Ryzen 5000)
# Then apply it
AutoAffinityApply.exe -l -p="ryzen_ccd0.json"

Scenario 2: Restrict all processes to half CPU (leaving other half free)

AutoAffinityApply.exe --half

Scenario 3: Reset all processes to full CPU

AutoAffinityApply.exe --reset

🐛 Known Limitations

  • Windows-only (uses Windows Process API)
  • Some system processes may not allow affinity changes
  • Changes are temporary; they reset on process restart
  • Does not persist settings across system reboots (use JSON import to reapply)

📄 License

Copyright (C) 2026 Matis André C.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

Version: 1.0
Framework: .NET 8.0
Platform: Windows
Last Updated: 2026-06-11