Skip to content

Commit 6d38492

Browse files
committed
Bug fixes
1 parent c206421 commit 6d38492

File tree

7 files changed

+48
-48
lines changed

7 files changed

+48
-48
lines changed

Universal x86 Tuning Utility V2/Universal x86 Tuning Utility V2.vdproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@
213213
{
214214
"Name" = "8:Microsoft Visual Studio"
215215
"ProductName" = "8:Universal x86 Tuning Utility"
216-
"ProductCode" = "8:{40162B89-0DFB-4610-AC13-3DE70401ECFF}"
217-
"PackageCode" = "8:{5EB1B03F-AB72-4D15-B39E-9B4E98803E44}"
216+
"ProductCode" = "8:{DEFBF397-8C9E-4623-83FC-0C19218A5BE0}"
217+
"PackageCode" = "8:{5C3789E5-0188-4F5D-A599-A411A1B05472}"
218218
"UpgradeCode" = "8:{300E743A-4C69-440D-9425-14C446AB2658}"
219219
"AspNetVersion" = "8:"
220220
"RestartWWWService" = "11:FALSE"
221221
"RemovePreviousVersions" = "11:TRUE"
222222
"DetectNewerInstalledVersion" = "11:FALSE"
223223
"InstallAllUsers" = "11:FALSE"
224-
"ProductVersion" = "8:2.5.2"
224+
"ProductVersion" = "8:2.5.3"
225225
"Manufacturer" = "8:JamesCJ60"
226226
"ARPHELPTELEPHONE" = "8:"
227227
"ARPHELPLINK" = "8:"
@@ -763,7 +763,7 @@
763763
{
764764
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_0FAC7670CF204A74B0B84BA8720E5EFC"
765765
{
766-
"SourcePath" = "8:..\\Universal x86 Tuning Utility\\obj\\x64\\Release\\net8.0-windows10.0.22621.0\\apphost.exe"
766+
"SourcePath" = "8:..\\Universal x86 Tuning Utility\\obj\\Debug\\net8.0-windows10.0.22621.0\\apphost.exe"
767767
"TargetName" = "8:"
768768
"Tag" = "8:"
769769
"Folder" = "8:_B208FDAB7341429AB15D831E1F00D044"

Universal x86 Tuning Utility/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static T GetService<T>()
6060
return _host.Services.GetService(typeof(T)) as T;
6161
}
6262

63-
public static string version = "2.5.2";
63+
public static string version = "2.5.3";
6464
private Mutex mutex;
6565
private const string MutexName = "UniversalX86TuningUtility";
6666

Universal x86 Tuning Utility/Scripts/RyzenAdj_To_UXTU.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using GameLib.Plugin.RiotGames.Model;
1+
using CpuAffinityUtility;
2+
using GameLib.Plugin.RiotGames.Model;
23
using NvAPIWrapper.Display;
34
using RyzenSmu;
45
using System;
Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
4-
using System.Linq;
53
using System.Management;
64
using System.Runtime.CompilerServices;
7-
using System.Text;
8-
using System.Threading.Tasks;
5+
using System.Runtime.InteropServices;
96

10-
namespace Universal_x86_Tuning_Utility.Services
7+
namespace CpuAffinityUtility
118
{
9+
/// <summary>
10+
/// CCD Affinity Manager
11+
/// Mode 0 = all CCDs, 1 = primary CCD, 2 = secondary CCD.
12+
/// Will be updated for big.LITTLE APUs/CPUs in the future.
13+
/// </summary>
1214
public static class CpuAffinityManager
1315
{
1416
private static readonly object _syncRoot = new();
@@ -19,35 +21,27 @@ public static class CpuAffinityManager
1921

2022
public static void SetGlobalAffinity(int mode)
2123
{
22-
try
24+
if (mode == _currentMode) return;
25+
26+
var newMask = BuildMask(mode);
27+
28+
lock (_syncRoot)
2329
{
24-
if (mode == _currentMode) // nothing to do
25-
return;
30+
if (mode == _currentMode) return;
31+
32+
_currentMode = mode;
33+
_mask = newMask;
2634

27-
var newMask = BuildMask(mode);
35+
foreach (var p in Process.GetProcesses())
36+
TrySetAffinity(p, _mask);
2837

29-
lock (_syncRoot)
38+
if (_watcher == null)
3039
{
31-
if (mode == _currentMode) // double-check inside lock
32-
return;
33-
34-
_currentMode = mode;
35-
_mask = newMask;
36-
37-
foreach (var p in Process.GetProcesses())
38-
TrySetAffinity(p, _mask);
39-
40-
if (_watcher == null)
41-
{
42-
_watcher = new ManagementEventWatcher(
43-
new WqlEventQuery("SELECT ProcessID FROM Win32_ProcessStartTrace"));
44-
_watcher.EventArrived += OnProcessStarted;
45-
_watcher.Start();
46-
}
40+
_watcher = new ManagementEventWatcher(
41+
new WqlEventQuery("SELECT ProcessID FROM Win32_ProcessStartTrace"));
42+
_watcher.EventArrived += OnProcessStarted;
43+
_watcher.Start();
4744
}
48-
} catch
49-
{
50-
/* permission or race; ignore */
5145
}
5246
}
5347

@@ -69,23 +63,24 @@ private static void OnProcessStarted(object? _, EventArrivedEventArgs e)
6963
try
7064
{
7165
using var np = Process.GetProcessById(pid);
72-
TrySetAffinity(np, _mask); // always latest mask
66+
TrySetAffinity(np, _mask);
7367
}
74-
catch { /* access denied or process gone */ }
68+
catch { /* permission or race; ignore */ }
7569
}
7670
}
7771

7872
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7973
private static void TrySetAffinity(Process proc, ulong mask)
8074
{
8175
try { proc.ProcessorAffinity = (IntPtr)mask; }
82-
catch { /* permission or race; ignore */ }
76+
catch { /* safe to ignore */ }
8377
}
8478

8579
private static ulong BuildMask(int mode)
8680
{
87-
int logical = Environment.ProcessorCount;
88-
if (logical < 2) throw new NotSupportedException("Needs multiple logical processors.");
81+
int logical = (int)GetActiveProcessorCount(ALL_GROUPS);
82+
83+
if (logical < 2) throw new NotSupportedException("Needs more than one logical processor.");
8984
if (logical > 64) throw new NotSupportedException("Only one processor group supported.");
9085

9186
int half = logical / 2;
@@ -94,9 +89,12 @@ private static ulong BuildMask(int mode)
9489
{
9590
0 => (1UL << logical) - 1, // all cores
9691
1 => (1UL << half) - 1, // lower half
97-
2 => (1UL << logical) - 1 ^ (1UL << half) - 1, // upper half
92+
2 => ((1UL << logical) - 1) ^ ((1UL << half) - 1), // upper half
9893
_ => throw new ArgumentOutOfRangeException(nameof(mode), "Mode must be 0, 1, or 2.")
9994
};
10095
}
96+
97+
private const uint ALL_GROUPS = 0xFFFF;
98+
[DllImport("kernel32.dll")] public static extern uint GetActiveProcessorCount(uint groupNumber);
10199
}
102-
}
100+
}

Universal x86 Tuning Utility/Universal x86 Tuning Utility.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<UseWindowsForms>True</UseWindowsForms>
1616
<SignAssembly>False</SignAssembly>
1717
<Copyright>© UXTU Team 2020 - 2025</Copyright>
18-
<AssemblyVersion>2.5.2</AssemblyVersion>
19-
<FileVersion>2.5.2</FileVersion>
18+
<AssemblyVersion>2.5.3</AssemblyVersion>
19+
<FileVersion>2.5.3</FileVersion>
2020
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2121
<SupportedOSPlatformVersion>10.0.22621.0</SupportedOSPlatformVersion>
22-
<Version>2.5.2</Version>
22+
<Version>2.5.3</Version>
2323
</PropertyGroup>
2424

2525
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

Universal x86 Tuning Utility/Views/Pages/CustomPresets.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using RyzenSmu;
1+
using CpuAffinityUtility;
2+
using RyzenSmu;
23
using System;
34
using System.Collections.Generic;
45
using System.Data;
@@ -144,7 +145,7 @@ public CustomPresets()
144145

145146
if (Family.FAM == Family.RyzenFamily.DragonRange || Family.FAM == Family.RyzenFamily.FireRange || Family.FAM == Family.RyzenFamily.StrixHalo)
146147
{
147-
if(Environment.ProcessorCount > 16) sdCcdAffinity.Visibility = Visibility.Visible;
148+
if((int)CpuAffinityManager.GetActiveProcessorCount(0xFFFF) > 16) sdCcdAffinity.Visibility = Visibility.Visible;
148149
}
149150
}
150151

Universal x86 Tuning Utility/Views/Pages/DashboardPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<TextBlock
6161
FontSize="18"
6262
Foreground="#B7FFFFFF"
63-
Text="V2.5.2 Stable" />
63+
Text="V2.5.3 Stable" />
6464
<ui:Button
6565
Name="btnPremade"
6666
Height="36"

0 commit comments

Comments
 (0)