Skip to content

ThrottleLimit calculation is incorrect on systems with more than one physical processor, breaking the build. (Added bonus: inf2cat travels through time to break the build) #1313

@gsuberland

Description

@gsuberland

The ThrottleLimit argument is currently implemented as follows:

$ThrottleFactor = 5
$LogicalProcessors = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
if ($ThrottleLimit -eq 0) {
$ThrottleLimit = $ThrottleFactor * $LogicalProcessors
}

However, this CIM query actually returns an array of values representing the logical processor cound per physical socket, rather than just a single integer:

PS C:\Users\Graham> $procs = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
PS C:\Users\Graham> $procs.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

PS C:\Users\Graham> $procs
56
56

As such, attempting to run the build without specifying the -ThrottleLimit argument results in an error when the script attempts to multiply the array by 5:

InvalidOperation: C:\Users\Graham\source\repos\Windows-driver-samples\Build-SampleSet.ps1:24
Line |
  24 |      $ThrottleLimit = $ThrottleFactor * $LogicalProcessors
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [System.Object[]] does not contain a method named 'op_Multiply'.

The code should probably be something like this instead:

$LogicalProcessorsList = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
$LogicalProcessors = ($LogicalProcessorsList | Measure-Object -Sum).Sum

Except... this doesn't really work. For some inexplicable reason, making this change causes the powershell script itself to work just fine without needing to specify -ThrottleLimit, but suddenly every single target fails to build due to inf2cat.exe exiting with a bad return code. Example error message:

Windows-driver-samples\packages\Microsoft.Windows.WDK.x64.10.0.26100.4204\c\build\10.0.26100.0\WindowsDriver.common.targets(1432,5): error MSB6006: "inf2cat.exe" exited with code -2. [C:\Users\Graham\source\repos\Windows-driver-samples\tools\dv\samples\DV-FailDriver-WDM\driver\defect_toastmon.vcxproj]

Initially I thought that it was something downstream not liking that I got rid of it being an array, so I swapped the code to this:

$LogicalProcessorsList = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
$LogicalProcessors = @(($LogicalProcessorsList | Measure-Object -Sum).Sum)

This did not fix it, but instead I noticed that a completely random subset of projects would fail to build each time, seemingly nondeterministically.

I looked into the log files and found the following:

  Building 'defect_toastmon' with toolset 'WindowsKernelModeDriver10.0' and the 'Universal' target platform.
  Stamping x64\Debug\defect_toastmon.inf
  Stamping [Version] section with DriverVer=07/24/2025,0.32.47.39
  defect_toastmon.c
  wmi.c
  Generating Code...
  defect_toastmon.vcxproj -> C:\Users\Graham\source\repos\Windows-driver-samples\tools\dv\samples\DV-FailDriver-WDM\driver\x64\Debug\defect_toastmon.sys
  Done Adding Additional Store
  Successfully signed: C:\Users\Graham\source\repos\Windows-driver-samples\tools\dv\samples\DV-FailDriver-WDM\driver\x64\Debug\defect_toastmon.sys
  
  Driver is 'Universal'.
  ........................
  Signability test failed.
  
  Errors:
  22.9.7: DriverVer set to a date in the future (postdated DriverVer not allowed) in defect_toastmon\defect_toastmon.inf.
  
  Warnings:
  None
C:\Users\Graham\source\repos\Windows-driver-samples\packages\Microsoft.Windows.WDK.x64.10.0.26100.4204\c\build\10.0.26100.0\WindowsDriver.common.targets(1432,5): error MSB6006: "inf2cat.exe" exited with code -2. [C:\Users\Graham\source\repos\Windows-driver-samples\tools\dv\samples\DV-FailDriver-WDM\driver\defect_toastmon.vcxproj]

Somehow these fixes are making inf2cat think the DriverVer is... in the future? What? I'm now deeply confused. I feel like maybe parallelism is somehow breaking the order of operations here and resulting in a weird race condition with inf2cat, but I'm very much questioning my sanity here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions