### Configure C-State Power Management in C# Source: https://context7.com/irusanov/zenstates/llms.txt This snippet demonstrates how to get and set C6 core and package states, as well as enable or disable Core Performance Boost (CPB) using the ZenStates library. It captures initial settings and reports the success or failure of the operations. ```csharp // Get current C6 state settings (captured at startup) bool c6CoreAtStart = cpu.ZenC6CoreAtStart; bool c6PackageAtStart = cpu.ZenC6PackageAtStart; Console.WriteLine($"C6 Core at startup: {c6CoreAtStart}"); Console.WriteLine($"C6 Package at startup: {c6PackageAtStart}"); // Enable/disable C6 core state (per-core deep sleep) // When enabled, individual cores can enter C6 state bool result = cpu.SetC6Core(true); // Enable C6 for cores Console.WriteLine($"Set C6 Core: {(result ? "Success" : "Failed")}"); // Enable/disable C6 package state (entire CPU deep sleep) // When enabled, entire CPU package can enter C6 when all cores idle result = cpu.SetC6Package(true); // Enable C6 for package Console.WriteLine($"Set C6 Package: {(result ? "Success" : "Failed")}"); // Enable/disable Core Performance Boost (turbo) bool cpbAtStart = cpu.ZenCorePerfBoostAtStart; Console.WriteLine($"CPB at startup: {cpbAtStart}"); result = cpu.SetCpb(true); // Enable Core Performance Boost Console.WriteLine($"Set CPB: {(result ? "Success" : "Failed")}"); ``` -------------------------------- ### P-State Management with C# Source: https://context7.com/irusanov/zenstates/llms.txt Manages CPU P-states (frequency and voltage) by reading current P-state definitions and writing new ones. P-states are encoded as 64-bit values, controlling FID, DID, VID, and enable status. ```csharp // P-state bit layout (64-bit): // [63] PstateEn - Enable bit (1=enabled) // [21:14] CpuVid - Voltage ID (0x00-0xA9, lower = higher voltage) // [13:8] CpuDfsId - Divider ID (frequency divider) // [7:0] CpuFid - Frequency ID (multiplier) // Frequency calculation: freq = (25 * FID) / (DID * 12.5) GHz // Read current P-states (stored at startup) UInt64[] currentPstates = cpu.PstateAtStart; for (int i = 0; i < CPUHandler.NumPstates; i++) { UInt64 pstate = currentPstates[i]; bool enabled = ((pstate >> 63) & 1) == 1; byte vid = (byte)((pstate >> 14) & 0xFF); byte did = (byte)((pstate >> 8) & 0x3F); byte fid = (byte)(pstate & 0xFF); double voltage = 1.55 - vid * 0.00625; double frequency = (25.0 * fid) / (did * 12.5); Console.WriteLine($"P{i}: Enabled={enabled}, Freq={frequency:F2}GHz, Voltage={voltage:F3}V"); } // Write a new P-state (example: P0 at 4.0GHz, 1.25V) // FID=0xA0 (160), DID=0x08 (/4 divider) -> 25*160/(8*12.5) = 40 = 4.0GHz // VID=0x30 -> 1.55 - 0x30*0.00625 = 1.25V UInt64 newPstate = 0x8000000000040CA0; // Enabled, VID=0x30, DID=0x08, FID=0xA0 bool success = cpu.WritePstate(0, newPstate); Console.WriteLine($"P-state write: {(success ? "Success" : "Failed")}"); ``` -------------------------------- ### Configure Overclocking Mode and Frequency in C# Source: https://context7.com/irusanov/zenstates/llms.txt This snippet shows how to enable manual overclocking mode, which bypasses normal boost algorithms. It demonstrates setting a fixed frequency and voltage for all cores using P-state encoding. It also includes how to set boost frequency limits for Zen2+ CPUs in non-OC mode and how to disable OC mode. ```csharp // Enable manual overclock mode (disables normal boost algorithms) // WARNING: This bypasses normal CPU protections except thermal shutdown bool result = cpu.SetOcMode(true); Console.WriteLine($"Enable OC Mode: {(result ? "Success" : "Failed")}"); // Set overclock frequency for all cores (requires OC mode enabled) // Uses P-state encoding: FID/DID for frequency, VID for voltage UInt64 ocPstate = cpu.PstateOc; // Get current OC P-state // Modify to 4.2GHz at 1.3V // FID=0xA8 (168), DID=0x08 -> 25*168/(8*12.5) = 4.2GHz // VID=0x28 -> 1.55 - 0x28*0.00625 = 1.3V UInt64 newOcPstate = 0x80000000000A08A8; result = cpu.setOverclockFrequencyAllCores(newOcPstate); Console.WriteLine($"Set OC Frequency: {(result ? "Success" : "Failed")}"); // For Zen2+ CPUs: Set boost frequency limits (non-OC mode) // These work with normal boost behavior enabled result = cpu.setBoostFrequencySingleCore(newOcPstate); // Max single-core boost Console.WriteLine($"Set Single Core Boost: {(result ? "Success" : "Failed")}"); result = cpu.setBoostFrequencyAllCores(newOcPstate); // Max all-core boost Console.WriteLine($"Set All Core Boost: {(result ? "Success" : "Failed")}"); // Disable manual overclock mode (returns to normal boost behavior) result = cpu.SetOcMode(false); Console.WriteLine($"Disable OC Mode: {(result ? "Success" : "Failed")}"); ``` -------------------------------- ### SMU Commands Reference for Zen Processors Source: https://context7.com/irusanov/zenstates/llms.txt This section outlines the System Management Unit (SMU) commands used for communication with the CPU. It includes memory addresses for message, response, and argument registers, which vary by CPU generation (Zen1/Zen+ vs. Zen2). Common commands for testing, version retrieval, and configuration are listed. ```csharp // SMU command reference (varies by CPU generation) // These are internal constants - shown for reference // Zen1/Zen+ SMU addresses: // SMU_ADDR_MSG = 0x03B10528 - Message register // SMU_ADDR_RSP = 0x03B10564 - Response register // SMU_ADDR_ARG0 = 0x03B10598 - Argument register // Zen2 SMU addresses (different offsets): // SMU_ADDR_MSG = 0x03B10524 // SMU_ADDR_RSP = 0x03B10570 // SMU_ADDR_ARG0 = 0x03B10A40 // Common SMU commands: // 0x01 - TestMessage (verify SMU communication) // 0x02 - GetSmuVersion // 0x23 - SetTjMax (Zen2) / EnableOverclocking (Zen1) // 0x24 - EnableOverclocking (Zen2) // 0x25 - DisableOverclocking (Zen2) // 0x26 - SetOverclockFreqAllCores // 0x27 - SetOverclockFreqPerCore // 0x28 - SetOverclockVid // 0x29 - SetBoostLimitFrequency // 0x2B - SetBoostLimitFrequencyAllCores // 0x2F - SetFITLimitScalar // 0x53 - SetPPTLimit (Zen2) // 0x54 - SetTDCLimit (Zen2) // 0x55 - SetEDCLimit (Zen2) ``` -------------------------------- ### Configure Power Limits (PPT, TDC, EDC) in C# Source: https://context7.com/irusanov/zenstates/llms.txt This code configures the Package Power Tracking (PPT), Thermal Design Current (TDC), and Electrical Design Current (EDC) limits for the CPU. It also sets the FIT (Fused In Temperature) Limit Scalar and reads the current power limit values. These settings control the maximum power and current the CPU can draw. ```csharp // Set Package Power Tracking limit (socket power in watts) // PPT controls the maximum power the CPU can consume bool result = cpu.SetPPT(142); // Set PPT to 142W (default for many Ryzen CPUs) Console.WriteLine($"Set PPT: {(result ? "Success" : "Failed")}"); // Set Thermal Design Current limit (sustained current in amps) // TDC is the sustained current limit under thermally-limited scenarios result = cpu.SetTDC(95); // Set TDC to 95A Console.WriteLine($"Set TDC: {(result ? "Success" : "Failed")}"); // Set Electrical Design Current limit (peak current in amps) // EDC is the maximum current the CPU can draw in short bursts result = cpu.SetEDC(140); // Set EDC to 140A Console.WriteLine($"Set EDC: {(result ? "Success" : "Failed")}"); // Set FIT (Fused In Temperature) Limit Scalar (1-10) // Higher values allow more aggressive boosting at the cost of longevity result = cpu.SetScalar(1); // Set scalar to 1 (default/safe) Console.WriteLine($"Set Scalar: {(result ? "Success" : "Failed")}"); // Read current power limit values Console.WriteLine($"Current PPT: {cpu.ZenPPT}W"); Console.WriteLine($"Current TDC: {cpu.ZenTDC}A"); Console.WriteLine($"Current EDC: {cpu.ZenEDC}A"); Console.WriteLine($"Current Scalar: {cpu.ZenScalar}"); ``` -------------------------------- ### C# Settings Persistence with XML Source: https://context7.com/irusanov/zenstates/llms.txt The Settings class manages the saving and loading of application configuration to an XML file. This file is located in `%ProgramData%\ZenStates\ZenStatesSettings.xml`. Settings are automatically loaded by CPUHandler and can be modified and saved programmatically. ```csharp using ZenStatesSrv; // Settings are loaded automatically by CPUHandler CPUHandler cpu = new CPUHandler(); Settings settings = cpu.SettingsStore; // Check if settings were reset (new installation or version change) if (settings.SettingsReset) { Console.WriteLine("Settings were reset to defaults"); } // Modify settings settings.TrayIconAtStart = true; // Show tray icon on startup settings.ApplyAtStart = true; // Apply saved settings on startup settings.P80Temp = false; // Don't output temp to POST port settings.ZenC6Core = true; // Enable C6 core state settings.ZenC6Package = true; // Enable C6 package state settings.ZenCorePerfBoost = true; // Enable CPB settings.ZenPPT = 142; // Power limit settings.ZenTDC = 95; // Current limit (sustained) settings.ZenEDC = 140; // Current limit (peak) settings.ZenScalar = 1; // FIT scalar // Save settings to file settings.Save(); // Save all current CPU settings (called from CPUHandler) cpu.SaveSettings(); // Restore settings to startup values cpu.Restore(); ``` -------------------------------- ### CPU Detection and Initialization with C# Source: https://context7.com/irusanov/zenstates/llms.txt Initializes the CPUHandler to detect CPU type, retrieve identification strings, CPUID, thread count, and SMU firmware version. This is typically handled automatically by the ZenStates service. ```csharp using ZenStatesSrv; // Initialize CPU handler (done automatically by service) CPUHandler cpu = new CPUHandler(); // Check CPU type - returns enum value // Supported types: Unsupported, DEBUG, SummitRidge, Threadripper, // RavenRidge, PinnacleRidge, Picasso, Matisse, Rome, Renoir CPUHandler.CPUType detectedCpu = cpu.cpuType; Console.WriteLine($"Detected CPU Type: {detectedCpu}"); // Get CPU identification string string cpuModel = cpu.GetCpuString(); Console.WriteLine($"CPU Model: {cpuModel}"); // Get raw CPUID value (Family/Model/Stepping) uint cpuInfo = cpu.GetCpuInfo(); Console.WriteLine($"CPUID: 0x{cpuInfo:X8}"); // Get number of logical threads int threadCount = cpu.Threads; Console.WriteLine($"Thread Count: {threadCount}"); // Get SMU firmware version uint smuVersion = cpu.GetSmuVersion(); Console.WriteLine($"SMU Version: {smuVersion >> 16}.{(smuVersion >> 8) & 0xFF}.{smuVersion & 0xFF}"); ``` -------------------------------- ### C# DataInterface for Service Communication Source: https://context7.com/irusanov/zenstates/llms.txt The DataInterface class facilitates shared memory communication between the GUI and background service using memory-mapped files. It allows reading system status and writing configuration values. Client mode connects to an existing shared memory, while server mode creates it. ```csharp using ZenStates; // Create data interface (false = client mode, true = server mode) // Client mode connects to existing shared memory created by service DataInterface di = new DataInterface(false); // Read values from shared memory registers UInt64 serverFlags = di.MemRead(DataInterface.REG_SERVER_FLAGS); UInt64 smuVersion = di.MemRead(DataInterface.REG_SMU_VERSION); UInt64 cpuType = di.MemRead(DataInterface.REG_CPU_TYPE); UInt64 temperature = di.MemRead(DataInterface.REG_TEMP); // Check server availability flag bool isAvailable = (serverFlags & DataInterface.FLAG_IS_AVAILABLE) != 0; bool supportedCpu = (serverFlags & DataInterface.FLAG_SUPPORTED_CPU) != 0; Console.WriteLine($"Service Available: {isAvailable}, Supported CPU: {supportedCpu}"); // Write values to shared memory di.MemWrite(DataInterface.REG_PPT, 142); di.MemWrite(DataInterface.REG_TDC, 95); di.MemWrite(DataInterface.REG_EDC, 140); // Write client flags (settings to apply) UInt64 clientFlags = 0; clientFlags |= DataInterface.FLAG_APPLY_AT_START; // Apply settings on boot clientFlags |= DataInterface.FLAG_C6CORE; // Enable C6 core state clientFlags |= DataInterface.FLAG_CPB; // Enable Core Performance Boost di.MemWrite(DataInterface.REG_CLIENT_FLAGS, clientFlags); // Send notification to service to apply settings di.MemWrite(DataInterface.REG_NOTIFY_STATUS, DataInterface.NOTIFY_APPLY); // Memory register constants for reference: // REG_P0, REG_P1, REG_P2 - P-state definitions // REG_PERF_BIAS - Performance bias setting // REG_TEMP - Current temperature // REG_PPT, REG_TDC, REG_EDC - Power limits // REG_SCALAR - FIT limit scalar // REG_SMU_VERSION - SMU firmware version // REG_CPU_TYPE - Detected CPU type enum // REG_BOOST_FREQ_0/1 - Boost frequency limits (Zen2+) ``` -------------------------------- ### Monitor CPU Temperature in C# Source: https://context7.com/irusanov/zenstates/llms.txt This code snippet demonstrates how to read the current CPU temperature directly from the thermal sensor via SMU registers using ZenStates. It also shows how to retrieve the Tctl offset and optionally write the temperature to the POST diagnostic port (port 0x80). ```csharp // Get current CPU temperature double temperature = 0; bool result = cpu.GetTemp(ref temperature); if (result) { Console.WriteLine($"CPU Temperature: {temperature:F1}C"); } else { Console.WriteLine("Failed to read temperature"); } // Get Tctl offset (used to normalize temperature across CPU models) // Some CPUs report Tctl = Tdie + offset for compatibility Console.WriteLine($"Tctl Offset: {cpu.TctlOffset}C"); // Write temperature to POST diagnostic port (port 0x80) // Useful for hardware-level temperature display if (cpu.P80Temp) { cpu.WritePort80Temp(temperature); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.