【问题标题】:Set affinity with start /AFFINITY command on Windows 7在 Windows 7 上使用 start /AFFINITY 命令设置关联
【发布时间】:2011-12-07 06:42:23
【问题描述】:

我正在使用start /AFFINITY [n] [.exe] 命令启动具有指定关联性的可执行文件。我有一个有 8 个处理器(1、2、3、4、5、6、7、8)的系统。我想将进程设置为使用所有奇数处理器(1、3、5、7)。我无法弄清楚如何做到这一点,并想知道是否可以使用 start 命令。如果没有,是否有替代的 命令行 方法?

启动命令的帮助并不是特别有用:

 AFFINITY    Specifies the processor affinity mask as a hexadecimal number.
             The process is restricted to running on these processors.

             The affinity mask is interpreted differently when /AFFINITY and
             /NODE are combined.  Specify the affinity mask as if the NUMA
             node's processor mask is right shifted to begin at bit zero.
             The process is restricted to running on those processors in
             common between the specified affinity mask and the NUMA node.
             If no processors are in common, the process is restricted to
             running on the specified NUMA node.

【问题讨论】:

    标签: windows-7 command-line affinity


    【解决方案1】:

    AFFINITY 与hexidecimal mask 一起使用,它应该允许对您的所有处理器进行精细控制。请注意,最右边的位指定最低阶 CPU (0)(请参阅KB 299641)。

    对于有问题的情况,0xAA (10101010) 请求您的进程使用处理器 1、3、5 和 7 运行,但不是 0、2、4 或 6。请务必省略命令中的“0x”行。

     start /affinity AA app.exe
    

    其他例子:

     start /affinity 1 app.exe     (only use CPU 0)
     start /affinity 2 app.exe     (only use CPU 1)
     start /affinity 1F app.exe    (only use CPUs 0, 1, 2, 3, and 4)
    

    【讨论】:

    • 看来,我的电脑和你的配置是一样的。请问语法,你是怎么添加的?我正在关注这个:support.microsoft.com/kb/299641,但是,仍然很困惑。谢谢。
    【解决方案2】:

    要获得正确的十六进制数,请想象您的内核在平面格式 8765 4321(用于 8 核 CPU)中反向(但不像 1234 5678)

    要激活核心 7、6 和 3,请输入数字 0x64 以获得关联:

    /AFFINITY 0x64
    

    为了更好看,匹配和比较:0110 0100 - number = 0x64 (8765 4321) - cores

    对于@ladenedge 示例:/AFFINITY AA 1010 1010 - number = 0xAA (8765 4321) - cores

    另请参阅:Start an Application Assigned to a Specific CPU in Windows 7, 8, or Vista

    【讨论】:

    • 只是补充一下,一个简单的方法来做到这一点......一旦你反向考虑你的处理器 ID,只需进入 calc 并切换到程序员模式。将左侧的“Bin”设置为二进制,然后输入您的代码以打开和关闭每个,然后点击“Hex”。这会给你启动代码。
    【解决方案3】:

    更多信息以满足您自己的计算需求:

    CPU ID  CPU value (dec)
    0       001 (= 2^0)
    1       002 (= 2^1)
    2       004 (= 2^2)
    3       008 (= 2^3)
    4       016 (= 2^4)
    5       032 (= 2^5)
    6       064 (= 2^6)
    7       128 (= 2^7)
    

    因此:

    • CPU ID 0、1、2、3、4、5、6、7 的掩码:255(各个 CPU 十进制值的总和),即十六进制的“FF”掩码
    • CPU ID 0、2、4、6 的掩码:85(各个 CPU 十进制值的总和),即十六进制的“55”掩码

    参考:在https://msdn.microsoft.com/en-US/library/ms187104.aspx 搜索“这些是 8-CPU 系统的关联掩码值”模式。

    【讨论】:

      猜你喜欢
      • 2018-04-22
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 2020-01-16
      • 1970-01-01
      相关资源
      最近更新 更多