繁体   English   中英

为高核心数调整进程的亲和力

[英]Adjusting the affinity of an process for high core counts

我想调整我的程序的亲和性,但是核心数很高

有没有办法可以通过 PowerShell 代码在应用程序上设置所有内核?

核心数是64个,有时候我们用112个核心。

这是我的代码

PowerShell "$Process = Get-Process -Id 6048; $Process.ProcessorAffinity=All"

我搜索了整个谷歌,但找不到任何使用所有内核的代码。

注意:我无法亲自验证以下是否有效。

.ProcessorAffinity是作为System.IntPtr值实现的位掩码

但是,位掩码必须仅包含实际可用内核的位,因此不能使用[IntPtr]::MaxValue

假设有112可用内核,您需要提供一个位掩码,将可用内核范围内的所有可能位设置为1 ,您可以按如下方式计算:

$allCores = 
 [Math]::Pow(
   2,
   [Math]::Ceiling([Math]::Log2(112))
 ) - 1

(Get-Process -Id 6048).ProcessorAffinity = $allCores

翻译成powershell.exe从PowerShell外部调用:

powershell.exe "(Get-Process -Id 6048).ProcessorAffinity = [Math]::Pow(2, [Math]::Ceiling([Math]::Log2(112))) - 1"

注意:如果您想以编程方式确定可用(逻辑)内核的数量,请使用:

$totalLogicalCores = (
  (Get-CimInstance –ClassName Win32_Processor).NumberOfLogicalProcessors |
    Measure-Object -Sum
).Sum

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM