How can I identify performance cores in PowerShell and build a processor-affinity mask?

0
2
Asked By MellowCedar42 On

I want to assign a process to selected performance cores on a hybrid CPU using PowerShell. I can set affinity manually—for example, cores 10 through 19 use the mask 0x00000000000FFC00—but I need a way to determine which logical processors are performance cores and which are efficiency cores, then combine the performance-core indexes into the correct hexadecimal affinity mask. Is there a PowerShell or Windows API approach for doing this automatically?

2 Answers

Answered By BrightOtter7 On

Windows exposes this through the GetSystemCpuSetInformation function in kernel32.dll. Its EfficiencyClass field identifies the core type: 0 generally represents efficiency cores and 1 represents performance cores. You can query that information from PowerShell, collect the processor indexes whose efficiency class is 1, and then construct an affinity mask from those indexes.

MellowCedar42 -

If the processor indexes are already known, each one can be converted into a bit with 1 -shl $index. Combine the selected bits using the bitwise OR operator (-bor) to produce the final affinity mask.

Answered By CopperLynx18 On

For a known range such as cores 10 through 19, you can generate the individual flags with 1 -shl for each processor number and merge them with bitwise OR. That produces the mask 0xFFC00, which is equivalent to 0x00000000000FFC00 when written with leading zeroes. This approach works in both Windows PowerShell 5 and PowerShell 7; the remaining step is obtaining the performance-core indexes from the Windows CPU-set data.

MellowCedar42 -

That matches the mask I needed. The merged value validates as 0xFFC00.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.